changeset 2890:3db0e82be499

Creole parser: further decouplig: split the Rules class
author Radomir Dopieralski <moindev@sheep.art.pl>
date Mon, 15 Oct 2007 20:55:33 +0200
parents 87881ad9ab3b
children 7e4627efd98e e24aaec5a557
files MoinMoin/parser/_creole.py MoinMoin/parser/text_creole.py
diffstat 2 files changed, 21 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/parser/_creole.py	Mon Oct 15 20:43:17 2007 +0200
+++ b/MoinMoin/parser/_creole.py	Mon Oct 15 20:55:33 2007 +0200
@@ -116,18 +116,6 @@
                 (?P<cell> (  %s | [^|])+ )
             ) \s*
         ''' % '|'.join([link, macro, image, code])
-    # For the link targets:
-    extern = r'(?P<extern_addr>(?P<extern_proto>%s):.*)' % proto
-    attach = r'''
-            (?P<attach_scheme> attachment | drawing | image ):
-            (?P<attach_addr> .* )
-        '''
-    interwiki = r'''
-            (?P<inter_wiki> [A-Z][a-zA-Z]+ ) :
-            (?P<inter_page> .* )
-        '''
-    page = r'(?P<page_name> .* )'
-
 
 class Parser:
     """
--- a/MoinMoin/parser/text_creole.py	Mon Oct 15 20:43:17 2007 +0200
+++ b/MoinMoin/parser/text_creole.py	Mon Oct 15 20:55:33 2007 +0200
@@ -25,7 +25,7 @@
 import StringIO
 from MoinMoin import config, macro, wikiutil
 from MoinMoin.support.python_compatibility import rsplit # Needed for python 2.3
-import _creole
+from _creole import Parser as CreoleParser
 
 Dependencies = []
 
@@ -49,10 +49,25 @@
     def format(self, formatter):
         """Create and call the true parser and emitter."""
 
-        document = _creole.Parser(self.raw, self.request).parse()
+        document = CreoleParser(self.raw, self.request).parse()
         result = Emitter(document, formatter, self.request).emit()
         self.request.write(result)
 
+class Rules:
+    # For the link targets:
+    proto = r'http|https|ftp|nntp|news|mailto|telnet|file|irc'
+    extern = r'(?P<extern_addr>(?P<extern_proto>%s):.*)' % proto
+    attach = r'''
+            (?P<attach_scheme> attachment | drawing | image ):
+            (?P<attach_addr> .* )
+        '''
+    interwiki = r'''
+            (?P<inter_wiki> [A-Z][a-zA-Z]+ ) :
+            (?P<inter_page> .* )
+        '''
+    page = r'(?P<page_name> .* )'
+
+
 class Emitter:
     """
     Generate the output for the document
@@ -60,10 +75,10 @@
     """
 
     addr_re = re.compile('|'.join([
-            _creole.Rules.extern,
-            _creole.Rules.attach,
-            _creole.Rules.interwiki,
-            _creole.Rules.page
+            Rules.extern,
+            Rules.attach,
+            Rules.interwiki,
+            Rules.page
         ]), re.X | re.U) # for addresses
 
     def __init__(self, root, formatter, request):