diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-09-23 09:12:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-23 09:12:59 +0300 |
commit | 4b860fd777e983f5d2a6bd1288e2b53099c6a803 (patch) | |
tree | b3da4545b4497195ba20c32ecbf1753bbf38d7d9 /Lib/distutils/log.py | |
parent | 8fabae3b00b2ccffd9f7bf4736734ae584ac5829 (diff) | |
download | cpython-git-4b860fd777e983f5d2a6bd1288e2b53099c6a803.tar.gz |
bpo-34421: Improve distutils logging for non-ASCII strings. (GH-9126)
Use "backslashreplace" instead of "unicode-escape". It is not
implementation depended and escapes only non-encodable characters.
Also simplify the code.
Diffstat (limited to 'Lib/distutils/log.py')
-rw-r--r-- | Lib/distutils/log.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/Lib/distutils/log.py b/Lib/distutils/log.py index 3a6602bc8b..8ef6b28ea2 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): |