Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/common.py @ 52398:c9baa3541b20
hgweb: stop using the `pycompat.open()` shim
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 04 Dec 2024 20:54:35 -0500 |
parents | f4733654f144 |
children | 08612516d436 |
comparison
equal
deleted
inserted
replaced
52397:bff68b6e5999 | 52398:c9baa3541b20 |
---|---|
13 import mimetypes | 13 import mimetypes |
14 import os | 14 import os |
15 import stat | 15 import stat |
16 | 16 |
17 from ..i18n import _ | 17 from ..i18n import _ |
18 from ..pycompat import ( | |
19 open, | |
20 ) | |
21 from .. import ( | 18 from .. import ( |
22 encoding, | 19 encoding, |
23 pycompat, | 20 pycompat, |
24 scmutil, | 21 scmutil, |
25 templater, | 22 templater, |
220 mimetypes.guess_type(pycompat.fsdecode(fpath))[0] or r"text/plain" | 217 mimetypes.guess_type(pycompat.fsdecode(fpath))[0] or r"text/plain" |
221 ) | 218 ) |
222 path = os.path.join(directory, fpath) | 219 path = os.path.join(directory, fpath) |
223 try: | 220 try: |
224 os.stat(path) | 221 os.stat(path) |
225 with open(path, b'rb') as fh: | 222 with open(path, 'rb') as fh: |
226 data = fh.read() | 223 data = fh.read() |
227 except TypeError: | 224 except TypeError: |
228 raise ErrorResponse(HTTP_SERVER_ERROR, b'illegal filename') | 225 raise ErrorResponse(HTTP_SERVER_ERROR, b'illegal filename') |
229 except OSError as err: | 226 except OSError as err: |
230 if err.errno == errno.ENOENT: | 227 if err.errno == errno.ENOENT: |