equal
deleted
inserted
replaced
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: |