summaryrefslogtreecommitdiff
path: root/Lib/zipfile.py
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2009-12-30 12:34:59 +0000
committerEzio Melotti <ezio.melotti@gmail.com>2009-12-30 12:34:59 +0000
commitfaa6b7f421ad1491ecbf4807a781202c155568e3 (patch)
treeabfde3288b0c0e53aa5be19a89eb1c6d1943dbc7 /Lib/zipfile.py
parent588009e934b891ded62d8c26063f48397d867aa6 (diff)
downloadcpython-git-faa6b7f421ad1491ecbf4807a781202c155568e3.tar.gz
Merged revisions 77136 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r77136 | ezio.melotti | 2009-12-30 08:14:51 +0200 (Wed, 30 Dec 2009) | 1 line #5511: Added the ability to use ZipFile as a context manager. Patch by Brian Curtin. ........
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r--Lib/zipfile.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index 79ca1527f9..f70cf63d7e 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -719,6 +719,12 @@ class ZipFile:
self.fp = None
raise RuntimeError('Mode must be "r", "w" or "a"')
+ def __enter__(self):
+ return self
+
+ def __exit__(self, type, value, traceback):
+ self.close()
+
def _GetContents(self):
"""Read the directory, making sure we close the file if the format
is bad."""