from time import clock
start_time = clock()
-import cgi, sys, string, os, re, errno, stat
+import cgi, sys, os, re, errno, stat
from os import path, environ
# Regular expression defining a WikiWord
try:
from socket import gethostbyaddr
return gethostbyaddr(addr)[0] + ' (' + addr + ')'
- except:
+ except Exception, er:
return addr
-def relative_url(path, privileged=False):
- if not (url_re.match(path) or path.startswith('/')):
+def relative_url(pathname, privileged=False):
+ if not (url_re.match(pathname) or pathname.startswith('/')):
if privileged:
url = privileged_path()
else:
url = script_name()
- path = url + '/' + path
- return path
+ pathname = url + '/' + pathname
+ return pathname
# Formatting stuff --------------------------------------------------
-def emit_header(type="text/html"):
- print "Content-type: " + type + "; charset=utf-8"
- print
+def emit_header(mime_type="text/html"):
+ print "Content-type: " + mime_type + "; charset=utf-8\n"
-def send_guru(msg, msg_type):
- if msg is None or msg == '': return
+def send_guru(msg_text, msg_type):
+ if not msg_text: return
print '<pre id="guru" onclick="this.style.display = \'none\'" class="' + msg_type + '">'
if msg_type == 'error':
print ' Software Failure. Press left mouse button to continue.\n'
- print msg
+ print msg_text
if msg_type == 'error':
print ' Guru Meditation #DEADBEEF.ABADC0DE'
print '</pre>'
}
</script>"""
-def send_title(name, text="Limbo", msg=None, msg_type='error'):
+def send_title(name, text="Limbo", msg_text=None, msg_type='error'):
global title_done
if title_done: return
print '<body>'
title_done = True
- send_guru(msg, msg_type)
+ send_guru(msg_text, msg_type)
# Navbar
print '<div class="nav">'
Page(pagename).send_raw()
def do_edit(pagename):
- global form
pg = Page(pagename)
if 'preview' in form:
pg.send_editor(form['savetext'].value)
pg.save_text(form['savetext'].value)
pg.send_page()
elif 'cancel' in form:
- pg.msg = 'Editing canceled'
+ pg.msg_text = 'Editing canceled'
pg.msg_type = 'notice'
pg.send_page()
else:
pg.send_editor()
def make_index_key():
- s = '<p><center>'
- links = map(lambda ch: '<a href="#%s">%s</a>' % (ch, ch),
- string.lowercase)
- s = s + string.join(links, ' | ')
- s = s + '</center></p>'
- return s
+ links = map(lambda ch: '<a href="#%s">%s</a>' % (ch, ch), 'abcdefghijklmnopqrstuvwxyz')
+ return '<p><center>'+ ' | '.join(links) + '</center></p>'
def page_list():
return filter(word_re.match, os.listdir(data_dir))
cgi.print_arguments()
cgi.print_form(cgi.FieldStorage())
cgi.print_environ()
- global __version__
print '<div id="footer"><hr />'
print ('<p class="copyright"><span class="benchmark">generated in %0.3fs</span>' +
' by <a href="http://www.codewiz.org/wiki/GeekiGeeki">GeekiGeeki</a>' +
last_letter = None
# set title
for word in all_words:
- letter = string.lower(word[0])
+ letter = word[0].lower()
if letter != last_letter:
s = s + '; <a name="%s"><h3>%s</h3></a>' % (letter, letter)
last_letter = letter
pages.sort()
current_letter = None
for name in pages:
- letter = string.lower(name[0])
+ letter = name[0].lower()
if letter != current_letter:
s += '<a name="%s"><h3>%s</h3></a>' % (letter, letter)
current_letter = letter
def _b_repl(self, word):
style = self.styles[word]
style[1] = not style[1]
- return ['</','<'][style[1]] + style[0] + '>'
+ return ['</', '<'][style[1]] + style[0] + '>'
def _tit_repl(self, word):
if self.h_level:
indent_re = re.compile(r"^\s*")
tr_re = re.compile(r"^\s*\|\|")
eol_re = re.compile(r"\r?\n")
- raw = string.expandtabs(self.raw)
- for line in eol_re.split(raw):
+ for line in eol_re.split(self.raw.expandtabs()):
# Skip ACLs
if self.in_header:
if line.startswith('#'):
- continue
+ continue
self.in_header = False
if self.in_pre:
class Page:
def __init__(self, page_name):
self.page_name = page_name
- self.msg = ''
+ self.msg_text = ''
self.msg_type = 'error'
def split_title(self):
#acl SomeUser:read,write All:read
acl = self.get_attr("acl", None)
for rule in acl.split():
- (user,perms) = rule.split(':')
+ (user, perms) = rule.split(':')
if user == remote_user() or user == "All":
return action in perms.split(',')
return False
#css foo.css bar.css
global css_url
- css_url = css_url + self.get_attr("css", "").split()
+ css_url = self.get_attr("css", "").split() + css_url
- send_title(page_name, self.split_title(), msg=self.msg, msg_type=self.msg_type)
+ send_title(page_name, self.split_title(), msg_text=self.msg_text, msg_type=self.msg_type)
if self.can_read():
PageFormatter(self.get_raw_body()).print_html()
else:
return strftime(datetime_fmt, modtime)
def send_editor(self, preview=None):
- send_title(None, 'Edit ' + self.split_title(), msg=self.msg, msg_type=self.msg_type)
+ send_title(None, 'Edit ' + self.split_title(), msg_text=self.msg_text, msg_type=self.msg_type)
if not self.can_write():
send_guru("Write access denied by ACLs", "error")
return
emit_header(mimetype)
print body
else:
- send_title(None, msg='Read access denied by ACLs', msg_type='notice')
+ send_title(None, msg_text='Read access denied by ACLs', msg_type='notice')
def _write_file(self, text):
tmp_filename = self._tmp_filename()
def save_text(self, newtext):
if not self.can_write():
- self.msg = 'Write access denied by ACLs'
+ self.msg_text = 'Write access denied by ACLs'
self.msg_type = 'error'
return
+ "' '" + remote_host() + "'"
)
out = os.popen(cmd)
- msg = out.read()
+ output = out.read()
rc = out.close()
if rc:
- self.msg += "Post-editing hook returned %d.\n" % rc
- self.msg += 'Command was: ' + cmd + '\n'
- if msg:
- self.msg += 'Output follows:\n' + msg
+ self.msg_text += "Post-editing hook returned %d.\n" % rc
+ self.msg_text += 'Command was: ' + cmd + '\n'
+ if output:
+ self.msg_text += 'Output follows:\n' + output
else:
- self.msg = 'Thank you for your contribution. Your attention to detail is appreciated.'
+ self.msg_text = 'Thank you for your contribution. Your attention to detail is appreciated.'
self.msg_type = 'success'
# Main ---------------------------------------------------------------
Page(query).send_raw(mimetype='application/octet-stream')
else:
print "Status: 404 Not Found"
- send_title(None, msg='Can\'t work out query: ' + query)
-except:
+ send_title(None, msg_text='Can\'t work out query: ' + query)
+except Exception:
import traceback
- msg=traceback.format_exc()
+ msg_text = traceback.format_exc()
if title_done:
- send_guru(msg, "error")
+ send_guru(msg_text, "error")
else:
- send_title(None, msg=msg)
+ send_title(None, msg_text=msg_text)
send_footer(None)
sys.stdout.flush()