XZise has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/195086

Change subject: [FIX] Win32 UI: Don't encode in Python 3
......................................................................

[FIX] Win32 UI: Don't encode in Python 3

The text has to be encoded for the streams in Python 2, but in Python 3
the streams like sys.stdout are working on Unicode strings.

Bug: T91921
Change-Id: I20480388fecc5dd0d476ce7896a5e5d410391270
---
M pywikibot/userinterfaces/terminal_interface_win32.py
1 file changed, 9 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/86/195086/1

diff --git a/pywikibot/userinterfaces/terminal_interface_win32.py 
b/pywikibot/userinterfaces/terminal_interface_win32.py
index 7e3fd89..bd0a6e7 100755
--- a/pywikibot/userinterfaces/terminal_interface_win32.py
+++ b/pywikibot/userinterfaces/terminal_interface_win32.py
@@ -8,6 +8,7 @@
 __version__ = '$Id$'
 
 import re
+import sys
 from . import terminal_interface_base
 
 try:
@@ -72,7 +73,10 @@
             tagM = colorTagR.search(text)
             if tagM:
                 # print the text up to the tag.
-                targetStream.write(text[:tagM.start()].encode(self.encoding, 
'replace'))
+                if sys.version_info[0] > 2:
+                    targetStream.write(text[:tagM.start()])
+                else:
+                    
targetStream.write(text[:tagM.start()].encode(self.encoding, 'replace'))
                 newColor = tagM.group('name')
                 if newColor == 'default':
                     if len(colorStack) > 0:
@@ -88,7 +92,10 @@
                     
ctypes.windll.kernel32.SetConsoleTextAttribute(std_out_handle, 
windowsColors[newColor])
                 text = text[tagM.end():]
         # print the rest of the text
-        targetStream.write(text.encode(self.encoding, 'replace'))
+        if sys.version_info[0] > 2:
+            targetStream.write(text)
+        else:
+            targetStream.write(text.encode(self.encoding, 'replace'))
         # just to be sure, reset the color
         ctypes.windll.kernel32.SetConsoleTextAttribute(std_out_handle, 
windowsColors['default'])
 

-- 
To view, visit https://gerrit.wikimedia.org/r/195086
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I20480388fecc5dd0d476ce7896a5e5d410391270
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <commodorefabia...@gmx.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to