# HG changeset patch # User Gregory Szorc # Date 1491024638 25200 # Node ID 161a87ed456ea8358a4a4d7f3ac0ed4ceed64c58 # Parent 417363736c11d05e225e55945c17a0f724250f57 hgweb: use context manager for file I/O diff -r 417363736c11 -r 161a87ed456e mercurial/hgweb/common.py --- 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')