mirror of https://github.com/python/cpython.git
Issue #12133: fix a ResourceWarning in urllib.request
AbstractHTTPHandler.do_open() of urllib.request closes the HTTP connection if its getresponse() method fails with a socket error. Patch written by Ezio Melotti.
This commit is contained in:
parent
0f83b1511c
commit
a4c45d73cf
|
@ -317,6 +317,9 @@ def request(self, method, url, body=None, headers=None):
|
||||||
def getresponse(self):
|
def getresponse(self):
|
||||||
return MockHTTPResponse(MockFile(), {}, 200, "OK")
|
return MockHTTPResponse(MockFile(), {}, 200, "OK")
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
pass
|
||||||
|
|
||||||
class MockHandler:
|
class MockHandler:
|
||||||
# useful for testing handler machinery
|
# useful for testing handler machinery
|
||||||
# see add_ordered_mock_handlers() docstring
|
# see add_ordered_mock_handlers() docstring
|
||||||
|
|
|
@ -1137,6 +1137,8 @@ def do_open(self, http_class, req, **http_conn_args):
|
||||||
r = h.getresponse() # an HTTPResponse instance
|
r = h.getresponse() # an HTTPResponse instance
|
||||||
except socket.error as err:
|
except socket.error as err:
|
||||||
raise URLError(err)
|
raise URLError(err)
|
||||||
|
finally:
|
||||||
|
h.close()
|
||||||
|
|
||||||
r.url = req.get_full_url()
|
r.url = req.get_full_url()
|
||||||
# This line replaces the .msg attribute of the HTTPResponse
|
# This line replaces the .msg attribute of the HTTPResponse
|
||||||
|
|
|
@ -25,6 +25,10 @@ Core and Builtins
|
||||||
Library
|
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
|
- Issue #9284: Allow inspect.findsource() to find the source of doctest
|
||||||
functions.
|
functions.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue