changeset 1754:15a38f95ad4a

optimize code
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 29 Jan 2007 22:51:11 +0100
parents c0c1a4d9151d
children 402275b0dac7
files MoinMoin/wikiutil.py
diffstat 1 files changed, 10 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/wikiutil.py	Sun Jan 28 22:41:12 2007 +0100
+++ b/MoinMoin/wikiutil.py	Mon Jan 29 22:51:11 2007 +0100
@@ -1644,6 +1644,7 @@
     ourticket = createTicket(request, timestamp_str)
     return ticket == ourticket
 
+
 def executeText(request, Parser, text, line_anchors=False):
     """executes raw wiki markup with all page elements"""
     import StringIO
@@ -1656,32 +1657,29 @@
     del out
     return result
 
+
 def getProcessingInstructions(text):
     """creates dict of processing instructions from raw wiki markup"""
-    lines = text.split('\n')
     kw = {}
-    kw["processing_instructions"] = False
-    for line in lines:
+    for line in text.split('\n'):
         if line.startswith('#'):
             for pi in ("format", "refresh", "redirect", "deprecated", "pragma", "form", "acl", "language"):
                 if line[1:].lower().startswith(pi):
-                    kw[str(pi)] = ((line.split(pi))[1]).strip()
-                    kw["processing_instructions"] = True
+                    kw[pi] = line[len(pi)+1:].strip()
                     break
     return kw
 
+
 def getParser(request, text):
     """gets the parser from raw wiki murkup"""
-    pi = getProcessingInstructions(text)
-    pi_format = request.cfg.default_markup or "wiki"
-
     # check for XML content
     if text and text[:5] == '<?xml':
         pi_format = "xslt"
-
-    # check processing instructions
-    if pi.has_key('format'):
-        pi_format = (pi["format"]).lower()
+    else:
+        # check processing instructions
+        pi = getProcessingInstructions(text)
+        pi_format = pi.get("format", request.cfg.default_markup or "wiki").lower()
 
     Parser = searchAndImportPlugin(request.cfg, "parser", pi_format)
     return Parser
+