osutil: implement __enter__ and __exit__ on posixfile
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 02 Jan 2016 16:41:57 -0800
changeset 27704 051b0dcec98b
parent 27703 4e27c0a70574
child 27705 2380889f8f52
osutil: implement __enter__ and __exit__ on posixfile So they can be used as context managers.
mercurial/pure/osutil.py
--- a/mercurial/pure/osutil.py	Mon Jan 11 15:25:43 2016 -0800
+++ b/mercurial/pure/osutil.py	Sat Jan 02 16:41:57 2016 -0800
@@ -254,3 +254,9 @@
               f = posixfile('foo.txt')
               f.name = 'bla'  '''
             return self._file.__setattr__(name, value)
+
+        def __enter__(self):
+            return self._file.__enter__()
+
+        def __exit__(self, exc_type, exc_value, exc_tb):
+            return self._file.__exit__(exc_type, exc_value, exc_tb)