Use six to handle both Py2 and Py3 on unicode

This commit is contained in:
Johann Dreo 2018-02-26 16:28:42 +01:00
commit 34c04c49db

View file

@ -18,6 +18,7 @@ import string
import hashlib
import functools
import argparse
import six
# set the SIGPIPE handler to kill the program instead of
# ending in a write error when a broken pipe occurs
@ -698,8 +699,9 @@ def write(colored, stream = sys.stdout):
"""
Write "colored" on sys.stdout, then flush.
"""
if isinstance(colored, unicode):
colored = colored.encode('utf-8')
if six.PY2: # If Python 2.x: force unicode
if isinstance(colored, unicode):
colored = colored.encode('utf-8')
try:
stream.write(colored)
stream.flush()