Fix casting of int/float to str or unicode
This commit is contained in:
parent
2e8be9ec6b
commit
df6cb5718a
1 changed files with 8 additions and 2 deletions
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue