Unicode display fix

This commit is contained in:
deathfantasy 2015-10-05 17:17:57 +07:00
parent d8d19f7ee7
commit 96852cd8b4
1 changed files with 7 additions and 2 deletions

View File

@ -116,8 +116,11 @@ def obj2utf8(obj):
for i in range(0,len(obj)): for i in range(0,len(obj)):
obj[i]=obj2utf8(obj[i]) obj[i]=obj2utf8(obj[i])
obj=tuple(obj) obj=tuple(obj)
elif type(obj)==unicode or type(obj)==str: elif type(obj)==unicode:
return obj.encode('utf8', errors='replace') return obj.encode('utf8', errors='replace')
elif type(obj)==str:
# assume str sent by client is already utf8
return obj
else: else:
obj=str(obj) obj=str(obj)
return obj return obj
@ -362,7 +365,9 @@ class PupyCmd(cmd.Cmd):
def display(self, msg, modifier=None): def display(self, msg, modifier=None):
if not type(msg) is unicode: if not type(msg) is unicode:
msg=str(msg) # force output unicode string to output
# Python will hopefully handle output printing
msg=str(msg).decode('utf8')
if msg: if msg:
if modifier=="error": if modifier=="error":
self.stdout.write(PupyCmd.format_error(msg)) self.stdout.write(PupyCmd.format_error(msg))