Commit a8d2f077 authored by Ezio Melotti's avatar Ezio Melotti

Merge with 3.2.

parents e7b305fc c30ec55e
...@@ -165,6 +165,12 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook, ...@@ -165,6 +165,12 @@ def JSONObject(s_and_end, strict, scan_once, object_hook, object_pairs_hook,
nextchar = s[end:end + 1] nextchar = s[end:end + 1]
# Trivial empty object # Trivial empty object
if nextchar == '}': if nextchar == '}':
if object_pairs_hook is not None:
result = object_pairs_hook(pairs)
return result, end
pairs = {}
if object_hook is not None:
pairs = object_hook(pairs)
return pairs, end + 1 return pairs, end + 1
elif nextchar != '"': elif nextchar != '"':
raise ValueError(errmsg("Expecting property name", s, end)) raise ValueError(errmsg("Expecting property name", s, end))
......
...@@ -31,6 +31,11 @@ class TestDecode(TestCase): ...@@ -31,6 +31,11 @@ class TestDecode(TestCase):
self.assertTrue(isinstance(rval, float)) self.assertTrue(isinstance(rval, float))
self.assertEqual(rval, 1.0) self.assertEqual(rval, 1.0)
def test_empty_objects(self):
self.assertEqual(json.loads('{}'), {})
self.assertEqual(json.loads('[]'), [])
self.assertEqual(json.loads('""'), "")
def test_object_pairs_hook(self): def test_object_pairs_hook(self):
s = '{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}' s = '{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4), p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4),
......
import sys import sys
import decimal from unittest import TestCase, skipUnless
from unittest import TestCase
import json import json
import json.decoder import json.decoder
try:
import _json
except ImportError:
_json = None
class TestScanString(TestCase): class TestScanString(TestCase):
def test_py_scanstring(self): def test_py_scanstring(self):
self._test_scanstring(json.decoder.py_scanstring) self._test_scanstring(json.decoder.py_scanstring)
@skipUnless(_json, 'test requires the _json module')
def test_c_scanstring(self): def test_c_scanstring(self):
if json.decoder.c_scanstring is not None: if json.decoder.c_scanstring is not None:
self._test_scanstring(json.decoder.c_scanstring) self._test_scanstring(json.decoder.c_scanstring)
......
from unittest import TestCase from unittest import TestCase, skipUnless
from json import decoder, encoder, scanner from json import decoder, encoder, scanner
try:
import _json
except ImportError:
_json = None
@skipUnless(_json, 'test requires the _json module')
class TestSpeedups(TestCase): class TestSpeedups(TestCase):
def test_scanstring(self): def test_scanstring(self):
self.assertEqual(decoder.scanstring.__module__, "_json") self.assertEqual(decoder.scanstring.__module__, "_json")
self.assertTrue(decoder.scanstring is decoder.c_scanstring) self.assertIs(decoder.scanstring, decoder.c_scanstring)
def test_encode_basestring_ascii(self): def test_encode_basestring_ascii(self):
self.assertEqual(encoder.encode_basestring_ascii.__module__, "_json") self.assertEqual(encoder.encode_basestring_ascii.__module__, "_json")
self.assertTrue(encoder.encode_basestring_ascii is self.assertIs(encoder.encode_basestring_ascii,
encoder.c_encode_basestring_ascii) encoder.c_encode_basestring_ascii)
class TestDecode(TestCase): class TestDecode(TestCase):
def test_make_scanner(self): def test_make_scanner(self):
......
...@@ -103,11 +103,14 @@ Core and Builtins ...@@ -103,11 +103,14 @@ Core and Builtins
Library Library
------- -------
- Issue #11830: Remove unnecessary introspection code in the decimal module. - Issue #9233: Fix json.loads('{}') to return a dict (instead of a list), when
_json is not available.
- Issue #11703 - urllib2.geturl() does not return correct url when the original - Issue #11830: Remove unnecessary introspection code in the decimal module.
- Issue #11703: urllib2.geturl() does not return correct url when the original
url contains #fragment. url contains #fragment.
- Issue #10019: Fixed regression in json module where an indent of 0 stopped - Issue #10019: Fixed regression in json module where an indent of 0 stopped
adding newlines and acted instead like 'None'. adding newlines and acted instead like 'None'.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment