[Python-3000-checkins] r57477 - python/branches/py3k/Lib/urllib.py python/branches/py3k/Lib/urllib2.py

neal.norwitz python-3000-checkins at python.org
Sat Aug 25 21:00:31 CEST 2007


Author: neal.norwitz
Date: Sat Aug 25 21:00:31 2007
New Revision: 57477

Modified:
   python/branches/py3k/Lib/urllib.py
   python/branches/py3k/Lib/urllib2.py
Log:
Get the urllib tests to pass without the email package

Modified: python/branches/py3k/Lib/urllib.py
==============================================================================
--- python/branches/py3k/Lib/urllib.py	(original)
+++ python/branches/py3k/Lib/urllib.py	Sat Aug 25 21:00:31 2007
@@ -403,7 +403,7 @@
 
     def open_local_file(self, url):
         """Use local file."""
-        import mimetypes, mimetools, email.utils
+        import mimetypes, mimetools #, email.utils
         from io import StringIO
         host, file = splithost(url)
         localname = url2pathname(file)
@@ -412,7 +412,17 @@
         except OSError as e:
             raise IOError(e.errno, e.strerror, e.filename)
         size = stats.st_size
-        modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
+        # XXX(nnorwitz): inline formatdate until it is restored.
+        #modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
+        now, zone = time.gmtime(stats.st_mtime), 'GMT'
+        modified = '%s, %02d %s %04d %02d:%02d:%02d %s' % (
+            ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][now[6]],
+            now[2],
+            ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
+             'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][now[1] - 1],
+            now[0], now[3], now[4], now[5],
+            zone)
+
         mtype = mimetypes.guess_type(url)[0]
         headers = mimetools.Message(StringIO(
             'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' %

Modified: python/branches/py3k/Lib/urllib2.py
==============================================================================
--- python/branches/py3k/Lib/urllib2.py	(original)
+++ python/branches/py3k/Lib/urllib2.py	Sat Aug 25 21:00:31 2007
@@ -1201,7 +1201,7 @@
 
     # not entirely sure what the rules are here
     def open_local_file(self, req):
-        import email.utils
+        #import email.utils
         import mimetypes
         host = req.get_host()
         file = req.get_selector()
@@ -1209,7 +1209,17 @@
         try:
             stats = os.stat(localfile)
             size = stats.st_size
-            modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
+            #modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
+            # XXX(nnorwitz): inline formatdate until it is restored.
+            now, zone = time.gmtime(stats.st_mtime), 'GMT'
+            modified = '%s, %02d %s %04d %02d:%02d:%02d %s' % (
+        ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][now[6]],
+        now[2],
+        ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
+         'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][now[1] - 1],
+        now[0], now[3], now[4], now[5],
+        zone)
+
             mtype = mimetypes.guess_type(file)[0]
             headers = mimetools.Message(StringIO(
                 'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %


More information about the Python-3000-checkins mailing list