X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=geekigeeki.py;h=764f3665de6fff91f4e773fc918cdae5adb65a7a;hb=99acd9376fc3cdaf9dfe9218c78aede47c54968c;hp=a1c99a02742b3a862e2590af9b64addcd40fe6a3;hpb=4b551793f87baab929ddac359aa48b3eac34ac54;p=geekigeeki.git diff --git a/geekigeeki.py b/geekigeeki.py index a1c99a0..764f366 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -23,13 +23,14 @@ __version__ = '$Id$'[4:12] 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 # (but this definition is also assumed in other places) -file_re = re.compile(r"^\b([A-Za-z0-9_\.\-/]+)\b$") word_re = re.compile(r"^\b((([A-Z][a-z]+){2,}/)*([A-Z][a-z]+){2,})\b$") +# FIXME: we accept stuff like foo/../bar and we shouldn't +file_re = re.compile(r"^\b([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)\b$") img_re = re.compile(r"^.*\.(png|gif|jpg|jpeg)$", re.IGNORECASE) url_re = re.compile(r"^[a-z]{3,8}://[^\s'\"]+\S$") @@ -57,30 +58,29 @@ def get_hostname(addr): 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 '
'
     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 '
' @@ -107,7 +107,7 @@ def send_guru(msg, msg_type): } """ -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 @@ -133,7 +133,7 @@ def send_title(name, text="Limbo", msg=None, msg_type='error'): print '' title_done = True - send_guru(msg, msg_type) + send_guru(msg_text, msg_type) # Navbar print '