Browse Source

Intermediate changes
commit_hash:b3bf8db64ac819f7d32c6a4f70488161800a345f

robot-piglet 1 week ago
parent
commit
8b3f4bb658

+ 1 - 1
contrib/python/simplejson/py2/.dist-info/METADATA

@@ -1,6 +1,6 @@
 Metadata-Version: 2.1
 Name: simplejson
-Version: 3.19.3
+Version: 3.20.1
 Summary: Simple, fast, extensible JSON encoder/decoder for Python
 Home-page: https://github.com/simplejson/simplejson
 Author: Bob Ippolito

+ 1 - 1
contrib/python/simplejson/py2/simplejson/__init__.py

@@ -118,7 +118,7 @@ Serializing multiple objects to JSON lines (newline-delimited JSON)::
 
 """
 from __future__ import absolute_import
-__version__ = '3.19.3'
+__version__ = '3.20.1'
 __all__ = [
     'dump', 'dumps', 'load', 'loads',
     'JSONDecoder', 'JSONDecodeError', 'JSONEncoder',

+ 20 - 14
contrib/python/simplejson/py2/simplejson/_speedups.c

@@ -10,11 +10,13 @@
 #define JSON_UNICHR Py_UCS4
 #define JSON_InternFromString PyUnicode_InternFromString
 #define PyString_GET_SIZE PyUnicode_GET_LENGTH
+#define JSON_StringCheck PyUnicode_Check
 #define PY2_UNUSED
 #define PY3_UNUSED UNUSED
 #else /* PY_MAJOR_VERSION >= 3 */
 #define PY2_UNUSED UNUSED
 #define PY3_UNUSED
+#define JSON_StringCheck(obj) (PyString_Check(obj) || PyUnicode_Check(obj))
 #define PyBytes_Check PyString_Check
 #define PyUnicode_READY(obj) 0
 #define PyUnicode_KIND(obj) (sizeof(Py_UNICODE))
@@ -3034,25 +3036,29 @@ encoder_listencode_dict(PyEncoderObject *s, JSON_Accu *rval, PyObject *dct, Py_s
         if (value == NULL)
             goto bail;
 
-        encoded = PyDict_GetItem(s->key_memo, key);
-        if (encoded != NULL) {
-            Py_INCREF(encoded);
-        } else {
-            kstr = encoder_stringify_key(s, key);
-            if (kstr == NULL)
-                goto bail;
-            else if (kstr == Py_None) {
-                /* skipkeys */
-                Py_DECREF(item);
-                Py_DECREF(kstr);
-                continue;
-            }
+        kstr = encoder_stringify_key(s, key);
+        if (kstr == NULL)
+            goto bail;
+        else if (kstr == Py_None) {
+            /* skipkeys */
+            Py_DECREF(item);
+            Py_DECREF(kstr);
+            continue;
         }
         if (idx) {
             if (JSON_Accu_Accumulate(rval, s->item_separator))
                 goto bail;
         }
-        if (encoded == NULL) {
+        /*
+         * Only cache the encoding of string keys. False and True are
+         * indistinguishable from 0 and 1 in a dictionary lookup and there
+         * may be other quirks with user defined subclasses.
+         */
+        encoded = PyDict_GetItem(s->key_memo, kstr);
+        if (encoded != NULL) {
+            Py_INCREF(encoded);
+            Py_CLEAR(kstr);
+        } else {
             encoded = encoder_encode_string(s, kstr);
             Py_CLEAR(kstr);
             if (encoded == NULL)

+ 6 - 0
contrib/python/simplejson/py2/simplejson/tests/test_dump.py

@@ -72,6 +72,12 @@ class TestDump(TestCase):
         self.assertEqual(json.dumps(
                  {True: False, False: True}, sort_keys=True),
                  '{"false": true, "true": false}')
+        self.assertEqual(
+            # load first because the keys are not sorted
+            json.loads(json.dumps({'k1': {False: 5}, 'k2': {0: 5}})),
+            {'k1': {'false': 5}, 'k2': {'0': 5}},
+        )
+
         self.assertEqual(
             json.dumps(
                 {2: 3.0,

+ 1 - 1
contrib/python/simplejson/py2/ya.make

@@ -2,7 +2,7 @@
 
 PY2_LIBRARY()
 
-VERSION(3.19.3)
+VERSION(3.20.1)
 
 LICENSE(MIT)