[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndex - GlobbingLexicon.py:1.11.4.1

Andreas Jung andreas@digicool.com
Thu, 28 Feb 2002 08:46:31 -0500


Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndex
In directory cvs.zope.org:/tmp/cvs-serv1486/lib/python/Products/PluginIndexes/TextIndex

Modified Files:
      Tag: Zope-2_5-branch
	GlobbingLexicon.py 
Log Message:
      - Collector #250: applied several patches for TextIndex for better
        unicode support for the GlobbingLexicon


=== Zope/lib/python/Products/PluginIndexes/TextIndex/GlobbingLexicon.py 1.11 => 1.11.4.1 ===
 from Products.PluginIndexes.TextIndex.TextIndex import Op
 
+from types import UnicodeType 
 
 class GlobbingLexicon(Lexicon):
     """Lexicon which supports basic globbing function ('*' and '?').
@@ -250,10 +251,16 @@
         """
 
         # Remove characters that are meaningful in a regex
-        transTable = string.maketrans("", "")
-        result = string.translate(pat, transTable,
-                                  r'()&|!@#$%^{}\<>.')
-        
+        if not isinstance(pat, UnicodeType):
+            transTable = string.maketrans("", "")
+            result = string.translate(pat, transTable,
+                                      r'()&|!@#$%^{}\<>.')
+        else:
+            transTable={}
+            for ch in r'()&|!@#$%^{}\<>.':
+                transTable[ord(ch)]=None
+            result=pat.translate(transTable)
+
         # First, deal with multi-character globbing
         result = result.replace( '*', '.*')