Fix casting of int/float to str or unicode

This commit is contained in:
croneter 2018-11-06 12:41:06 +01:00
parent 2e8be9ec6b
commit df6cb5718a

View file

@ -328,8 +328,14 @@ def cast(func, value):
if func == bool:
return bool(int(value))
elif func == unicode:
if isinstance(value, (int, long, float)):
return unicode(value)
else:
return value.decode('utf-8')
elif func == str:
if isinstance(value, (int, long, float)):
return str(value)
else:
return value.encode('utf-8')
elif func in (int, float):
try: