summaryrefslogtreecommitdiffstats
path: root/Doc/library/imaplib.rst
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na92@gmail.com>2020-01-07 17:28:10 (GMT)
committerVictor Stinner <vstinner@python.org>2020-01-07 17:28:10 (GMT)
commit13a7ee8d62dafe7d2291708312fa2a86e171c7fa (patch)
tree1e7faf47f7cb00a2a540553c8686941d1f4a0852 /Doc/library/imaplib.rst
parent950c6795aa0ffa85e103a13e7a04e08cb34c66ad (diff)
downloadcpython-13a7ee8d62dafe7d2291708312fa2a86e171c7fa.zip
cpython-13a7ee8d62dafe7d2291708312fa2a86e171c7fa.tar.gz
cpython-13a7ee8d62dafe7d2291708312fa2a86e171c7fa.tar.bz2
bpo-38615: Add timeout parameter for IMAP4 and IMAP4_SSL constructor (GH-17203)
imaplib.IMAP4 and imaplib.IMAP4_SSL now have an optional *timeout* parameter for their constructors. Also, the imaplib.IMAP4.open() method now has an optional *timeout* parameter with this change. The overridden methods of imaplib.IMAP4_SSL and imaplib.IMAP4_stream were applied to this change.
Diffstat (limited to 'Doc/library/imaplib.rst')
-rw-r--r--Doc/library/imaplib.rst37
1 files changed, 27 insertions, 10 deletions
diff --git a/Doc/library/imaplib.rst b/Doc/library/imaplib.rst
index df63d82..5b8ca7c 100644
--- a/Doc/library/imaplib.rst
+++ b/Doc/library/imaplib.rst
@@ -30,12 +30,14 @@ Three classes are provided by the :mod:`imaplib` module, :class:`IMAP4` is the
base class:
-.. class:: IMAP4(host='', port=IMAP4_PORT)
+.. class:: IMAP4(host='', port=IMAP4_PORT, timeout=None)
This class implements the actual IMAP4 protocol. The connection is created and
protocol version (IMAP4 or IMAP4rev1) is determined when the instance is
initialized. If *host* is not specified, ``''`` (the local host) is used. If
- *port* is omitted, the standard IMAP4 port (143) is used.
+ *port* is omitted, the standard IMAP4 port (143) is used. The optional *timeout*
+ parameter specifies a timeout in seconds for the connection attempt.
+ If timeout is not given or is None, the global default socket timeout is used.
The :class:`IMAP4` class supports the :keyword:`with` statement. When used
like this, the IMAP4 ``LOGOUT`` command is issued automatically when the
@@ -50,6 +52,9 @@ base class:
.. versionchanged:: 3.5
Support for the :keyword:`with` statement was added.
+ .. versionchanged:: 3.9
+ The optional *timeout* parameter was added.
+
Three exceptions are defined as attributes of the :class:`IMAP4` class:
@@ -78,7 +83,7 @@ There's also a subclass for secure connections:
.. class:: IMAP4_SSL(host='', port=IMAP4_SSL_PORT, keyfile=None, \
- certfile=None, ssl_context=None)
+ certfile=None, ssl_context=None, timeout=None)
This is a subclass derived from :class:`IMAP4` that connects over an SSL
encrypted socket (to use this class you need a socket module that was compiled
@@ -95,8 +100,12 @@ There's also a subclass for secure connections:
mutually exclusive with *ssl_context*, a :class:`ValueError` is raised
if *keyfile*/*certfile* is provided along with *ssl_context*.
+ The optional *timeout* parameter specifies a timeout in seconds for the
+ connection attempt. If timeout is not given or is None, the global default
+ socket timeout is used.
+
.. versionchanged:: 3.3
- *ssl_context* parameter added.
+ *ssl_context* parameter was added.
.. versionchanged:: 3.4
The class now supports hostname check with
@@ -110,6 +119,8 @@ There's also a subclass for secure connections:
:func:`ssl.create_default_context` select the system's trusted CA
certificates for you.
+ .. versionchanged:: 3.9
+ The optional *timeout* parameter was added.
The second subclass allows for connections created by a child process:
@@ -353,16 +364,22 @@ An :class:`IMAP4` instance has the following methods:
Send ``NOOP`` to server.
-.. method:: IMAP4.open(host, port)
+.. method:: IMAP4.open(host, port, timeout=None)
- Opens socket to *port* at *host*. This method is implicitly called by
- the :class:`IMAP4` constructor. The connection objects established by this
- method will be used in the :meth:`IMAP4.read`, :meth:`IMAP4.readline`,
- :meth:`IMAP4.send`, and :meth:`IMAP4.shutdown` methods. You may override
- this method.
+ Opens socket to *port* at *host*. The optional *timeout* parameter
+ specifies a timeout in seconds for the connection attempt.
+ If timeout is not given or is None, the global default socket timeout
+ is used. Also note that if the *timeout* parameter is set to be zero,
+ it will raise a :class:`ValueError` to reject creating a non-blocking socket.
+ This method is implicitly called by the :class:`IMAP4` constructor.
+ The connection objects established by this method will be used in
+ the :meth:`IMAP4.read`, :meth:`IMAP4.readline`, :meth:`IMAP4.send`,
+ and :meth:`IMAP4.shutdown` methods. You may override this method.
.. audit-event:: imaplib.open self,host,port imaplib.IMAP4.open
+ .. versionchanged:: 3.9
+ The *timeout* parameter was added.
.. method:: IMAP4.partial(message_num, message_part, start, length)