[Python-modules-commits] [simplejson] 01/04: Import simplejson_3.11.1.orig.tar.gz
Piotr Ożarowski
piotr at moszumanska.debian.org
Thu Jun 22 20:44:27 UTC 2017
This is an automated email from the git hooks/post-receive script.
piotr pushed a commit to branch master
in repository simplejson.
commit ef376a1883d20da067c78a1a2397cbef3b098551
Author: Piotr Ożarowski <piotr at debian.org>
Date: Thu Jun 22 22:34:57 2017 +0200
Import simplejson_3.11.1.orig.tar.gz
---
CHANGES.txt | 28 +++++
PKG-INFO | 4 +-
conf.py | 6 +-
index.rst | 2 +-
scripts/artifacts.py | 2 -
scripts/make_docs.py | 1 -
setup.py | 4 +-
simplejson.egg-info/PKG-INFO | 4 +-
simplejson/__init__.py | 2 +-
simplejson/_speedups.c | 214 ++++++++++++++-------------------
simplejson/decoder.py | 8 +-
simplejson/encoder.py | 2 +-
simplejson/ordered_dict.py | 18 +--
simplejson/tests/__init__.py | 38 ++----
simplejson/tests/test_item_sort_key.py | 7 ++
simplejson/tests/test_speedups.py | 53 +++++++-
16 files changed, 204 insertions(+), 189 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index bd01fe8..eecb59e 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,31 @@
+Version 3.11.1 released 2017-06-19
+
+* Fix issue with item_sort_key when speedups are available, and add
+ auto-discovery to test suites to prevent similar regressions
+ https://github.com/simplejson/simplejson/issues/173
+
+Version 3.11.0 released 2017-06-18
+
+* docstring fix in JSONEncoder
+ https://github.com/simplejson/simplejson/pull/172
+* Call PyObject_IsTrue() only once for the strict argument of scanner
+ https://github.com/simplejson/simplejson/pull/170
+* Fix a crash with unencodable encoding in the encoder
+ https://github.com/simplejson/simplejson/pull/171
+* Remove unused imports
+ https://github.com/simplejson/simplejson/pull/162
+* Remove remnants of Python 2.4 support
+ https://github.com/simplejson/simplejson/pull/168
+* Fix argument checking errors in _speedups.c
+ https://github.com/simplejson/simplejson/pull/169
+* Remove the `__init__` methods in extension classes
+ https://github.com/simplejson/simplejson/pull/166
+* Fix typo in the doc for loads
+ https://github.com/simplejson/simplejson/issues/161
+* Add Python 3.6 to testing matrix and PyPI metadata
+ https://github.com/simplejson/simplejson/pull/153
+ https://github.com/simplejson/simplejson/pull/152
+
Version 3.10.0 released 2016-10-28
* Add RawJSON class to allow a faster path for already encoded JSON.
diff --git a/PKG-INFO b/PKG-INFO
index 1097ad3..b0a6429 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: simplejson
-Version: 3.10.0
+Version: 3.11.1
Summary: Simple, fast, extensible JSON encoder/decoder for Python
Home-page: http://github.com/simplejson/simplejson
Author: Bob Ippolito
@@ -55,6 +55,8 @@ Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Software Development :: Libraries :: Python Modules
diff --git a/conf.py b/conf.py
index c7ea050..44451a8 100644
--- a/conf.py
+++ b/conf.py
@@ -36,15 +36,15 @@ master_doc = 'index'
# General substitutions.
project = 'simplejson'
-copyright = '2016, Bob Ippolito'
+copyright = '2017, Bob Ippolito'
# The default replacements for |version| and |release|, also used in various
# other places throughout the built documents.
#
# The short X.Y version.
-version = '3.10'
+version = '3.11'
# The full version, including alpha/beta/rc tags.
-release = '3.10.0'
+release = '3.11.1'
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
diff --git a/index.rst b/index.rst
index fce07b9..3869a50 100644
--- a/index.rst
+++ b/index.rst
@@ -407,7 +407,7 @@ Basic Usage
only one JSON document, it is recommended to use :func:`loads`.
-.. function:: loads(fp, encoding='utf-8', cls=None, object_hook=None, \
+.. function:: loads(s, encoding='utf-8', cls=None, object_hook=None, \
parse_float=None, parse_int=None, \
parse_constant=None, object_pairs_hook=None, \
use_decimal=None, **kw)
diff --git a/scripts/artifacts.py b/scripts/artifacts.py
index 2aed12d..8d220af 100644
--- a/scripts/artifacts.py
+++ b/scripts/artifacts.py
@@ -3,8 +3,6 @@ try:
except ImportError:
from urllib import urlopen
-import glob
-import io
import json
import os
import re
diff --git a/scripts/make_docs.py b/scripts/make_docs.py
index 0d36f98..7a1de5b 100755
--- a/scripts/make_docs.py
+++ b/scripts/make_docs.py
@@ -1,7 +1,6 @@
#!/usr/bin/env python
import os
import subprocess
-import shutil
SPHINX_BUILD = 'sphinx-build'
diff --git a/setup.py b/setup.py
index ade96fa..fd304f1 100644
--- a/setup.py
+++ b/setup.py
@@ -11,7 +11,7 @@ from distutils.errors import CCompilerError, DistutilsExecError, \
DistutilsPlatformError
IS_PYPY = hasattr(sys, 'pypy_translation_info')
-VERSION = '3.10.0'
+VERSION = '3.11.1'
DESCRIPTION = "Simple, fast, extensible JSON encoder/decoder for Python"
with open('README.rst', 'r') as f:
@@ -31,6 +31,8 @@ Programming Language :: Python :: 2.7
Programming Language :: Python :: 3
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
+Programming Language :: Python :: 3.5
+Programming Language :: Python :: 3.6
Programming Language :: Python :: Implementation :: CPython
Programming Language :: Python :: Implementation :: PyPy
Topic :: Software Development :: Libraries :: Python Modules
diff --git a/simplejson.egg-info/PKG-INFO b/simplejson.egg-info/PKG-INFO
index 1097ad3..b0a6429 100644
--- a/simplejson.egg-info/PKG-INFO
+++ b/simplejson.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: simplejson
-Version: 3.10.0
+Version: 3.11.1
Summary: Simple, fast, extensible JSON encoder/decoder for Python
Home-page: http://github.com/simplejson/simplejson
Author: Bob Ippolito
@@ -55,6 +55,8 @@ Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.3
Classifier: Programming Language :: Python :: 3.4
+Classifier: Programming Language :: Python :: 3.5
+Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Software Development :: Libraries :: Python Modules
diff --git a/simplejson/__init__.py b/simplejson/__init__.py
index d4876cd..bd144ff 100644
--- a/simplejson/__init__.py
+++ b/simplejson/__init__.py
@@ -97,7 +97,7 @@ Using simplejson.tool from the shell to validate and pretty-print::
Expecting property name: line 1 column 3 (char 2)
"""
from __future__ import absolute_import
-__version__ = '3.10.0'
+__version__ = '3.11.1'
__all__ = [
'dump', 'dumps', 'load', 'loads',
'JSONDecoder', 'JSONDecodeError', 'JSONEncoder',
diff --git a/simplejson/_speedups.c b/simplejson/_speedups.c
index 2d81063..36dcf91 100644
--- a/simplejson/_speedups.c
+++ b/simplejson/_speedups.c
@@ -68,19 +68,6 @@ json_PyOS_string_to_double(const char *s, char **endptr, PyObject *overflow_exce
#endif
#endif /* PY_VERSION_HEX < 0x02060000 */
-#if PY_VERSION_HEX < 0x02050000
-#if !defined(PY_SSIZE_T_MIN)
-typedef int Py_ssize_t;
-#define PY_SSIZE_T_MAX INT_MAX
-#define PY_SSIZE_T_MIN INT_MIN
-#define PyInt_FromSsize_t PyInt_FromLong
-#define PyInt_AsSsize_t PyInt_AsLong
-#endif
-#if !defined(Py_IS_FINITE)
-#define Py_IS_FINITE(X) (!Py_IS_INFINITY(X) && !Py_IS_NAN(X))
-#endif
-#endif /* PY_VERSION_HEX < 0x02050000 */
-
#ifdef __GNUC__
#define UNUSED __attribute__((__unused__))
#else
@@ -129,7 +116,8 @@ JSON_Accu_Destroy(JSON_Accu *acc);
typedef struct _PyScannerObject {
PyObject_HEAD
PyObject *encoding;
- PyObject *strict;
+ PyObject *strict_bool;
+ int strict;
PyObject *object_hook;
PyObject *pairs_hook;
PyObject *parse_float;
@@ -140,7 +128,7 @@ typedef struct _PyScannerObject {
static PyMemberDef scanner_members[] = {
{"encoding", T_OBJECT, offsetof(PyScannerObject, encoding), READONLY, "encoding"},
- {"strict", T_OBJECT, offsetof(PyScannerObject, strict), READONLY, "strict"},
+ {"strict", T_OBJECT, offsetof(PyScannerObject, strict_bool), READONLY, "strict"},
{"object_hook", T_OBJECT, offsetof(PyScannerObject, object_hook), READONLY, "object_hook"},
{"object_pairs_hook", T_OBJECT, offsetof(PyScannerObject, pairs_hook), READONLY, "object_pairs_hook"},
{"parse_float", T_OBJECT, offsetof(PyScannerObject, parse_float), READONLY, "parse_float"},
@@ -231,16 +219,12 @@ static PyObject *
_build_rval_index_tuple(PyObject *rval, Py_ssize_t idx);
static PyObject *
scanner_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
-static int
-scanner_init(PyObject *self, PyObject *args, PyObject *kwds);
static void
scanner_dealloc(PyObject *self);
static int
scanner_clear(PyObject *self);
static PyObject *
encoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
-static int
-encoder_init(PyObject *self, PyObject *args, PyObject *kwds);
static void
encoder_dealloc(PyObject *self);
static int
@@ -659,10 +643,13 @@ encoder_stringify_key(PyEncoderObject *s, PyObject *key)
}
else if (PyString_Check(key)) {
#if PY_MAJOR_VERSION >= 3
+ const char *encoding = JSON_ASCII_AS_STRING(s->encoding);
+ if (encoding == NULL)
+ return NULL;
return PyUnicode_Decode(
PyString_AS_STRING(key),
PyString_GET_SIZE(key),
- JSON_ASCII_AS_STRING(s->encoding),
+ encoding,
NULL);
#else /* PY_MAJOR_VERSION >= 3 */
Py_INCREF(key);
@@ -1397,7 +1384,7 @@ scanner_traverse(PyObject *self, visitproc visit, void *arg)
assert(PyScanner_Check(self));
s = (PyScannerObject *)self;
Py_VISIT(s->encoding);
- Py_VISIT(s->strict);
+ Py_VISIT(s->strict_bool);
Py_VISIT(s->object_hook);
Py_VISIT(s->pairs_hook);
Py_VISIT(s->parse_float);
@@ -1414,7 +1401,7 @@ scanner_clear(PyObject *self)
assert(PyScanner_Check(self));
s = (PyScannerObject *)self;
Py_CLEAR(s->encoding);
- Py_CLEAR(s->strict);
+ Py_CLEAR(s->strict_bool);
Py_CLEAR(s->object_hook);
Py_CLEAR(s->pairs_hook);
Py_CLEAR(s->parse_float);
@@ -1444,7 +1431,6 @@ _parse_object_str(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_
PyObject *key = NULL;
PyObject *val = NULL;
char *encoding = JSON_ASCII_AS_STRING(s->encoding);
- int strict = PyObject_IsTrue(s->strict);
int has_pairs_hook = (s->pairs_hook != Py_None);
int did_parse = 0;
Py_ssize_t next_idx;
@@ -1474,7 +1460,7 @@ _parse_object_str(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_
raise_errmsg(ERR_OBJECT_PROPERTY, pystr, idx);
goto bail;
}
- key = scanstring_str(pystr, idx + 1, encoding, strict, &next_idx);
+ key = scanstring_str(pystr, idx + 1, encoding, s->strict, &next_idx);
if (key == NULL)
goto bail;
memokey = PyDict_GetItem(s->memo, key);
@@ -1605,7 +1591,6 @@ _parse_object_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ss
PyObject *item;
PyObject *key = NULL;
PyObject *val = NULL;
- int strict = PyObject_IsTrue(s->strict);
int has_pairs_hook = (s->pairs_hook != Py_None);
int did_parse = 0;
Py_ssize_t next_idx;
@@ -1636,7 +1621,7 @@ _parse_object_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ss
raise_errmsg(ERR_OBJECT_PROPERTY, pystr, idx);
goto bail;
}
- key = scanstring_unicode(pystr, idx + 1, strict, &next_idx);
+ key = scanstring_unicode(pystr, idx + 1, s->strict, &next_idx);
if (key == NULL)
goto bail;
memokey = PyDict_GetItem(s->memo, key);
@@ -2180,7 +2165,7 @@ scan_once_str(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_t *n
/* string */
rval = scanstring_str(pystr, idx + 1,
JSON_ASCII_AS_STRING(s->encoding),
- PyObject_IsTrue(s->strict),
+ s->strict,
next_idx_ptr);
break;
case '{':
@@ -2287,7 +2272,7 @@ scan_once_unicode(PyScannerObject *s, PyObject *pystr, Py_ssize_t idx, Py_ssize_
case '"':
/* string */
rval = scanstring_unicode(pystr, idx + 1,
- PyObject_IsTrue(s->strict),
+ s->strict,
next_idx_ptr);
break;
case '{':
@@ -2430,23 +2415,6 @@ scanner_call(PyObject *self, PyObject *args, PyObject *kwds)
}
static PyObject *
-scanner_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyScannerObject *s;
- s = (PyScannerObject *)type->tp_alloc(type, 0);
- if (s != NULL) {
- s->encoding = NULL;
- s->strict = NULL;
- s->object_hook = NULL;
- s->pairs_hook = NULL;
- s->parse_float = NULL;
- s->parse_int = NULL;
- s->parse_constant = NULL;
- }
- return (PyObject *)s;
-}
-
-static PyObject *
JSON_ParseEncoding(PyObject *encoding)
{
if (encoding == NULL)
@@ -2465,8 +2433,8 @@ JSON_ParseEncoding(PyObject *encoding)
return NULL;
}
-static int
-scanner_init(PyObject *self, PyObject *args, PyObject *kwds)
+static PyObject *
+scanner_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
/* Initialize Scanner object */
PyObject *ctx;
@@ -2474,11 +2442,12 @@ scanner_init(PyObject *self, PyObject *args, PyObject *kwds)
PyScannerObject *s;
PyObject *encoding;
- assert(PyScanner_Check(self));
- s = (PyScannerObject *)self;
-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:make_scanner", kwlist, &ctx))
- return -1;
+ return NULL;
+
+ s = (PyScannerObject *)type->tp_alloc(type, 0);
+ if (s == NULL)
+ return NULL;
if (s->memo == NULL) {
s->memo = PyDict_New();
@@ -2494,8 +2463,11 @@ scanner_init(PyObject *self, PyObject *args, PyObject *kwds)
goto bail;
/* All of these will fail "gracefully" so we don't need to verify them */
- s->strict = PyObject_GetAttrString(ctx, "strict");
- if (s->strict == NULL)
+ s->strict_bool = PyObject_GetAttrString(ctx, "strict");
+ if (s->strict_bool == NULL)
+ goto bail;
+ s->strict = PyObject_IsTrue(s->strict_bool);
+ if (s->strict < 0)
goto bail;
s->object_hook = PyObject_GetAttrString(ctx, "object_hook");
if (s->object_hook == NULL)
@@ -2513,17 +2485,11 @@ scanner_init(PyObject *self, PyObject *args, PyObject *kwds)
if (s->parse_constant == NULL)
goto bail;
- return 0;
+ return (PyObject *)s;
bail:
- Py_CLEAR(s->encoding);
- Py_CLEAR(s->strict);
- Py_CLEAR(s->object_hook);
- Py_CLEAR(s->pairs_hook);
- Py_CLEAR(s->parse_float);
- Py_CLEAR(s->parse_int);
- Py_CLEAR(s->parse_constant);
- return -1;
+ Py_DECREF(s);
+ return NULL;
}
PyDoc_STRVAR(scanner_doc, "JSON scanner object");
@@ -2565,7 +2531,7 @@ PyTypeObject PyScannerType = {
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
- scanner_init, /* tp_init */
+ 0, /* tp_init */
0,/* PyType_GenericAlloc, */ /* tp_alloc */
scanner_new, /* tp_new */
0,/* PyObject_GC_Del, */ /* tp_free */
@@ -2574,30 +2540,6 @@ PyTypeObject PyScannerType = {
static PyObject *
encoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
- PyEncoderObject *s;
- s = (PyEncoderObject *)type->tp_alloc(type, 0);
- if (s != NULL) {
- s->markers = NULL;
- s->defaultfn = NULL;
- s->encoder = NULL;
- s->encoding = NULL;
- s->indent = NULL;
- s->key_separator = NULL;
- s->item_separator = NULL;
- s->key_memo = NULL;
- s->sort_keys = NULL;
- s->item_sort_key = NULL;
- s->item_sort_kw = NULL;
- s->Decimal = NULL;
- s->max_long_size = NULL;
- s->min_long_size = NULL;
- }
- return (PyObject *)s;
-}
-
-static int
-encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
-{
static char *kwlist[] = {
"markers",
"default",
@@ -2627,9 +2569,7 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
PyObject *use_decimal, *namedtuple_as_object, *tuple_as_array, *iterable_as_array;
PyObject *int_as_string_bitcount, *item_sort_key, *encoding, *for_json;
PyObject *ignore_nan, *Decimal;
-
- assert(PyEncoder_Check(self));
- s = (PyEncoderObject *)self;
+ int is_true;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOOOOOOOOOOOOOOOOOO:make_encoder", kwlist,
&markers, &defaultfn, &encoder, &indent, &key_separator, &item_separator,
@@ -2637,7 +2577,11 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
&namedtuple_as_object, &tuple_as_array,
&int_as_string_bitcount, &item_sort_key, &encoding, &for_json,
&ignore_nan, &Decimal, &iterable_as_array))
- return -1;
+ return NULL;
+
+ s = (PyEncoderObject *)type->tp_alloc(type, 0);
+ if (s == NULL)
+ return NULL;
Py_INCREF(markers);
s->markers = markers;
@@ -2647,7 +2591,9 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
s->encoder = encoder;
s->encoding = JSON_ParseEncoding(encoding);
if (s->encoding == NULL)
- return -1;
+ goto bail;
+ if (JSON_ASCII_AS_STRING(s->encoding) == NULL)
+ goto bail;
Py_INCREF(indent);
s->indent = indent;
Py_INCREF(key_separator);
@@ -2657,31 +2603,46 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
Py_INCREF(skipkeys);
s->skipkeys_bool = skipkeys;
s->skipkeys = PyObject_IsTrue(skipkeys);
+ if (s->skipkeys < 0)
+ goto bail;
Py_INCREF(key_memo);
s->key_memo = key_memo;
s->fast_encode = (PyCFunction_Check(s->encoder) && PyCFunction_GetFunction(s->encoder) == (PyCFunction)py_encode_basestring_ascii);
- s->allow_or_ignore_nan = (
- (PyObject_IsTrue(ignore_nan) ? JSON_IGNORE_NAN : 0) |
- (PyObject_IsTrue(allow_nan) ? JSON_ALLOW_NAN : 0));
+ is_true = PyObject_IsTrue(ignore_nan);
+ if (is_true < 0)
+ goto bail;
+ s->allow_or_ignore_nan = is_true ? JSON_IGNORE_NAN : 0;
+ is_true = PyObject_IsTrue(allow_nan);
+ if (is_true < 0)
+ goto bail;
+ s->allow_or_ignore_nan |= is_true ? JSON_ALLOW_NAN : 0;
s->use_decimal = PyObject_IsTrue(use_decimal);
+ if (s->use_decimal < 0)
+ goto bail;
s->namedtuple_as_object = PyObject_IsTrue(namedtuple_as_object);
+ if (s->namedtuple_as_object < 0)
+ goto bail;
s->tuple_as_array = PyObject_IsTrue(tuple_as_array);
+ if (s->tuple_as_array < 0)
+ goto bail;
s->iterable_as_array = PyObject_IsTrue(iterable_as_array);
+ if (s->iterable_as_array < 0)
+ goto bail;
if (PyInt_Check(int_as_string_bitcount) || PyLong_Check(int_as_string_bitcount)) {
- static const unsigned int long_long_bitsize = SIZEOF_LONG_LONG * 8;
- int int_as_string_bitcount_val = (int)PyLong_AsLong(int_as_string_bitcount);
- if (int_as_string_bitcount_val > 0 && int_as_string_bitcount_val < (int)long_long_bitsize) {
- s->max_long_size = PyLong_FromUnsignedLongLong(1ULL << int_as_string_bitcount_val);
- s->min_long_size = PyLong_FromLongLong(-1LL << int_as_string_bitcount_val);
+ static const unsigned long long_long_bitsize = SIZEOF_LONG_LONG * 8;
+ long int_as_string_bitcount_val = PyLong_AsLong(int_as_string_bitcount);
+ if (int_as_string_bitcount_val > 0 && int_as_string_bitcount_val < (long)long_long_bitsize) {
+ s->max_long_size = PyLong_FromUnsignedLongLong(1ULL << (int)int_as_string_bitcount_val);
+ s->min_long_size = PyLong_FromLongLong(-1LL << (int)int_as_string_bitcount_val);
if (s->min_long_size == NULL || s->max_long_size == NULL) {
- return -1;
+ goto bail;
}
}
else {
PyErr_Format(PyExc_TypeError,
- "int_as_string_bitcount (%d) must be greater than 0 and less than the number of bits of a `long long` type (%u bits)",
+ "int_as_string_bitcount (%ld) must be greater than 0 and less than the number of bits of a `long long` type (%lu bits)",
int_as_string_bitcount_val, long_long_bitsize);
- return -1;
+ goto bail;
}
}
else if (int_as_string_bitcount == Py_None) {
@@ -2692,26 +2653,31 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
}
else {
PyErr_SetString(PyExc_TypeError, "int_as_string_bitcount must be None or an integer");
- return -1;
+ goto bail;
}
if (item_sort_key != Py_None) {
if (!PyCallable_Check(item_sort_key)) {
PyErr_SetString(PyExc_TypeError, "item_sort_key must be None or callable");
- return -1;
+ goto bail;
}
}
- else if (PyObject_IsTrue(sort_keys)) {
- static PyObject *itemgetter0 = NULL;
- if (!itemgetter0) {
- PyObject *operator = PyImport_ImportModule("operator");
- if (!operator)
- return -1;
- itemgetter0 = PyObject_CallMethod(operator, "itemgetter", "i", 0);
- Py_DECREF(operator);
+ else {
+ is_true = PyObject_IsTrue(sort_keys);
+ if (is_true < 0)
+ goto bail;
+ if (is_true) {
+ static PyObject *itemgetter0 = NULL;
+ if (!itemgetter0) {
+ PyObject *operator = PyImport_ImportModule("operator");
+ if (!operator)
+ goto bail;
+ itemgetter0 = PyObject_CallMethod(operator, "itemgetter", "i", 0);
+ Py_DECREF(operator);
+ }
+ item_sort_key = itemgetter0;
+ if (!item_sort_key)
+ goto bail;
}
- item_sort_key = itemgetter0;
- if (!item_sort_key)
- return -1;
}
if (item_sort_key == Py_None) {
Py_INCREF(Py_None);
@@ -2720,9 +2686,9 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
else {
s->item_sort_kw = PyDict_New();
if (s->item_sort_kw == NULL)
- return -1;
+ goto bail;
if (PyDict_SetItemString(s->item_sort_kw, "key", item_sort_key))
- return -1;
+ goto bail;
}
Py_INCREF(sort_keys);
s->sort_keys = sort_keys;
@@ -2731,8 +2697,14 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
Py_INCREF(Decimal);
s->Decimal = Decimal;
s->for_json = PyObject_IsTrue(for_json);
+ if (s->for_json < 0)
+ goto bail;
- return 0;
+ return (PyObject *)s;
+
+bail:
+ Py_DECREF(s);
+ return NULL;
}
static PyObject *
@@ -3342,7 +3314,7 @@ PyTypeObject PyEncoderType = {
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
- encoder_init, /* tp_init */
+ 0, /* tp_init */
0, /* tp_alloc */
encoder_new, /* tp_new */
0, /* tp_free */
@@ -3381,10 +3353,8 @@ static PyObject *
moduleinit(void)
{
PyObject *m;
- PyScannerType.tp_new = PyType_GenericNew;
if (PyType_Ready(&PyScannerType) < 0)
return NULL;
- PyEncoderType.tp_new = PyType_GenericNew;
if (PyType_Ready(&PyEncoderType) < 0)
return NULL;
diff --git a/simplejson/decoder.py b/simplejson/decoder.py
index 29de124..e0b55a4 100644
--- a/simplejson/decoder.py
+++ b/simplejson/decoder.py
@@ -4,7 +4,7 @@ from __future__ import absolute_import
import re
import sys
import struct
-from .compat import b, u, text_type, binary_type, PY3, unichr
+from .compat import u, text_type, binary_type, PY3, unichr
from .scanner import make_scanner, JSONDecodeError
def _import_c_scanstring():
@@ -24,11 +24,7 @@ FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL
def _floatconstants():
if sys.version_info < (2, 6):
_BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
- # The struct module in Python 2.4 would get frexp() out of range here
- # when an endian is specified in the format string. Fixed in Python 2.5+
- if sys.byteorder != 'big':
- _BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
- nan, inf = struct.unpack('dd', _BYTES)
+ nan, inf = struct.unpack('>dd', _BYTES)
else:
nan = float('nan')
inf = float('inf')
diff --git a/simplejson/encoder.py b/simplejson/encoder.py
index 226480f..b5c3141 100644
--- a/simplejson/encoder.py
+++ b/simplejson/encoder.py
@@ -185,7 +185,7 @@ class JSONEncoder(object):
transformed into unicode using that encoding prior to JSON-encoding.
The default is UTF-8.
- If use_decimal is true (not the default), ``decimal.Decimal`` will
+ If use_decimal is true (default: ``True``), ``decimal.Decimal`` will
be supported directly by the encoder. For the inverse, decode JSON
with ``parse_float=decimal.Decimal``.
diff --git a/simplejson/ordered_dict.py b/simplejson/ordered_dict.py
index 87ad888..d5a55eb 100644
--- a/simplejson/ordered_dict.py
+++ b/simplejson/ordered_dict.py
@@ -5,17 +5,6 @@ http://code.activestate.com/recipes/576693/
"""
from UserDict import DictMixin
-# Modified from original to support Python 2.4, see
-# http://code.google.com/p/simplejson/issues/detail?id=53
-try:
- all
-except NameError:
- def all(seq):
- for elem in seq:
- if not elem:
- return False
- return True
-
class OrderedDict(dict, DictMixin):
def __init__(self, *args, **kwds):
@@ -63,12 +52,7 @@ class OrderedDict(dict, DictMixin):
def popitem(self, last=True):
if not self:
raise KeyError('dictionary is empty')
- # Modified from original to support Python 2.4, see
- # http://code.google.com/p/simplejson/issues/detail?id=53
- if last:
- key = reversed(self).next()
- else:
- key = iter(self).next()
+ key = reversed(self).next() if last else iter(self).next()
value = self.pop(key)
return key, value
diff --git a/simplejson/tests/__init__.py b/simplejson/tests/__init__.py
index 95e98e5..8d2642f 100644
--- a/simplejson/tests/__init__.py
+++ b/simplejson/tests/__init__.py
@@ -2,6 +2,7 @@ from __future__ import absolute_import
import unittest
import doctest
import sys
+import os
class NoExtensionTestSuite(unittest.TestSuite):
@@ -35,38 +36,13 @@ def additional_tests(suite=None):
def all_tests_suite():
def get_suite():
+ suite_names = [
+ 'simplejson.tests.%s' % (os.path.splitext(f)[0],)
+ for f in os.listdir(os.path.dirname(__file__))
+ if f.startswith('test_') and f.endswith('.py')
+ ]
return additional_tests(
- unittest.TestLoader().loadTestsFromNames([
- 'simplejson.tests.test_bitsize_int_as_string',
- 'simplejson.tests.test_bigint_as_string',
- 'simplejson.tests.test_check_circular',
- 'simplejson.tests.test_decode',
- 'simplejson.tests.test_default',
- 'simplejson.tests.test_dump',
- 'simplejson.tests.test_encode_basestring_ascii',
- 'simplejson.tests.test_encode_for_html',
- 'simplejson.tests.test_errors',
- 'simplejson.tests.test_fail',
- 'simplejson.tests.test_float',
- 'simplejson.tests.test_indent',
- 'simplejson.tests.test_iterable',
- 'simplejson.tests.test_pass1',
- 'simplejson.tests.test_pass2',
- 'simplejson.tests.test_pass3',
- 'simplejson.tests.test_recursion',
- 'simplejson.tests.test_scanstring',
- 'simplejson.tests.test_separators',
- 'simplejson.tests.test_speedups',
- 'simplejson.tests.test_str_subclass',
- 'simplejson.tests.test_unicode',
- 'simplejson.tests.test_decimal',
- 'simplejson.tests.test_tuple',
- 'simplejson.tests.test_namedtuple',
- 'simplejson.tests.test_tool',
- 'simplejson.tests.test_for_json',
- 'simplejson.tests.test_subclass',
- 'simplejson.tests.test_raw_json',
- ]))
+ unittest.TestLoader().loadTestsFromNames(suite_names))
suite = get_suite()
import simplejson
if simplejson._import_c_make_encoder() is None:
diff --git a/simplejson/tests/test_item_sort_key.py b/simplejson/tests/test_item_sort_key.py
index b05bfc8..98971b8 100644
--- a/simplejson/tests/test_item_sort_key.py
+++ b/simplejson/tests/test_item_sort_key.py
@@ -18,3 +18,10 @@ class TestItemSortKey(TestCase):
self.assertEqual(
'{"a": 1, "Array": [1, 5, 6, 9], "c": 5, "crate": "dog", "Jack": "jill", "pick": "axe", "tuple": [83, 12, 3], "zeak": "oh"}',
json.dumps(a, item_sort_key=lambda kv: kv[0].lower()))
+
+ def test_item_sort_key_value(self):
+ # https://github.com/simplejson/simplejson/issues/173
+ a = {'a': 1, 'b': 0}
+ self.assertEqual(
+ '{"b": 0, "a": 1}',
+ json.dumps(a, item_sort_key=lambda kv: kv[1]))
diff --git a/simplejson/tests/test_speedups.py b/simplejson/tests/test_speedups.py
index 0a2b63b..b59eeca 100644
--- a/simplejson/tests/test_speedups.py
+++ b/simplejson/tests/test_speedups.py
@@ -1,8 +1,12 @@
+from __future__ import with_statement
+
import sys
import unittest
from unittest import TestCase
-from simplejson import encoder, scanner
+import simplejson
+from simplejson import encoder, decoder, scanner
+from simplejson.compat import PY3, long_type, b
def has_speedups():
@@ -22,12 +26,29 @@ def skip_if_speedups_missing(func):
return wrapper
+class BadBool:
+ def __bool__(self):
+ 1/0
+ __nonzero__ = __bool__
+
+
class TestDecode(TestCase):
@skip_if_speedups_missing
def test_make_scanner(self):
self.assertRaises(AttributeError, scanner.c_make_scanner, 1)
@skip_if_speedups_missing
+ def test_bad_bool_args(self):
+ def test(value):
+ decoder.JSONDecoder(strict=BadBool()).decode(value)
+ self.assertRaises(ZeroDivisionError, test, '""')
+ self.assertRaises(ZeroDivisionError, test, '{}')
+ if not PY3:
+ self.assertRaises(ZeroDivisionError, test, u'""')
+ self.assertRaises(ZeroDivisionError, test, u'{}')
+
+class TestEncode(TestCase):
+ @skip_if_speedups_missing
def test_make_encoder(self):
self.assertRaises(
TypeError,
@@ -37,3 +58,33 @@ class TestDecode(TestCase):
"\x52\xBA\x82\xF2\x27\x4A\x7D\xA0\xCA\x75"),
None
)
+
+ @skip_if_speedups_missing
+ def test_bad_bool_args(self):
+ def test(name):
+ encoder.JSONEncoder(**{name: BadBool()}).encode({})
+ self.assertRaises(ZeroDivisionError, test, 'skipkeys')
+ self.assertRaises(ZeroDivisionError, test, 'ensure_ascii')
+ self.assertRaises(ZeroDivisionError, test, 'check_circular')
+ self.assertRaises(ZeroDivisionError, test, 'allow_nan')
+ self.assertRaises(ZeroDivisionError, test, 'sort_keys')
+ self.assertRaises(ZeroDivisionError, test, 'use_decimal')
+ self.assertRaises(ZeroDivisionError, test, 'namedtuple_as_object')
+ self.assertRaises(ZeroDivisionError, test, 'tuple_as_array')
+ self.assertRaises(ZeroDivisionError, test, 'bigint_as_string')
+ self.assertRaises(ZeroDivisionError, test, 'for_json')
+ self.assertRaises(ZeroDivisionError, test, 'ignore_nan')
+ self.assertRaises(ZeroDivisionError, test, 'iterable_as_array')
+
+ @skip_if_speedups_missing
+ def test_int_as_string_bitcount_overflow(self):
+ long_count = long_type(2)**32+31
+ def test():
+ encoder.JSONEncoder(int_as_string_bitcount=long_count).encode(0)
+ self.assertRaises((TypeError, OverflowError), test)
+
+ if PY3:
+ @skip_if_speedups_missing
+ def test_bad_encoding(self):
+ with self.assertRaises(UnicodeEncodeError):
+ encoder.JSONEncoder(encoding='\udcff').encode({b('key'): 123})
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/simplejson.git
More information about the Python-modules-commits
mailing list