summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Daly Jr <timjr@yahoo-inc.com>2012-06-26 02:48:42 +0000
committerTim Daly Jr <timjr@yahoo-inc.com>2012-06-26 02:48:51 +0000
commit4c9d439ef24f5afdd74aa9153aa8fc772051e6cb (patch)
tree11d4991dc74b11ae4019a367a69274d0a56e3a41
parent5a93e1d790422ddf21c223ec77b0355e6b790021 (diff)
downloadoslo-4c9d439ef24f5afdd74aa9153aa8fc772051e6cb.tar.gz
oslo-4c9d439ef24f5afdd74aa9153aa8fc772051e6cb.tar.xz
oslo-4c9d439ef24f5afdd74aa9153aa8fc772051e6cb.zip
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
-rw-r--r--openstack/common/jsonutils.py6
-rw-r--r--tests/unit/test_jsonutils.py5
2 files changed, 10 insertions, 1 deletions
diff --git a/openstack/common/jsonutils.py b/openstack/common/jsonutils.py
index 7522669..11b7e1e 100644
--- a/openstack/common/jsonutils.py
+++ b/openstack/common/jsonutils.py
@@ -130,11 +130,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__)
diff --git a/tests/unit/test_jsonutils.py b/tests/unit/test_jsonutils.py
index 5764f45..9b987cd 100644
--- a/tests/unit/test_jsonutils.py
+++ b/tests/unit/test_jsonutils.py
@@ -18,6 +18,7 @@
import datetime
import unittest
import xmlrpclib
+import StringIO
from openstack.common import jsonutils
@@ -30,6 +31,10 @@ class JSONUtilsTestCase(unittest.TestCase):
def test_loads(self):
self.assertEqual(jsonutils.loads('{"a": "b"}'), {'a': 'b'})
+ def test_load(self):
+ x = StringIO.StringIO('{"a": "b"}')
+ self.assertEqual(jsonutils.load(x), {'a': 'b'})
+
class ToPrimitiveTestCase(unittest.TestCase):
def test_list(self):