comparison mercurial/hgweb/server.py @ 49283:44b26349127b

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.
author Manuel Jacob <me@manueljacob.de>
date Sun, 29 May 2022 12:38:54 +0200
parents 642e31cb55f0
children 48f1b314056b
comparison
equal deleted inserted replaced
49282:d7f3f745f20c 49283:44b26349127b
6 # This software may be used and distributed according to the terms of the 6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version. 7 # GNU General Public License version 2 or any later version.
8 8
9 9
10 import errno 10 import errno
11 import importlib
12 import os 11 import os
13 import socket 12 import socket
14 import sys 13 import sys
15 import traceback 14 import traceback
16 import wsgiref.validate 15 import wsgiref.validate
402 cls = IPv6HTTPServer 401 cls = IPv6HTTPServer
403 else: 402 else:
404 cls = MercurialHTTPServer 403 cls = MercurialHTTPServer
405 404
406 # ugly hack due to python issue5853 (for threaded use) 405 # ugly hack due to python issue5853 (for threaded use)
407 try: 406 import mimetypes
408 import mimetypes 407
409 408 mimetypes.init()
410 mimetypes.init()
411 except UnicodeDecodeError:
412 # Python 2.x's mimetypes module attempts to decode strings
413 # from Windows' ANSI APIs as ascii (fail), then re-encode them
414 # as ascii (clown fail), because the default Python Unicode
415 # codec is hardcoded as ascii.
416
417 sys.argv # unwrap demand-loader so that reload() works
418 # resurrect sys.setdefaultencoding()
419 try:
420 importlib.reload(sys)
421 except AttributeError:
422 reload(sys)
423 oldenc = sys.getdefaultencoding()
424 sys.setdefaultencoding(b"latin1") # or any full 8-bit encoding
425 mimetypes.init()
426 sys.setdefaultencoding(oldenc)
427 409
428 address = ui.config(b'web', b'address') 410 address = ui.config(b'web', b'address')
429 port = urlutil.getport(ui.config(b'web', b'port')) 411 port = urlutil.getport(ui.config(b'web', b'port'))
430 try: 412 try:
431 return cls(ui, app, (address, port), handler) 413 return cls(ui, app, (address, port), handler)