X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=geekigeeki.py;h=cc0373621ab6e4c11da560c253d9383cc40a9948;hb=c0c495043d8f2f4edb5a37b108d7c400e0eb1498;hp=4450aead0d3617848117f6c7ad6098a758b8877d;hpb=042882ca5918a6f84a176e4ef9dc19428ac4566f;p=geekigeeki.git diff --git a/geekigeeki.py b/geekigeeki.py index 4450aea..cc03736 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -3,7 +3,7 @@ # # Copyright 1999, 2000 Martin Pool # Copyright 2002 Gerardo Poggiali -# Copyright 2007, 2008 Bernie Innocenti +# Copyright 2007, 2008, 2009 Bernie Innocenti # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -151,11 +151,11 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal # Navbar print '' @@ -206,6 +206,13 @@ def link_tag(params, text=None, link_class=None, privileged=False): return '%s' % (classattr, relative_url(params, privileged=privileged), text) +def link_inline(name, descr=None, args=''): + if not descr: descr = name + if video_re.match(name): + return '' % name + else: + return '%s' % (name, name + args, descr) + # Search --------------------------------------------------- def handle_fullsearch(needle): @@ -321,14 +328,14 @@ class WikiFormatter: self.styles = { #wiki html enabled? "//": ["em", False], - "''": ["em", False], "**": ["b", False], - "'''": ["b", False], "##": ["tt", False], - "``": ["tt", False], "__": ["u", False], "^^": ["sup", False], - ",,": ["sub", False] + ",,": ["sub", False], + "''": ["em", False], # LEGACY + "'''": ["b", False], # LEGACY + "``": ["tt", False], # LEGACY } def _b_repl(self, word): @@ -379,12 +386,6 @@ class WikiFormatter: m = link_re.match(word) return link_tag(m.group(1), m.group(2)) - def _url_repl(self, word): - return link_tag(word) - - def _word_repl(self, word): - return link_tag(word) - def _inl_repl(self, word): m = link_re.match(word) name = relative_url(m.group(1)) @@ -398,18 +399,11 @@ class WikiFormatter: args = '?' + '&'.join(argv) # The "extthumb" nonsense works around a limitation of the HTML block model - return '
%s
%s
' \ - % (name, name + args, descr, descr) - elif video_re.match(name): - return '' % name + return '
' \ + + link_inline(name, descr, args) \ + + '
' + descr + '
' else: - return '' % (name, name) - - def _img_repl(self, word): - return self._inl_repl('{{' + word + '}}') - - def _email_repl(self, word): - return '%s' % (word, word) + return link_inline(name, name) def _html_repl(self, word): self.in_html += 1 @@ -426,6 +420,21 @@ class WikiFormatter: '<': '<', '>': '>'}[s] + def _img_repl(self, word): # LEGACY + return self._inl_repl('{{' + word + '}}') + + def _word_repl(self, word): # LEGACY + if self.in_html: return word # pass through + return link_tag(word) + + def _url_repl(self, word): # LEGACY + if self.in_html: return word # pass through + return link_tag(word) + + def _email_repl(self, word): # LEGACY + if self.in_html: return word # pass through + return '%s' % (word, word) + def _li_repl(self, match): if self.in_li: return '
  • ' @@ -733,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) @@ -749,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() @@ -800,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)