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)
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
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
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)