diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2014-09-06 18:43:49 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2014-09-06 18:43:49 (GMT) |
commit | 91453026ffab6f0b3278417dc6348f3310d70be0 (patch) | |
tree | a41533f76b143e563b01666d0c09a7e2ec6780c0 /Lib/test/test_urllib.py | |
parent | d8a1447c9980be5f1d8ae806f7aecd814b1cd6f6 (diff) | |
parent | f54c350160c16cdaf9f692e0f61ef062d4f379f4 (diff) | |
download | cpython-91453026ffab6f0b3278417dc6348f3310d70be0.zip cpython-91453026ffab6f0b3278417dc6348f3310d70be0.tar.gz cpython-91453026ffab6f0b3278417dc6348f3310d70be0.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.py | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index ca029d3..5478837 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 |