Mercurial > hg
changeset 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 | 051b0dcec98b |
children | 22e362da27cf |
files | mercurial/statichttprepo.py |
diffstat | 1 files changed, 7 insertions(+), 0 deletions(-) [+] |
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):