diff mercurial/statichttprepo.py @ 27705:2380889f8f52

statichttprepo: implement __enter__ and __exit__ on httprangeheader httprangeheader behaves like a file object. Implement __enter__ and __exit__ so it can be used as a context manager, just like file objects.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 02 Jan 2016 15:33:01 -0800
parents 56b2bcea2529
children 032c4c2f802a
line wrap: on
line diff
--- a/mercurial/statichttprepo.py	Sat Jan 02 16:41:57 2016 -0800
+++ b/mercurial/statichttprepo.py	Sat Jan 02 15:33:01 2016 -0800
@@ -35,6 +35,13 @@
         self.pos = 0
         self.opener = opener
         self.name = url
+
+    def __enter__(self):
+        return self
+
+    def __exit__(self, exc_type, exc_value, traceback):
+        self.close()
+
     def seek(self, pos):
         self.pos = pos
     def read(self, bytes=None):