diff --git a/hg b/hg index 72af9fa3483254d3f6e8374ee7f2ecbe9ac9be58_aGc=..12c0df3ccd9d1b1dc2599291c32a5c3040fae8d2_aGc= 100755 --- a/hg +++ b/hg @@ -12,6 +12,33 @@ import os import sys +# PYTHONLEGACYWINDOWSSTDIO=1 even when not defined +if os.name == "nt" and os.environ.get("PYTHONLEGACYWINDOWSSTDIO", None) is None: + import io + + # avoid deallocation + saved_stdin = sys.__stdin__ + saved_stdout = sys.__stdout__ + saved_stderr = sys.__stderr__ + + sys.stdin = io.TextIOWrapper( + io.FileIO(sys.stdin.fileno(), closefd=False), encoding="mbcs" + ) + sys.stdout = io.TextIOWrapper( + io.FileIO(sys.stdout.fileno(), "wb", closefd=False), + encoding="mbcs", + errors="replace", + ) + sys.stderr = io.TextIOWrapper( + io.FileIO(sys.stderr.fileno(), "wb", closefd=False), + encoding="mbcs", + errors="replace", + ) + + sys.__stdin__ = sys.stdin + sys.__stdout__ = sys.stdout + sys.__stderr__ = sys.stderr + libdir = '@LIBDIR@' if libdir != '@' 'LIBDIR' '@':