" % (hits, searched)
-
-def handle_raw(pagename):
+def handle_raw(pagename, form):
if not file_re.match(pagename):
send_httperror("403 Forbidden", pagename)
return
Page(pagename).send_raw()
-def handle_edit(pagename):
+def handle_edit(pagename, form):
if not file_re.match(pagename):
send_httperror("403 Forbidden", pagename)
return
- pg = Page(pagename)
+ pg = Page(form['q'].value)
if 'save' in form:
if form['file'].value:
pg.save(form['file'].file.read(), form['changelog'].value)
@@ -296,11 +309,27 @@ def handle_edit(pagename):
text = form['savetext'].value
pg.send_editor(text)
+def handle_get(pagename, form):
+ if file_re.match(pagename):
+ # FIMXE: this is all bullshit, MimeTypes bases its guess on the extension!
+ from mimetypes import MimeTypes
+ mimetype, encoding = MimeTypes().guess_type(pagename)
+ if mimetype:
+ Page(pagename).send_raw(mimetype=mimetype, args=form)
+ else:
+ Page(pagename).format()
+ else:
+ send_httperror("403 Forbidden", pagename)
+
+# Used by macros/WordIndex and macros/TitleIndex
def make_index_key():
- links = map(lambda ch: '%s' % (ch, ch), 'abcdefghijklmnopqrstuvwxyz')
- return '
'+ ' | '.join(links) + '
'
+ links = ['%s' % (ch, ch) for ch in 'abcdefghijklmnopqrstuvwxyz']
+ return '
' + ' | '.join(links) + '
'
-def page_list(dirname = None, re = word_re):
+def page_list(dirname=None, re=None):
+ if re is None:
+ # FIXME: WikiWord is too restrictive now!
+ re = re.compile(r"^\b((([A-Z][a-z0-9]+){2,}/)*([A-Z][a-z0-9]+){2,})\b$")
return sorted(filter(re.match, os.listdir(dirname or data_dir)))
def send_footer(mod_string=None):
@@ -308,16 +337,17 @@ def send_footer(mod_string=None):
cgi.print_arguments()
cgi.print_form(form)
cgi.print_environ()
- print '''
+ #FIXME link_inline("sys/footer")
+ print('''
'
+ print('
last modified %s
' % mod_string)
+ print('')
class WikiFormatter:
"""Object that turns Wiki markup into HTML.
@@ -367,55 +397,44 @@ class WikiFormatter:
return self._undent() + '\n\n' % (len(word) - 2)
def _macro_repl(self, word):
- m = re.compile("\<\<([^\s\|\>]+)(?:\s*\|\s*([^\>]+)|)\>\>").match(word)
- name = m.group(1)
- argv = [name]
- if m.group(2):
- argv.extend(m.group(2).split('|'))
- argv = map(str.strip, argv)
-
- macro = globals().get('_macro_' + name)
- if not macro:
- try:
- execfile("macros/" + name + ".py", globals())
- except IOError, err:
- if err.errno == errno.ENOENT: pass
- macro = globals().get('_macro_' + name)
- if macro:
- return macro(argv)
- else:
- msg = '<<' + '|'.join(argv) + '>>'
+ try:
+ args, kwargs = parse_args(word)
+ macro = globals().get('_macro_' + args[0])
+ if not macro:
+ exec(open("macros/" + name + ".py").read(), globals())
+ macro = globals().get('_macro_' + name)
+ return macro(*args, **kwargs)
+ except Exception:
+ msg = cgi.escape(word)
if not self.in_html:
msg = '' + msg + ''
return msg
def _hurl_repl(self, word):
- m = link_re.match(word)
- return link_tag(m.group(1), m.group(2))
+ args, kvargs = parse_args(word)
+ return link_tag(*args, **kvargs)
def _inl_repl(self, word):
- (name, descr) = link_re.match(word).groups()
-
- if descr:
- argv = descr.split('|')
- descr = argv.pop(0)
- args = ''
- if argv:
- args = '?' + '&'.join(argv)
-
- # The "extthumb" nonsense works around a limitation of the HTML block model
- return '
' \
- + link_inline(name, descr, args) \
+ args, kvargs = parse_args(word)
+ name = args.pop(0)
+ if len(args):
+ descr = args.pop(0)
+ # This double div nonsense works around a limitation of the HTML block model
+ return '
' \
+ + '
' \
+ + link_inline(name, descr, kvargs) \
+ '
' + descr + '
'
else:
- return link_inline(name, name)
+ return link_inline(name, None, kvargs)
def _html_repl(self, word):
+ if not self.in_html and word.startswith('
'
return word; # Pass through
def _ent_repl(self, s):
@@ -506,14 +525,14 @@ class WikiFormatter:
return res
def replace(self, match):
- for rule, hit in match.groupdict().items():
+ for rule, hit in list(match.groupdict().items()):
if hit:
return getattr(self, '_' + rule + '_repl')(hit)
else:
raise "Can't handle match " + repr(match)
def print_html(self):
- print '
\{\{\{|\s*\}\}\})
| (?P \{\{([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\}\})
@@ -558,9 +577,9 @@ class WikiFormatter:
indent_re = re.compile(r"^\s*")
tr_re = re.compile(r"^\s*\|\|")
eol_re = re.compile(r"\r?\n")
-
# For each line, we scan through looking for magic strings, outputting verbatim any intervening text
- for self.line in eol_re.split(self.raw.expandtabs()):
+ #3.0: for self.line in eol_re.split(str(self.raw.expandtabs(), 'utf-8')):
+ for self.line in eol_re.split(str(self.raw.expandtabs())):
# Skip pragmas
if self.in_header:
if self.line.startswith('#'):
@@ -568,23 +587,24 @@ class WikiFormatter:
self.in_header = False
if self.in_pre:
- print re.sub(pre_re, self.replace, self.line)
+ print(re.sub(pre_re, self.replace, self.line))
else:
if self.in_table and not tr_re.match(self.line):
self.in_table = False
- print '