[Python-checkins] cpython (2.7): Issue #12133: AbstractHTTPHandler.do_open() of urllib.request closes the HTTP

victor.stinner python-checkins at python.org
Fri Jun 17 14:06:29 CEST 2011


http://hg.python.org/cpython/rev/18e6ccc332d5
changeset:   70837:18e6ccc332d5
branch:      2.7
parent:      70824:0cb49ca95109
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Fri Jun 17 14:06:27 2011 +0200
summary:
  Issue #12133: AbstractHTTPHandler.do_open() of urllib.request closes the HTTP
connection if its getresponse() method fails with a socket error. Patch written
by Ezio Melotti.

files:
  Lib/test/test_urllib2.py |  5 +++++
  Lib/urllib2.py           |  2 ++
  Misc/NEWS                |  4 ++++
  3 files changed, 11 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -293,6 +293,7 @@
             self._tunnel_headers = headers
         else:
             self._tunnel_headers.clear()
+
     def request(self, method, url, body=None, headers=None):
         self.method = method
         self.selector = url
@@ -304,9 +305,13 @@
         if self.raise_on_endheaders:
             import socket
             raise socket.error()
+
     def getresponse(self):
         return MockHTTPResponse(MockFile(), {}, 200, "OK")
 
+    def close(self):
+        pass
+
 class MockHandler:
     # useful for testing handler machinery
     # see add_ordered_mock_handlers() docstring
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -1172,6 +1172,8 @@
                 r = h.getresponse()
         except socket.error, err: # XXX what error?
             raise URLError(err)
+        finally:
+            h.close()
 
         # Pick apart the HTTPResponse object to get the addinfourl
         # object initialized properly.
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -16,6 +16,10 @@
 Library
 -------
 
+- Issue #12133: AbstractHTTPHandler.do_open() of urllib.request closes the HTTP
+  connection if its getresponse() method fails with a socket error. Patch
+  written by Ezio Melotti.
+
 - Issue #9284: Allow inspect.findsource() to find the source of doctest
   functions.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list