Don't rely on MimeType to identify wiki pages
authorBernie Innocenti <bernie@codewiz.org>
Tue, 23 Mar 2010 03:21:39 +0000 (00:21 -0300)
committerBernie Innocenti <bernie@codewiz.org>
Tue, 23 Mar 2010 03:21:39 +0000 (00:21 -0300)
geekigeeki.py

index 972df7c45608877c52025dca52f0cda029480ad0..e45a3ba3fef75914c3872cd03ef059aecd383a6f 100755 (executable)
@@ -29,7 +29,6 @@ file_re  = re.compile(r"([A-Za-z0-9_\-][A-Za-z0-9_\.\-/ ]*)$")
 url_re   = re.compile(r"[a-z]{3,8}://[^\s'\"]+\S$")
 ext_re   = re.compile(r"\.([^\./]+)$")
 
-# CGI stuff ---------------------------------------------------------
 def config_get(key, default=None):
     return globals().get(key, default)
 
@@ -106,11 +105,12 @@ def url_args(kvargs):
         return '?' + '&amp;'.join(argv)
     return ''
 
-# Formatting stuff --------------------------------------------------
 def emit_header(mtime=None, mime_type="text/html"):
     if mtime:
         print("Last-Modified: " + strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime(mtime)))
-    print("Content-type: " + mime_type + "; charset=utf-8\n")
+    if mime_type:
+        print("Content-type: " + mime_type + "; charset=utf-8")
+    print('')
 
 def send_guru(msg_text, msg_type):
     if not msg_text: return
@@ -175,10 +175,8 @@ def link_inline_glob(pattern, descr=None, kvargs={}):
     else:
         return link_inline(pattern, descr, kvargs)
 
-# Search ---------------------------------------------------
-
 def search_stats(hits, searched):
-    return("%d hits out of %d pages searched.\n" % (hits, searched))
+    return "%d hits out of %d pages searched.\n" % (hits, searched)
 
 def handle_fullsearch(query, form):
     needle = form['q'].value
@@ -250,13 +248,13 @@ def handle_edit(pagename, form):
 
 def handle_get(pagename, form):
         if file_re.match(pagename):
-            # FIMXE: this is all bullshit, MimeTypes bases its guess on the extension!
-            from mimetypes import MimeTypes
-            mimetype, encoding = MimeTypes().guess_type(pagename)
-            if mimetype:
-                Page(pagename).send_raw(mimetype=mimetype, args=form)
-            else:
+            if not ext_re.search(pagename): # FIXME: no extension guesses a wiki page
                 Page(pagename).format()
+            else:
+                # FIMXE: this is all bullshit, MimeTypes bases its guess on the extension!
+                from mimetypes import MimeTypes
+                mimetype, encoding = MimeTypes().guess_type(pagename)
+                Page(pagename).send_raw(mimetype=mimetype, args=form)
         else:
             send_httperror("403 Forbidden", pagename)