# 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$")
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)