[Python-checkins] r54376 - in python/trunk: Lib/test/test_urllib.py Lib/urllib.py Misc/NEWS

georg.brandl python-checkins at python.org
Wed Mar 14 09:27:53 CET 2007


Author: georg.brandl
Date: Wed Mar 14 09:27:52 2007
New Revision: 54376

Modified:
   python/trunk/Lib/test/test_urllib.py
   python/trunk/Lib/urllib.py
   python/trunk/Misc/NEWS
Log:
Bug #767111: fix long-standing bug in urllib which caused an
AttributeError instead of an IOError when the server's response didn't
contain a valid HTTP status line.


Modified: python/trunk/Lib/test/test_urllib.py
==============================================================================
--- python/trunk/Lib/test/test_urllib.py	(original)
+++ python/trunk/Lib/test/test_urllib.py	Wed Mar 14 09:27:52 2007
@@ -122,6 +122,15 @@
         finally:
             self.unfakehttp()
 
+    def test_empty_socket(self):
+        """urlopen() raises IOError if the underlying socket does not send any
+        data. (#1680230) """
+        self.fakehttp('')
+        try:
+            self.assertRaises(IOError, urllib.urlopen, 'http://something')
+        finally:
+            self.unfakehttp()
+
 class urlretrieve_FileTests(unittest.TestCase):
     """Test urllib.urlretrieve() on local files"""
 

Modified: python/trunk/Lib/urllib.py
==============================================================================
--- python/trunk/Lib/urllib.py	(original)
+++ python/trunk/Lib/urllib.py	Wed Mar 14 09:27:52 2007
@@ -326,6 +326,10 @@
         if data is not None:
             h.send(data)
         errcode, errmsg, headers = h.getreply()
+        if errcode == -1:
+            # something went wrong with the HTTP status line
+            raise IOError, ('http protocol error', 0,
+                            'got a bad status line', None)
         fp = h.getfile()
         if errcode == 200:
             return addinfourl(fp, headers, "http:" + url)
@@ -413,6 +417,10 @@
             if data is not None:
                 h.send(data)
             errcode, errmsg, headers = h.getreply()
+            if errcode == -1:
+                # something went wrong with the HTTP status line
+                raise IOError, ('http protocol error', 0,
+                                'got a bad status line', None)
             fp = h.getfile()
             if errcode == 200:
                 return addinfourl(fp, headers, "https:" + url)

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Wed Mar 14 09:27:52 2007
@@ -170,6 +170,10 @@
 Library
 -------
 
+- Bug #767111: fix long-standing bug in urllib which caused an
+  AttributeError instead of an IOError when the server's response didn't
+  contain a valid HTTP status line.
+
 - Patch #957650: "%var%" environment variable references are now properly
   expanded in ntpath.expandvars(), also "~user" home directory references
   are recognized and handled on Windows.


More information about the Python-checkins mailing list