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:
|
if func == bool:
|
||||||
return bool(int(value))
|
return bool(int(value))
|
||||||
elif func == unicode:
|
elif func == unicode:
|
||||||
|
if isinstance(value, (int, long, float)):
|
||||||
|
return unicode(value)
|
||||||
|
else:
|
||||||
return value.decode('utf-8')
|
return value.decode('utf-8')
|
||||||
elif func == str:
|
elif func == str:
|
||||||
|
if isinstance(value, (int, long, float)):
|
||||||
|
return str(value)
|
||||||
|
else:
|
||||||
return value.encode('utf-8')
|
return value.encode('utf-8')
|
||||||
elif func in (int, float):
|
elif func in (int, float):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue