From 637b5e74007d806f09cae0704fc356b8765919f1 Mon Sep 17 00:00:00 2001
From: Bernie Innocenti
Date: Sat, 15 Aug 2009 03:15:01 +0200
Subject: [PATCH] Send Last-Modified HTTP header
---
geekigeeki.py | 47 +++++++++++++++++++++--------------------------
1 file changed, 21 insertions(+), 26 deletions(-)
diff --git a/geekigeeki.py b/geekigeeki.py
index 5a401ab..c5b5109 100755
--- a/geekigeeki.py
+++ b/geekigeeki.py
@@ -20,7 +20,7 @@
__version__ = '4.0-' + '$Id$'[4:11]
-from time import clock
+from time import clock, localtime, gmtime, strftime
start_time = clock()
title_done = False
@@ -105,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):
@@ -119,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('')
@@ -332,7 +334,7 @@ def page_list(dirname=None, re=None):
re = re.compile(r"^\b((([A-Z][a-z0-9]+){2,}/)*([A-Z][a-z0-9]+){2,})\b$")
return sorted(filter(re.match, os.listdir(dirname or data_dir)))
-def send_footer(mod_string=None):
+def send_footer(mtime=None):
if globals().get('debug_cgi', False):
cgi.print_arguments()
cgi.print_form(form)
@@ -345,8 +347,8 @@ def send_footer(mod_string=None):
generated in %0.3fs by GeekiGeeki version %s
''' % (relative_url('sys/cc-by-sa.png'), clock() - start_time, __version__))
- if mod_string:
- print('last modified %s
' % mod_string)
+ if mtime:
+ print('last modified %s
' % strftime(datetime_fmt, localtime(mtime)))
print('