From c0c495043d8f2f4edb5a37b108d7c400e0eb1498 Mon Sep 17 00:00:00 2001 From: Bernie Innocenti Date: Wed, 8 Apr 2009 23:21:11 +0200 Subject: [PATCH] Simplify mimetype handling --- geekigeeki.py | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/geekigeeki.py b/geekigeeki.py index f3ce1dc..cc03736 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -742,15 +742,11 @@ class Page: print "" send_footer() - def send_raw(self, mimetype='text/plain'): - if self.can_read(): - body = self.get_raw_body() - emit_header(mimetype) - print body - else: + def send_raw(self, mimetype='text/plain', args=[]): + if not self.can_read(): send_title(None, msg_text='Read access denied by ACLs', msg_type='notice') + return - def send_image(self, mimetype, args=[]): if 'maxwidth' in args: import subprocess emit_header(mimetype) @@ -758,7 +754,9 @@ class Page: subprocess.check_call(['gm', 'convert', self._filename(), '-scale', args['maxwidth'].value + ' >', '-']) else: - self.send_raw(mimetype) + body = self.get_raw_body() + emit_header(mimetype) + print body def _write_file(self, data): tmp_filename = self._tmp_filename() @@ -809,18 +807,13 @@ def main(): else: query = query_string() if file_re.match(query): - if word_re.match(query): - Page(query).format() + # FIMXE: this is all bullshit, MimeTypes bases its guess on the extension! + from mimetypes import MimeTypes + mimetype, encoding = MimeTypes().guess_type(query) + if mimetype: + Page(query).send_raw(mimetype=mimetype, args=form) else: - from mimetypes import MimeTypes - mimetype, encoding = MimeTypes().guess_type(query) - if mimetype: - if mimetype.startswith('image/'): - Page(query).send_image(mimetype=mimetype, args=form) - else: - Page(query).send_raw(mimetype=mimetype) - else: - Page(query).format() + Page(query).format() else: send_httperror("403 Forbidden", query) -- 2.25.1