From 99acd9376fc3cdaf9dfe9218c78aede47c54968c Mon Sep 17 00:00:00 2001 From: Bernardo Innocenti Date: Sun, 27 Jan 2008 09:06:37 +1100 Subject: [PATCH] Add automatic mimetype detection. --- geekigeeki.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/geekigeeki.py b/geekigeeki.py index b34f152..764f366 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -28,8 +28,9 @@ from os import path, environ # Regular expression defining a WikiWord # (but this definition is also assumed in other places) -file_re = re.compile(r"^\b([A-Za-z0-9_\.\-/]+)\b$") word_re = re.compile(r"^\b((([A-Z][a-z]+){2,}/)*([A-Z][a-z]+){2,})\b$") +# FIXME: we accept stuff like foo/../bar and we shouldn't +file_re = re.compile(r"^\b([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)\b$") img_re = re.compile(r"^.*\.(png|gif|jpg|jpeg)$", re.IGNORECASE) url_re = re.compile(r"^[a-z]{3,8}://[^\s'\"]+\S$") @@ -755,11 +756,10 @@ try: if file_re.match(query): if word_re.match(query): Page(query).send_page() - elif img_re.match(query): - #FIXME: use correct mime type - Page(query).send_raw(mimetype='image/jpeg') else: - Page(query).send_raw(mimetype='application/octet-stream') + from mimetypes import MimeTypes + type, encoding = MimeTypes().guess_type(query) + Page(query).send_raw(mimetype=type) else: print "Status: 404 Not Found" send_title(None, msg_text='Can\'t work out query: ' + query) -- 2.25.1