summaryrefslogtreecommitdiffstats
path: root/Demo
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2002-10-17 21:43:47 (GMT)
committerGuido van Rossum <guido@python.org>2002-10-17 21:43:47 (GMT)
commit154c08894b9003671c92af751b3b889808e43e1c (patch)
tree417ac9684f393b55ca150c6a9dc60ba14de66ac3 /Demo
parent9c3848b39b9b87bd0f81b145b1402093e659673e (diff)
downloadcpython-154c08894b9003671c92af751b3b889808e43e1c.zip
cpython-154c08894b9003671c92af751b3b889808e43e1c.tar.gz
cpython-154c08894b9003671c92af751b3b889808e43e1c.tar.bz2
Refactor cmd_view(): move line formatting to a helper method.
Diffstat (limited to 'Demo')
-rw-r--r--Demo/cgi/wiki.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/Demo/cgi/wiki.py b/Demo/cgi/wiki.py
index c04b57e..ee094a8 100644
--- a/Demo/cgi/wiki.py
+++ b/Demo/cgi/wiki.py
@@ -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