Improve pycompat when stdout is not a tty (no stdout.encoding)

This commit is contained in:
hakril
2024-05-20 17:58:17 +02:00
parent 7a7e6935d1
commit 6586018059
+4 -1
View File
@@ -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 ?