From: Bernie Innocenti Date: Mon, 22 Mar 2010 21:17:55 +0000 (-0300) Subject: Refactoring: move send_footer() into Page() X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=74ea71bcbb270f0114dd4946c831dc0d76983958;p=geekigeeki.git Refactoring: move send_footer() into Page() --- diff --git a/geekigeeki.py b/geekigeeki.py index b00838a..624a8c7 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -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("") - def _macro_ELAPSED_TIME(*args, **kvargs): return "%03f" % (clock() - start_time) @@ -624,7 +614,7 @@ class WikiFormatter: print('

') 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("") + 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("
") WikiFormatter(preview).print_html() print("
") - 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()