# HG changeset patch # User Paul Boddie # Date 1226947979 -3600 # Node ID 74944fdeb7b95bd6c4f9446245b73c92dd856c36 # Parent 80acb43f574adbe0bd08c5eff260e75446a34666 Fixed support for Python 2.3. diff -r 80acb43f574a -r 74944fdeb7b9 WebStack/Resources/Static.py --- a/WebStack/Resources/Static.py Sat Nov 15 02:33:55 2008 +0100 +++ b/WebStack/Resources/Static.py Mon Nov 17 19:52:59 2008 +0100 @@ -22,7 +22,17 @@ from WebStack.Generic import ContentType, EndOfResponse import os -import email.utils +try: + from email.utils import formatdate +except ImportError: + from email.Utils import formatdate as _formatdate + def formatdate(timeval=None, localtime=False, usegmt=False): + s = _formatdate(timeval, localtime) + l = s.split(" ") # get components + if usegmt: + del l[-1] # remove time-zone offset + l.append("GMT") # add mandatory name + return " ".join(l) class DirectoryResource: @@ -119,7 +129,7 @@ # Write the file to the client. pathname = os.path.join(self.directory, filename) - mtime = email.utils.formatdate(os.path.getmtime(pathname), usegmt=1) + mtime = formatdate(os.path.getmtime(pathname), usegmt=1) trans.set_header_value("Last-Modified", mtime) f = open(pathname, "rb") @@ -148,7 +158,7 @@ self.content_type = content_type def respond(self, trans): - mtime = email.utils.formatdate(os.path.getmtime(self.filename), usegmt=1) + mtime = formatdate(os.path.getmtime(self.filename), usegmt=1) trans.set_content_type(self.content_type) trans.set_header_value("Last-Modified", mtime)