mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
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, :)
This commit is contained in:
parent
f18a707205
commit
4f1b1ed975
24 changed files with 231 additions and 180 deletions
|
|
@ -53,35 +53,52 @@ class GeneralTests(TestCase):
|
|||
# connects
|
||||
ftp = ftplib.FTP(HOST)
|
||||
self.evt.wait()
|
||||
ftp.sock.close()
|
||||
ftp.close()
|
||||
|
||||
def testTimeoutDefault(self):
|
||||
# default
|
||||
ftp = ftplib.FTP(HOST)
|
||||
# default -- use global socket timeout
|
||||
self.assert_(socket.getdefaulttimeout() is None)
|
||||
socket.setdefaulttimeout(30)
|
||||
try:
|
||||
ftp = ftplib.FTP("localhost")
|
||||
finally:
|
||||
socket.setdefaulttimeout(None)
|
||||
self.assertEqual(ftp.sock.gettimeout(), 30)
|
||||
self.evt.wait()
|
||||
ftp.close()
|
||||
|
||||
def testTimeoutNone(self):
|
||||
# no timeout -- do not use global socket timeout
|
||||
self.assert_(socket.getdefaulttimeout() is None)
|
||||
socket.setdefaulttimeout(30)
|
||||
try:
|
||||
ftp = ftplib.FTP("localhost", timeout=None)
|
||||
finally:
|
||||
socket.setdefaulttimeout(None)
|
||||
self.assertTrue(ftp.sock.gettimeout() is None)
|
||||
self.evt.wait()
|
||||
ftp.sock.close()
|
||||
ftp.close()
|
||||
|
||||
def testTimeoutValue(self):
|
||||
# a value
|
||||
ftp = ftplib.FTP(HOST, timeout=30)
|
||||
self.assertEqual(ftp.sock.gettimeout(), 30)
|
||||
self.evt.wait()
|
||||
ftp.sock.close()
|
||||
ftp.close()
|
||||
|
||||
def testTimeoutConnect(self):
|
||||
ftp = ftplib.FTP()
|
||||
ftp.connect(HOST, timeout=30)
|
||||
self.assertEqual(ftp.sock.gettimeout(), 30)
|
||||
self.evt.wait()
|
||||
ftp.sock.close()
|
||||
ftp.close()
|
||||
|
||||
def testTimeoutDifferentOrder(self):
|
||||
ftp = ftplib.FTP(timeout=30)
|
||||
ftp.connect(HOST)
|
||||
self.assertEqual(ftp.sock.gettimeout(), 30)
|
||||
self.evt.wait()
|
||||
ftp.sock.close()
|
||||
ftp.close()
|
||||
|
||||
def testTimeoutDirectAccess(self):
|
||||
ftp = ftplib.FTP()
|
||||
|
|
@ -89,18 +106,6 @@ class GeneralTests(TestCase):
|
|||
ftp.connect(HOST)
|
||||
self.assertEqual(ftp.sock.gettimeout(), 30)
|
||||
self.evt.wait()
|
||||
ftp.sock.close()
|
||||
|
||||
def testTimeoutNone(self):
|
||||
# None, having other default
|
||||
previous = socket.getdefaulttimeout()
|
||||
socket.setdefaulttimeout(30)
|
||||
try:
|
||||
ftp = ftplib.FTP(HOST, timeout=None)
|
||||
finally:
|
||||
socket.setdefaulttimeout(previous)
|
||||
self.assertEqual(ftp.sock.gettimeout(), 30)
|
||||
self.evt.wait()
|
||||
ftp.close()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue