diff options
| author | Facundo Batista <facundobatista@gmail.com> | 2008-05-29 16:39:26 (GMT) |
|---|---|---|
| committer | Facundo Batista <facundobatista@gmail.com> | 2008-05-29 16:39:26 (GMT) |
| commit | 4f1b1ed975fe25170d00559e63f992c9bf8e9b8a (patch) | |
| tree | 0f2a0434dc9ad0181633f649611e417aa4a6ea61 /Lib/test/test_httplib.py | |
| parent | f18a70720542268586e271bbadab3fb0332b8a39 (diff) | |
| download | cpython-4f1b1ed975fe25170d00559e63f992c9bf8e9b8a.zip cpython-4f1b1ed975fe25170d00559e63f992c9bf8e9b8a.tar.gz cpython-4f1b1ed975fe25170d00559e63f992c9bf8e9b8a.tar.bz2 | |
Fixed the semantic of timeout for socket.create_connection and
all the upper level libraries that use it, including urllib2.
Added and fixed some tests, and changed docs correspondingly.
Thanks to John J Lee for the patch and the pusing, :)
Diffstat (limited to 'Lib/test/test_httplib.py')
| -rw-r--r-- | Lib/test/test_httplib.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index fcbddd0..e2560b6 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -214,27 +214,32 @@ class TimeoutTest(TestCase): '''This will prove that the timeout gets through HTTPConnection and into the socket. ''' - # default - httpConn = httplib.HTTPConnection(HOST, TimeoutTest.PORT) - httpConn.connect() - self.assertTrue(httpConn.sock.gettimeout() is None) - httpConn.close() - - # a value - httpConn = httplib.HTTPConnection(HOST, TimeoutTest.PORT, timeout=30) - httpConn.connect() + # default -- use global socket timeout + self.assert_(socket.getdefaulttimeout() is None) + socket.setdefaulttimeout(30) + try: + httpConn = httplib.HTTPConnection(HOST, TimeoutTest.PORT) + httpConn.connect() + finally: + socket.setdefaulttimeout(None) self.assertEqual(httpConn.sock.gettimeout(), 30) httpConn.close() - # None, having other default - previous = socket.getdefaulttimeout() + # no timeout -- do not use global socket default + self.assert_(socket.getdefaulttimeout() is None) socket.setdefaulttimeout(30) try: httpConn = httplib.HTTPConnection(HOST, TimeoutTest.PORT, timeout=None) httpConn.connect() finally: - socket.setdefaulttimeout(previous) + socket.setdefaulttimeout(None) + self.assertEqual(httpConn.sock.gettimeout(), None) + httpConn.close() + + # a value + httpConn = httplib.HTTPConnection(HOST, TimeoutTest.PORT, timeout=30) + httpConn.connect() self.assertEqual(httpConn.sock.gettimeout(), 30) httpConn.close() |
