From 5adb018aaeaf6c05478cae72fe3f97e1b20e0935 Mon Sep 17 00:00:00 2001 From: Vincent Untz Date: Thu, 19 Jul 2012 11:42:18 +0200 Subject: Sync jsonutils from openstack-common This makes keystone work with recent versions of anyjson. Changes from openstack-common: commit ce3071437d1871f77c4d8573cbe5f4ea8c817650 Author: Russell Bryant 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. Change-Id: I725b333695930e12e2832378102514326fec639c commit 4c9d439ef24f5afdd74aa9153aa8fc772051e6cb Author: Tim Daly Jr 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: I7bd012a7b4afa9b1ec987c3e6393cc922b5dadff Change-Id: Icfd5c39c322ed6e73148c7f5ae03f704a3aa160e --- keystone/openstack/common/jsonutils.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/keystone/openstack/common/jsonutils.py b/keystone/openstack/common/jsonutils.py index 75226698..ea409e49 100644 --- a/keystone/openstack/common/jsonutils.py +++ b/keystone/openstack/common/jsonutils.py @@ -39,6 +39,8 @@ import itertools import json import xmlrpclib +from keystone.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__) -- cgit