[Python-modules-commits] [simplejson] 01/03: Import simplejson_3.8.1.orig.tar.gz
Piotr Ożarowski
piotr at moszumanska.debian.org
Sun Dec 27 09:28:07 UTC 2015
This is an automated email from the git hooks/post-receive script.
piotr pushed a commit to branch master
in repository simplejson.
commit fdf035dd39f923902a7243bdbd8649b72f00a3dd
Author: Piotr Ożarowski <piotr at debian.org>
Date: Sun Dec 27 10:20:38 2015 +0100
Import simplejson_3.8.1.orig.tar.gz
---
CHANGES.txt | 12 ++++++++++++
PKG-INFO | 2 +-
conf.py | 4 ++--
index.rst | 28 +++++++++++++++++++++++++---
setup.py | 2 +-
simplejson.egg-info/PKG-INFO | 2 +-
simplejson.egg-info/SOURCES.txt | 1 +
simplejson/__init__.py | 31 +++++++++++++++++++++----------
simplejson/_speedups.c | 20 ++++++++++++++++----
simplejson/encoder.py | 35 ++++++++++++++++++++++++++++-------
simplejson/tests/__init__.py | 1 +
simplejson/tests/test_iterable.py | 31 +++++++++++++++++++++++++++++++
simplejson/tests/test_tuple.py | 4 ----
13 files changed, 140 insertions(+), 33 deletions(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index 503c8a6..af8e566 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,15 @@
+Version 3.8.1 released 2015-10-27
+
+* Fix issue with iterable_as_array and indent option
+ https://github.com/simplejson/simplejson/issues/128
+* Fix typo in keyword argument name introduced in 3.8.0
+ https://github.com/simplejson/simplejson/pull/123
+
+Version 3.8.0 released 2015-07-18
+
+* New iterable_as_array encoder option to perform lazy serialization of
+ any iterable objects, without having to convert to tuple or list.
+
Version 3.7.3 released 2015-05-31
* Fix typo introduced in 3.7.0 (behavior should be indistinguishable)
diff --git a/PKG-INFO b/PKG-INFO
index 2e4caea..b244932 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: simplejson
-Version: 3.7.3
+Version: 3.8.1
Summary: Simple, fast, extensible JSON encoder/decoder for Python
Home-page: http://github.com/simplejson/simplejson
Author: Bob Ippolito
diff --git a/conf.py b/conf.py
index 5aa0a41..d83bca4 100644
--- a/conf.py
+++ b/conf.py
@@ -42,9 +42,9 @@ copyright = '2015, Bob Ippolito'
# other places throughout the built documents.
#
# The short X.Y version.
-version = '3.7'
+version = '3.8'
# The full version, including alpha/beta/rc tags.
-release = '3.7.3'
+release = '3.8.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 fedf7ee..fce07b9 100644
--- a/index.rst
+++ b/index.rst
@@ -142,7 +142,7 @@ Basic Usage
namedtuple_as_object=True, tuple_as_array=True, \
bigint_as_string=False, sort_keys=False, \
item_sort_key=None, for_json=None, ignore_nan=False, \
- int_as_string_bitcount=None, **kw)
+ int_as_string_bitcount=None, iterable_as_array=False, **kw)
Serialize *obj* as a JSON formatted stream to *fp* (a ``.write()``-supporting
file-like object) using this :ref:`conversion table <py-to-json-table>`.
@@ -230,6 +230,13 @@ Basic Usage
If *tuple_as_array* is true (default: ``True``),
:class:`tuple` (and subclasses) will be encoded as JSON arrays.
+ If *iterable_as_array* is true (default: ``False``),
+ any object not in the above table that implements ``__iter__()``
+ will be encoded as a JSON array.
+
+ .. versionchanged:: 3.8.0
+ *iterable_as_array* is new in 3.8.0.
+
.. versionchanged:: 2.2.0
*tuple_as_array* is new in 2.2.0.
@@ -302,7 +309,7 @@ Basic Usage
namedtuple_as_object=True, tuple_as_array=True, \
bigint_as_string=False, sort_keys=False, \
item_sort_key=None, for_json=None, ignore_nan=False, \
- int_as_string_bitcount=None, **kw)
+ int_as_string_bitcount=None, iterable_as_array=False, **kw)
Serialize *obj* to a JSON formatted :class:`str`.
@@ -374,6 +381,14 @@ Basic Usage
.. versionchanged:: 2.1.0
*use_decimal* is new in 2.1.0.
+ If *iterable_as_array* is true (default: ``False``),
+ any object not in the above table that implements ``__iter__()``
+ will be encoded as a JSON array.
+
+ .. versionchanged:: 3.8.0
+ *iterable_as_array* is new in 3.8.0.
+
+
To use a custom :class:`JSONDecoder` subclass, specify it with the ``cls``
kwarg. Additional keyword arguments will be passed to the constructor of the
class. You probably shouldn't do this.
@@ -527,7 +542,7 @@ Encoders and decoders
namedtuple_as_object=True, tuple_as_array=True, \
bigint_as_string=False, item_sort_key=None, \
for_json=True, ignore_nan=False, \
- int_as_string_bitcount=None)
+ int_as_string_bitcount=None, iterable_as_array=False)
Extensible JSON encoder for Python data structures.
@@ -662,6 +677,13 @@ Encoders and decoders
.. versionchanged:: 2.2.0
*tuple_as_array* is new in 2.2.0.
+ If *iterable_as_array* is true (default: ``False``),
+ any object not in the above table that implements ``__iter__()``
+ will be encoded as a JSON array.
+
+ .. versionchanged:: 3.8.0
+ *iterable_as_array* is new in 3.8.0.
+
If *bigint_as_string* is true (default: ``False``), :class:`int`` ``2**53``
and higher or lower than ``-2**53`` will be encoded as strings. This is to
avoid the rounding that happens in Javascript otherwise. Note that this
diff --git a/setup.py b/setup.py
index c3d206e..a5d3500 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.7.3'
+VERSION = '3.8.1'
DESCRIPTION = "Simple, fast, extensible JSON encoder/decoder for Python"
with open('README.rst', 'r') as f:
diff --git a/simplejson.egg-info/PKG-INFO b/simplejson.egg-info/PKG-INFO
index 2e4caea..b244932 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.7.3
+Version: 3.8.1
Summary: Simple, fast, extensible JSON encoder/decoder for Python
Home-page: http://github.com/simplejson/simplejson
Author: Bob Ippolito
diff --git a/simplejson.egg-info/SOURCES.txt b/simplejson.egg-info/SOURCES.txt
index d2a4e15..4b75657 100644
--- a/simplejson.egg-info/SOURCES.txt
+++ b/simplejson.egg-info/SOURCES.txt
@@ -34,6 +34,7 @@ simplejson/tests/test_float.py
simplejson/tests/test_for_json.py
simplejson/tests/test_indent.py
simplejson/tests/test_item_sort_key.py
+simplejson/tests/test_iterable.py
simplejson/tests/test_namedtuple.py
simplejson/tests/test_pass1.py
simplejson/tests/test_pass2.py
diff --git a/simplejson/__init__.py b/simplejson/__init__.py
index b8d5097..c448742 100644
--- a/simplejson/__init__.py
+++ b/simplejson/__init__.py
@@ -5,9 +5,8 @@ interchange format.
:mod:`simplejson` exposes an API familiar to users of the standard library
:mod:`marshal` and :mod:`pickle` modules. It is the externally maintained
version of the :mod:`json` library contained in Python 2.6, but maintains
-compatibility with Python 2.4 and Python 2.5 and (currently) has
-significant performance advantages, even without using the optional C
-extension for speedups.
+compatibility back to Python 2.5 and (currently) has significant performance
+advantages, even without using the optional C extension for speedups.
Encoding basic Python object hierarchies::
@@ -98,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.7.3'
+__version__ = '3.8.1'
__all__ = [
'dump', 'dumps', 'load', 'loads',
'JSONDecoder', 'JSONDecodeError', 'JSONEncoder',
@@ -140,6 +139,7 @@ _default_encoder = JSONEncoder(
use_decimal=True,
namedtuple_as_object=True,
tuple_as_array=True,
+ iterable_as_array=False,
bigint_as_string=False,
item_sort_key=None,
for_json=False,
@@ -152,7 +152,8 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
encoding='utf-8', default=None, use_decimal=True,
namedtuple_as_object=True, tuple_as_array=True,
bigint_as_string=False, sort_keys=False, item_sort_key=None,
- for_json=False, ignore_nan=False, int_as_string_bitcount=None, **kw):
+ for_json=False, ignore_nan=False, int_as_string_bitcount=None,
+ iterable_as_array=False, **kw):
"""Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
``.write()``-supporting file-like object).
@@ -204,6 +205,10 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
If *tuple_as_array* is true (default: ``True``),
:class:`tuple` (and subclasses) will be encoded as JSON arrays.
+ If *iterable_as_array* is true (default: ``False``),
+ any object not in the above table that implements ``__iter__()``
+ will be encoded as a JSON array.
+
If *bigint_as_string* is true (default: ``False``), ints 2**53 and higher
or lower than -2**53 will be encoded as strings. This is to avoid the
rounding that happens in Javascript otherwise. Note that this is still a
@@ -242,7 +247,7 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
check_circular and allow_nan and
cls is None and indent is None and separators is None and
encoding == 'utf-8' and default is None and use_decimal
- and namedtuple_as_object and tuple_as_array
+ and namedtuple_as_object and tuple_as_array and not iterable_as_array
and not bigint_as_string and not sort_keys
and not item_sort_key and not for_json
and not ignore_nan and int_as_string_bitcount is None
@@ -258,6 +263,7 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
default=default, use_decimal=use_decimal,
namedtuple_as_object=namedtuple_as_object,
tuple_as_array=tuple_as_array,
+ iterable_as_array=iterable_as_array,
bigint_as_string=bigint_as_string,
sort_keys=sort_keys,
item_sort_key=item_sort_key,
@@ -276,7 +282,8 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
encoding='utf-8', default=None, use_decimal=True,
namedtuple_as_object=True, tuple_as_array=True,
bigint_as_string=False, sort_keys=False, item_sort_key=None,
- for_json=False, ignore_nan=False, int_as_string_bitcount=None, **kw):
+ for_json=False, ignore_nan=False, int_as_string_bitcount=None,
+ iterable_as_array=False, **kw):
"""Serialize ``obj`` to a JSON formatted ``str``.
If ``skipkeys`` is false then ``dict`` keys that are not basic types
@@ -324,6 +331,10 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
If *tuple_as_array* is true (default: ``True``),
:class:`tuple` (and subclasses) will be encoded as JSON arrays.
+ If *iterable_as_array* is true (default: ``False``),
+ any object not in the above table that implements ``__iter__()``
+ will be encoded as a JSON array.
+
If *bigint_as_string* is true (not the default), ints 2**53 and higher
or lower than -2**53 will be encoded as strings. This is to avoid the
rounding that happens in Javascript otherwise.
@@ -356,12 +367,11 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
"""
# cached encoder
- if (
- not skipkeys and ensure_ascii and
+ if (not skipkeys and ensure_ascii and
check_circular and allow_nan and
cls is None and indent is None and separators is None and
encoding == 'utf-8' and default is None and use_decimal
- and namedtuple_as_object and tuple_as_array
+ and namedtuple_as_object and tuple_as_array and not iterable_as_array
and not bigint_as_string and not sort_keys
and not item_sort_key and not for_json
and not ignore_nan and int_as_string_bitcount is None
@@ -377,6 +387,7 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
use_decimal=use_decimal,
namedtuple_as_object=namedtuple_as_object,
tuple_as_array=tuple_as_array,
+ iterable_as_array=iterable_as_array,
bigint_as_string=bigint_as_string,
sort_keys=sort_keys,
item_sort_key=item_sort_key,
diff --git a/simplejson/_speedups.c b/simplejson/_speedups.c
index bc1648a..173c5e1 100644
--- a/simplejson/_speedups.c
+++ b/simplejson/_speedups.c
@@ -169,6 +169,7 @@ typedef struct _PyEncoderObject {
int use_decimal;
int namedtuple_as_object;
int tuple_as_array;
+ int iterable_as_array;
PyObject *max_long_size;
PyObject *min_long_size;
PyObject *item_sort_key;
@@ -2581,7 +2582,6 @@ encoder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static int
encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
{
- /* initialize Encoder object */
static char *kwlist[] = {
"markers",
"default",
@@ -2602,24 +2602,25 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
"for_json",
"ignore_nan",
"Decimal",
+ "iterable_as_array",
NULL};
PyEncoderObject *s;
PyObject *markers, *defaultfn, *encoder, *indent, *key_separator;
PyObject *item_separator, *sort_keys, *skipkeys, *allow_nan, *key_memo;
- PyObject *use_decimal, *namedtuple_as_object, *tuple_as_array;
+ 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;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOOOOOOOOOOOOOOOOO:make_encoder", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOOOOOOOOOOOOOOOOOO:make_encoder", kwlist,
&markers, &defaultfn, &encoder, &indent, &key_separator, &item_separator,
&sort_keys, &skipkeys, &allow_nan, &key_memo, &use_decimal,
&namedtuple_as_object, &tuple_as_array,
&int_as_string_bitcount, &item_sort_key, &encoding, &for_json,
- &ignore_nan, &Decimal))
+ &ignore_nan, &Decimal, &iterable_as_array))
return -1;
Py_INCREF(markers);
@@ -2649,6 +2650,7 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
s->use_decimal = PyObject_IsTrue(use_decimal);
s->namedtuple_as_object = PyObject_IsTrue(namedtuple_as_object);
s->tuple_as_array = PyObject_IsTrue(tuple_as_array);
+ s->iterable_as_array = PyObject_IsTrue(iterable_as_array);
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);
@@ -2936,6 +2938,16 @@ encoder_listencode_obj(PyEncoderObject *s, JSON_Accu *rval, PyObject *obj, Py_ss
else {
PyObject *ident = NULL;
PyObject *newobj;
+ if (s->iterable_as_array) {
+ newobj = PyObject_GetIter(obj);
+ if (newobj == NULL)
+ PyErr_Clear();
+ else {
+ rv = encoder_listencode_list(s, rval, newobj, indent_level);
+ Py_DECREF(newobj);
+ break;
+ }
+ }
if (s->markers != Py_None) {
int has_key;
ident = PyLong_FromVoidPtr(obj);
diff --git a/simplejson/encoder.py b/simplejson/encoder.py
index d240438..5b9bda7 100644
--- a/simplejson/encoder.py
+++ b/simplejson/encoder.py
@@ -124,7 +124,7 @@ class JSONEncoder(object):
use_decimal=True, namedtuple_as_object=True,
tuple_as_array=True, bigint_as_string=False,
item_sort_key=None, for_json=False, ignore_nan=False,
- int_as_string_bitcount=None):
+ int_as_string_bitcount=None, iterable_as_array=False):
"""Constructor for JSONEncoder, with sensible defaults.
If skipkeys is false, then it is a TypeError to attempt
@@ -179,6 +179,10 @@ class JSONEncoder(object):
If tuple_as_array is true (the default), tuple (and subclasses) will
be encoded as JSON arrays.
+ If *iterable_as_array* is true (default: ``False``),
+ any object not in the above table that implements ``__iter__()``
+ will be encoded as a JSON array.
+
If bigint_as_string is true (not the default), ints 2**53 and higher
or lower than -2**53 will be encoded as strings. This is to avoid the
rounding that happens in Javascript otherwise.
@@ -210,6 +214,7 @@ class JSONEncoder(object):
self.use_decimal = use_decimal
self.namedtuple_as_object = namedtuple_as_object
self.tuple_as_array = tuple_as_array
+ self.iterable_as_array = iterable_as_array
self.bigint_as_string = bigint_as_string
self.item_sort_key = item_sort_key
self.for_json = for_json
@@ -338,7 +343,7 @@ class JSONEncoder(object):
self.namedtuple_as_object, self.tuple_as_array,
int_as_string_bitcount,
self.item_sort_key, self.encoding, self.for_json,
- self.ignore_nan, decimal.Decimal)
+ self.ignore_nan, decimal.Decimal, self.iterable_as_array)
else:
_iterencode = _make_iterencode(
markers, self.default, _encoder, self.indent, floatstr,
@@ -347,7 +352,7 @@ class JSONEncoder(object):
self.namedtuple_as_object, self.tuple_as_array,
int_as_string_bitcount,
self.item_sort_key, self.encoding, self.for_json,
- Decimal=decimal.Decimal)
+ self.iterable_as_array, Decimal=decimal.Decimal)
try:
return _iterencode(o, 0)
finally:
@@ -386,6 +391,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
_use_decimal, _namedtuple_as_object, _tuple_as_array,
_int_as_string_bitcount, _item_sort_key,
_encoding,_for_json,
+ _iterable_as_array,
## HACK: hand-optimized bytecode; turn globals into locals
_PY3=PY3,
ValueError=ValueError,
@@ -399,6 +405,7 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
list=list,
str=str,
tuple=tuple,
+ iter=iter,
):
if _use_decimal and Decimal is None:
Decimal = decimal.Decimal
@@ -489,10 +496,14 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
chunks = _iterencode(value, _current_indent_level)
for chunk in chunks:
yield chunk
- if newline_indent is not None:
- _current_indent_level -= 1
- yield '\n' + (_indent * _current_indent_level)
- yield ']'
+ if first:
+ # iterable_as_array misses the fast path at the top
+ yield '[]'
+ else:
+ if newline_indent is not None:
+ _current_indent_level -= 1
+ yield '\n' + (_indent * _current_indent_level)
+ yield ']'
if markers is not None:
del markers[markerid]
@@ -646,6 +657,16 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
elif _use_decimal and isinstance(o, Decimal):
yield str(o)
else:
+ while _iterable_as_array:
+ # Markers are not checked here because it is valid for
+ # an iterable to return self.
+ try:
+ o = iter(o)
+ except TypeError:
+ break
+ for chunk in _iterencode_list(o, _current_indent_level):
+ yield chunk
+ return
if markers is not None:
markerid = id(o)
if markerid in markers:
diff --git a/simplejson/tests/__init__.py b/simplejson/tests/__init__.py
index 8c1a4f1..88249d1 100644
--- a/simplejson/tests/__init__.py
+++ b/simplejson/tests/__init__.py
@@ -49,6 +49,7 @@ def all_tests_suite():
'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',
diff --git a/simplejson/tests/test_iterable.py b/simplejson/tests/test_iterable.py
new file mode 100644
index 0000000..35d3e75
--- /dev/null
+++ b/simplejson/tests/test_iterable.py
@@ -0,0 +1,31 @@
+import unittest
+from simplejson.compat import StringIO
+
+import simplejson as json
+
+def iter_dumps(obj, **kw):
+ return ''.join(json.JSONEncoder(**kw).iterencode(obj))
+
+def sio_dump(obj, **kw):
+ sio = StringIO()
+ json.dumps(obj, **kw)
+ return sio.getvalue()
+
+class TestIterable(unittest.TestCase):
+ def test_iterable(self):
+ for l in ([], [1], [1, 2], [1, 2, 3]):
+ for opts in [{}, {'indent': 2}]:
+ for dumps in (json.dumps, iter_dumps, sio_dump):
+ expect = dumps(l, **opts)
+ default_expect = dumps(sum(l), **opts)
+ # Default is False
+ self.assertRaises(TypeError, dumps, iter(l), **opts)
+ self.assertRaises(TypeError, dumps, iter(l), iterable_as_array=False, **opts)
+ self.assertEqual(expect, dumps(iter(l), iterable_as_array=True, **opts))
+ # Ensure that the "default" gets called
+ self.assertEqual(default_expect, dumps(iter(l), default=sum, **opts))
+ self.assertEqual(default_expect, dumps(iter(l), iterable_as_array=False, default=sum, **opts))
+ # Ensure that the "default" does not get called
+ self.assertEqual(
+ expect,
+ dumps(iter(l), iterable_as_array=True, default=sum, **opts))
diff --git a/simplejson/tests/test_tuple.py b/simplejson/tests/test_tuple.py
index a6a9910..4ad7b0e 100644
--- a/simplejson/tests/test_tuple.py
+++ b/simplejson/tests/test_tuple.py
@@ -45,7 +45,3 @@ class TestTuples(unittest.TestCase):
self.assertEqual(
json.dumps(repr(t)),
sio.getvalue())
-
-class TestNamedTuple(unittest.TestCase):
- def test_namedtuple_dump(self):
- pass
--
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