mercurial/hgweb/common.py
changeset 31789 161a87ed456e
parent 31435 2daeab02b4b1
child 31790 62f9679df1f2
--- 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')