jenkins-bot has submitted this change and it was merged.
Change subject: Fix py2.6 unicode output test cases ......................................................................
Fix py2.6 unicode output test cases
The behavior of streams with an '.encoding' parameter changed from 2.6 to 2.7: writing unicode is not allowed in 2.6, but is in 2.7. In 3.x, the latter is the standard behavior.
At least, for stdin/stdout. We can also have a binary file stream, in which case we have to decide the encoding ourselves.
Change-Id: I29118b548ef95544d0f6a148d76bae109e9cfbe5 --- M pywikibot/userinterfaces/terminal_interface_unix.py 1 file changed, 6 insertions(+), 1 deletion(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/userinterfaces/terminal_interface_unix.py b/pywikibot/userinterfaces/terminal_interface_unix.py index 4ab6158..da6f43e 100755 --- a/pywikibot/userinterfaces/terminal_interface_unix.py +++ b/pywikibot/userinterfaces/terminal_interface_unix.py @@ -6,6 +6,7 @@ # __version__ = '$Id$'
+import sys from . import terminal_interface_base
unixColors = { @@ -41,7 +42,11 @@ # just to be sure, reset the color text += unixColors['default']
- if hasattr(targetStream, 'encoding') and targetStream.encoding: + # .encoding does not mean we can write unicode + # to the stream pre-2.7. + if sys.version_info >= (2, 7) and \ + hasattr(targetStream, 'encoding') and \ + targetStream.encoding: text = text.encode(targetStream.encoding, 'replace').decode(targetStream.encoding) targetStream.write(text) else:
pywikibot-commits@lists.wikimedia.org