]> granicus.if.org Git - python/commitdiff
Issue #8663: distutils.log emulates backslashreplace error handler. Fix
authorVictor Stinner <victor.stinner@haypocalc.com>
Wed, 19 May 2010 17:00:07 +0000 (17:00 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Wed, 19 May 2010 17:00:07 +0000 (17:00 +0000)
compilation in a non-ASCII directory if stdout encoding is ASCII (eg. if stdout
is not a TTY).

Lib/distutils/log.py
Misc/NEWS

index 758857081c80e13ec772aea668323961478a752b..b301a8338c20dbbf7dee4b92b7b7ede449991ef0 100644 (file)
@@ -27,6 +27,10 @@ class Log:
                 stream = sys.stderr
             else:
                 stream = sys.stdout
+            if stream.errors == 'strict':
+                # emulate backslashreplace error handler
+                encoding = stream.encoding
+                msg = msg.encode(encoding, "backslashreplace").decode(encoding)
             stream.write('%s\n' % msg)
             stream.flush()
 
index ceda9b7392b5a8e79820a8aef8165f811c1e989f..3e582cdbc584b0c57838ed1c2b3383e5c13f6efc 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -370,6 +370,10 @@ C-API
 Library
 -------
 
+- Issue #8663: distutils.log emulates backslashreplace error handler. Fix
+  compilation in a non-ASCII directory if stdout encoding is ASCII (eg. if
+  stdout is not a TTY).
+
 - Issue #8513: os.get_exec_path() supports b'PATH' key and bytes value.
   subprocess.Popen() and os._execvpe() support bytes program name. Add
   os.supports_bytes_environ flag: True if the native OS type of the environment