summaryrefslogtreecommitdiffstats
path: root/Lib/imaplib.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-09-09 16:07:49 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-09-09 16:07:49 (GMT)
commit38684c366364fcd4071534a1de62f728407224d8 (patch)
treee16b93cf0f5a416770a873331792e5d4d6611b9c /Lib/imaplib.py
parentbb1e3f1ebe99e1cb5a7c136991b8e8f41e4fa4bb (diff)
downloadcpython-38684c366364fcd4071534a1de62f728407224d8.zip
cpython-38684c366364fcd4071534a1de62f728407224d8.tar.gz
cpython-38684c366364fcd4071534a1de62f728407224d8.tar.bz2
imaplib.IMAP4 now supports the context manager protocol.
Original patch by Tarek Ziadé.
Diffstat (limited to 'Lib/imaplib.py')
-rw-r--r--Lib/imaplib.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index ad104fe..27445dd 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -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