summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/log.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-09-23 07:31:53 (GMT)
committerGitHub <noreply@github.com>2018-09-23 07:31:53 (GMT)
commitc73df53569f86d0c7742bafa55958c53d57a02e4 (patch)
tree5707f75e8f2407853e0419c895b374e9af8ff5ad /Lib/distutils/log.py
parent2756ef31656399a120589b7aa19c32e2b91a4758 (diff)
downloadcpython-c73df53569f86d0c7742bafa55958c53d57a02e4.zip
cpython-c73df53569f86d0c7742bafa55958c53d57a02e4.tar.gz
cpython-c73df53569f86d0c7742bafa55958c53d57a02e4.tar.bz2
bpo-34421: Improve distutils logging for non-ASCII strings. (GH-9126) (GH-9506)
Use "backslashreplace" instead of "unicode-escape". It is not implementation depended and escapes only non-encodable characters. Also simplify the code. (cherry picked from commit 4b860fd)
Diffstat (limited to 'Lib/distutils/log.py')
-rw-r--r--Lib/distutils/log.py7
1 files changed, 3 insertions, 4 deletions
diff --git a/Lib/distutils/log.py b/Lib/distutils/log.py
index 3a6602b..8ef6b28 100644
--- a/Lib/distutils/log.py
+++ b/Lib/distutils/log.py
@@ -27,14 +27,13 @@ class Log:
stream = sys.stderr
else:
stream = sys.stdout
- if stream.errors == 'strict':
+ try:
+ stream.write('%s\n' % msg)
+ except UnicodeEncodeError:
# emulate backslashreplace error handler
encoding = stream.encoding
msg = msg.encode(encoding, "backslashreplace").decode(encoding)
- try:
stream.write('%s\n' % msg)
- except UnicodeEncodeError:
- stream.write('%s\n' % msg.encode('unicode-escape').decode('ascii'))
stream.flush()
def log(self, level, msg, *args):