From 8c14022139af74dcfcc705809c8b2e43e1a9fc4b Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Tue, 9 Sep 2014 19:07:49 +0300 Subject: imaplib.IMAP4 now supports the context manager protocol. Original patch by Tarek Ziad?. --- Doc/library/imaplib.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Doc/library/imaplib.rst') diff --git a/Doc/library/imaplib.rst b/Doc/library/imaplib.rst index fa736fe3af..f263bab9f0 100644 --- a/Doc/library/imaplib.rst +++ b/Doc/library/imaplib.rst @@ -37,6 +37,19 @@ base class: initialized. If *host* is not specified, ``''`` (the local host) is used. If *port* is omitted, the standard IMAP4 port (143) is used. + The :class:`IMAP4` class supports the :keyword:`with` statement. When used + like this, the IMAP4 ``LOGOUT`` command is issued automatically when the + :keyword:`with` statement exits. E.g.:: + + >>> from imaplib import IMAP4 + >>> with IMAP4("domain.org") as M: + ... M.noop() + ... + ('OK', [b'Nothing Accomplished. d25if65hy903weo.87']) + + .. versionchanged:: 3.5 + Support for the :keyword:`with` statement was added. + Three exceptions are defined as attributes of the :class:`IMAP4` class: -- cgit v1.2.1