From 6586018059991b696bd11e6bd4aa84135d6ab393 Mon Sep 17 00:00:00 2001 From: hakril Date: Mon, 20 May 2024 17:58:17 +0200 Subject: [PATCH] Improve pycompat when stdout is not a tty (no stdout.encoding) --- windows/pycompat.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/windows/pycompat.py b/windows/pycompat.py index 38ea8aa..957c5af 100644 --- a/windows/pycompat.py +++ b/windows/pycompat.py @@ -1,4 +1,5 @@ import sys +import locale is_py3 = (sys.version_info.major >= 3) @@ -47,7 +48,9 @@ else: # py2.7 # No unicode for now on py2 return s - repr_encoding = sys.stdout.encoding + # sys.stdout.encoding may be None if not a tty + # Use sys.stdout.isatty() ? + repr_encoding = sys.stdout.encoding or locale.getpreferredencoding() def urepr_encode(ustr): # assert isinstance(s, unicode) # Make the check explicitly ?