From: Bernie Innocenti Date: Tue, 23 Mar 2010 03:21:39 +0000 (-0300) Subject: Don't rely on MimeType to identify wiki pages X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=29de4990aca1e209eb20de44bbde709db7de70be;p=geekigeeki.git Don't rely on MimeType to identify wiki pages --- diff --git a/geekigeeki.py b/geekigeeki.py index 972df7c..e45a3ba 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -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 '?' + '&'.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)