Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/common.py @ 13400:14f3795a5ed7
explicitly close files
Add missing calls to close() to many places where files are
opened. Relying on reference counting to catch them soon-ish is not
portable and fails in environments with a proper GC, such as PyPy.
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Fri, 24 Dec 2010 15:23:01 +0100 |
parents | f64b416b0ac8 |
children | 75f5f312df5f |
comparison
equal
deleted
inserted
replaced
13399:eff102facb15 | 13400:14f3795a5ed7 |
---|---|
117 break | 117 break |
118 try: | 118 try: |
119 os.stat(path) | 119 os.stat(path) |
120 ct = mimetypes.guess_type(path)[0] or "text/plain" | 120 ct = mimetypes.guess_type(path)[0] or "text/plain" |
121 req.respond(HTTP_OK, ct, length = os.path.getsize(path)) | 121 req.respond(HTTP_OK, ct, length = os.path.getsize(path)) |
122 return open(path, 'rb').read() | 122 fp = open(path, 'rb') |
123 data = fp.read() | |
124 fp.close() | |
125 return data | |
123 except TypeError: | 126 except TypeError: |
124 raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') | 127 raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') |
125 except OSError, err: | 128 except OSError, err: |
126 if err.errno == errno.ENOENT: | 129 if err.errno == errno.ENOENT: |
127 raise ErrorResponse(HTTP_NOT_FOUND) | 130 raise ErrorResponse(HTTP_NOT_FOUND) |