summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-08-18 23:54:14 +0000
committerGerrit Code Review <review@openstack.org>2014-08-18 23:54:14 +0000
commit092afec0d79fcec3434c65139d07478d80753aec (patch)
tree40183f3b86b59babe4bbf72cdcc0817709535786
parent991cf147269cd00251b64a5aeb9d8923702c81d7 (diff)
parent710dd17a6e51b9770d26de6c598163b783acd14b (diff)
downloadoslo-messaging-092afec0d79fcec3434c65139d07478d80753aec.tar.gz
Merge "Sync jsonutils from oslo-incubator"
-rw-r--r--oslo/messaging/openstack/common/jsonutils.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/oslo/messaging/openstack/common/jsonutils.py b/oslo/messaging/openstack/common/jsonutils.py
index 971a228..5455f4e 100644
--- a/oslo/messaging/openstack/common/jsonutils.py
+++ b/oslo/messaging/openstack/common/jsonutils.py
@@ -38,11 +38,13 @@ import inspect
import itertools
import sys
+is_simplejson = False
if sys.version_info < (2, 7):
# On Python <= 2.6, json module is not C boosted, so try to use
# simplejson module if available
try:
import simplejson as json
+ is_simplejson = True
except ImportError:
import json
else:
@@ -165,9 +167,17 @@ def to_primitive(value, convert_instances=False, convert_datetime=True,
def dumps(value, default=to_primitive, **kwargs):
+ if is_simplejson:
+ kwargs['namedtuple_as_object'] = False
return json.dumps(value, default=default, **kwargs)
+def dump(obj, fp, *args, **kwargs):
+ if is_simplejson:
+ kwargs['namedtuple_as_object'] = False
+ return json.dump(obj, fp, *args, **kwargs)
+
+
def loads(s, encoding='utf-8', **kwargs):
return json.loads(strutils.safe_decode(s, encoding), **kwargs)