Refactoring: move send_footer() into Page()
authorBernie Innocenti <bernie@codewiz.org>
Mon, 22 Mar 2010 21:17:55 +0000 (18:17 -0300)
committerBernie Innocenti <bernie@codewiz.org>
Mon, 22 Mar 2010 21:17:55 +0000 (18:17 -0300)
geekigeeki.py

index b00838ae923d45ac5320579096b7d6f1cebb1b8d..624a8c72abd7e6b644fc8762d589334d0f357395 100755 (executable)
@@ -198,8 +198,9 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal
 
 def send_httperror(status="403 Not Found", query=""):
     print("Status: %s" % status)
+    page = Page()
     send_title(None, msg_text=("%s: on query '%s'" % (status, query)))
-    send_footer()
+    page.send_footer()
 
 def link_tag(dest, text=None, privileged=False, **kvargs):
     if text is None:
@@ -347,17 +348,6 @@ def page_list(dirname=None, search_re=None):
         search_re = re.compile(r"^\b((([A-Z][a-z0-9]+){2,}/)*([A-Z][a-z0-9]+){2,})\b$")
     return sorted(filter(search_re.match, os.listdir(dirname or '.')))
 
-def send_footer(mtime=None, footer="sys/footer"):
-    if config_get('debug_cgi', False):
-        cgi.print_arguments()
-        cgi.print_form(form)
-        cgi.print_environ()
-    if footer != "off":
-        link_inline(footer, kvargs = {
-            'LAST_MODIFIED': strftime(config_get('datetime_fmt', '%a %d %b %Y %I:%M %p'), localtime(mtime))
-        })
-    print("</body></html>")
-
 def _macro_ELAPSED_TIME(*args, **kvargs):
     return "%03f" % (clock() - start_time)
 
@@ -624,7 +614,7 @@ class WikiFormatter:
         print('</p></div>')
 
 class Page:
-    def __init__(self, page_name):
+    def __init__(self, page_name="Limbo"):
         self.page_name = page_name.rstrip('/');
         self.msg_text = ''
         self.msg_type = 'error'
@@ -724,6 +714,17 @@ class Page:
     def can_read(self):
         return self.can("read", True)
 
+    def send_footer(mtime=None, footer="sys/footer"):
+        if config_get('debug_cgi', False):
+            cgi.print_arguments()
+            cgi.print_form(form)
+            cgi.print_environ()
+        if footer != "off":
+            link_inline(footer, kvargs = {
+                'LAST_MODIFIED': strftime(config_get('datetime_fmt', '%a %d %b %Y %I:%M %p'), localtime(mtime))
+            })
+        print("</body></html>")
+
     def send_naked(self, kvargs=None):
         if self.can_read():
             WikiFormatter(self.get_raw_body(), kvargs).print_html()
@@ -741,7 +742,7 @@ class Page:
             msg_text=self.msg_text, msg_type=self.msg_type, writable=self.can_write(), mtime=self._mtime(),
             navbar=self.pragma("navbar", "on"))
         self.send_naked()
-        send_footer(mtime=self._mtime(), footer=self.pragma("footer", "sys/footer"))
+        self.send_footer(mtime=self._mtime(), footer=self.pragma("footer", "sys/footer"))
 
     def send_editor(self, preview=None):
         send_title(None, 'Edit ' + self.split_title(), msg_text=self.msg_text, msg_type=self.msg_type)
@@ -761,7 +762,7 @@ class Page:
             print("<div class='preview'>")
             WikiFormatter(preview).print_html()
             print("</div>")
-        send_footer()
+        self.send_footer()
 
     def send_raw(self, mimetype='text/plain', args=[]):
         if not self.can_read():
@@ -838,6 +839,6 @@ except Exception:
         send_guru(msg_text, "error")
     else:
         send_title(None, msg_text=msg_text)
-    send_footer()
+    Page().send_footer()
 
 sys.stdout.flush()