# HG changeset patch # User Manuel Jacob # Date 2022-05-29 10:38:54 # Node ID 44b26349127b7c9fb32e1f641e23ae75c9e8496a # Parent d7f3f745f20c184931aff762edd736d7eb771858 hgweb: remove dead code handling UnicodeDecodeError I’m quite confident that the error can’t happen on Python 3, as the main motivation for separating bytes and str in Python 3 was to avoid this class of errors. diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py --- a/mercurial/hgweb/server.py +++ b/mercurial/hgweb/server.py @@ -8,7 +8,6 @@ import errno -import importlib import os import socket import sys @@ -404,26 +403,9 @@ def create_server(ui, app): cls = MercurialHTTPServer # ugly hack due to python issue5853 (for threaded use) - try: - import mimetypes - - mimetypes.init() - except UnicodeDecodeError: - # Python 2.x's mimetypes module attempts to decode strings - # from Windows' ANSI APIs as ascii (fail), then re-encode them - # as ascii (clown fail), because the default Python Unicode - # codec is hardcoded as ascii. + import mimetypes - sys.argv # unwrap demand-loader so that reload() works - # resurrect sys.setdefaultencoding() - try: - importlib.reload(sys) - except AttributeError: - reload(sys) - oldenc = sys.getdefaultencoding() - sys.setdefaultencoding(b"latin1") # or any full 8-bit encoding - mimetypes.init() - sys.setdefaultencoding(oldenc) + mimetypes.init() address = ui.config(b'web', b'address') port = urlutil.getport(ui.config(b'web', b'port')) diff --git a/tests/test-check-pyflakes.t b/tests/test-check-pyflakes.t --- a/tests/test-check-pyflakes.t +++ b/tests/test-check-pyflakes.t @@ -20,7 +20,6 @@ run pyflakes on all tracked files ending > 2>/dev/null \ > | xargs "$PYTHON" -m pyflakes 2>/dev/null | "$TESTDIR/filterpyflakes.py" contrib/perf.py:*:* undefined name 'xrange' (glob) (?) - mercurial/hgweb/server.py:*:* undefined name 'reload' (glob) (?) mercurial/pycompat.py:*:* 'codecs' imported but unused (glob) mercurial/pycompat.py:*:* 'concurrent.futures' imported but unused (glob) mercurial/pycompat.py:*:* 'http.client as httplib' imported but unused (glob)