mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
#5511: Added the ability to use ZipFile as a context manager. Patch by Brian Curtin.
This commit is contained in:
parent
eb74da8e67
commit
569e61f351
4 changed files with 465 additions and 486 deletions
|
@ -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."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue