diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-06-17 12:06:27 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-06-17 12:06:27 (GMT) |
commit | c74a6ba2d6c1f331896cf8dacc698b0b88c7e670 (patch) | |
tree | 0ca7a6da7610fa8d084519c371e1ef7100289fc9 | |
parent | 898d43c7af909ba2e154cfd2d09dd8d604b0615c (diff) | |
download | cpython-c74a6ba2d6c1f331896cf8dacc698b0b88c7e670.zip cpython-c74a6ba2d6c1f331896cf8dacc698b0b88c7e670.tar.gz cpython-c74a6ba2d6c1f331896cf8dacc698b0b88c7e670.tar.bz2 |
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.
-rw-r--r-- | Lib/test/test_urllib2.py | 5 | ||||
-rw-r--r-- | Lib/urllib2.py | 2 | ||||
-rw-r--r-- | Misc/NEWS | 4 |
3 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py index e96f948..e889bc3 100644 --- a/Lib/test/test_urllib2.py +++ b/Lib/test/test_urllib2.py @@ -293,6 +293,7 @@ class MockHTTPClass: 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 @@ class MockHTTPClass: 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 index abc84b1..2641619 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -1172,6 +1172,8 @@ class AbstractHTTPHandler(BaseHandler): 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. @@ -16,6 +16,10 @@ Core and Builtins 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. |