#2452: timeout is used for all blocking operations.

This commit is contained in:
Georg Brandl 2008-05-11 11:09:35 +00:00
parent 0aaf559bfe
commit ab756f60bd
5 changed files with 54 additions and 47 deletions

View File

@ -40,11 +40,12 @@ The module defines the following items:
.. class:: FTP([host[, user[, passwd[, acct[, timeout]]]]]) .. class:: FTP([host[, user[, passwd[, acct[, timeout]]]]])
Return a new instance of the :class:`FTP` class. When *host* is given, the Return a new instance of the :class:`FTP` class. When *host* is given, the
method call ``connect(host)`` is made. When *user* is given, additionally the method call ``connect(host)`` is made. When *user* is given, additionally
method call ``login(user, passwd, acct)`` is made (where *passwd* and *acct* the method call ``login(user, passwd, acct)`` is made (where *passwd* and
default to the empty string when not given). The optional *timeout* parameter *acct* default to the empty string when not given). The optional *timeout*
specifies a timeout in seconds for the connection attempt (if is not specified, parameter specifies a timeout in seconds for blocking operations like the
or passed as None, the global default timeout setting will be used). connection attempt (if is not specified, or passed as None, the global
default timeout setting will be used).
.. versionchanged:: 2.6 .. versionchanged:: 2.6
*timeout* was added. *timeout* was added.
@ -125,9 +126,10 @@ followed by ``lines`` for the text version or ``binary`` for the binary version.
made. made.
The optional *timeout* parameter specifies a timeout in seconds for the The optional *timeout* parameter specifies a timeout in seconds for the
connection attempt. If is not specified, or passed as None, the object timeout connection attempt. If is not specified, or passed as None, the object
is used (the timeout that you passed when instantiating the class); if the timeout is used (the timeout that you passed when instantiating the class);
object timeout is also None, the global default timeout setting will be used. if the object timeout is also None, the global default timeout setting will
be used.
.. versionchanged:: 2.6 .. versionchanged:: 2.6
*timeout* was added. *timeout* was added.

View File

@ -33,14 +33,14 @@ The module provides the following classes:
.. class:: HTTPConnection(host[, port[, strict[, timeout]]]) .. class:: HTTPConnection(host[, port[, strict[, timeout]]])
An :class:`HTTPConnection` instance represents one transaction with an HTTP An :class:`HTTPConnection` instance represents one transaction with an HTTP
server. It should be instantiated passing it a host and optional port number. server. It should be instantiated passing it a host and optional port
If no port number is passed, the port is extracted from the host string if it number. If no port number is passed, the port is extracted from the host
has the form ``host:port``, else the default HTTP port (80) is used. When True, string if it has the form ``host:port``, else the default HTTP port (80) is
the optional parameter *strict* causes ``BadStatusLine`` to be raised if the used. When True, the optional parameter *strict* causes ``BadStatusLine`` to
status line can't be parsed as a valid HTTP/1.0 or 1.1 status line. If the be raised if the status line can't be parsed as a valid HTTP/1.0 or 1.1
optional *timeout* parameter is given, connection attempts will timeout after status line. If the optional *timeout* parameter is given, blocking
that many seconds (if it is not given or ``None``, the global default timeout operations (like connection attempts) will timeout after that many seconds
setting is used). (if it is not given or ``None``, the global default timeout setting is used).
For example, the following calls all create instances that connect to the server For example, the following calls all create instances that connect to the server
at the same host and port:: at the same host and port::

View File

@ -19,13 +19,14 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions).
.. class:: SMTP([host[, port[, local_hostname[, timeout]]]]) .. class:: SMTP([host[, port[, local_hostname[, timeout]]]])
A :class:`SMTP` instance encapsulates an SMTP connection. It has methods that A :class:`SMTP` instance encapsulates an SMTP connection. It has methods
support a full repertoire of SMTP and ESMTP operations. If the optional host and that support a full repertoire of SMTP and ESMTP operations. If the optional
port parameters are given, the SMTP :meth:`connect` method is called with those host and port parameters are given, the SMTP :meth:`connect` method is called
parameters during initialization. An :exc:`SMTPConnectError` is raised if the with those parameters during initialization. An :exc:`SMTPConnectError` is
specified host doesn't respond correctly. The optional *timeout* parameter raised if the specified host doesn't respond correctly. The optional
specifies a timeout in seconds for the connection attempt (if not specified, or *timeout* parameter specifies a timeout in seconds for blocking operations
passed as None, the global default timeout setting will be used). like the connection attempt (if not specified, or passed as None, the global
default timeout setting will be used).
For normal use, you should only require the initialization/connect, For normal use, you should only require the initialization/connect,
:meth:`sendmail`, and :meth:`quit` methods. An example is included below. :meth:`sendmail`, and :meth:`quit` methods. An example is included below.
@ -38,13 +39,14 @@ Protocol) and :rfc:`1869` (SMTP Service Extensions).
A :class:`SMTP_SSL` instance behaves exactly the same as instances of A :class:`SMTP_SSL` instance behaves exactly the same as instances of
:class:`SMTP`. :class:`SMTP_SSL` should be used for situations where SSL is :class:`SMTP`. :class:`SMTP_SSL` should be used for situations where SSL is
required from the beginning of the connection and using :meth:`starttls` is not required from the beginning of the connection and using :meth:`starttls` is
appropriate. If *host* is not specified, the local host is used. If *port* is not appropriate. If *host* is not specified, the local host is used. If
omitted, the standard SMTP-over-SSL port (465) is used. *keyfile* and *certfile* *port* is omitted, the standard SMTP-over-SSL port (465) is used. *keyfile*
are also optional, and can contain a PEM formatted private key and certificate and *certfile* are also optional, and can contain a PEM formatted private key
chain file for the SSL connection. The optional *timeout* parameter specifies a and certificate chain file for the SSL connection. The optional *timeout*
timeout in seconds for the connection attempt (if not specified, or passed as parameter specifies a timeout in seconds for blocking operations like the
None, the global default timeout setting will be used). connection attempt (if not specified, or passed as None, the global default
timeout setting will be used).
.. versionchanged:: 2.6 .. versionchanged:: 2.6
*timeout* was added. *timeout* was added.

