From 154c08894b9003671c92af751b3b889808e43e1c Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Thu, 17 Oct 2002 21:43:47 +0000 Subject: [PATCH] Refactor cmd_view(): move line formatting to a helper method. --- Demo/cgi/wiki.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Demo/cgi/wiki.py b/Demo/cgi/wiki.py index c04b57ef496..ee094a8ef89 100644 --- a/Demo/cgi/wiki.py +++ b/Demo/cgi/wiki.py @@ -31,23 +31,25 @@ class WikiPage: line = line.rstrip() if not line: print "

" - 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 "


" print "

", 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 "

", label, self.name, "

" print '
' % self.scripturl