Mercurial > moin > 1.9
changeset 3729:fef3c5039997
wikidicts: simplify regex compiling
author | Thomas Waldmann <tw AT waldmann-edv DOT de> |
---|---|
date | Fri, 20 Jun 2008 23:54:46 +0200 |
parents | fd63e84632df |
children | 4204677846cb |
files | MoinMoin/wikidicts.py |
diffstat | 1 files changed, 6 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/MoinMoin/wikidicts.py Fri Jun 20 22:00:21 2008 +0200 +++ b/MoinMoin/wikidicts.py Fri Jun 20 23:54:46 2008 +0200 @@ -26,18 +26,12 @@ if request is not None and pagename is not None: self.loadFromPage(request, pagename) - # Regular expression used to parse text - subclass should override this - regex = u'' - def initRegex(cls): - """ Make it a class attribute to avoid it being pickled. """ - if isinstance(cls.regex, unicode): # not compiled yet - cls.regex = re.compile(cls.regex, re.MULTILINE | re.UNICODE) - initRegex = classmethod(initRegex) + # Regular expression used to parse text - subclass must override this + regex = None # re.compile(u'...', re.MULTILINE | re.UNICODE) def loadFromPage(self, request, name): """ load the dict from wiki page <name>'s content """ self.name = name - self.initRegex() text = Page.Page(request, name).get_raw_body() self.initFromText(text) @@ -59,8 +53,8 @@ keyn:: .... any text ignored """ - # Key:: Value - ignore all but key:: value pairs, strip whitespace - regex = ur'^ (?P<key>.+?):: (?P<val>.*?) *$' # exactly one space after the :: is required + # Key:: Value - ignore all but key:: value pairs, strip whitespace, exactly one space after the :: is required + regex = re.compile(ur'^ (?P<key>.+?):: (?P<val>.*?) *$', re.MULTILINE | re.UNICODE) def initFromText(self, text): for match in self.regex.finditer(text): @@ -87,9 +81,8 @@ If there are any free links using [[free link]] notation, the markup is stripped from the member. """ - # * Member - ignore all but first level list items, strip whitespace, - # strip free links markup if exists. - regex = ur'^ \* +(?:\[\[)?(?P<member>.+?)(?:\]\])? *$' + # * Member - ignore all but first level list items, strip whitespace, strip free links markup + regex = re.compile(ur'^ \* +(?:\[\[)?(?P<member>.+?)(?:\]\])? *$', re.MULTILINE | re.UNICODE) def __init__(self, request=None, pagename=None): self._list = []