[py-svn] commit/py: hpk42: fix windows writing wrt to unicode handling

Bitbucket commits-noreply at bitbucket.org
Thu Oct 25 12:50:49 CEST 2012


1 new commit in py:


https://bitbucket.org/hpk42/py/changeset/56d95d9647e3/
changeset:   56d95d9647e3
user:        hpk42
date:        2012-10-25 12:50:05
summary:     fix windows writing wrt to unicode handling
affected #:  1 file

diff -r acb835fc29676018b2c643b83e0980ae3427fc62 -r 56d95d9647e37a55ecdbc799f8176b62f2417706 py/_io/terminalwriter.py
--- a/py/_io/terminalwriter.py
+++ b/py/_io/terminalwriter.py
@@ -196,8 +196,10 @@
             self.write(" " * diff2last)
 
 class Win32ConsoleWriter(TerminalWriter):
-    def write(self, s, **kw):
-        if s:
+    def write(self, msg, **kw):
+        if msg:
+            if not isinstance(msg, (bytes, text)):
+                msg = text(s)
             oldcolors = None
             if self.hasmarkup and kw:
                 handle = GetStdHandle(STD_OUTPUT_HANDLE)
@@ -219,9 +221,11 @@
                     attr |= oldcolors & 0x0007
 
                 SetConsoleTextAttribute(handle, attr)
-            if not isinstance(self._file, WriteFile):
-                s = self._getbytestring(s)
-            self._file.write(s)
+            try:
+                self._file.write(msg)
+            except UnicodeEncodeError:
+                msg = msg.encode("unicode-escape").decode("ascii")
+                self._file.write(msg)
             self._file.flush()
             if oldcolors:
                 SetConsoleTextAttribute(handle, oldcolors)

Repository URL: https://bitbucket.org/hpk42/py/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the pytest-commit mailing list