summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-02-12 22:17:38 +0000
committerGerrit Code Review <review@openstack.org>2013-02-12 22:17:38 +0000
commit65241f96f900fd1eaad9c2731fda7d63b18a8f11 (patch)
tree25d450437b0c795fbd084da830b01c477a7ae7d6
parent0e38c7da886e24ff183ac3bdf16803528760902a (diff)
parent7b206ad53d0ecfb9176a3c47e574552998caa0f7 (diff)
downloadnova-65241f96f900fd1eaad9c2731fda7d63b18a8f11.tar.gz
nova-65241f96f900fd1eaad9c2731fda7d63b18a8f11.tar.xz
nova-65241f96f900fd1eaad9c2731fda7d63b18a8f11.zip
Merge "Sync jsonutils from openstack-common"
-rw-r--r--nova/openstack/common/jsonutils.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/nova/openstack/common/jsonutils.py b/nova/openstack/common/jsonutils.py
index 290435450..b06055117 100644
--- a/nova/openstack/common/jsonutils.py
+++ b/nova/openstack/common/jsonutils.py
@@ -38,13 +38,17 @@ import functools
import inspect
import itertools
import json
+import logging
import xmlrpclib
+from nova.openstack.common.gettextutils import _
from nova.openstack.common import timeutils
+LOG = logging.getLogger(__name__)
+
def to_primitive(value, convert_instances=False, convert_datetime=True,
- level=0):
+ level=0, max_depth=3):
"""Convert a complex object into primitives.
Handy for JSON serialization. We can optionally handle instances,
@@ -80,7 +84,9 @@ def to_primitive(value, convert_instances=False, convert_datetime=True,
if getattr(value, '__module__', None) == 'mox':
return 'mock'
- if level > 3:
+ if level > max_depth:
+ LOG.error(_('Max serialization depth exceeded on object: %d %s'),
+ level, value)
return '?'
# The try block may not be necessary after the class check above,
@@ -89,7 +95,8 @@ def to_primitive(value, convert_instances=False, convert_datetime=True,
recursive = functools.partial(to_primitive,
convert_instances=convert_instances,
convert_datetime=convert_datetime,
- level=level)
+ level=level,
+ max_depth=max_depth)
# It's not clear why xmlrpclib created their own DateTime type, but
# for our purposes, make it a datetime type which is explicitly
# handled