Details
Details
- Reviewers
yuja - Group Reviewers
hg-reviewers - Commits
- rHGbaee5512f262: hgweb: mimetype guessing needs a unicode path
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
| yuja |
| hg-reviewers |
| Lint Skipped |
| Unit Tests Skipped |
| if isinstance(directory, str): | if isinstance(directory, str): | ||||
| directory = [directory] | directory = [directory] | ||||
| for d in directory: | for d in directory: | ||||
| path = os.path.join(d, fpath) | path = os.path.join(d, fpath) | ||||
| if os.path.exists(path): | if os.path.exists(path): | ||||
| break | break | ||||
| try: | try: | ||||
| os.stat(path) | os.stat(path) | ||||
| ct = mimetypes.guess_type(path)[0] or "text/plain" | ct = mimetypes.guess_type(pycompat.fsdecode(path))[0] or "text/plain" | ||||
| with open(path, 'rb') as fh: | with open(path, 'rb') as fh: | ||||
| data = fh.read() | data = fh.read() | ||||
| req.respond(HTTP_OK, ct, body=data) | req.respond(HTTP_OK, ct, body=data) | ||||
| except TypeError: | except TypeError: | ||||
| raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') | raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') | ||||
| except OSError as err: | except OSError as err: | ||||
| if err.errno == errno.ENOENT: | if err.errno == errno.ENOENT: | ||||