]> granicus.if.org Git - python/commitdiff
Fix issue8582: urllib.urlretrieve fails with ValueError: Invalid format string
authorSenthil Kumaran <orsenthil@gmail.com>
Sat, 1 May 2010 08:01:56 +0000 (08:01 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Sat, 1 May 2010 08:01:56 +0000 (08:01 +0000)
Lib/test/test_urllibnet.py
Lib/urllib.py

index 8eb01e577e02b35a8d97905b67d8a6274e2c1e16..8cba2dc779302fa044713fe253b135e9dea20d1f 100644 (file)
@@ -7,6 +7,8 @@ import socket
 import urllib
 import sys
 import os
+import time
+
 mimetools = test_support.import_module("mimetools", deprecated=True)
 
 
@@ -178,6 +180,17 @@ class urlretrieveNetworkTests(unittest.TestCase):
         self.assertIsInstance(header, mimetools.Message,
                               "header is not an instance of mimetools.Message")
 
+    def test_data_header(self):
+        logo = "http://www.python.org/community/logos/python-logo-master-v3-TM.png"
+        file_location, fileheaders = self.urlretrieve(logo)
+        os.unlink(file_location)
+        datevalue = fileheaders.getheader('Date')
+        dateformat = '%a, %d %b %Y %H:%M:%S GMT'
+        try:
+            time.strptime(datevalue, dateformat)
+        except ValueError:
+            self.fail('Date value not in %r format', dateformat)
+
 
 
 def test_main():
index c74dd3c0c81f8534ba6eb7ff5af3ba587d9bf24f..652be754b6efa20673f29760ab7fcdbd9a10f5d8 100644 (file)
@@ -588,7 +588,7 @@ class URLopener:
         else:
             encoding = ''
         msg = []
-        msg.append('Date: %s'%time.strftime('%a, %d %b %Y %T GMT',
+        msg.append('Date: %s'%time.strftime('%a, %d %b %Y %H:%M:%S GMT',
                                             time.gmtime(time.time())))
         msg.append('Content-type: %s' % type)
         if encoding == 'base64':