Commit c74a6ba2 authored by Victor Stinner's avatar Victor Stinner

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.
parent 898d43c7
......@@ -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
......
......@@ -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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment