Mercurial > public > mercurial-scm > hg-stable
diff mercurial/hgweb/server.py @ 43069:e554cfd93975
hgweb: use importlib.reload() if available
reload() was nuked in Python 3. We need to use importlib.reload()
instead.
But pyflakes isn't smart enough to detect our conditional usage, so
we allow this error.
Differential Revision: https://phab.mercurial-scm.org/D6992
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 05 Oct 2019 17:44:54 -0400 |
parents | 6bbb12cba5a8 |
children | 2372284d9457 |
line wrap: on
line diff
--- a/mercurial/hgweb/server.py Sat Oct 05 16:57:45 2019 -0400 +++ b/mercurial/hgweb/server.py Sat Oct 05 17:44:54 2019 -0400 @@ -9,6 +9,7 @@ from __future__ import absolute_import import errno +import importlib import os import socket import sys @@ -370,7 +371,11 @@ # codec is hardcoded as ascii. sys.argv # unwrap demand-loader so that reload() works - reload(sys) # resurrect sys.setdefaultencoding() + # resurrect sys.setdefaultencoding() + try: + importlib.reload(sys) + except AttributeError: + reload(sys) oldenc = sys.getdefaultencoding() sys.setdefaultencoding("latin1") # or any full 8-bit encoding mimetypes.init()