hgweb: use context manager for file I/O
authorGregory Szorc <gregory.szorc@gmail.com>
Fri, 31 Mar 2017 22:30:38 -0700
changeset 31789 161a87ed456e
parent 31788 417363736c11
child 31790 62f9679df1f2
hgweb: use context manager for file I/O
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')