summaryrefslogtreecommitdiffstats
path: root/openstack/common/jsonutils.py
diff options
context:
space:
mode:
authorChuck Short <chuck.short@canonical.com>2013-05-01 11:22:23 -0500
committerChuck Short <chuck.short@canonical.com>2013-05-06 15:52:26 -0500
commitfde1e156a38633ce9018569145390bce2047fea8 (patch)
treeff31b1d70f5e6e35cff4a40101db0ea90ed58bcb /openstack/common/jsonutils.py
parent0c9047cc334578f9f4974c3bc006ba9bc62814d2 (diff)
downloadoslo-fde1e156a38633ce9018569145390bce2047fea8.tar.gz
oslo-fde1e156a38633ce9018569145390bce2047fea8.tar.xz
oslo-fde1e156a38633ce9018569145390bce2047fea8.zip
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>
Diffstat (limited to 'openstack/common/jsonutils.py')
-rw-r--r--openstack/common/jsonutils.py8
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):