From 34c04c49db99bc5041b1f5107b43f97d8ec91795 Mon Sep 17 00:00:00 2001 From: nojhan Date: Mon, 26 Feb 2018 16:28:42 +0100 Subject: [PATCH] Use six to handle both Py2 and Py3 on unicode --- colout/colout.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/colout/colout.py b/colout/colout.py index b80e065..3028f39 100755 --- a/colout/colout.py +++ b/colout/colout.py @@ -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()