summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5b02534)
raw | patch | inline | side by side (parent: 5b02534)
author | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Wed, 26 Feb 2003 04:51:41 +0000 (04:51 +0000) | ||
committer | richard <richard@57a73879-2fb5-44c3-a270-3262357dd7e2> | |
Wed, 26 Feb 2003 04:51:41 +0000 (04:51 +0000) |
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1546 57a73879-2fb5-44c3-a270-3262357dd7e2
roundup/cgi/client.py | patch | blob | history | |
roundup/scripts/roundup_server.py | patch | blob | history |
diff --git a/roundup/cgi/client.py b/roundup/cgi/client.py
index 10848f0808401e582e5d5814490bff6e235922d7..174e4e8a95d9a6298111ca3abc5753c0145a78c3 100644 (file)
--- a/roundup/cgi/client.py
+++ b/roundup/cgi/client.py
-# $Id: client.py,v 1.98 2003-02-26 04:08:04 richard Exp $
+# $Id: client.py,v 1.99 2003-02-26 04:51:41 richard Exp $
__doc__ = """
WWW request handler (also used in the stand-alone server).
import os, os.path, cgi, StringIO, urlparse, re, traceback, mimetypes, urllib
import binascii, Cookie, time, random, MimeWriter, smtplib, socket, quopri
+import stat, rfc822
from roundup import roundupdb, date, hyperdb, password
from roundup.i18n import _
pass
class Redirect(HTTPException):
pass
+class NotModified(HTTPException):
+ pass
# XXX actually _use_ FormError
class FormError(ValueError):
except SendFile, designator:
self.serve_file(designator)
except SendStaticFile, file:
- self.serve_static_file(str(file))
+ try:
+ self.serve_static_file(str(file))
+ except NotModified:
+ # send the 304 response
+ self.request.send_response(304)
+ self.request.end_headers()
except Unauthorised, message:
self.classname = None
self.template = ''
self.write(file.get(nodeid, 'content'))
def serve_static_file(self, file):
+ # see if there's an if-modified-since...
+ ims = self.request.headers.getheader('if-modified-since')
+ # cgi will put the header in the env var
+ if not ims and self.env.has_key('HTTP_IF_MODIFIED_SINCE'):
+ ims = self.env['HTTP_IF_MODIFIED_SINCE']
+ filename = os.path.join(self.instance.config.TEMPLATES, file)
+ lmt = os.stat(filename)[stat.ST_MTIME]
+ if ims:
+ ims = rfc822.parsedate(ims)[:6]
+ lmtt = time.gmtime(lmt)[:6]
+ if lmtt <= ims:
+ raise NotModified
+
# we just want to serve up the file named
mt = mimetypes.guess_type(str(file))[0]
+ if not mt:
+ mt = 'text/plain'
self.additional_headers['Content-Type'] = mt
- self.write(open(os.path.join(self.instance.config.TEMPLATES,
- file)).read())
+ self.additional_headers['Last-Modifed'] = rfc822.formatdate(lmt)
+ self.write(open(filename).read())
def renderContext(self):
''' Return a PageTemplate for the named page
index afe9d5edead6b4c96705337df4dee7a33af33a70..8c850488522c5ebf862bb7c373f9735d1fc45ed8 100644 (file)
#
""" HTTP Server that serves roundup.
-$Id: roundup_server.py,v 1.18 2003-02-06 05:43:49 richard Exp $
+$Id: roundup_server.py,v 1.19 2003-02-26 04:51:41 richard Exp $
"""
# python version check
self.wfile.write(cgitb.breaker())
self.wfile.write(cgitb.html())
except:
- self.wfile.write("<pre>")
s = StringIO.StringIO()
traceback.print_exc(None, s)
+ self.wfile.write("<pre>")
self.wfile.write(cgi.escape(s.getvalue()))
self.wfile.write("</pre>\n")
sys.stdin = save_stdin