diff options
author | Bob Ippolito <bob@redivi.com> | 2009-03-29 22:33:58 (GMT) |
---|---|---|
committer | Bob Ippolito <bob@redivi.com> | 2009-03-29 22:33:58 (GMT) |
commit | 76a982a027d72287a6d9113b1d65ec6d327d744d (patch) | |
tree | 0c2536d595c4b31e9bc996609123129e02b4543c /Lib/json | |
parent | 8e1a3381293466a6d9a3873b46194a4ed9277619 (diff) | |
download | cpython-76a982a027d72287a6d9113b1d65ec6d327d744d.zip cpython-76a982a027d72287a6d9113b1d65ec6d327d744d.tar.gz cpython-76a982a027d72287a6d9113b1d65ec6d327d744d.tar.bz2 |
Issue 5381: fix regression in pure python code path, Issue 5584: fix a decoder bug for unicode float literals outside of a container
Diffstat (limited to 'Lib/json')
-rw-r--r-- | Lib/json/__init__.py | 3 | ||||
-rw-r--r-- | Lib/json/scanner.py | 3 | ||||
-rw-r--r-- | Lib/json/tests/test_decode.py | 11 | ||||
-rw-r--r-- | Lib/json/tests/test_float.py | 6 |
4 files changed, 16 insertions, 7 deletions
diff --git a/Lib/json/__init__.py b/Lib/json/__init__.py index 01c26d9..ba584a3 100644 --- a/Lib/json/__init__.py +++ b/Lib/json/__init__.py @@ -266,7 +266,8 @@ def load(fp, encoding=None, cls=None, object_hook=None, parse_float=None, return loads(fp.read(), encoding=encoding, cls=cls, object_hook=object_hook, parse_float=parse_float, parse_int=parse_int, - parse_constant=parse_constant, object_pairs_hook=None, **kw) + parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, + **kw) def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, diff --git a/Lib/json/scanner.py b/Lib/json/scanner.py index 00c5470..74e6805 100644 --- a/Lib/json/scanner.py +++ b/Lib/json/scanner.py @@ -23,6 +23,7 @@ def py_make_scanner(context): parse_int = context.parse_int parse_constant = context.parse_constant object_hook = context.object_hook + object_pairs_hook = context.object_pairs_hook def _scan_once(string, idx): try: @@ -34,7 +35,7 @@ def py_make_scanner(context): return parse_string(string, idx + 1, encoding, strict) elif nextchar == '{': return parse_object((string, idx + 1), encoding, strict, - _scan_once, object_hook) + _scan_once, object_hook, object_pairs_hook) elif nextchar == '[': return parse_array((string, idx + 1), _scan_once) elif nextchar == 'n' and string[idx:idx + 4] == 'null': diff --git a/Lib/json/tests/test_decode.py b/Lib/json/tests/test_decode.py index 0744b52..7109527 100644 --- a/Lib/json/tests/test_decode.py +++ b/Lib/json/tests/test_decode.py @@ -1,5 +1,6 @@ import decimal from unittest import TestCase +from StringIO import StringIO import json from collections import OrderedDict @@ -27,12 +28,14 @@ class TestDecode(TestCase): p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4), ("qrt", 5), ("pad", 6), ("hoy", 7)] self.assertEqual(json.loads(s), eval(s)) - self.assertEqual(json.loads(s, object_pairs_hook = lambda x: x), p) - od = json.loads(s, object_pairs_hook = OrderedDict) + self.assertEqual(json.loads(s, object_pairs_hook=lambda x: x), p) + self.assertEqual(json.load(StringIO(s), + object_pairs_hook=lambda x: x), p) + od = json.loads(s, object_pairs_hook=OrderedDict) self.assertEqual(od, OrderedDict(p)) self.assertEqual(type(od), OrderedDict) # the object_pairs_hook takes priority over the object_hook self.assertEqual(json.loads(s, - object_pairs_hook = OrderedDict, - object_hook = lambda x: None), + object_pairs_hook=OrderedDict, + object_hook=lambda x: None), OrderedDict(p)) diff --git a/Lib/json/tests/test_float.py b/Lib/json/tests/test_float.py index 20d41d9..15e7913 100644 --- a/Lib/json/tests/test_float.py +++ b/Lib/json/tests/test_float.py @@ -5,11 +5,15 @@ import json class TestFloat(TestCase): def test_floats(self): - for num in [1617161771.7650001, math.pi, math.pi**100, math.pi**-100, 3.1]: + for num in [1617161771.7650001, math.pi, math.pi**100, + math.pi**-100, 3.1]: self.assertEquals(float(json.dumps(num)), num) self.assertEquals(json.loads(json.dumps(num)), num) + self.assertEquals(json.loads(unicode(json.dumps(num))), num) def test_ints(self): for num in [1, 1L, 1<<32, 1<<64]: self.assertEquals(json.dumps(num), str(num)) self.assertEquals(int(json.dumps(num)), num) + self.assertEquals(json.loads(json.dumps(num)), num) + self.assertEquals(json.loads(unicode(json.dumps(num))), num) |