#17368: merge with 3.3.

This commit is contained in:
Ezio Melotti 2013-03-13 01:55:07 +02:00
commit 405952f1a8
3 changed files with 15 additions and 5 deletions

View File

@ -158,7 +158,7 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook,
if nextchar == '}': if nextchar == '}':
if object_pairs_hook is not None: if object_pairs_hook is not None:
result = object_pairs_hook(pairs) result = object_pairs_hook(pairs)
return result, end return result, end + 1
pairs = {} pairs = {}
if object_hook is not None: if object_hook is not None:
pairs = object_hook(pairs) pairs = object_hook(pairs)

View File

@ -25,16 +25,22 @@ class TestDecode:
p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4), p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4),
("qrt", 5), ("pad", 6), ("hoy", 7)] ("qrt", 5), ("pad", 6), ("hoy", 7)]
self.assertEqual(self.loads(s), eval(s)) self.assertEqual(self.loads(s), eval(s))
self.assertEqual(self.loads(s, object_pairs_hook = lambda x: x), p) self.assertEqual(self.loads(s, object_pairs_hook=lambda x: x), p)
self.assertEqual(self.json.load(StringIO(s), self.assertEqual(self.json.load(StringIO(s),
object_pairs_hook=lambda x: x), p) object_pairs_hook=lambda x: x), p)
od = self.loads(s, object_pairs_hook = OrderedDict) od = self.loads(s, object_pairs_hook=OrderedDict)
self.assertEqual(od, OrderedDict(p)) self.assertEqual(od, OrderedDict(p))
self.assertEqual(type(od), OrderedDict) self.assertEqual(type(od), OrderedDict)
# the object_pairs_hook takes priority over the object_hook # the object_pairs_hook takes priority over the object_hook
self.assertEqual(self.loads(s, object_pairs_hook = OrderedDict, self.assertEqual(self.loads(s, object_pairs_hook=OrderedDict,
object_hook = lambda x: None), object_hook=lambda x: None),
OrderedDict(p)) OrderedDict(p))
# check that empty objects literals work (see #17368)
self.assertEqual(self.loads('{}', object_pairs_hook=OrderedDict),
OrderedDict())
self.assertEqual(self.loads('{"empty": {}}',
object_pairs_hook=OrderedDict),
OrderedDict([('empty', OrderedDict())]))
def test_decoder_optimizations(self): def test_decoder_optimizations(self):
# Several optimizations were made that skip over calls to # Several optimizations were made that skip over calls to

View File

@ -277,6 +277,10 @@ Core and Builtins
Library Library
------- -------
- Issue #17368: Fix an off-by-one error in the Python JSON decoder that caused
a failure while decoding empty object literals when object_pairs_hook was
specified.
_ Issue #17385: Fix quadratic behavior in threading.Condition. The FIFO _ Issue #17385: Fix quadratic behavior in threading.Condition. The FIFO
queue now uses a deque instead of a list. queue now uses a deque instead of a list.