mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
imaplib.IMAP4 now supports the context manager protocol.
Original patch by Tarek Ziadé.
This commit is contained in:
parent
bb1e3f1ebe
commit
38684c3663
5 changed files with 67 additions and 0 deletions
|
@ -238,6 +238,14 @@ class IMAP4:
|
|||
return getattr(self, attr.lower())
|
||||
raise AttributeError("Unknown IMAP4 command: '%s'" % attr)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
try:
|
||||
self.logout()
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
# Overridable methods
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue