Use six to handle both Py2 and Py3 on unicode
This commit is contained in:
parent
eca25b4106
commit
34c04c49db
1 changed files with 4 additions and 2 deletions
|
|
@ -18,6 +18,7 @@ import string
|
||||||
import hashlib
|
import hashlib
|
||||||
import functools
|
import functools
|
||||||
import argparse
|
import argparse
|
||||||
|
import six
|
||||||
|
|
||||||
# set the SIGPIPE handler to kill the program instead of
|
# set the SIGPIPE handler to kill the program instead of
|
||||||
# ending in a write error when a broken pipe occurs
|
# ending in a write error when a broken pipe occurs
|
||||||
|
|
@ -698,6 +699,7 @@ def write(colored, stream = sys.stdout):
|
||||||
"""
|
"""
|
||||||
Write "colored" on sys.stdout, then flush.
|
Write "colored" on sys.stdout, then flush.
|
||||||
"""
|
"""
|
||||||
|
if six.PY2: # If Python 2.x: force unicode
|
||||||
if isinstance(colored, unicode):
|
if isinstance(colored, unicode):
|
||||||
colored = colored.encode('utf-8')
|
colored = colored.encode('utf-8')
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue