mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
Added the posibility to pass the timeout to FTP.connect, not only when
instantiating the class. Docs and tests are updated.
This commit is contained in:
parent
b6a5c9d605
commit
93c33680a0
3 changed files with 40 additions and 7 deletions
|
|
@ -8,14 +8,20 @@ from test import test_support
|
|||
|
||||
def server(evt):
|
||||
serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
serv.settimeout(3)
|
||||
serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
serv.bind(("", 9091))
|
||||
serv.listen(5)
|
||||
conn, addr = serv.accept()
|
||||
conn.send("1 Hola mundo\n")
|
||||
conn.close()
|
||||
serv.close()
|
||||
evt.set()
|
||||
try:
|
||||
conn, addr = serv.accept()
|
||||
except socket.timeout:
|
||||
pass
|
||||
else:
|
||||
conn.send("1 Hola mundo\n")
|
||||
conn.close()
|
||||
finally:
|
||||
serv.close()
|
||||
evt.set()
|
||||
|
||||
class GeneralTests(TestCase):
|
||||
|
||||
|
|
@ -48,6 +54,25 @@ class GeneralTests(TestCase):
|
|||
self.assertEqual(ftp.sock.gettimeout(), 30)
|
||||
ftp.sock.close()
|
||||
|
||||
def testTimeoutConnect(self):
|
||||
ftp = ftplib.FTP()
|
||||
ftp.connect("localhost", timeout=30)
|
||||
self.assertEqual(ftp.sock.gettimeout(), 30)
|
||||
ftp.sock.close()
|
||||
|
||||
def testTimeoutDifferentOrder(self):
|
||||
ftp = ftplib.FTP(timeout=30)
|
||||
ftp.connect("localhost")
|
||||
self.assertEqual(ftp.sock.gettimeout(), 30)
|
||||
ftp.sock.close()
|
||||
|
||||
def testTimeoutDirectAccess(self):
|
||||
ftp = ftplib.FTP()
|
||||
ftp.timeout = 30
|
||||
ftp.connect("localhost")
|
||||
self.assertEqual(ftp.sock.gettimeout(), 30)
|
||||
ftp.sock.close()
|
||||
|
||||
def testTimeoutNone(self):
|
||||
# None, having other default
|
||||
previous = socket.getdefaulttimeout()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue