Mercurial > hg
changeset 31789:161a87ed456e
hgweb: use context manager for file I/O
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 31 Mar 2017 22:30:38 -0700 |
parents | 417363736c11 |
children | 62f9679df1f2 |
files | mercurial/hgweb/common.py |
diffstat | 1 files changed, 3 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/common.py Mon Apr 03 10:01:38 2017 -0700 +++ b/mercurial/hgweb/common.py Fri Mar 31 22:30:38 2017 -0700 @@ -160,9 +160,9 @@ try: os.stat(path) ct = mimetypes.guess_type(path)[0] or "text/plain" - fp = open(path, 'rb') - data = fp.read() - fp.close() + with open(path, 'rb') as fh: + data = fh.read() + req.respond(HTTP_OK, ct, body=data) except TypeError: raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename')