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,9 +328,15 @@ def cast(func, value):
if func == bool:
return bool(int(value))
elif func == unicode:
return value.decode('utf-8')
if isinstance(value, (int, long, float)):
return unicode(value)
else:
return value.decode('utf-8')
elif func == str:
return value.encode('utf-8')
if isinstance(value, (int, long, float)):
return str(value)
else:
return value.encode('utf-8')
elif func in (int, float):
try:
return func(value)