statichttprepo: implement __enter__ and __exit__ on httprangeheader
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 02 Jan 2016 15:33:01 -0800
changeset 27705 2380889f8f52
parent 27704 051b0dcec98b
child 27706 22e362da27cf
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.
mercurial/statichttprepo.py
--- 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):