#
# Copyright (C) 1999, 2000 Martin Pool <mbp@humbug.org.au>
# Copyright (C) 2002 Gerardo Poggiali
-# Copyright (C) 2007, 2008, 2009 Bernie Innocenti <bernie@codewiz.org>
+# Copyright (C) 2007, 2008, 2009, 2010 Bernie Innocenti <bernie@codewiz.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
print('</pre><script type="text/javascript" src="%s" defer="defer"></script>' \
% relative_url('sys/GuruMeditation.js'))
-def send_httperror(status="403 Not Found", query=""):
+def send_httperror(status="403 Not Found", query="", trace=False):
print("Status: %s" % status)
+ msg_text = "%s: on query '%s'" % (status, query)
+ if trace:
+ import traceback
+ msg_text += '\n\n' + traceback.format_exc()
page = Page()
- page.send_title(msg_text=("%s: on query '%s'" % (status, query)))
+ page.send_title(msg_text=msg_text)
page.send_footer()
def link_tag(dest, text=None, privileged=False, **kvargs):
WikiFormatter(out).print_html()
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, form):
- if not file_re.match(pagename):
- send_httperror("403 Forbidden", pagename)
- return
+def handle_atom(pagename, form):
+ Page(pagename).send_atom()
+def handle_edit(pagename, form):
pg = Page(form['q'].value)
if 'save' in form:
if form['file'].value:
pg.save(form['file'].file.read(), form['changelog'].value)
else:
pg.save(form['savetext'].value.replace('\r\n', '\n'), form['changelog'].value)
- pg.format()
+ pg.send()
elif 'cancel' in form:
pg.msg_text = 'Editing canceled'
pg.msg_type = 'notice'
- pg.format()
+ pg.send()
else: # preview or edit
text = None
if 'preview' in form:
pg.send_editor(text)
def handle_get(pagename, form):
- if file_re.match(pagename):
- if not ext_re.search(pagename): # FIXME: no extension guesses a wiki page
- Page(pagename).format()
- else:
- # FIMXE: this is all bullshit, MimeTypes bases its guess on the extension!
- from mimetypes import MimeTypes
- mimetype, encoding = MimeTypes().guess_type(pagename)
- Page(pagename).send_raw(mimetype=mimetype, args=form)
- else:
- send_httperror("403 Forbidden", pagename)
+ if not ext_re.search(pagename): # FIXME: no extension guesses a wiki page
+ Page(pagename).send()
+ else:
+ # FIMXE: this is all bullshit, MimeTypes bases its guess on the extension!
+ from mimetypes import MimeTypes
+ mimetype, encoding = MimeTypes().guess_type(pagename)
+ Page(pagename).send_raw(mimetype=mimetype, args=form)
# Used by sys/macros/WordIndex and sys/macros/TitleIndex
def make_index_key():
print(self._indent_to(0))
print('</p></div>')
+class HttpException(Exception):
+ def __init__(self, error, query):
+ self.error = error
+ self.query = query
+
class Page:
def __init__(self, page_name="Limbo"):
self.page_name = page_name.rstrip('/');
self.msg_text = ''
self.msg_type = 'error'
+ if not file_re.match(self.page_name):
+ raise HttpException("403 Forbidden", self.page_name)
def split_title(self):
# look for the end of words and the start of a new word and insert a space there
footer = self.pragma("footer", "sys/footer")
if footer != "off":
link_inline(footer, kvargs = {
- 'LAST_MODIFIED': strftime(config_get('datetime_fmt', '%a %d %b %Y %I:%M %p'), localtime(self._mtime()))
+ 'LAST_MODIFIED': strftime(config_get('datetime_fmt', '%Y-%m-%dT%I:%M:%S%p'), localtime(self._mtime()))
})
print("</body></html>")
else:
send_guru("Read access denied by ACLs", "notice")
- def format(self):
+ def send(self):
#css foo.css
value = self.pragma("css", None)
if value:
self.send_naked()
self.send_footer()
+ def send_atom(self):
+ emit_header(self._mtime(), 'application/atom+xml')
+ self.in_html = True
+ link_inline("sys/atom_header", kvargs = {
+ 'LAST_MODIFIED': strftime(config_get('datetime_fmt', '%a, %d %b %Y %I:%M:%S %p'), localtime(self._mtime()))
+ })
+ self.in_html = False
+ self.send_naked()
+ self.in_html = True
+ link_inline("sys/atom_footer")
+ self.in_html = False
+
def send_editor(self, preview=None):
self.send_title(text='Edit ' + self.split_title(), msg_text=self.msg_text, msg_type=self.msg_type)
if not self.can_write():
else:
send_httperror("403 Forbidden", query_string())
+except HttpException, e:
+ send_httperror(e.error, query=e.query)
except Exception:
- import traceback
- msg_text = traceback.format_exc()
- page = Page()
- if title_done:
- send_guru(msg_text, "error")
- else:
- page.send_title(msg_text=msg_text)
- page.send_footer()
+ send_httperror("500 Internal Server Error", query=query_string(), trace=True)
sys.stdout.flush()