[Python-checkins] cpython (3.3): Backporing the fix from Issue #12692

senthil.kumaran python-checkins at python.org
Sun Dec 29 02:37:47 CET 2013


http://hg.python.org/cpython/rev/a43e96695203
changeset: 88219:a43e96695203
branch: 3.3
parent: 88212:a00842b783cf
user: Senthil Kumaran <senthil at uthcode.com>
date: Sat Dec 28 17:36:18 2013 -0800
summary:
 Backporing the fix from Issue #12692
files:
 Lib/test/test_urllib2.py | 1 +
 Lib/urllib/request.py | 6 ++++++
 Misc/NEWS | 3 +++
 3 files changed, 10 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
@@ -283,6 +283,7 @@
 self.req_headers = []
 self.data = None
 self.raise_on_endheaders = False
+ self.sock = None
 self._tunnel_headers = {}
 
 def __call__(self, host, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -1251,6 +1251,12 @@
 raise URLError(err)
 else:
 r = h.getresponse()
+ # If the server does not send us a 'Connection: close' header,
+ # HTTPConnection assumes the socket should be left open. Manually
+ # mark the socket to be closed when this response object goes away.
+ if h.sock:
+ h.sock.close()
+ h.sock = None
 
 r.url = req.get_full_url()
 # This line replaces the .msg attribute of the HTTPResponse
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,9 @@
 Library
 -------
 
+- Issue #12692: Backport the fix for ResourceWarning in test_urllib2net. This
+ also helps in closing the socket when Connection Close header is not sent.
+
 - Issue #19422: Explicitly disallow non-SOCK_STREAM sockets in the ssl
 module, rather than silently let them emit clear text data.
 
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /