From c510dd0285bbce594fd772b462eb859a39bf4a9f Mon Sep 17 00:00:00 2001 From: Bob Ippolito Date: Wed, 24 Sep 2014 16:23:41 -0700 Subject: ensure cached encoder is only used when all settings are default --- simplejson/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/simplejson/__init__.py b/simplejson/__init__.py index a02c4de..1dd5a71 100644 --- a/simplejson/__init__.py +++ b/simplejson/__init__.py @@ -243,8 +243,11 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, 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 not bigint_as_string and int_as_string_bitcount is None - and not item_sort_key and not for_json and not ignore_nan and not kw): + 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 + and not kw + ): iterable = _default_encoder.iterencode(obj) else: if cls is None: @@ -359,9 +362,10 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, 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 not bigint_as_string and int_as_string_bitcount is None - and not sort_keys and not item_sort_key and not for_json - and not ignore_nan and not kw + 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 + and not kw ): return _default_encoder.encode(obj) if cls is None: -- cgit v1.2.1 From 77437f037f99e9df49dab740b32bdb20af93af44 Mon Sep 17 00:00:00 2001 From: Bob Ippolito Date: Mon, 29 Sep 2014 14:07:14 -0700 Subject: update version for v3.6.4 --- CHANGES.txt | 5 +++++ conf.py | 2 +- setup.py | 2 +- simplejson/__init__.py | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 0bfde2e..bd6d978 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,3 +1,8 @@ +Version 3.6.4 released 2014-09-29 + +* Important bug fix for dump when only sort_keys is set + https://github.com/simplejson/simplejson/issues/106 + Version 3.6.3 released 2014-08-18 * Documentation updates diff --git a/conf.py b/conf.py index 952b979..5d44941 100644 --- a/conf.py +++ b/conf.py @@ -44,7 +44,7 @@ copyright = '2014, Bob Ippolito' # The short X.Y version. version = '3.6' # The full version, including alpha/beta/rc tags. -release = '3.6.3' +release = '3.6.4' # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: diff --git a/setup.py b/setup.py index 31237bf..d937ae2 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.6.3' +VERSION = '3.6.4' DESCRIPTION = "Simple, fast, extensible JSON encoder/decoder for Python" with open('README.rst', 'r') as f: diff --git a/simplejson/__init__.py b/simplejson/__init__.py index 1dd5a71..cbb5b34 100644 --- a/simplejson/__init__.py +++ b/simplejson/__init__.py @@ -98,7 +98,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.6.3' +__version__ = '3.6.4' __all__ = [ 'dump', 'dumps', 'load', 'loads', 'JSONDecoder', 'JSONDecodeError', 'JSONEncoder', -- cgit v1.2.1 From ccc8a2bc450f8b7f6db71a6daef4d4b069ba5851 Mon Sep 17 00:00:00 2001 From: Bob Ippolito Date: Mon, 29 Sep 2014 14:14:38 -0700 Subject: failing test for #106 --- simplejson/tests/test_dump.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/simplejson/tests/test_dump.py b/simplejson/tests/test_dump.py index 1d118d9..3661de0 100644 --- a/simplejson/tests/test_dump.py +++ b/simplejson/tests/test_dump.py @@ -119,3 +119,12 @@ class TestDump(TestCase): # the C API uses an accumulator that collects after 100,000 appends lst = [0] * 100000 self.assertEqual(json.loads(json.dumps(lst)), lst) + + def test_sort_keys(self): + # https://github.com/simplejson/simplejson/issues/106 + for num_keys in range(2, 32): + p = dict((str(x), x) for x in range(num_keys)) + sio = StringIO() + json.dump(p, sio, sort_keys=True) + self.assertEqual(sio.getvalue(), json.dumps(p, sort_keys=True)) + self.assertEqual(json.loads(sio.getvalue()), p) -- cgit v1.2.1