X-Git-Url: https://codewiz.org/gitweb?p=geekigeeki.git;a=blobdiff_plain;f=geekigeeki.py;h=5340646c63101b24629d96a26ff2adea8e66a3b7;hp=99234c539c0d23b2cd69c587773de617bdc05a70;hb=61f00a0d333aeb1cb45e98ab4c1902ff1981ad6a;hpb=64737bb01dc7cf5cb5759f7a077e8edbede2dbca
diff --git a/geekigeeki.py b/geekigeeki.py
index 99234c5..5340646 100755
--- a/geekigeeki.py
+++ b/geekigeeki.py
@@ -1,10 +1,9 @@
-#! /usr/bin/env python
-"""Quick-quick implementation of WikiWikiWeb in Python
-"""
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
#
-# Copyright (C) 1999, 2000 Martin Pool
-# This version includes additional changes by Gerardo Poggiali (2002)
-# This version includes additional changes by Bernardo Innocenti (2007)
+# Copyright 1999, 2000 Martin Pool
+# Copyright 2002 Gerardo Poggiali
+# Copyright 2007, 2008 Bernardo Innocenti
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -19,40 +18,65 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-__version__ = '$Revision: 1.63+gerry+bernie $'[11:-2];
+__version__ = '$Id$'[4:12]
-import cgi, sys, string, os, re, errno, time, stat
+from time import clock
+start_time = clock()
+
+import cgi, sys, string, os, re, errno, stat
from os import path, environ
-from socket import gethostbyaddr
-from time import localtime, strftime
# 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,}\b$")
+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$")
img_re = re.compile(r"^.*\.(png|gif|jpg|jpeg)$", re.IGNORECASE)
url_re = re.compile(r"^[a-z]{3,8}://[^\s'\"]+\S$")
title_done = False
-def emit_header(type="text/html"):
- print "Content-type: " + type + "; charset=utf-8"
- print
-
-# Formatting stuff --------------------------------------------------
+# CGI stuff ---------------------------------------------------------
-def get_scriptname():
+def script_name():
return environ.get('SCRIPT_NAME', '')
+def privileged_path():
+ return privileged_url or script_name()
+
+def remote_user():
+ user = environ.get('REMOTE_USER', '')
+ if user is None or user == '' or user == 'anonymous':
+ user = 'AnonymousCoward'
+ return user
+
+def remote_host():
+ return environ.get('REMOTE_ADDR', '')
+
def get_hostname(addr):
try:
+ from socket import gethostbyaddr
return gethostbyaddr(addr)[0] + ' (' + addr + ')'
except:
- return addr;
+ return addr
+
+def relative_url(path, privileged=False):
+ if not (url_re.match(path) or path.startswith('/')):
+ if privileged:
+ url = privileged_path()
+ else:
+ url = script_name()
+ path = url + '/' + path
+ return path
+
+# Formatting stuff --------------------------------------------------
+
+def emit_header(type="text/html"):
+ print "Content-type: " + type + "; charset=utf-8"
+ print
def send_guru(msg, msg_type):
- if msg is None or len(msg) == 0: return
+ if msg is None or msg == '': return
print '
'
if msg_type == 'error':
print ' Software Failure. Press left mouse button to continue.\n'
@@ -60,7 +84,7 @@ def send_guru(msg, msg_type):
if msg_type == 'error':
print ' Guru Meditation #DEADBEEF.ABADC0DE'
print '
'
- # FIXME: This simple JS code is harder to pass than ACID 3.0
+ # FIXME: This simple JS snippet is harder to pass than ACID 3.0
print """
"""
-def send_title(name, text="Limbo", msg=None, msg_type = 'error'):
+def send_title(name, text="Limbo", msg=None, msg_type='error'):
global title_done
if title_done: return
# Head
emit_header()
- print """
-
-"""
+ print ''
+ print ''
+
+ site_name = globals().get('site_name', 'Unconfigured Site')
print "%s: %s" % (site_name, text)
- print ' '
+ print ' '
if not name:
- print ' '
- if css_url:
- print ' ' % css_url
+ print ' '
+ for css in css_url:
+ print ' ' % relative_url(css)
print ''
# Body
- if name and allow_edit:
- print ''
+ if name and privileged_url is not None:
+ print ''
else:
print ''
+ title_done = True
send_guru(msg, msg_type)
# Navbar
- print '