console: be more tolerant on UTF8 checks, but enforce encoding (#5250)

This commit is contained in:
Maximilian Hils 2022-04-06 20:13:19 +02:00 committed by GitHub
parent 02d2b6d310
commit 0b4cbfab99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 21 deletions

View File

@ -200,6 +200,16 @@ class ConsoleMaster(master.Master):
"Please run mitmproxy in an interactive shell environment.", file=sys.stderr)
sys.exit(1)
if os.name != "nt" and "utf" not in urwid.detected_encoding.lower():
print(
f"mitmproxy expects a UTF-8 console environment, not {urwid.detected_encoding!r}. "
f"Set your LANG environment variable to something like en_US.UTF-8.",
file=sys.stderr
)
# Experimental (04/2022): We just don't exit here and see if/how that affects users.
# sys.exit(1)
urwid.set_encoding("utf8")
signals.call_in.connect(self.sig_call_in)
self.ui = window.Screen()
self.ui.set_terminal_properties(256)

View File

@ -12,22 +12,6 @@ from mitmproxy.tools import cmdline
from mitmproxy.utils import debug, arg_check
def assert_utf8_env():
spec = ""
for i in ["LANG", "LC_CTYPE", "LC_ALL"]:
spec += os.environ.get(i, "").lower()
if "utf" not in spec:
print(
"Error: mitmproxy requires a UTF console environment.",
file=sys.stderr
)
print(
"Set your LANG environment variable to something like en_US.UTF-8",
file=sys.stderr
)
sys.exit(1)
def process_options(parser, opts, args):
if args.version:
print(debug.dump_system_info())
@ -123,11 +107,6 @@ def run(
def mitmproxy(args=None) -> typing.Optional[int]: # pragma: no cover
if os.name == "nt":
import urwid
urwid.set_encoding("utf8")
else:
assert_utf8_env()
from mitmproxy.tools import console
run(console.master.ConsoleMaster, cmdline.mitmproxy, args)
return None