changeset 3725:874c4070bd7d

wikidicts: only compile regex if it is not compiled yet (seems to be ignored for python < 2.6, but crashes with 2.6b1)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 20 Jun 2008 13:06:38 +0200
parents 78f1b1c0affb
children cf391507fe8e
files MoinMoin/wikidicts.py
diffstat 1 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/wikidicts.py	Sat Jun 14 18:43:24 2008 +0200
+++ b/MoinMoin/wikidicts.py	Fri Jun 20 13:06:38 2008 +0200
@@ -27,10 +27,11 @@
             self.loadFromPage(request, pagename)
 
     # Regular expression used to parse text - subclass should override this
-    regex = ''
+    regex = u''
     def initRegex(cls):
         """ Make it a class attribute to avoid it being pickled. """
-        cls.regex = re.compile(cls.regex, re.MULTILINE | re.UNICODE)
+        if isinstance(cls.regex, unicode):  # not compiled yet
+            cls.regex = re.compile(cls.regex, re.MULTILINE | re.UNICODE)
     initRegex = classmethod(initRegex)
 
     def loadFromPage(self, request, name):
@@ -59,7 +60,7 @@
        any text ignored
     """
     # Key:: Value - ignore all but key:: value pairs, strip whitespace
-    regex = r'^ (?P<key>.+?):: (?P<val>.*?) *$' # exactly one space after the :: is required
+    regex = ur'^ (?P<key>.+?):: (?P<val>.*?) *$' # exactly one space after the :: is required
 
     def initFromText(self, text):
         for match in self.regex.finditer(text):
@@ -88,7 +89,7 @@
     """
     # * Member - ignore all but first level list items, strip whitespace,
     # strip free links markup if exists.
-    regex = r'^ \* +(?:\[\[)?(?P<member>.+?)(?:\]\])? *$'
+    regex = ur'^ \* +(?:\[\[)?(?P<member>.+?)(?:\]\])? *$'
 
     def __init__(self, request=None, pagename=None):
         self._list = []