]> granicus.if.org Git - python/commitdiff
bpo-34421 avoid unicode error in distutils logging (GH-8799)
authorJulien Malard <julien.malard@mail.mcgill.ca>
Sat, 8 Sep 2018 20:31:26 +0000 (02:01 +0530)
committerÉric Araujo <merwok@netwok.org>
Sat, 8 Sep 2018 20:31:26 +0000 (16:31 -0400)
This caused installation errors in some cases on Windows.
Patch by Julien Malard.

Lib/distutils/log.py
Misc/NEWS.d/next/Library/2018-09-07-10-57-00.bpo-34421.AKJISD.rst [new file with mode: 0644]

index b301a8338c20dbbf7dee4b92b7b7ede449991ef0..3a6602bc8b8ef6c10954bcdc17b064c6daa51908 100644 (file)
@@ -31,7 +31,10 @@ class Log:
                 # emulate backslashreplace error handler
                 encoding = stream.encoding
                 msg = msg.encode(encoding, "backslashreplace").decode(encoding)
-            stream.write('%s\n' % msg)
+            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):
diff --git a/Misc/NEWS.d/next/Library/2018-09-07-10-57-00.bpo-34421.AKJISD.rst b/Misc/NEWS.d/next/Library/2018-09-07-10-57-00.bpo-34421.AKJISD.rst
new file mode 100644 (file)
index 0000000..cc1db08
--- /dev/null
@@ -0,0 +1 @@
+Fix distutils logging for non-ASCII strings.  This caused installation issues on Windows.