mirror of
https://github.com/python/cpython.git
synced 2025-09-13 12:17:24 +00:00
Issue #3860: GzipFile and BZ2File now support the context manager protocol.
This commit is contained in:
parent
7c303e9a98
commit
b74fc2b5fe
4 changed files with 83 additions and 1 deletions
|
@ -454,6 +454,14 @@ class GzipFile:
|
|||
else:
|
||||
raise StopIteration
|
||||
|
||||
def __enter__(self):
|
||||
if self.fileobj is None:
|
||||
raise ValueError("I/O operation on closed GzipFile object")
|
||||
return self
|
||||
|
||||
def __exit__(self, *args):
|
||||
self.close()
|
||||
|
||||
|
||||
def _test():
|
||||
# Act like gzip; with -d, act like gunzip.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue