summaryrefslogtreecommitdiffstats
path: root/nova/openstack
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2012-07-02 11:53:46 -0400
committerRussell Bryant <rbryant@redhat.com>2012-07-02 11:53:46 -0400
commit58ea5134100cbdbfdda7820ae31bcc775abc2381 (patch)
tree4c1129a39b66d4b084c39823c253af42acbd185f /nova/openstack
parentcb6bf34898771e6171ef5dbf898ec5705c904195 (diff)
downloadnova-58ea5134100cbdbfdda7820ae31bcc775abc2381.tar.gz
nova-58ea5134100cbdbfdda7820ae31bcc775abc2381.tar.xz
nova-58ea5134100cbdbfdda7820ae31bcc775abc2381.zip
Sync jsonutils from openstack-common.
This patch syncs the latest changes to the jsonutils module from openstack-common. It includes a fix for dealing with xmlrpclib.DateTime types in to_primitive() and allows customizing the default param to json.dumps(). Change-Id: I61f6734cdf0c85b56a71b350ca07f564454285a5
Diffstat (limited to 'nova/openstack')
-rw-r--r--nova/openstack/common/jsonutils.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/nova/openstack/common/jsonutils.py b/nova/openstack/common/jsonutils.py
index fa8b8f9d1..752266981 100644
--- a/nova/openstack/common/jsonutils.py
+++ b/nova/openstack/common/jsonutils.py
@@ -37,6 +37,7 @@ import datetime
import inspect
import itertools
import json
+import xmlrpclib
def to_primitive(value, convert_instances=False, level=0):
@@ -81,6 +82,12 @@ def to_primitive(value, convert_instances=False, level=0):
# The try block may not be necessary after the class check above,
# but just in case ...
try:
+ # It's not clear why xmlrpclib created their own DateTime type, but
+ # for our purposes, make it a datetime type which is explicitly
+ # handled
+ if isinstance(value, xmlrpclib.DateTime):
+ value = datetime.datetime(*tuple(value.timetuple())[:6])
+
if isinstance(value, (list, tuple)):
o = []
for v in value:
@@ -115,8 +122,8 @@ def to_primitive(value, convert_instances=False, level=0):
return unicode(value)
-def dumps(value):
- return json.dumps(value, default=to_primitive)
+def dumps(value, default=to_primitive, **kwargs):
+ return json.dumps(value, default=default, **kwargs)
def loads(s):