summaryrefslogtreecommitdiff
path: root/Lib/gzip.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/gzip.py')
-rw-r--r--Lib/gzip.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 560a722bae..019c3e2df1 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -472,6 +472,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.