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:
Facundo Batista 2008-05-29 16:39:26 +00:00
parent f18a707205
commit 4f1b1ed975
24 changed files with 231 additions and 180 deletions

View file

@ -184,13 +184,13 @@ class Telnet:
"""
def __init__(self, host=None, port=0, timeout=None):
def __init__(self, host=None, port=0,
timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
"""Constructor.
When called without arguments, create an unconnected instance.
With a hostname argument, it connects the instance; a port
number is optional.
With a hostname argument, it connects the instance; port number
and timeout are optional.
"""
self.debuglevel = DEBUGLEVEL
self.host = host
@ -208,23 +208,21 @@ class Telnet:
if host is not None:
self.open(host, port, timeout)
def open(self, host, port=0, timeout=None):
def open(self, host, port=0, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
"""Connect to a host.
The optional second argument is the port number, which
defaults to the standard telnet port (23).
Don't try to reopen an already connected instance.
"""
self.eof = 0
if not port:
port = TELNET_PORT
self.host = host
self.port = port
if timeout is not None:
self.timeout = timeout
self.sock = socket.create_connection((host, port), self.timeout)
self.timeout = timeout
self.sock = socket.create_connection((host, port), timeout)
def __del__(self):
"""Destructor -- close the connection."""