From cc5df9ba5625f7e789a30aea769287c2c93bd5ea Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Mon, 22 Mar 2010 23:24:48 -0300 Subject: [PATCH] Fold send_page() into class Page --- geekigeeki.py | 166 +++++++++++++++++++++++++------------------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/geekigeeki.py b/geekigeeki.py index f088774..0fdd421 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -123,83 +123,10 @@ def send_guru(msg_text, msg_type): print('' \ % relative_url('sys/GuruMeditation.js')) -def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=False, mtime=None, navbar="on"): - global title_done - if title_done: return - - # HEAD - emit_header(mtime) - print('\n') - print("%s: %s" % (config_get('site_name', "Unconfigured Wiki"), text)) - print(' ') - if not name: - print(' ') - - for http_equiv, content in config_get('meta_urls', {}): - print(' ' % (http_equiv, relative_url(content))) - - for link in config_get('link_urls', {}): - rel, href = link - print(' ' % (rel, relative_url(href))) - - editable = name and writable and is_privileged() - if editable: - print(' ' \ - % relative_url('?a=edit&q=' + name, privileged=True)) - - history = config_get('history_url') - if history is not None: - print(' ' \ - % relative_url(history + '?a=rss')) - - print('') - - # BODY - if editable: - print('') - else: - print('') - - title_done = True - send_guru(msg_text, msg_type) - - if navbar != "on": - return - - # NAVBAR - print('') - 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))) + page.send_title(msg_text=("%s: on query '%s'" % (status, query))) page.send_footer() def link_tag(dest, text=None, privileged=False, **kvargs): @@ -255,7 +182,7 @@ def print_search_stats(hits, searched): def handle_fullsearch(query, form): needle = form['q'].value - send_title(None, 'Full text search for "' + needle + '"') + Page().send_title(text='Full text search for "' + needle + '"') needle_re = re.compile(needle, re.IGNORECASE) hits = [] @@ -283,7 +210,7 @@ def handle_fullsearch(query, form): def handle_titlesearch(query, form): needle = form['q'].value - send_title(None, 'Title search for "' + needle + '"') + Page().send_title(text='Title search for "' + needle + '"') needle_re = re.compile(needle, re.IGNORECASE) all_pages = page_list() @@ -714,6 +641,80 @@ class Page: def can_read(self): return self.can("read", True) + def send_title(self, name=None, text="Limbo", msg_text=None, msg_type='error'): + global title_done + if title_done: return + + # HEAD + emit_header(self._mtime()) + print('\n') + print("%s: %s" % (config_get('site_name', "Unconfigured Wiki"), text)) + print(' ') + if not name: + print(' ') + + for http_equiv, content in config_get('meta_urls', {}): + print(' ' % (http_equiv, relative_url(content))) + + for link in config_get('link_urls', {}): + rel, href = link + print(' ' % (rel, relative_url(href))) + + editable = name and self.can_write() and is_privileged() + if editable: + print(' ' \ + % relative_url('?a=edit&q=' + name, privileged=True)) + + history = config_get('history_url') + if history is not None: + print(' ' \ + % relative_url(history + '?a=rss')) + + print('') + + # BODY + if editable: + print('') + else: + print('') + + title_done = True + send_guru(msg_text, msg_type) + + if self.pragma("navbar", "on") != "on": + return + + # NAVBAR + print('') + + def send_footer(self): if config_get('debug_cgi', False): cgi.print_arguments() @@ -739,14 +740,12 @@ class Page: global link_urls link_urls += [ [ "stylesheet", value ] ] - send_title(self.page_name, self.split_title(), - msg_text=self.msg_text, msg_type=self.msg_type, writable=self.can_write(), mtime=self._mtime(), - navbar=self.pragma("navbar", "on")) + self.send_title(name=self.page_name, text=self.split_title(), msg_text=self.msg_text, msg_type=self.msg_type) self.send_naked() self.send_footer() def send_editor(self, preview=None): - send_title(None, 'Edit ' + self.split_title(), msg_text=self.msg_text, msg_type=self.msg_type) + self.send_title(text='Edit ' + self.split_title(), msg_text=self.msg_text, msg_type=self.msg_type) if not self.can_write(): send_guru("Write access denied by ACLs", "error") return @@ -767,7 +766,7 @@ class Page: def send_raw(self, mimetype='text/plain', args=[]): if not self.can_read(): - send_title(None, msg_text='Read access denied by ACLs', msg_type='notice', mtime=self._mtime()) + self.send_title(msg_text='Read access denied by ACLs', msg_type='notice') return emit_header(self._mtime(), mimetype) @@ -836,10 +835,11 @@ try: except Exception: import traceback msg_text = traceback.format_exc() + page = Page() if title_done: send_guru(msg_text, "error") else: - send_title(None, msg_text=msg_text) - Page().send_footer() + page.send_title(msg_text=msg_text) + page.send_footer() sys.stdout.flush() -- 2.25.1