[entropy.const] const_convert_to_{rawstring,unicode}: add float support

This commit is contained in:
Fabio Erculiani
2013-05-30 10:23:31 +02:00
parent 6d94e86870
commit f8d5d062ab
+13 -13
View File
@@ -1301,30 +1301,28 @@ def const_convert_to_unicode(obj, enctype = RAW_ENCODING):
else:
return unicode("None")
# int support
if isinstance(obj, const_get_int()):
if const_isnumber(obj) or isinstance(obj, float):
if const_is_python3():
return str(obj)
else:
return unicode(obj)
# buffer support
if isinstance(obj, const_get_buffer()):
if const_is_python3():
return str(obj.tobytes(), enctype)
else:
return unicode(obj, enctype)
# string/unicode support
if const_isunicode(obj):
return obj
if hasattr(obj, 'decode'):
return obj.decode(enctype)
if const_is_python3():
return str(obj, enctype)
else:
if const_is_python3():
return str(obj, enctype)
else:
return unicode(obj, enctype)
return unicode(obj, enctype)
def const_convert_to_rawstring(obj, from_enctype = RAW_ENCODING):
"""
@@ -1340,18 +1338,20 @@ def const_convert_to_rawstring(obj, from_enctype = RAW_ENCODING):
"""
if obj is None:
return const_convert_to_rawstring("None")
if const_isnumber(obj):
if const_isnumber(obj) or isinstance(obj, float):
if const_is_python3():
return bytes(str(obj), from_enctype)
else:
return str(obj)
return str(obj)
if isinstance(obj, const_get_buffer()):
if const_is_python3():
return obj.tobytes()
else:
return str(obj)
return str(obj)
if not const_isunicode(obj):
return obj
return obj.encode(from_enctype)
def const_get_buffer():