diff options
| author | Russell Bryant <rbryant@redhat.com> | 2012-07-16 12:20:44 -0400 |
|---|---|---|
| committer | Russell Bryant <rbryant@redhat.com> | 2012-07-16 13:51:37 -0400 |
| commit | 12e663a8b0b253970e3bccd373d3d2f3d462f6b6 (patch) | |
| tree | 4d942c3490e312d809ccd4f5a69fb74d79a4b28d /nova/openstack | |
| parent | 9f33802364887dd22e7e87e329f51452650b1edd (diff) | |
| download | nova-12e663a8b0b253970e3bccd373d3d2f3d462f6b6.tar.gz nova-12e663a8b0b253970e3bccd373d3d2f3d462f6b6.tar.xz nova-12e663a8b0b253970e3bccd373d3d2f3d462f6b6.zip | |
Sync jsonutils from openstack-common.
In addition to the following changes from openstack-common, this patch
includes some tweak to nova unit tests. timeutils.strtime() will raise
an exception if the year in a datetime object is before 1900.
Changes from openstack-common:
commit ce3071437d1871f77c4d8573cbe5f4ea8c817650
Author: Russell Bryant <rbryant@redhat.com>
Date: Mon Jul 16 10:30:25 2012 -0400
Use strtime() in to_primitive() for datetime objs.
This patch updates jsonutils.to_primitive() to use timeutils.strtime()
to convert a datimetime object to a string instead of just using str().
This ensures that we can easily convert the string back to a datetime
using timeutils.parse_strtime().
Required for the nova blueprint no-db-messaging.
commit 4c9d439ef24f5afdd74aa9153aa8fc772051e6cb
Author: Tim Daly Jr <timjr@yahoo-inc.com>
Date: Tue Jun 26 02:48:42 2012 +0000
Add 'filedecoder' method to the jsonutils wrapper module.
Fixes bug #1017765
After version 3.3.2, the anyjson library will throw a KeyError if
filedecoder isn't present. The filedecoder is just like the decoder
except it takes a file instead of a string, like json.load() instead
of json.loads().
Change-Id: Ib51f0da8641c035371e09047de9abe3cb83203e9
Diffstat (limited to 'nova/openstack')
| -rw-r--r-- | nova/openstack/common/jsonutils.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/nova/openstack/common/jsonutils.py b/nova/openstack/common/jsonutils.py index 752266981..5f6a7edab 100644 --- a/nova/openstack/common/jsonutils.py +++ b/nova/openstack/common/jsonutils.py @@ -39,6 +39,8 @@ import itertools import json import xmlrpclib +from nova.openstack.common import timeutils + def to_primitive(value, convert_instances=False, level=0): """Convert a complex object into primitives. @@ -101,7 +103,7 @@ def to_primitive(value, convert_instances=False, level=0): level=level) return o elif isinstance(value, datetime.datetime): - return str(value) + return timeutils.strtime(value) elif hasattr(value, 'iteritems'): return to_primitive(dict(value.iteritems()), convert_instances=convert_instances, @@ -130,11 +132,15 @@ def loads(s): return json.loads(s) +def load(s): + return json.load(s) + + try: import anyjson except ImportError: pass else: anyjson._modules.append((__name__, 'dumps', TypeError, - 'loads', ValueError)) + 'loads', ValueError, 'load')) anyjson.force_implementation(__name__) |
