[Python-checkins] cpython (merge 3.2 -> default): Merge with 3.2.

ezio.melotti python-checkins at python.org
Wed Apr 13 06:21:59 CEST 2011


http://hg.python.org/cpython/rev/e8e3f2b72a32
changeset:   69321:e8e3f2b72a32
parent:      69315:c2ea543f5a66
parent:      69320:b279611146d7
user:        Ezio Melotti <ezio.melotti at gmail.com>
date:        Wed Apr 13 07:21:24 2011 +0300
summary:
  Merge with 3.2.

files:
  Lib/json/decoder.py                    |   6 ++++++
  Lib/test/json_tests/test_decode.py     |   5 +++++
  Lib/test/json_tests/test_scanstring.py |   9 +++++++--
  Lib/test/json_tests/test_speedups.py   |  14 ++++++++++----
  Misc/NEWS                              |  11 +++++++----
  5 files changed, 35 insertions(+), 10 deletions(-)


diff --git a/Lib/json/decoder.py b/Lib/json/decoder.py
--- a/Lib/json/decoder.py
+++ b/Lib/json/decoder.py
@@ -165,6 +165,12 @@
             nextchar = s[end:end + 1]
         # Trivial empty object
         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
         elif nextchar != '"':
             raise ValueError(errmsg("Expecting property name", s, end))
diff --git a/Lib/test/json_tests/test_decode.py b/Lib/test/json_tests/test_decode.py
--- a/Lib/test/json_tests/test_decode.py
+++ b/Lib/test/json_tests/test_decode.py
@@ -31,6 +31,11 @@
         self.assertTrue(isinstance(rval, float))
         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):
         s = '{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
         p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4),
diff --git a/Lib/test/json_tests/test_scanstring.py b/Lib/test/json_tests/test_scanstring.py
--- a/Lib/test/json_tests/test_scanstring.py
+++ b/Lib/test/json_tests/test_scanstring.py
@@ -1,14 +1,19 @@
 import sys
-import decimal
-from unittest import TestCase
+from unittest import TestCase, skipUnless
 
 import json
 import json.decoder
 
+try:
+    import _json
+except ImportError:
+    _json = None
+
 class TestScanString(TestCase):
     def test_py_scanstring(self):
         self._test_scanstring(json.decoder.py_scanstring)
 
+    @skipUnless(_json, 'test requires the _json module')
     def test_c_scanstring(self):
         if json.decoder.c_scanstring is not None:
             self._test_scanstring(json.decoder.c_scanstring)
diff --git a/Lib/test/json_tests/test_speedups.py b/Lib/test/json_tests/test_speedups.py
--- a/Lib/test/json_tests/test_speedups.py
+++ b/Lib/test/json_tests/test_speedups.py
@@ -1,16 +1,22 @@
-from unittest import TestCase
+from unittest import TestCase, skipUnless
 
 from json import decoder, encoder, scanner
 
+try:
+    import _json
+except ImportError:
+    _json = None
+
+ at skipUnless(_json, 'test requires the _json module')
 class TestSpeedups(TestCase):
     def test_scanstring(self):
         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):
         self.assertEqual(encoder.encode_basestring_ascii.__module__, "_json")
-        self.assertTrue(encoder.encode_basestring_ascii is
-                          encoder.c_encode_basestring_ascii)
+        self.assertIs(encoder.encode_basestring_ascii,
+                      encoder.c_encode_basestring_ascii)
 
 class TestDecode(TestCase):
     def test_make_scanner(self):
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -103,11 +103,14 @@
 Library
 -------
 
-- Issue #11830: Remove unnecessary introspection code in the decimal module.                                                                
-
-- Issue #11703 - urllib2.geturl() does not return correct url when the original
+- Issue #9233: Fix json.loads('{}') to return a dict (instead of a list), when
+  _json is not available.
+
+- 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.
-  
+
 - Issue #10019: Fixed regression in json module where an indent of 0 stopped
   adding newlines and acted instead like 'None'.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list