#5511: Added the ability to use ZipFile as a context manager. Patch by Brian Curtin.

This commit is contained in:
Ezio Melotti 2009-12-30 06:14:51 +00:00
parent eb74da8e67
commit 569e61f351
4 changed files with 465 additions and 486 deletions

View file

@ -721,6 +721,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."""