Get rid of obsolete apply()
authorBernardo Innocenti <bernie@codewiz.org>
Tue, 12 Feb 2008 07:34:13 +0000 (17:34 +1000)
committerBernardo Innocenti <bernie@codewiz.org>
Tue, 12 Feb 2008 07:34:13 +0000 (17:34 +1000)
geekigeeki.py

index eef3d6c6736ff76f06e0b44f428f359a7eeab9ac..a6158a3122b41b184930bf0255664a428851858d 100755 (executable)
@@ -177,7 +177,7 @@ def link_tag(params, text=None, ss_class=None, privileged=False):
 
 # Search ---------------------------------------------------
 
-def do_fullsearch(needle):
+def handle_fullsearch(needle):
     send_title(None, 'Full text search for "%s"' % (needle))
 
     needle_re = re.compile(needle, re.IGNORECASE)
@@ -204,7 +204,7 @@ def do_fullsearch(needle):
 
     print_search_stats(len(hits), len(all_pages))
 
-def do_titlesearch(needle):
+def handle_titlesearch(needle):
     # TODO: check needle is legal -- but probably we can just accept any RE
     send_title(None, "Title search for \"" + needle + '"')
 
@@ -222,10 +222,10 @@ def do_titlesearch(needle):
 def print_search_stats(hits, searched):
     print "<p>%d hits out of %d pages searched.</p>" % (hits, searched)
 
-def do_raw(pagename):
+def handle_raw(pagename):
     Page(pagename).send_raw()
 
-def do_edit(pagename):
+def handle_edit(pagename):
     pg = Page(pagename)
     if 'save' in form:
         if form['file'].value:
@@ -237,7 +237,7 @@ def do_edit(pagename):
         pg.msg_text = 'Editing canceled'
         pg.msg_type = 'notice'
         pg.send_page()
-    else:
+    else: # preview or edit
         text = None
         if 'preview' in form:
             text = form['savetext'].value
@@ -395,7 +395,7 @@ class PageFormatter:
 
         macro = globals().get('_macro_' + name)
         if macro:
-            return apply(macro, (name, descr))
+            return macro(name, descr)
         elif img_re.match(name):
             name = relative_url(name)
             # The "extthumb" nonsense works around a limitation of the HTML block model
@@ -478,7 +478,7 @@ class PageFormatter:
     def replace(self, match):
         for type, hit in match.groupdict().items():
             if hit:
-                return apply(getattr(self, '_' + type + '_repl'), (hit,))
+                return getattr(self, '_' + type + '_repl')(hit)
         else:
             raise "Can't handle match " + `match`
 
@@ -744,16 +744,11 @@ class Page:
 try:
     execfile("geekigeeki.conf.py")
     form = cgi.FieldStorage()
-    handlers = {
-        'fullsearch':  do_fullsearch,
-        'titlesearch': do_titlesearch,
-        'edit':        do_edit,
-        'raw':         do_raw,
-    }
-
-    for cmd in handlers.keys():
-        if cmd in form:
-            apply(handlers[cmd], (form[cmd].value,))
+
+    for cmd in form:
+        handler = globals().get('handle_' + cmd)
+        if handler:
+            handler(form[cmd].value)
             break
     else:
         path_info = environ.get('PATH_INFO', '')
@@ -773,6 +768,7 @@ try:
         else:
             print "Status: 404 Not Found"
             send_title(None, msg_text='Can\'t work out query: ' + query)
+            send_footer(None)
 except Exception:
     import traceback
     msg_text = traceback.format_exc()