summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_urllib.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-09-06 18:41:39 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-09-06 18:41:39 (GMT)
commitf54c350160c16cdaf9f692e0f61ef062d4f379f4 (patch)
tree2d75c60bdc81c8837372c9e61e5f9f471c5f57a5 /Lib/test/test_urllib.py
parent1d52096d1466ed771c22a2d97e8cae6935fcdf8e (diff)
downloadcpython-f54c350160c16cdaf9f692e0f61ef062d4f379f4.zip
cpython-f54c350160c16cdaf9f692e0f61ef062d4f379f4.tar.gz
cpython-f54c350160c16cdaf9f692e0f61ef062d4f379f4.tar.bz2
Issue #19524: Fixed resource leak in the HTTP connection when an invalid
response is received. Patch by Martin Panter.
Diffstat (limited to 'Lib/test/test_urllib.py')
-rw-r--r--Lib/test/test_urllib.py59
1 files changed, 32 insertions, 27 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index 1a5013e..7eb34c8 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -48,43 +48,48 @@ def urlopen(url, data=None, proxies=None):
return opener.open(url, data)
-class FakeHTTPMixin(object):
- def fakehttp(self, fakedata):
- class FakeSocket(io.BytesIO):
- io_refs = 1
+def fakehttp(fakedata):
+ class FakeSocket(io.BytesIO):
+ io_refs = 1
- def sendall(self, data):
- FakeHTTPConnection.buf = data
+ def sendall(self, data):
+ FakeHTTPConnection.buf = data
- def makefile(self, *args, **kwds):
- self.io_refs += 1
- return self
+ def makefile(self, *args, **kwds):
+ self.io_refs += 1
+ return self
- def read(self, amt=None):
- if self.closed:
- return b""
- return io.BytesIO.read(self, amt)
+ def read(self, amt=None):
+ if self.closed:
+ return b""
+ return io.BytesIO.read(self, amt)
- def readline(self, length=None):
- if self.closed:
- return b""
- return io.BytesIO.readline(self, length)
+ def readline(self, length=None):
+ if self.closed:
+ return b""
+ return io.BytesIO.readline(self, length)
- def close(self):
- self.io_refs -= 1
- if self.io_refs == 0:
- io.BytesIO.close(self)
+ def close(self):
+ self.io_refs -= 1
+ if self.io_refs == 0:
+ io.BytesIO.close(self)
+
+ class FakeHTTPConnection(http.client.HTTPConnection):
- class FakeHTTPConnection(http.client.HTTPConnection):
+ # buffer to store data for verification in urlopen tests.
+ buf = None
+ fakesock = FakeSocket(fakedata)
- # buffer to store data for verification in urlopen tests.
- buf = None
+ def connect(self):
+ self.sock = self.fakesock
- def connect(self):
- self.sock = FakeSocket(fakedata)
+ return FakeHTTPConnection
+
+class FakeHTTPMixin(object):
+ def fakehttp(self, fakedata):
self._connection_class = http.client.HTTPConnection
- http.client.HTTPConnection = FakeHTTPConnection
+ http.client.HTTPConnection = fakehttp(fakedata)
def unfakehttp(self):
http.client.HTTPConnection = self._connection_class