summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_socket.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-01-21 10:35:10 (GMT)
committerGeorg Brandl <georg@python.org>2007-01-21 10:35:10 (GMT)
commitdd7b0525e902ee12a612611ea082e12f5999c823 (patch)
treeea6fda1769b0311d8f166d05d32d112afaa82c25 /Lib/test/test_socket.py
parentb84c13792db49abdfac97663badfeda0bba11279 (diff)
downloadcpython-dd7b0525e902ee12a612611ea082e12f5999c823.zip
cpython-dd7b0525e902ee12a612611ea082e12f5999c823.tar.gz
cpython-dd7b0525e902ee12a612611ea082e12f5999c823.tar.bz2
Patch #1627441: close sockets properly in urllib2.
Diffstat (limited to 'Lib/test/test_socket.py')
-rw-r--r--Lib/test/test_socket.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py
index 1357d54..c56c3b7 100644
--- a/Lib/test/test_socket.py
+++ b/Lib/test/test_socket.py
@@ -809,6 +809,31 @@ class SmallBufferedFileObjectClassTestCase(FileObjectClassTestCase):
bufsize = 2 # Exercise the buffering code
+
+class Urllib2FileobjectTest(unittest.TestCase):
+
+ # urllib2.HTTPHandler has "borrowed" socket._fileobject, and requires that
+ # it close the socket if the close c'tor argument is true
+
+ def testClose(self):
+ class MockSocket:
+ closed = False
+ def flush(self): pass
+ def close(self): self.closed = True
+
+ # must not close unless we request it: the original use of _fileobject
+ # by module socket requires that the underlying socket not be closed until
+ # the _socketobject that created the _fileobject is closed
+ s = MockSocket()
+ f = socket._fileobject(s)
+ f.close()
+ self.assert_(not s.closed)
+
+ s = MockSocket()
+ f = socket._fileobject(s, close=True)
+ f.close()
+ self.assert_(s.closed)
+
class TCPTimeoutTest(SocketTCPTest):
def testTCPTimeout(self):
@@ -961,7 +986,8 @@ def test_main():
FileObjectClassTestCase,
UnbufferedFileObjectClassTestCase,
LineBufferedFileObjectClassTestCase,
- SmallBufferedFileObjectClassTestCase
+ SmallBufferedFileObjectClassTestCase,
+ Urllib2FileobjectTest,
])
if hasattr(socket, "socketpair"):
tests.append(BasicSocketPairTest)