X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=geekigeeki.py;h=cd92c54edffbd737d1d6affdbe7e94f83faf3a2b;hb=f21a426a573a28806267553a963a5930304e2f01;hp=12b6b7cdaec57d05e14baadd381c17a6431029bb;hpb=75836706224e9f6b8ede6c59deea646e31672924;p=geekigeeki.git diff --git a/geekigeeki.py b/geekigeeki.py index 12b6b7c..cd92c54 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -1,4 +1,5 @@ -#! /usr/bin/env python +#!/usr/bin/python +# -*- coding: utf-8 -*- # # Copyright 1999, 2000 Martin Pool # Copyright 2002 Gerardo Poggiali @@ -112,8 +113,8 @@ def send_title(name, text="Limbo", msg=None, msg_type='error'): print ' ' if not name: print ' ' - if globals().has_key('css_url'): - print ' ' % css_url + for css in css_url: + print ' ' % css print '' # Body @@ -335,18 +336,27 @@ class PageFormatter: def __init__(self, raw): self.raw = raw self.h_level = 0 - self.in_pre = self.in_table = self.in_var = self.in_em = self.in_b = False + self.in_pre = self.in_table = False self.in_header = True self.list_indents = [] self.tr_cnt = self.h_cnt = 0 + self.styles = { + #wiki html enabled? + "//": ["em", False], + "''": ["em", False], + "**": ["b", False], + "'''": ["b", False], + "##": ["tt", False], + "``": ["tt", False], + "__": ["u", False], + "^^": ["sup", False], + ",,": ["sub", False] + } def _b_repl(self, word): - self.in_b = not self.in_b - return ['', ''][self.in_b] - - def _em_repl(self, word): - self.in_em = not self.in_em - return ['', ''][self.in_em] + style = self.styles[word] + style[1] = not style[1] + return ['' def _tit_repl(self, word): if self.h_level: @@ -355,7 +365,8 @@ class PageFormatter: else: self.h_level = len(word) - 1 self.h_cnt += 1 - result = '* ' % (self.h_level, self.h_cnt, self.h_cnt) + #abridged = re.sub('[^a-z_]', '', word.lower().replace(' ', '_')) + result = '¶ ' % (self.h_level, self.h_cnt, self.h_cnt) return result def _br_repl(self, word): @@ -378,7 +389,7 @@ class PageFormatter: return '%s' % (word, word) def _hurl_repl(self, word): - m = re.compile("\[\[(\S+)(?:\s*\|\s*([^\]]*)|)\]\]").match(word) + m = re.compile("\[\[([^ \t\n\r\f\v\|]+)(?:\s*\|\s*([^\]]+)|)\]\]").match(word) name = m.group(1) descr = m.group(2) or name @@ -386,13 +397,17 @@ class PageFormatter: if macro: return apply(macro, (name, descr)) elif img_re.match(name): - return '%s' % (name, name, descr) - elif url_re.match(name): - return '%s' % (name, descr) - elif name.startswith('/'): - return '%s' % (name, descr) + return '
%s
%s
' % (name, name, descr, descr) else: - return link_tag(name, descr, 'wikilink') + if img_re.match(descr): + descr = '' + + if url_re.match(name): + return '%s' % (name, descr) + elif name.startswith('/'): + return '%s' % (name, descr) + else: + return link_tag(name, descr, 'wikilink') def _email_repl(self, word): return '%s' % (word, word) @@ -426,15 +441,6 @@ class PageFormatter: cl = 'notice' return '' + word + '' - def _var_repl(self, word): - if word == '{{' and not self.in_var: - self.in_var = True - return '' - elif self.in_var: - self.in_var = False - return '' - return '' - def _tr_repl(self, word): out = '' if not self.in_table: @@ -494,8 +500,7 @@ class PageFormatter: scan_re = re.compile( r"(?:" # Formatting - + r"(?P\*\*|''')" - + r"|(?P//|'')" + + r"(?P\*\*|'''|//|''|##|``|__|\^\^|,,)" + r"|(?P\={2,6})" + r"|(?P
\\\\)" + r"|(?P^-{3,})" @@ -506,14 +511,13 @@ class PageFormatter: # Links + r"|(?P\b[a-zA-Z0-9_-]+\.(png|gif|jpg|jpeg|bmp))" + r"|(?P\b(?:[A-Z][a-z]+){2,}\b)" - + r"|(?P\[\[(\S+)(?:\s*\|\s*([^\]]*)|)\]\])" + + r"|(?P\[\[([^ \t\n\r\f\v\|]+)(?:\s*\|\s*([^\]]+)|)\]\])" + r"|(?P(http|https|ftp|mailto)\:[^\s'\"]+\S)" + r"|(?P[-\w._+]+\@[\w.-]+)" # Lists, divs, spans + r"|(?P
  • ^\s+[\*#] +)" + r"|(?P
    \{\{\{|\s*\}\}\})"
    -            + r"|(?P\{\{|\}\})"
     
                 # Tables
                 + r"|(?P^\s*\|\|(=|)\s*)"
    @@ -561,7 +565,6 @@ class Page:
             self.page_name = page_name
             self.msg = ''
             self.msg_type = 'error'
    -        self.attrs = {}
     
         def split_title(self):
             # look for the end of words and the start of a new word,
    @@ -600,8 +603,9 @@ class Page:
                 raise er
     
         def get_attrs(self):
    -        if self.attrs:
    +        if self.__dict__.has_key('attrs'):
                 return self.attrs
    +        self.attrs = {}
             try:
                 file = open(self._text_filename(), 'rt')
                 attr_re = re.compile(r"^#(\S*)(.*)$")
    @@ -616,11 +620,16 @@ class Page:
                     raise er
             return self.attrs
     
    +    def get_attr(self, name, default):
    +        if self.get_attrs().has_key(name):
    +            return self.get_attrs()[name]
    +        else:
    +            return default
    +
         def can(self, action, default=True):
    -        attrs = self.get_attrs()
             try:
    -            # SomeUser:read,write All:read
    -            acl = attrs["acl"]
    +            #acl SomeUser:read,write All:read
    +            acl = self.get_attr("acl", None)
                 for rule in acl.split():
                     (user,perms) = rule.split(':')
                     if user == remote_user() or user == "All":
    @@ -643,6 +652,12 @@ class Page:
             page_name = None
             if self.can_write():
                 page_name = self.page_name
    +
    +        #FIXME: are there security implications?
    +        #css foo.css bar.css
    +        global css_url
    +        css_url = css_url + self.get_attr("css", "").split()
    +
             send_title(page_name, self.split_title(), msg=self.msg, msg_type=self.msg_type)
             if self.can_read():
                 PageFormatter(self.get_raw_body()).print_html()
    @@ -672,7 +687,7 @@ class Page:
                 + '

    ') print '
    ' % (script_name(), self.page_name) print '' % (self.page_name) - print """""" % (preview or self.get_raw_body()) + print """""" % (preview or self.get_raw_body()) print """