X-Git-Url: https://codewiz.org/gitweb?p=geekigeeki.git;a=blobdiff_plain;f=geekigeeki.py;h=c5b51096a1fbecfe242b189b8d84625b152cdb65;hp=368cf8dace07ae045d9580f9616e9370e1b45221;hb=99fb949cf7923eaab08664706287c120b1a93d79;hpb=b70950f8de51524453f99b4809c726212a5fa2f3 diff --git a/geekigeeki.py b/geekigeeki.py index 368cf8d..c5b5109 100755 --- a/geekigeeki.py +++ b/geekigeeki.py @@ -18,21 +18,22 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -__version__ = '$Id$'[4:12] +__version__ = '4.0-' + '$Id$'[4:11] -from time import clock +from time import clock, localtime, gmtime, strftime start_time = clock() +title_done = False import cgi, sys, os, re, errno, stat +image_ext = 'png|gif|jpg|jpeg|bmp|ico' +video_ext = "ogg|ogv|oga" # Not supported by Firefox 3.5: mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt +image_re = re.compile(r".*\.(" + image_ext + "|" + video_ext + ")", re.IGNORECASE) +video_re = re.compile(r".*\.(" + video_ext + ")", re.IGNORECASE) # 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|bmp|ico|ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt)$", re.IGNORECASE) -video_re = re.compile(r"^.*\.(ogm|ogg|mkv|mpg|mpeg|mp4|avi|asf|flv|wmv|qt)$", re.IGNORECASE) -url_re = re.compile(r"^[a-z]{3,8}://[^\s'\"]+\S$") -ext_re = re.compile(r"\.([^\./]+)$") - -title_done = False +file_re = re.compile(r"([A-Za-z0-9_\-][A-Za-z0-9_\.\-/]*)") +url_re = re.compile(r"[a-z]{3,8}://[^\s'\"]+\S") +ext_re = re.compile(r"\.([^\./]+)$") # CGI stuff --------------------------------------------------------- def script_name(): @@ -80,7 +81,7 @@ def permalink(s): return re.sub(' ', '-', re.sub('[^a-z0-9_ ]', '', s.lower()).strip()) def humanlink(s): - return re.compile('([^:/\.]+)(?:\.[^/:]+|)$').search(s).group(1).replace('_', ' ') + return re.sub(r'(?:.*[/:]|)([^:/\.]+)(?:\.[^/:]+|)$', r'\1', s.replace('_', ' ')) # Split arg lists like "blah| blah blah| width=100 | align = center", # return a list containing anonymous arguments and a map containing the named arguments @@ -88,10 +89,10 @@ def parse_args(s): args = [] kwargs = {} for arg in s.strip('<[{}]>').split('|'): - try: - key, val = arg.split('=', 1) - kwargs[key.strip()] = val.strip() - except ValueError: + m = re.match('\s*(\w+)\s*=\s*(.+)\s*', arg) + if m is not None: + kwargs[m.group(1)] = m.group(2) + else: args.append(arg.strip()) return (args, kwargs) @@ -104,7 +105,9 @@ def url_args(kvargs): return '' # Formatting stuff -------------------------------------------------- -def emit_header(mime_type="text/html"): +def emit_header(mtime=None, mime_type="text/html"): + if mtime: + print("Last-Modified: " + strftime("%a, %d %b %Y %H:%M:%S GMT", gmtime(mtime))) print("Content-type: " + mime_type + "; charset=utf-8\n") def send_guru(msg_text, msg_type): @@ -118,12 +121,12 @@ def send_guru(msg_text, msg_type): print('' \ % relative_url('sys/GuruMeditation.js')) -def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=False): +def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=False, mtime=None): global title_done if title_done: return # Head - emit_header() + emit_header(mtime) print('') print('') @@ -162,24 +165,24 @@ def send_title(name, text="Limbo", msg_text=None, msg_type='error', writable=Fal # Navbar print('