Prevent UnicodeEncodeError

Prevents UnicodeEncodeError: 'ascii' codec can't encode character, while printing shell commands output
This commit is contained in:
cavassin 2013-12-05 13:17:57 -02:00
parent cbfeb0a2ea
commit 10f5af82f9

View file

@ -128,9 +128,15 @@ def display(msg, color=None, stderr=False, screen_only=False, log_only=False, ru
msg2 = stringc(msg, color)
if not log_only:
if not stderr:
try:
print msg2
except UnicodeEncodeError:
print msg2.encode('utf-8')
else:
try:
print >>sys.stderr, msg2
except UnicodeEncodeError:
print >>sys.stderr, msg2.encode('utf-8')
if constants.DEFAULT_LOG_PATH != '':
while msg.startswith("\n"):
msg = msg.replace("\n","")