comparison mercurial/pure/osutil.py @ 27704:051b0dcec98b

osutil: implement __enter__ and __exit__ on posixfile So they can be used as context managers.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 02 Jan 2016 16:41:57 -0800
parents e2aa9c4030c4
children f7d0c28d34b3
comparison
equal deleted inserted replaced
27703:4e27c0a70574 27704:051b0dcec98b
252 '''mimics the read-only attributes of Python file objects 252 '''mimics the read-only attributes of Python file objects
253 by raising 'TypeError: readonly attribute' if someone tries: 253 by raising 'TypeError: readonly attribute' if someone tries:
254 f = posixfile('foo.txt') 254 f = posixfile('foo.txt')
255 f.name = 'bla' ''' 255 f.name = 'bla' '''
256 return self._file.__setattr__(name, value) 256 return self._file.__setattr__(name, value)
257
258 def __enter__(self):
259 return self._file.__enter__()
260
261 def __exit__(self, exc_type, exc_value, exc_tb):
262 return self._file.__exit__(exc_type, exc_value, exc_tb)