Issue #3860: GzipFile and BZ2File now support the context manager protocol.
diff --git a/Lib/gzip.py b/Lib/gzip.py
index 931c9ef..f568796 100644
--- a/Lib/gzip.py
+++ b/Lib/gzip.py
@@ -454,6 +454,14 @@
         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.