__version__ = '4.0-' + '$Id$'[4:11]
-from time import clock
+from time import clock, localtime, gmtime, strftime
start_time = clock()
title_done = False
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):
print('</pre><script language="JavaScript" type="text/javascript" src="%s" defer="defer"></script>' \
% 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('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"')
print(' "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">')
print('<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">')
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)
<span class="benchmark">generated in %0.3fs</span> by <a href="http://www.codewiz.org/wiki/GeekiGeeki">GeekiGeeki</a> version %s
</p>
''' % (relative_url('sys/cc-by-sa.png'), clock() - start_time, __version__))
- if mod_string:
- print('<p class="modified">last modified %s</p>' % mod_string)
+ if mtime:
+ print('<p class="modified">last modified %s</p>' % strftime(datetime_fmt, localtime(mtime)))
print('</div></body></html>')
class WikiFormatter:
def _tmp_filename(self):
return os.path.join(data_dir, ('#' + self.page_name.replace('/','_') + '.' + str(os.getpid()) + '#'))
- def exists(self):
+ def _mtime(self):
try:
- os.stat(self._filename())
- return True
+ return os.stat(self._filename()).st_mtime
except OSError, err:
if err.errno == errno.ENOENT:
- return False
+ return None
raise err
+ def exists(self):
+ if self._mtime():
+ return True
+ return False
+
def get_raw_body(self, default=None):
try:
return open(self._filename(), 'rb').read()
link_urls += [ [ "stylesheet", value ] ]
send_title(self.page_name, self.split_title(),
- msg_text=self.msg_text, msg_type=self.msg_type, writable=self.can_write())
+ msg_text=self.msg_text, msg_type=self.msg_type, writable=self.can_write(), mtime=self._mtime())
self.send_naked()
- send_footer(self._last_modified())
-
- def _last_modified(self):
- try:
- from time import localtime, strftime
- modtime = localtime(os.stat(self._filename())[stat.ST_MTIME])
- except OSError, err:
- if err.errno != errno.ENOENT:
- raise err
- return None
- return strftime(datetime_fmt, modtime)
+ send_footer(mtime=self._mtime())
def send_editor(self, preview=None):
send_title(None, 'Edit ' + self.split_title(), msg_text=self.msg_text, msg_type=self.msg_type)
def send_raw(self, mimetype='text/plain', args=[]):
if not self.can_read():
- send_title(None, msg_text='Read access denied by ACLs', msg_type='notice')
+ send_title(None, msg_text='Read access denied by ACLs', msg_type='notice', mtime=self._mtime())
return
+ emit_header(self._mtime(), mimetype)
if 'maxwidth' in args:
import subprocess
- emit_header(mimetype)
sys.stdout.flush()
subprocess.check_call(['gm', 'convert', self._filename(),
'-scale', args['maxwidth'].value + ' >', '-'])
else:
body = self.get_raw_body()
- emit_header(mimetype)
print(body)
def _write_file(self, data):