[Python-checkins] r63788 - in python/trunk: Doc/library/ftplib.rst Doc/library/httplib.rst Doc/library/poplib.rst Doc/library/smtplib.rst Doc/library/socket.rst Doc/library/telnetlib.rst Doc/library/urllib2.rst Lib/ftplib.py Lib/httplib.py Lib/po

Neal Norwitz nnorwitz at gmail.com
Fri May 30 06:49:40 CEST 2008


On Thu, May 29, 2008 at 9:39 AM, facundo.batista
<python-checkins at python.org> wrote:
> Author: facundo.batista
> Date: Thu May 29 18:39:26 2008
> New Revision: 63788
>
> Log:
>
> 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, :)

> Modified: python/trunk/Lib/ftplib.py
> ==============================================================================
> --- python/trunk/Lib/ftplib.py  (original)
> +++ python/trunk/Lib/ftplib.py  Thu May 29 18:39:26 2008
> @@ -44,6 +44,7 @@
>     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 @@
>  # 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 @@
>     # 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 @@
>             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

Why is a magic number used here, but in all other places I saw
_GLOBAL_DEFAULT_TIMEOUT is used?
Can't this code also use _GLOBAL_DEFAULT_TIMEOUT?

n


More information about the Python-checkins mailing list