summaryrefslogtreecommitdiffstats
path: root/Lib/gzip.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-01-10 16:22:51 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-01-10 16:22:51 (GMT)
commit308705e4fab1fe784218bde5cc8c8d2daddf6700 (patch)
treec179157d874086e0e6472b292287e1eb3e7806c0 /Lib/gzip.py
parentab868311a5282f188a8cf831b021938420fee5c4 (diff)
downloadcpython-308705e4fab1fe784218bde5cc8c8d2daddf6700.zip
cpython-308705e4fab1fe784218bde5cc8c8d2daddf6700.tar.gz
cpython-308705e4fab1fe784218bde5cc8c8d2daddf6700.tar.bz2
Merged revisions 68484-68485 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r68484 | antoine.pitrou | 2009-01-10 17:13:45 +0100 (sam., 10 janv. 2009) | 3 lines Issue #3860: GzipFile and BZ2File now support the context manager protocol. ........ r68485 | antoine.pitrou | 2009-01-10 17:15:24 +0100 (sam., 10 janv. 2009) | 1 line Add NEWS entry for r68484. ........
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 560a722..019c3e2 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.