mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +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
|
@ -44,6 +44,7 @@ try:
|
|||
from socket import getfqdn; socket.getfqdn = getfqdn; del getfqdn
|
||||
except ImportError:
|
||||
import socket
|
||||
from socket import _GLOBAL_DEFAULT_TIMEOUT
|
||||
|
||||
__all__ = ["FTP","Netrc"]
|
||||
|
||||
|
@ -71,7 +72,6 @@ all_errors = (Error, IOError, EOFError)
|
|||
# Line terminators (we always output CRLF, but accept any of CRLF, CR, LF)
|
||||
CRLF = '\r\n'
|
||||
|
||||
|
||||
# The class itself
|
||||
class FTP:
|
||||
|
||||
|
@ -109,14 +109,15 @@ class FTP:
|
|||
# Initialize host to localhost, port to standard ftp port
|
||||
# Optional arguments are host (for connect()),
|
||||
# and user, passwd, acct (for login())
|
||||
def __init__(self, host='', user='', passwd='', acct='', timeout=None):
|
||||
def __init__(self, host='', user='', passwd='', acct='',
|
||||
timeout=_GLOBAL_DEFAULT_TIMEOUT):
|
||||
self.timeout = timeout
|
||||
if host:
|
||||
self.connect(host)
|
||||
if user:
|
||||
self.login(user, passwd, acct)
|
||||
|
||||
def connect(self, host='', port=0, timeout=None):
|
||||
def connect(self, host='', port=0, timeout=-999):
|
||||
'''Connect to host. Arguments are:
|
||||
- host: hostname to connect to (string, default previous host)
|
||||
- port: port to connect to (integer, default previous port)
|
||||
|
@ -125,7 +126,7 @@ class FTP:
|
|||
self.host = host
|
||||
if port > 0:
|
||||
self.port = port
|
||||
if timeout is not None:
|
||||
if timeout != -999:
|
||||
self.timeout = timeout
|
||||
self.sock = socket.create_connection((self.host, self.port), self.timeout)
|
||||
self.af = self.sock.family
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue