[Python-checkins] cpython (merge 3.2 -> default): Closes issue11563 test_urllibnet is triggering a ResourceWarning. Patch by Jeff

senthil.kumaran python-checkins at python.org
Sat Mar 19 10:47:44 CET 2011


http://hg.python.org/cpython/rev/dfceb98767c0
changeset: 68678:dfceb98767c0
parent: 68676:f5433ff205ed
parent: 68677:d84896ba7576
user: Senthil Kumaran <orsenthil at gmail.com>
date: Sat Mar 19 17:47:26 2011 +0800
summary:
 Closes issue11563 test_urllibnet is triggering a ResourceWarning. Patch by Jeff McNeil.
files:
 Lib/test/test_urllib.py
 Lib/urllib/request.py
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -91,7 +91,7 @@
 "did not return the expected text")
 
 def test_close(self):
- # Test close() by calling it hear and then having it be called again
+ # Test close() by calling it here and then having it be called again
 # by the tearDown() method for the test
 self.returned_obj.close()
 
@@ -174,6 +174,11 @@
 finally:
 self.unfakehttp()
 
+ def test_willclose(self):
+ self.fakehttp(b"HTTP/1.1 200 OK\r\n\r\nHello!")
+ resp = urlopen("http://www.python.org")
+ self.assertTrue(resp.fp.will_close)
+
 def test_read_0_9(self):
 # "0.9" response accepted (but not "simple responses" without
 # a status line)
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -1657,6 +1657,12 @@
 headers["Authorization"] = "Basic %s" % auth
 if realhost:
 headers["Host"] = realhost
+
+ # Add Connection:close as we don't support persistent connections yet.
+ # This helps in closing the socket and avoiding ResourceWarning
+
+ headers["Connection"] = "close"
+
 for header, value in self.addheaders:
 headers[header] = value
 
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

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