]> granicus.if.org Git - python/commitdiff
Refactor cmd_view(): move line formatting to a helper method.
authorGuido van Rossum <guido@python.org>
Thu, 17 Oct 2002 21:43:47 +0000 (21:43 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 17 Oct 2002 21:43:47 +0000 (21:43 +0000)
Demo/cgi/wiki.py

index c04b57ef4966bf134225d0fd3d2bae9c0e57dd9d..ee094a8ef8968993c4c73991891f814f89c11ebf 100644 (file)
@@ -31,23 +31,25 @@ class WikiPage:
             line = line.rstrip()
             if not line:
                 print "<p>"
-                continue
-            words = re.split('(\W+)', line)
-            for i in range(len(words)):
-                word = words[i]
-                if self.iswikiword(word):
-                    if os.path.isfile(self.mkfile(word)):
-                        word = self.mklink("view", word, word)
-                    else:
-                        word = self.mklink("new", word, word + "*")
-                else:
-                    word = escape(word)
-                words[i] = word
-            print "".join(words)
+            else:
+                print self.formatline(line)
         print "<hr>"
         print "<p>", self.mklink("edit", self.name, "Edit this page") + ";"
         print self.mklink("view", "FrontPage", "go to front page") + "."
 
+    def formatline(self, line):
+        words = []
+        for word in re.split('(\W+)', line):
+            if self.iswikiword(word):
+                if os.path.isfile(self.mkfile(word)):
+                    word = self.mklink("view", word, word)
+                else:
+                    word = self.mklink("new", word, word + "*")
+            else:
+                word = escape(word)
+            words.append(word)
+        return "".join(words)
+
     def cmd_edit(self, form, label="Change"):
         print "<h1>", label, self.name, "</h1>"
         print '<form method="POST" action="%s">' % self.scripturl