[Python-checkins] r42450 - in python/trunk: Doc/lib/libbasehttp.tex Doc/lib/libsimplehttp.tex Lib/BaseHTTPServer.py Lib/SimpleHTTPServer.py

georg.brandl python-checkins at python.org
Fri Feb 17 14:34:17 CET 2006


Author: georg.brandl
Date: Fri Feb 17 14:34:16 2006
New Revision: 42450

Modified:
   python/trunk/Doc/lib/libbasehttp.tex
   python/trunk/Doc/lib/libsimplehttp.tex
   python/trunk/Lib/BaseHTTPServer.py
   python/trunk/Lib/SimpleHTTPServer.py
Log:
Patch #1417555: SimpleHTTPServer now returns Last-Modified headers.


Modified: python/trunk/Doc/lib/libbasehttp.tex
==============================================================================
--- python/trunk/Doc/lib/libbasehttp.tex	(original)
+++ python/trunk/Doc/lib/libbasehttp.tex	Fri Feb 17 14:34:16 2006
@@ -217,11 +217,16 @@
 of the \member{server_version} and \member{sys_version} class variables.
 \end{methoddesc}
 
-\begin{methoddesc}{date_time_string}{}
-Returns the current date and time, formatted for a message header.
+\begin{methoddesc}{date_time_string}{\optional{timestamp}}
+Returns the date and time given by \var{timestamp} (which must be in the
+format returned by \function{time.time()}), formatted for a message header.
+If \var{timestamp} is omitted, it uses the current date and time.
+
+The result looks like \code{'Sun, 06 Nov 1994 08:49:37 GMT'}.
+\versionadded[The \var{timestamp} parameter]{2.5}
 \end{methoddesc}
 
-\begin{methoddesc}{log_data_time_string}{}
+\begin{methoddesc}{log_date_time_string}{}
 Returns the current date and time, formatted for logging.
 \end{methoddesc}
 

Modified: python/trunk/Doc/lib/libsimplehttp.tex
==============================================================================
--- python/trunk/Doc/lib/libsimplehttp.tex	(original)
+++ python/trunk/Doc/lib/libsimplehttp.tex	Fri Feb 17 14:34:16 2006
@@ -65,13 +65,18 @@
 \var{extensions_map} variable.
 
 A \code{'Content-type:'} header with the guessed content type is
-output, followed by a blank line signifying the end of the headers,
+output, followed by a \code{'Content-Length:'} header with the file's
+size and a \code{'Last-Modified:'} header with the file's modification
+time.
+
+Then follows a blank line signifying the end of the headers,
 and then the contents of the file are output. If the file's MIME type
 starts with \code{text/} the file is opened in text mode; otherwise
 binary mode is used.
 
 For example usage, see the implementation of the \function{test()}
 function.
+\versionadded[The \code{'Last-Modified'} header]{2.5}
 \end{methoddesc}
 
 

Modified: python/trunk/Lib/BaseHTTPServer.py
==============================================================================
--- python/trunk/Lib/BaseHTTPServer.py	(original)
+++ python/trunk/Lib/BaseHTTPServer.py	Fri Feb 17 14:34:16 2006
@@ -436,10 +436,11 @@
         """Return the server software version string."""
         return self.server_version + ' ' + self.sys_version
 
-    def date_time_string(self):
+    def date_time_string(self, timestamp=None):
         """Return the current date and time formatted for a message header."""
-        now = time.time()
-        year, month, day, hh, mm, ss, wd, y, z = time.gmtime(now)
+        if timestamp is None:
+            timestamp = time.time()
+        year, month, day, hh, mm, ss, wd, y, z = time.gmtime(timestamp)
         s = "%s, %02d %3s %4d %02d:%02d:%02d GMT" % (
                 self.weekdayname[wd],
                 day, self.monthname[month], year,

Modified: python/trunk/Lib/SimpleHTTPServer.py
==============================================================================
--- python/trunk/Lib/SimpleHTTPServer.py	(original)
+++ python/trunk/Lib/SimpleHTTPServer.py	Fri Feb 17 14:34:16 2006
@@ -85,7 +85,9 @@
             return None
         self.send_response(200)
         self.send_header("Content-type", ctype)
-        self.send_header("Content-Length", str(os.fstat(f.fileno())[6]))
+        fs = os.fstat(f.fileno())
+        self.send_header("Content-Length", str(fs[6]))
+        self.send_header("Last-Modified", self.date_time_string(fs.st_mtime))
         self.end_headers()
         return f
 


More information about the Python-checkins mailing list