diff options
author | Chuck Short <chuck.short@canonical.com> | 2013-05-01 11:22:23 -0500 |
---|---|---|
committer | Chuck Short <chuck.short@canonical.com> | 2013-05-01 11:22:23 -0500 |
commit | 7fa8325525f7dd1802261a071dad1f5effd9b95a (patch) | |
tree | 5abae66fb64ce706d63a9c2fb53a9bca637c00a8 | |
parent | c69fb7f3d139b392027f0552bc7ddafee48eef6d (diff) | |
download | oslo-serialization-7fa8325525f7dd1802261a071dad1f5effd9b95a.tar.gz |
Convert unicode for python3 portability
From http://docs.python.org/3.1/whatsnew/3.0.html:
"Python 3.0 uses the concepts of text and (binary) data instead of
Unicode strings and 8-bit strings."
Use six.text_type to Type for representing (Unicode) textual data. This
is unicode() in Python 2 and str in Python 3.
Change-Id: I3da268a714a34a8e626a2590f01b86e414dc3411
Signed-off-by: Chuck Short <chuck.short@canonical.com>
-rw-r--r-- | openstack/common/jsonutils.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/openstack/common/jsonutils.py b/openstack/common/jsonutils.py index f3cc0e9..bf23403 100644 --- a/openstack/common/jsonutils.py +++ b/openstack/common/jsonutils.py @@ -41,6 +41,8 @@ import json import types import xmlrpclib +import six + from openstack.common import timeutils @@ -93,7 +95,7 @@ def to_primitive(value, convert_instances=False, convert_datetime=True, # value of itertools.count doesn't get caught by nasty_type_tests # and results in infinite loop when list(value) is called. if type(value) == itertools.count: - return unicode(value) + return six.text_type(value) # FIXME(vish): Workaround for LP bug 852095. Without this workaround, # tests that raise an exception in a mocked method that @@ -137,12 +139,12 @@ def to_primitive(value, convert_instances=False, convert_datetime=True, return recursive(value.__dict__, level=level + 1) else: if any(test(value) for test in _nasty_type_tests): - return unicode(value) + return six.text_type(value) return value except TypeError: # Class objects are tricky since they may define something like # __iter__ defined but it isn't callable as list(). - return unicode(value) + return six.text_type(value) def dumps(value, default=to_primitive, **kwargs): |