View File

@ -27,11 +27,12 @@ Character), EL (Erase Line), GA (Go Ahead), SB (Subnegotiation Begin).
:class:`Telnet` represents a connection to a Telnet server. The instance is :class:`Telnet` represents a connection to a Telnet server. The instance is
initially not connected by default; the :meth:`open` method must be used to initially not connected by default; the :meth:`open` method must be used to
establish a connection. Alternatively, the host name and optional port number establish a connection. Alternatively, the host name and optional port
can be passed to the constructor, to, in which case the connection to the server number can be passed to the constructor, to, in which case the connection to
will be established before the constructor returns. The optional *timeout* the server will be established before the constructor returns. The optional
parameter specifies a timeout in seconds for the connection attempt (if not *timeout* parameter specifies a timeout in seconds for blocking operations
specified, or passed as None, the global default timeout setting will be used). like the connection attempt (if not specified, or passed as None, the global
default timeout setting will be used).
Do not reopen an already connected instance. Do not reopen an already connected instance.
@ -126,8 +127,9 @@ Telnet Objects
Connect to a host. The optional second argument is the port number, which Connect to a host. The optional second argument is the port number, which
defaults to the standard Telnet port (23). The optional *timeout* parameter defaults to the standard Telnet port (23). The optional *timeout* parameter
specifies a timeout in seconds for the connection attempt (if not specified, or specifies a timeout in seconds for blocking operations like the connection
passed as None, the global default timeout setting will be used). attempt (if not specified, or passed as None, the global default timeout
setting will be used).
Do not try to reopen an already connected instance. Do not try to reopen an already connected instance.

View File

@ -26,10 +26,10 @@ The :mod:`urllib2` module defines the following functions:
:func:`urllib.urlencode` function takes a mapping or sequence of 2-tuples and :func:`urllib.urlencode` function takes a mapping or sequence of 2-tuples and
returns a string in this format. returns a string in this format.
The optional *timeout* parameter specifies a timeout in seconds for the The optional *timeout* parameter specifies a timeout in seconds for blocking
connection attempt (if not specified, or passed as None, the global default operations like the connection attempt (if not specified, or passed as
timeout setting will be used). This actually only work for HTTP, HTTPS, FTP and ``None``, the global default timeout setting will be used). This actually
FTPS connections. only works for HTTP, HTTPS, FTP and FTPS connections.
This function returns a file-like object with two additional methods: This function returns a file-like object with two additional methods:
@ -407,12 +407,13 @@ OpenerDirector Objects
.. method:: OpenerDirector.open(url[, data][, timeout]) .. method:: OpenerDirector.open(url[, data][, timeout])
Open the given *url* (which can be a request object or a string), optionally Open the given *url* (which can be a request object or a string), optionally
passing the given *data*. Arguments, return values and exceptions raised are the passing the given *data*. Arguments, return values and exceptions raised are
same as those of :func:`urlopen` (which simply calls the :meth:`open` method on the same as those of :func:`urlopen` (which simply calls the :meth:`open`
the currently installed global :class:`OpenerDirector`). The optional *timeout* method on the currently installed global :class:`OpenerDirector`). The
parameter specifies a timeout in seconds for the connection attempt (if not optional *timeout* parameter specifies a timeout in seconds for blocking
specified, or passed as None, the global default timeout setting will be used; operations like the connection attempt (if not specified, or passed as
this actually only work for HTTP, HTTPS, FTP and FTPS connections). ``None``, the global default timeout setting will be used; this actually only
works for HTTP, HTTPS, FTP and FTPS connections).
.. versionchanged:: 2.6 .. versionchanged:: 2.6
*timeout* was added. *timeout* was added.