From b6a029e7834bac2da6691633f964f0fc19252ef0 Mon Sep 17 00:00:00 2001 From: L2501 Date: Wed, 19 Jul 2023 18:57:26 +0000 Subject: [PATCH] [script.module.simplejson] 3.19.1 --- script.module.simplejson/CHANGES.txt | 662 ------------------ script.module.simplejson/README.rst | 35 - script.module.simplejson/addon.xml | 21 +- .../lib/simplejson/__init__.py | 155 ++-- .../lib/simplejson/decoder.py | 80 ++- .../lib/simplejson/encoder.py | 86 ++- .../lib/simplejson/scanner.py | 6 +- .../lib/simplejson/tool.py | 42 -- 8 files changed, 172 insertions(+), 915 deletions(-) delete mode 100644 script.module.simplejson/CHANGES.txt delete mode 100644 script.module.simplejson/README.rst delete mode 100644 script.module.simplejson/lib/simplejson/tool.py diff --git a/script.module.simplejson/CHANGES.txt b/script.module.simplejson/CHANGES.txt deleted file mode 100644 index 40083a8aeb..0000000000 --- a/script.module.simplejson/CHANGES.txt +++ /dev/null @@ -1,662 +0,0 @@ -Version 3.16.1 released 2018-09-07 - -* Added examples for JSON lines use cases - https://github.com/simplejson/simplejson/pull/236 -* Add wheels for more Python versions and platforms - https://github.com/simplejson/simplejson/pull/234 - https://github.com/simplejson/simplejson/pull/233 - https://github.com/simplejson/simplejson/pull/231 - -Version 3.16.0 released 2018-06-28 - -* Restore old behavior with regard to the type of decoded empty - strings with speedups enabled on Python 2.x - https://github.com/simplejson/simplejson/pull/225 -* Add python_requires to setup.py to help pip - https://github.com/simplejson/simplejson/pull/224 -* Fix CSS in docs when built locally - https://github.com/simplejson/simplejson/pull/222 - -Version 3.15.0 released 2018-05-12 - -* Clean up the C code - https://github.com/simplejson/simplejson/pull/220 -* Bypass the decode() method in bytes subclasses - https://github.com/simplejson/simplejson/pull/219 -* Support builds without cStringIO - https://github.com/simplejson/simplejson/pull/217 -* Allow to disable serializing bytes by default in Python 3 - https://github.com/simplejson/simplejson/pull/216 -* Simplify the compatibility code - https://github.com/simplejson/simplejson/pull/215 -* Fix tests in Python 2.5 - https://github.com/simplejson/simplejson/pull/214 - -Version 3.14.0 released 2018-04-21 - -* Defer is_raw_json test (performance improvement) - https://github.com/simplejson/simplejson/pull/212 -* Avoid escaping U+2028 and U+2029 without ensure_ascii - https://github.com/simplejson/simplejson/pull/211 -* Fix an incorrect type test in Python 2, avoiding an unnecessary unicode copy. - https://github.com/simplejson/simplejson/pull/210 - -Version 3.13.2 released 2017-11-24 - -* Fix additional Python 2.x compilation issue on Windows - -Version 3.13.1 released 2017-11-24 - -* Improve CI to catch speedups build regressions -* Fix speedups build regression in Python 2.x - https://github.com/simplejson/simplejson/issues/193 - -Version 3.13.0 released 2017-11-23 - -* Workarounds for NamedTemporaryFile issues with Windows for tool tests -* Make TypeError messages contain type name instead of a repr. - https://github.com/simplejson/simplejson/pull/191 -* Ensure that encoding of text subtypes is consistent with or without speedups - https://github.com/simplejson/simplejson/issues/185 - -Version 3.12.1 released 2017-11-23 - -* Misc updates to build infrastructure -* Fix an assertion failure when make_encoder receives a bad encoder argument - https://github.com/simplejson/simplejson/pull/188 -* Fix potential crash during GC - https://github.com/simplejson/simplejson/pull/187 -* Fix a reference leak when sorting keys - https://github.com/simplejson/simplejson/pull/186 - -Version 3.12.0 released 2017-11-05 - -* Fix threaded import race condition - https://github.com/simplejson/simplejson/issues/184 -* Move RawJSON implementation to simplejson.raw_json module -* Move JSONDecodeError implementation to simplejson.errors module - -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. - https://github.com/simplejson/simplejson/pull/143 - -Version 3.9.0 released 2016-10-21 - -* Workaround for bad behavior in string subclasses - https://github.com/simplejson/simplejson/issues/144 -* Fix warnings flagged by -3 - https://github.com/simplejson/simplejson/pull/146 -* Update readthedocs documentation links - https://github.com/simplejson/simplejson/pull/137 -* Add build status badge to README - https://github.com/simplejson/simplejson/pull/134 - -Version 3.8.2 released 2016-02-14 - -* Fix implicit cast compiler warning in _speedups.c -* simplejson is now available as wheels for OS X and Windows thanks to Travis-CI - and AppVeyor respectively! Many thanks to @aebrahim for getting this party - started. - https://github.com/simplejson/simplejson/pull/130 - https://github.com/simplejson/simplejson/issues/122 - -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) - https://github.com/simplejson/simplejson/commit/e18cc09b688ea1f3305c27616fd3cadd2adc6d31#commitcomment-11443842 - -Version 3.7.2 released 2015-05-22 - -* Do not cache Decimal class in encoder, only reference the decimal module. - This may make reload work in more common scenarios. - -Version 3.7.1 released 2015-05-18 - -* Fix compilation with MSVC - https://github.com/simplejson/simplejson/pull/119 - -Version 3.7.0 released 2015-05-18 - -* simplejson no longer trusts custom str/repr methods for int, long, float - subclasses. These instances are now formatted as if they were exact - instances of those types. - https://github.com/simplejson/simplejson/issues/118 - -Version 3.6.5 released 2014-10-24 - -* Importing bug fix for reference leak when an error occurs during - dict encoding - https://github.com/simplejson/simplejson/issues/109 - -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 - https://github.com/simplejson/simplejson/issues/103 - -Version 3.6.2 released 2014-08-09 - -* Documentation updates - http://bugs.python.org/issue21514 - -Version 3.6.1 released 2014-08-09 - -* Documentation updates - https://github.com/simplejson/simplejson/issues/102 - -Version 3.6.0 released 2014-07-21 - -* Automatically strip any UTF-8 BOM from input to more closely - follow the latest specs - https://github.com/simplejson/simplejson/pull/101 - -Version 3.5.3 released 2014-06-24 - -* Fix lower bound checking in scan_once / raw_decode API - https://github.com/simplejson/simplejson/issues/98 - -Version 3.5.2 released 2014-05-22 - -* Fix Windows build with VS2008 - https://github.com/simplejson/simplejson/pull/97 - -Version 3.5.1 released 2014-05-21 - -* Consistently reject int_as_string_bitcount settings that are not - positive integers - -Version 3.5.0 released 2014-05-20 - -* Added int_as_string_bitcount encoder option - https://github.com/simplejson/pull/96 -* Fixed potential crash when encoder created with incorrect options - -Version 3.4.1 released 2014-04-30 - -* Fixed tests to run on Python 3.4 - -Version 3.4.0 released 2014-04-02 - -* Native setuptools support re-introduced - https://github.com/simplejson/simplejson/pull/92 - -Version 3.3.3 released 2014-02-14 - -* Improve test suite's Python 3.4 compatibility - https://github.com/simplejson/simplejson/issues/87 - -Version 3.3.2 released 2014-01-06 - -* Docstring fix for decoded string types - https://github.com/simplejson/simplejson/pull/82 - -Version 3.3.1 released 2013-10-05 - -* JSONDecodeError exceptions can now be pickled - https://github.com/simplejson/simplejson/pull/78 - -Version 3.3.0 released 2013-05-07 - -* Unpaired surrogates once again pass through the decoder, to match older - behavior and the RFC-4627 spec. - https://github.com/simplejson/simplejson/issues/62 - -Version 3.2.0 released 2013-05-01 - -* New ignore_nan kwarg in encoder that serializes out - of range floats (Infinity, -Infinity, NaN) as null for ECMA-262 - compliance. - https://github.com/simplejson/simplejson/pull/63 -* New for_json kwarg in encoder to make it possible to for - subclasses of dict and list to be specialized. - https://github.com/simplejson/simplejson/pull/69 - -Version 3.1.3 released 2013-04-06 - -* Updated documentation to discourage subclassing whenever possible. - default, object_hook, and object_pairs_hook provide almost all of - the functionality of subclassing. - -Version 3.1.2 released 2013-03-20 - -* Updated documentation to reflect separators behavior when indent is - not None - https://github.com/simplejson/simplejson/issues/59 -* Test suite should be compatible with debug builds of Python 2.x and 3.x - https://github.com/simplejson/simplejson/pull/65 - -Version 3.1.1 released 2013-02-21 - -* setup.py now has another workaround for Windows machines without - MSVC installed - http://bugs.python.org/issue7511 - -Version 3.1.0 released 2013-02-21 - -* Updated JSON conformance test suite - http://bugs.python.org/issue16559 -* simplejson.tool tests and bugfix for Python 3.x - http://bugs.python.org/issue16549 -* Improve error messages for certain kinds of truncated input - http://bugs.python.org/issue16009 -* Moved JSONDecodeError to json.scanner (still available for import - from json.decoder) -* Changed scanner to use JSONDecodeError directly rather than - StopIteration to improve error messages - -Version 3.0.9 released 2013-02-21 - -* Fix an off-by-one error in the colno property of JSONDecodeError - (when lineno == 1) - http://bugs.python.org/issue17225 - -Version 3.0.8 released 2013-02-19 - -* Fix a Python 2.x compiler warning for narrow unicode builds - https://github.com/simplejson/simplejson/issues/56 - -Version 3.0.7 released 2013-01-11 - -* NOTE: this release only changes the license. -* simplejson is now dual-licensed software, MIT or AFL v2.1. It is - also made explicit that this code is also licensed to the PSF under - a Contributor Agreement. - -Version 3.0.6 released 2013-01-11 - -* Fix for major Python 2.x ensure_ascii=False encoding regression - introduced in simplejson 3.0.0. If you use this setting, please - upgrade immediately. - https://github.com/simplejson/simplejson/issues/50 - -Version 3.0.5 released 2013-01-03 - -* NOTE: this release only changes the tests, it is - not essential to upgrade -* Tests now run with deprecation warnings printed -* Fixed Python 3 syntax error in simplejson.tool - https://github.com/simplejson/simplejson/issues/49 -* Fixed Python 3.3 deprecation warnings in test suite - https://github.com/simplejson/simplejson/issues/48 - -Version 3.0.4 released 2013-01-02 - -* MSVC compatibility for Python 3.3 - https://github.com/simplejson/simplejson/pull/47 - -Version 3.0.3 released 2013-01-01 - -* Fixes for bugs introduced in 3.0.2 -* Fixes for Python 2.5 compatibility -* MSVC compatibility for Python 2.x - https://github.com/simplejson/simplejson/pull/46 - -Version 3.0.2 released 2013-01-01 - -* THIS VERSION HAS BEEN REMOVED -* Missed a changeset to _speedups.c in the 3.0.1 branch cut - -Version 3.0.1 released 2013-01-01 - -* THIS VERSION HAS BEEN REMOVED -* Add accumulator optimization to encoder, equivalent to the usage of - `_Py_Accu` in the Python 3.3 json library. Only relevant if encoding - very large JSON documents. - -Version 3.0.0 released 2012-12-30 - -* Python 3.3 is now supported, thanks to Vinay Sajip - https://github.com/simplejson/simplejson/issues/8 -* `sort_keys`/`item_sort_key` now sort on the stringified version of the - key, rather than the original object. This ensures that the sort - only compares string types and makes the behavior consistent between - Python 2.x and Python 3.x. -* Like other number types, Decimal instances used as keys are now - coerced to strings when use_decimal is True. - -Version 2.6.2 released 2012-09-21 - -* JSONEncoderForHTML was not exported in the simplejson module - https://github.com/simplejson/simplejson/issues/41 - -Version 2.6.1 released 2012-07-27 - -* raw_decode() now skips whitespace before the object - https://github.com/simplejson/simplejson/pull/38 - -Version 2.6.0 released 2012-06-26 - -* Error messages changed to match proposal for Python 3.3.1 - http://bugs.python.org/issue5067 - -Version 2.5.2 released 2012-05-10 - -* Fix for regression introduced in 2.5.1 - https://github.com/simplejson/simplejson/issues/35 - -Version 2.5.1 released 2012-05-10 - -* Support for use_decimal=True in environments that use Python - sub-interpreters such as uWSGI - https://github.com/simplejson/simplejson/issues/34 - -Version 2.5.0 released 2012-03-29 - -* New item_sort_key option for encoder to allow fine grained control of sorted - output - -Version 2.4.0 released 2012-03-06 - -* New bigint_as_string option for encoder to trade JavaScript number precision - issues for type issues. - https://github.com/simplejson/simplejson/issues/31 - -Version 2.3.3 released 2012-02-27 - -* Allow unknown numerical types for indent parameter - https://github.com/simplejson/simplejson/pull/29 - -Version 2.3.2 released 2011-12-30 - -* Fix crashing regression in speedups introduced in 2.3.1 - -Version 2.3.1 released 2011-12-29 - -* namedtuple_as_object now checks _asdict to ensure that it - is callable. - https://github.com/simplejson/simplejson/issues/26 - -Version 2.3.0 released 2011-12-05 - -* Any objects with _asdict() methods are now considered for - namedtuple_as_object. - https://github.com/simplejson/simplejson/pull/22 - -Version 2.2.1 released 2011-09-06 - -* Fix MANIFEST.in issue when building a sdist from a sdist. - https://github.com/simplejson/simplejson/issues/16 - -Version 2.2.0 released 2011-09-04 - -* Remove setuptools requirement, reverted to pure distutils -* use_decimal default for encoding (dump, dumps, JSONEncoder) is now True -* tuple encoding as JSON objects can be turned off with new - tuple_as_array=False option. - https://github.com/simplejson/simplejson/pull/6 -* namedtuple (or other tuple subclasses with _asdict methods) are now - encoded as JSON objects rather than arrays by default. Can be disabled - and treated as a tuple with the new namedtuple_as_object=False option. - https://github.com/simplejson/simplejson/pull/6 -* JSONDecodeError is now raised instead of ValueError when a document - ends with an opening quote and the C speedups are in use. - https://github.com/simplejson/simplejson/issues/15 -* Updated documentation with information about JSONDecodeError -* Force unicode linebreak characters to be escaped (U+2028 and U+2029) - http://timelessrepo.com/json-isnt-a-javascript-subset -* Moved documentation from a git submodule to - https://simplejson.readthedocs.io/ - -Version 2.1.6 released 2011-05-08 - -* Prevent segfaults with deeply nested JSON documents - https://github.com/simplejson/simplejson/issues/11 -* Fix compatibility with Python 2.5 - https://github.com/simplejson/simplejson/issues/5 - -Version 2.1.5 released 2011-04-17 - -* Built sdist tarball with setuptools_git installed. Argh. - -Version 2.1.4 released 2011-04-17 - -* Does not try to build the extension when using PyPy -* Trailing whitespace after commas no longer emitted when indent is used -* Migrated to github http://github.com/simplejson/simplejson - -Version 2.1.3 released 2011-01-17 - -* Support the sort_keys option in C encoding speedups - http://code.google.com/p/simplejson/issues/detail?id=86 -* Allow use_decimal to work with dump() - http://code.google.com/p/simplejson/issues/detail?id=87 - -Version 2.1.2 released 2010-11-01 - -* Correct wrong end when object_pairs_hook is used - http://code.google.com/p/simplejson/issues/detail?id=85 -* Correct output for indent=0 - http://bugs.python.org/issue10019 -* Correctly raise TypeError when non-string keys are used with speedups - http://code.google.com/p/simplejson/issues/detail?id=82 -* Fix the endlineno, endcolno attributes of the JSONDecodeError exception. - http://code.google.com/p/simplejson/issues/detail?id=81 - -Version 2.1.1 released 2010-03-31 - -* Change how setup.py imports ez_setup.py to try and workaround old versions - of setuptools. - http://code.google.com/p/simplejson/issues/detail?id=75 -* Fix compilation on Windows platform (and other platforms with very - picky compilers) -* Corrected simplejson.__version__ and other minor doc changes. -* Do not fail speedups tests if speedups could not be built. - http://code.google.com/p/simplejson/issues/detail?id=73 - -Version 2.1.0 released 2010-03-10 - -* Decimal serialization officially supported for encoding with - use_decimal=True. For encoding this encodes Decimal objects and - for decoding it implies parse_float=Decimal -* Python 2.4 no longer supported (may still work, but no longer tested) -* Decoding performance and memory utilization enhancements - http://bugs.python.org/issue7451 -* JSONEncoderForHTML class for escaping &, <, > - http://code.google.com/p/simplejson/issues/detail?id=66 -* Memoization of object keys during encoding (when using speedups) -* Encoder changed to use PyIter_Next for list iteration to avoid - potential threading issues -* Encoder changed to use iteritems rather than PyDict_Next in order to - support dict subclasses that have a well defined ordering - http://bugs.python.org/issue6105 -* indent encoding parameter changed to be a string rather than an integer - (integer use still supported for backwards compatibility) - http://code.google.com/p/simplejson/issues/detail?id=56 -* Test suite (python setup.py test) now automatically runs with and without - speedups - http://code.google.com/p/simplejson/issues/detail?id=55 -* Fixed support for older versions of easy_install (e.g. stock Mac OS X config) - http://code.google.com/p/simplejson/issues/detail?id=54 -* Fixed str/unicode mismatches when using ensure_ascii=False - http://code.google.com/p/simplejson/issues/detail?id=48 -* Fixed error message when parsing an array with trailing comma with speedups - http://code.google.com/p/simplejson/issues/detail?id=46 -* Refactor decoder errors to raise JSONDecodeError instead of ValueError - http://code.google.com/p/simplejson/issues/detail?id=45 -* New ordered_pairs_hook feature in decoder which makes it possible to - preserve key order. http://bugs.python.org/issue5381 -* Fixed containerless unicode float decoding (same bug as 2.0.4, oops!) - http://code.google.com/p/simplejson/issues/detail?id=43 -* Share PosInf definition between encoder and decoder -* Minor reformatting to make it easier to backport simplejson changes - to Python 2.7/3.1 json module - -Version 2.0.9 released 2009-02-18 - -* Adds cyclic GC to the Encoder and Scanner speedups, which could've - caused uncollectible cycles in some cases when using custom parser - or encoder functions - -Version 2.0.8 released 2009-02-15 - -* Documentation fixes -* Fixes encoding True and False as keys -* Fixes checking for True and False by identity for several parameters - -Version 2.0.7 released 2009-01-04 - -* Documentation fixes -* C extension now always returns unicode strings when the input string is - unicode, even for empty strings - -Version 2.0.6 released 2008-12-19 - -* Windows build fixes - -Version 2.0.5 released 2008-11-23 - -* Fixes a segfault in the C extension when using check_circular=False and - encoding an invalid document - -Version 2.0.4 released 2008-10-24 - -* Fixes a parsing error in the C extension when the JSON document is (only) - a floating point number. It would consume one too few characters in that - case, and claim the document invalid. - -Version 2.0.3 released 2008-10-11 - -* Fixes reference leaks in the encoding speedups (sorry about that!) -* Fixes doctest suite for Python 2.6 -* More optimizations for the decoder - -Version 2.0.2 released 2008-10-06 - -* Fixes MSVC2003 build regression -* Fixes Python 2.4 compatibility in _speedups.c - -Version 2.0.1 released 2008-09-29 - -* Fixes long encoding regression introduced in 2.0.0 -* Fixes MinGW build regression introduced in 2.0.0 - -Version 2.0.0 released 2008-09-27 - -* optimized Python encoding path -* optimized Python decoding path -* optimized C encoding path -* optimized C decoding path -* switched to sphinx docs (nearly the same as the json module in python 2.6) - -Version 1.9.3 released 2008-09-23 - -* Decoding is significantly faster (for our internal benchmarks) -* Pretty-printing tool changed from simplejson to simplejson.tool for better - Python 2.6 comaptibility -* Misc. bug fixes - -Version 1.9 released 2008-05-03 - -* Rewrote test suite with unittest and doctest (no more nosetest dependency) -* Better PEP 7 and PEP 8 source compliance -* Removed simplejson.jsonfilter demo module -* simplejson.jsonfilter is no longer included - -Version 1.8.1 released 2008-03-24 - -* Optional C extension for accelerating the decoding of JSON strings -* Command line interface for pretty-printing JSON (via python -msimplejson) -* Decoding of integers and floats is now extensible (e.g. to use Decimal) via - parse_int, parse_float options. -* Subversion and issue tracker moved to google code: - http://code.google.com/p/simplejson/ -* "/" is no longer escaped, so if you're embedding JSON directly in HTML - you'll want to use .replace("/", "\\/") to prevent a close-tag attack. - -Version 1.7 released 2007-03-18 - -* Improves encoding performance with an optional C extension to speed up - str/unicode encoding (by 10-150x or so), which yields an overall speed - boost of 2x+ (JSON is string-heavy). -* Support for encoding unicode code points outside the BMP to UTF-16 - surrogate code pairs (specified by the Strings section of RFC 4627). - -Version 1.6 released 2007-03-03 - -* Improved str support for encoding. Previous versions of simplejson - integrated strings directly into the output stream, this version ensures - they're of a particular encoding (default is UTF-8) so that the output - stream is valid. - -Version 1.5 released 2007-01-18 - -* Better Python 2.5 compatibility -* Better Windows compatibility -* indent encoding parameter for pretty printing -* separators encoding parameter for generating optimally compact JSON - -Version 1.3 released 2006-04-01 - -* The optional object_hook function is called upon decoding of any JSON - object literal, and its return value is used instead of the dict that - would normally be used. This can be used to efficiently implement - features such as JSON-RPC class hinting, or other custom decodings of - JSON. See the documentation for more information. - -Version 1.1 released 2005-12-31 - -* Renamed from simple_json to simplejson to comply with PEP 8 module naming - guidelines -* Full set of documentation -* More tests -* The encoder and decoder have been extended to understand NaN, Infinity, and - -Infinity (but this can be turned off via allow_nan=False for strict JSON - compliance) -* The decoder's scanner has been fixed so that it no longer accepts invalid - JSON documents -* The decoder now reports line and column information as well as character - numbers for easier debugging -* The encoder now has a circular reference checker, which can be optionally - disabled with check_circular=False -* dump, dumps, load, loads now accept an optional cls kwarg to use an - alternate JSONEncoder or JSONDecoder class for convenience. -* The read/write compatibility shim for json-py now have deprecation warnings - -Version 1.0 released 2005-12-25 - - * Initial release diff --git a/script.module.simplejson/README.rst b/script.module.simplejson/README.rst deleted file mode 100644 index 196148f9cc..0000000000 --- a/script.module.simplejson/README.rst +++ /dev/null @@ -1,35 +0,0 @@ -simplejson ----------- - -.. image:: https://travis-ci.org/simplejson/simplejson.svg?branch=master - :target: https://travis-ci.org/simplejson/simplejson - -simplejson is a simple, fast, complete, correct and extensible -JSON encoder and decoder for Python 2.5+ -and Python 3.3+. It is pure Python code with no dependencies, -but includes an optional C extension for a serious speed boost. - -The latest documentation for simplejson can be read online here: -https://simplejson.readthedocs.io/ - -simplejson is the externally maintained development version of the -json library included with Python 2.6 and Python 3.0, but maintains -backwards compatibility with Python 2.5. - -The encoder can be specialized to provide serialization in any kind of -situation, without any special support by the objects to be serialized -(somewhat like pickle). This is best done with the ``default`` kwarg -to dumps. - -The decoder can handle incoming JSON strings of any specified encoding -(UTF-8 by default). It can also be specialized to post-process JSON -objects with the ``object_hook`` or ``object_pairs_hook`` kwargs. This -is particularly useful for implementing protocols such as JSON-RPC -that have a richer type system than JSON itself. - -For those of you that have legacy systems to maintain, there is a -very old fork of simplejson in the `python2.2`_ branch that supports -Python 2.2. This is based off of a very old version of simplejson, -is not maintained, and should only be used as a last resort. - -.. _python2.2: https://github.com/simplejson/simplejson/tree/python2.2 diff --git a/script.module.simplejson/addon.xml b/script.module.simplejson/addon.xml index a317e57de7..3d353acaaa 100644 --- a/script.module.simplejson/addon.xml +++ b/script.module.simplejson/addon.xml @@ -1,21 +1,18 @@ - + - + + Simple, fast, extensible JSON encoder/decoder for Python + Simple, fast, extensible JSON encoder/decoder for Python + MIT all - - Simple, fast, extensible JSON encoder/decoder for Python - Simple, fast, extensible JSON encoder/decoder for Python - Code taken from https://pypi.org/project/simplejson/ - MIT License, Academic Free License v. 2.1 - https://pypi.org/project/simplejson/ + https://github.com/simplejson/simplejson https://github.com/simplejson/simplejson + + icon.png + diff --git a/script.module.simplejson/lib/simplejson/__init__.py b/script.module.simplejson/lib/simplejson/__init__.py index 9d9b737006..7e533a24ae 100644 --- a/script.module.simplejson/lib/simplejson/__init__.py +++ b/script.module.simplejson/lib/simplejson/__init__.py @@ -118,7 +118,7 @@ """ from __future__ import absolute_import -__version__ = '3.16.1' +__version__ = '3.19.1' __all__ = [ 'dump', 'dumps', 'load', 'loads', 'JSONDecoder', 'JSONDecodeError', 'JSONEncoder', @@ -149,28 +149,10 @@ def _import_c_make_encoder(): except ImportError: return None -_default_encoder = JSONEncoder( - skipkeys=False, - ensure_ascii=True, - check_circular=True, - allow_nan=True, - indent=None, - separators=None, - encoding='utf-8', - default=None, - 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, - ignore_nan=False, - int_as_string_bitcount=None, -) +_default_encoder = JSONEncoder() def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, - allow_nan=True, cls=None, indent=None, separators=None, + allow_nan=False, cls=None, indent=None, separators=None, 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, @@ -180,31 +162,23 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, ``.write()``-supporting file-like object). If *skipkeys* is true then ``dict`` keys that are not basic types - (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``) + (``str``, ``int``, ``long``, ``float``, ``bool``, ``None``) will be skipped instead of raising a ``TypeError``. - If *ensure_ascii* is false, then the some chunks written to ``fp`` - may be ``unicode`` instances, subject to normal Python ``str`` to - ``unicode`` coercion rules. Unless ``fp.write()`` explicitly - understands ``unicode`` (as in ``codecs.getwriter()``) this is likely - to cause an error. + If *ensure_ascii* is false (default: ``True``), then the output may + contain non-ASCII characters, so long as they do not need to be escaped + by JSON. When it is true, all non-ASCII characters are escaped. - If *check_circular* is false, then the circular reference check - for container types will be skipped and a circular reference will - result in an ``OverflowError`` (or worse). - - If *allow_nan* is false, then it will be a ``ValueError`` to - serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) - in strict compliance of the original JSON specification, instead of using - the JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``). See + If *allow_nan* is true (default: ``False``), then out of range ``float`` + values (``nan``, ``inf``, ``-inf``) will be serialized to + their JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``) + instead of raising a ValueError. See *ignore_nan* for ECMA-262 compliant behavior. If *indent* is a string, then JSON array elements and object members will be pretty-printed with a newline followed by that string repeated for each level of nesting. ``None`` (the default) selects the most compact - representation without any newlines. For backwards compatibility with - versions of simplejson earlier than 2.1.0, an integer is also accepted - and is converted to a string with that many spaces. + representation without any newlines. If specified, *separators* should be an ``(item_separator, key_separator)`` tuple. The default is ``(', ', ': ')`` @@ -266,7 +240,7 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, """ # cached encoder if (not skipkeys and ensure_ascii and - check_circular and allow_nan and + check_circular and not 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 not iterable_as_array @@ -300,7 +274,7 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True, def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, - allow_nan=True, cls=None, indent=None, separators=None, + allow_nan=False, cls=None, indent=None, separators=None, 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, @@ -308,22 +282,23 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, iterable_as_array=False, **kw): """Serialize ``obj`` to a JSON formatted ``str``. - If ``skipkeys`` is false then ``dict`` keys that are not basic types - (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``) + If ``skipkeys`` is true then ``dict`` keys that are not basic types + (``str``, ``int``, ``long``, ``float``, ``bool``, ``None``) will be skipped instead of raising a ``TypeError``. - If ``ensure_ascii`` is false, then the return value will be a - ``unicode`` instance subject to normal Python ``str`` to ``unicode`` - coercion rules instead of being escaped to an ASCII ``str``. + If *ensure_ascii* is false (default: ``True``), then the output may + contain non-ASCII characters, so long as they do not need to be escaped + by JSON. When it is true, all non-ASCII characters are escaped. If ``check_circular`` is false, then the circular reference check for container types will be skipped and a circular reference will result in an ``OverflowError`` (or worse). - If ``allow_nan`` is false, then it will be a ``ValueError`` to - serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in - strict compliance of the JSON specification, instead of using the - JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``). + If *allow_nan* is true (default: ``False``), then out of range ``float`` + values (``nan``, ``inf``, ``-inf``) will be serialized to + their JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``) + instead of raising a ValueError. See + *ignore_nan* for ECMA-262 compliant behavior. If ``indent`` is a string, then JSON array elements and object members will be pretty-printed with a newline followed by that string repeated @@ -338,7 +313,8 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, compact JSON representation, you should specify ``(',', ':')`` to eliminate whitespace. - ``encoding`` is the character encoding for str instances, default is UTF-8. + ``encoding`` is the character encoding for bytes instances, default is + UTF-8. ``default(obj)`` is a function that should return a serializable version of obj or raise TypeError. The default simply raises TypeError. @@ -367,7 +343,7 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, If specified, *item_sort_key* is a callable used to sort the items in each dictionary. This is useful if you want to sort items other than - in alphabetical order by key. This option takes precendence over + in alphabetical order by key. This option takes precedence over *sort_keys*. If *sort_keys* is true (default: ``False``), the output of dictionaries @@ -390,7 +366,7 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, """ # cached encoder if (not skipkeys and ensure_ascii and - check_circular and allow_nan and + check_circular and not 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 not iterable_as_array @@ -419,23 +395,18 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True, **kw).encode(obj) -_default_decoder = JSONDecoder(encoding=None, object_hook=None, - object_pairs_hook=None) +_default_decoder = JSONDecoder() def load(fp, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, - use_decimal=False, namedtuple_as_object=True, tuple_as_array=True, - **kw): + use_decimal=False, allow_nan=False, **kw): """Deserialize ``fp`` (a ``.read()``-supporting file-like object containing - a JSON document) to a Python object. + a JSON document as `str` or `bytes`) to a Python object. *encoding* determines the encoding used to interpret any - :class:`str` objects decoded by this instance (``'utf-8'`` by - default). It has no effect when decoding :class:`unicode` objects. - - Note that currently only encodings that are a superset of ASCII work, - strings of other encodings should be passed in as :class:`unicode`. + `bytes` objects decoded by this instance (``'utf-8'`` by + default). It has no effect when decoding `str` objects. *object_hook*, if specified, will be called with the result of every JSON object decoded and its return value will be used in place of the @@ -452,23 +423,27 @@ def load(fp, encoding=None, cls=None, object_hook=None, parse_float=None, takes priority. *parse_float*, if specified, will be called with the string of every - JSON float to be decoded. By default, this is equivalent to + JSON float to be decoded. By default, this is equivalent to ``float(num_str)``. This can be used to use another datatype or parser for JSON floats (e.g. :class:`decimal.Decimal`). *parse_int*, if specified, will be called with the string of every - JSON int to be decoded. By default, this is equivalent to + JSON int to be decoded. By default, this is equivalent to ``int(num_str)``. This can be used to use another datatype or parser for JSON integers (e.g. :class:`float`). - *parse_constant*, if specified, will be called with one of the - following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This - can be used to raise an exception if invalid JSON numbers are - encountered. + *allow_nan*, if True (default false), will allow the parser to + accept the non-standard floats ``NaN``, ``Infinity``, and ``-Infinity`` + and enable the use of the deprecated *parse_constant*. If *use_decimal* is true (default: ``False``) then it implies parse_float=decimal.Decimal for parity with ``dump``. + *parse_constant*, if specified, will be + called with one of the following strings: ``'-Infinity'``, + ``'Infinity'``, ``'NaN'``. It is not recommended to use this feature, + as it is rare to parse non-compliant JSON containing these values. + To use a custom ``JSONDecoder`` subclass, specify it with the ``cls`` kwarg. NOTE: You should use *object_hook* or *object_pairs_hook* instead of subclassing whenever possible. @@ -478,21 +453,18 @@ def load(fp, encoding=None, cls=None, object_hook=None, parse_float=None, encoding=encoding, cls=cls, object_hook=object_hook, parse_float=parse_float, parse_int=parse_int, parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, - use_decimal=use_decimal, **kw) + use_decimal=use_decimal, allow_nan=allow_nan, **kw) def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, - use_decimal=False, **kw): + use_decimal=False, allow_nan=False, **kw): """Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON document) to a Python object. *encoding* determines the encoding used to interpret any - :class:`str` objects decoded by this instance (``'utf-8'`` by - default). It has no effect when decoding :class:`unicode` objects. - - Note that currently only encodings that are a superset of ASCII work, - strings of other encodings should be passed in as :class:`unicode`. + :class:`bytes` objects decoded by this instance (``'utf-8'`` by + default). It has no effect when decoding :class:`unicode` objects. *object_hook*, if specified, will be called with the result of every JSON object decoded and its return value will be used in place of the @@ -518,14 +490,18 @@ def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, ``int(num_str)``. This can be used to use another datatype or parser for JSON integers (e.g. :class:`float`). - *parse_constant*, if specified, will be called with one of the - following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This - can be used to raise an exception if invalid JSON numbers are - encountered. + *allow_nan*, if True (default false), will allow the parser to + accept the non-standard floats ``NaN``, ``Infinity``, and ``-Infinity`` + and enable the use of the deprecated *parse_constant*. If *use_decimal* is true (default: ``False``) then it implies parse_float=decimal.Decimal for parity with ``dump``. + *parse_constant*, if specified, will be + called with one of the following strings: ``'-Infinity'``, + ``'Infinity'``, ``'NaN'``. It is not recommended to use this feature, + as it is rare to parse non-compliant JSON containing these values. + To use a custom ``JSONDecoder`` subclass, specify it with the ``cls`` kwarg. NOTE: You should use *object_hook* or *object_pairs_hook* instead of subclassing whenever possible. @@ -534,7 +510,7 @@ def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, if (cls is None and encoding is None and object_hook is None and parse_int is None and parse_float is None and parse_constant is None and object_pairs_hook is None - and not use_decimal and not kw): + and not use_decimal and not allow_nan and not kw): return _default_decoder.decode(s) if cls is None: cls = JSONDecoder @@ -552,6 +528,8 @@ def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None, if parse_float is not None: raise TypeError("use_decimal=True implies parse_float=Decimal") kw['parse_float'] = Decimal + if allow_nan: + kw['allow_nan'] = True return cls(encoding=encoding, **kw).decode(s) @@ -573,22 +551,9 @@ def _toggle_speedups(enabled): scan.make_scanner = scan.py_make_scanner dec.make_scanner = scan.make_scanner global _default_decoder - _default_decoder = JSONDecoder( - encoding=None, - object_hook=None, - object_pairs_hook=None, - ) + _default_decoder = JSONDecoder() global _default_encoder - _default_encoder = JSONEncoder( - skipkeys=False, - ensure_ascii=True, - check_circular=True, - allow_nan=True, - indent=None, - separators=None, - encoding='utf-8', - default=None, - ) + _default_encoder = JSONEncoder() def simple_first(kv): """Helper function to pass to item_sort_key to sort simple diff --git a/script.module.simplejson/lib/simplejson/decoder.py b/script.module.simplejson/lib/simplejson/decoder.py index 7f0b0568fd..c99a976d84 100644 --- a/script.module.simplejson/lib/simplejson/decoder.py +++ b/script.module.simplejson/lib/simplejson/decoder.py @@ -46,9 +46,35 @@ def _floatconstants(): DEFAULT_ENCODING = "utf-8" +if hasattr(sys, 'get_int_max_str_digits'): + bounded_int = int +else: + def bounded_int(s, INT_MAX_STR_DIGITS=4300): + """Backport of the integer string length conversion limitation + + https://docs.python.org/3/library/stdtypes.html#int-max-str-digits + """ + if len(s) > INT_MAX_STR_DIGITS: + raise ValueError("Exceeds the limit (%s) for integer string conversion: value has %s digits" % (INT_MAX_STR_DIGITS, len(s))) + return int(s) + + +def scan_four_digit_hex(s, end, _m=re.compile(r'^[0-9a-fA-F]{4}$').match): + """Scan a four digit hex number from s[end:end + 4] + """ + msg = "Invalid \\uXXXX escape sequence" + esc = s[end:end + 4] + if not _m(esc): + raise JSONDecodeError(msg, s, end - 2) + try: + return int(esc, 16), end + 4 + except ValueError: + raise JSONDecodeError(msg, s, end - 2) + def py_scanstring(s, end, encoding=None, strict=True, _b=BACKSLASH, _m=STRINGCHUNK.match, _join=u''.join, - _PY3=PY3, _maxunicode=sys.maxunicode): + _PY3=PY3, _maxunicode=sys.maxunicode, + _scan_four_digit_hex=scan_four_digit_hex): """Scan the string s for a JSON string. End is the index of the character in s after the quote that started the JSON string. Unescapes all valid JSON string escape sequences and raises ValueError @@ -67,6 +93,7 @@ def py_scanstring(s, end, encoding=None, strict=True, if chunk is None: raise JSONDecodeError( "Unterminated string starting at", s, begin) + prev_end = end end = chunk.end() content, terminator = chunk.groups() # Content is contains zero or more unescaped string characters @@ -81,7 +108,7 @@ def py_scanstring(s, end, encoding=None, strict=True, elif terminator != '\\': if strict: msg = "Invalid control character %r at" - raise JSONDecodeError(msg, s, end) + raise JSONDecodeError(msg, s, prev_end) else: _append(terminator) continue @@ -100,33 +127,18 @@ def py_scanstring(s, end, encoding=None, strict=True, end += 1 else: # Unicode escape sequence - msg = "Invalid \\uXXXX escape sequence" - esc = s[end + 1:end + 5] - escX = esc[1:2] - if len(esc) != 4 or escX == 'x' or escX == 'X': - raise JSONDecodeError(msg, s, end - 1) - try: - uni = int(esc, 16) - except ValueError: - raise JSONDecodeError(msg, s, end - 1) - end += 5 + uni, end = _scan_four_digit_hex(s, end + 1) # Check for surrogate pair on UCS-4 systems # Note that this will join high/low surrogate pairs # but will also pass unpaired surrogates through if (_maxunicode > 65535 and uni & 0xfc00 == 0xd800 and s[end:end + 2] == '\\u'): - esc2 = s[end + 2:end + 6] - escX = esc2[1:2] - if len(esc2) == 4 and not (escX == 'x' or escX == 'X'): - try: - uni2 = int(esc2, 16) - except ValueError: - raise JSONDecodeError(msg, s, end) - if uni2 & 0xfc00 == 0xdc00: - uni = 0x10000 + (((uni - 0xd800) << 10) | - (uni2 - 0xdc00)) - end += 6 + uni2, end2 = _scan_four_digit_hex(s, end + 2) + if uni2 & 0xfc00 == 0xdc00: + uni = 0x10000 + (((uni - 0xd800) << 10) | + (uni2 - 0xdc00)) + end = end2 char = unichr(uni) # Append the unescaped character _append(char) @@ -167,7 +179,7 @@ def JSONObject(state, encoding, strict, scan_once, object_hook, return pairs, end + 1 elif nextchar != '"': raise JSONDecodeError( - "Expecting property name enclosed in double quotes", + "Expecting property name enclosed in double quotes or '}'", s, end) end += 1 while True: @@ -294,14 +306,15 @@ class JSONDecoder(object): | null | None | +---------------+-------------------+ - It also understands ``NaN``, ``Infinity``, and ``-Infinity`` as + When allow_nan=True, it also understands + ``NaN``, ``Infinity``, and ``-Infinity`` as their corresponding ``float`` values, which is outside the JSON spec. """ def __init__(self, encoding=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, - object_pairs_hook=None): + object_pairs_hook=None, allow_nan=False): """ *encoding* determines the encoding used to interpret any :class:`str` objects decoded by this instance (``'utf-8'`` by @@ -334,10 +347,13 @@ def __init__(self, encoding=None, object_hook=None, parse_float=None, ``int(num_str)``. This can be used to use another datatype or parser for JSON integers (e.g. :class:`float`). - *parse_constant*, if specified, will be called with one of the - following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This - can be used to raise an exception if invalid JSON numbers are - encountered. + *allow_nan*, if True (default false), will allow the parser to + accept the non-standard floats ``NaN``, ``Infinity``, and ``-Infinity``. + + *parse_constant*, if specified, will be + called with one of the following strings: ``'-Infinity'``, + ``'Infinity'``, ``'NaN'``. It is not recommended to use this feature, + as it is rare to parse non-compliant JSON containing these values. *strict* controls the parser's behavior when it encounters an invalid control character in a string. The default setting of @@ -351,8 +367,8 @@ def __init__(self, encoding=None, object_hook=None, parse_float=None, self.object_hook = object_hook self.object_pairs_hook = object_pairs_hook self.parse_float = parse_float or float - self.parse_int = parse_int or int - self.parse_constant = parse_constant or _CONSTANTS.__getitem__ + self.parse_int = parse_int or bounded_int + self.parse_constant = parse_constant or (allow_nan and _CONSTANTS.__getitem__ or None) self.strict = strict self.parse_object = JSONObject self.parse_array = JSONArray diff --git a/script.module.simplejson/lib/simplejson/encoder.py b/script.module.simplejson/lib/simplejson/encoder.py index 7ea172e7d2..661ff361bf 100644 --- a/script.module.simplejson/lib/simplejson/encoder.py +++ b/script.module.simplejson/lib/simplejson/encoder.py @@ -5,7 +5,7 @@ from operator import itemgetter # Do not import Decimal directly to avoid reload issues import decimal -from .compat import unichr, binary_type, text_type, string_types, integer_types, PY3 +from .compat import binary_type, text_type, string_types, integer_types, PY3 def _import_speedups(): try: from . import _speedups @@ -32,6 +32,7 @@ def _import_speedups(): for i in range(0x20): #ESCAPE_DCT.setdefault(chr(i), '\\u{0:04x}'.format(i)) ESCAPE_DCT.setdefault(chr(i), '\\u%04x' % (i,)) +del i FLOAT_REPR = repr @@ -139,7 +140,7 @@ class JSONEncoder(object): key_separator = ': ' def __init__(self, skipkeys=False, ensure_ascii=True, - check_circular=True, allow_nan=True, sort_keys=False, + check_circular=True, allow_nan=False, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None, use_decimal=True, namedtuple_as_object=True, tuple_as_array=True, bigint_as_string=False, @@ -160,10 +161,11 @@ def __init__(self, skipkeys=False, ensure_ascii=True, prevent an infinite recursion (which would cause an OverflowError). Otherwise, no such check takes place. - If allow_nan is true, then NaN, Infinity, and -Infinity will be - encoded as such. This behavior is not JSON specification compliant, - but is consistent with most JavaScript based encoders and decoders. - Otherwise, it will be a ValueError to encode such floats. + If allow_nan is true (default: False), then out of range float + values (nan, inf, -inf) will be serialized to + their JavaScript equivalents (NaN, Infinity, -Infinity) + instead of raising a ValueError. See + ignore_nan for ECMA-262 compliant behavior. If sort_keys is true, then the output of dictionaries will be sorted by key; this is useful for regression tests to ensure @@ -293,7 +295,7 @@ def encode(self, o): # This doesn't pass the iterator directly to ''.join() because the # exceptions aren't as detailed. The list call should be roughly # equivalent to the PySequence_Fast that ''.join() would do. - chunks = self.iterencode(o, _one_shot=True) + chunks = self.iterencode(o) if not isinstance(chunks, (list, tuple)): chunks = list(chunks) if self.ensure_ascii: @@ -301,7 +303,7 @@ def encode(self, o): else: return u''.join(chunks) - def iterencode(self, o, _one_shot=False): + def iterencode(self, o): """Encode the given object and yield each string representation as available. @@ -355,8 +357,7 @@ def floatstr(o, allow_nan=self.allow_nan, ignore_nan=self.ignore_nan, key_memo = {} int_as_string_bitcount = ( 53 if self.bigint_as_string else self.int_as_string_bitcount) - if (_one_shot and c_make_encoder is not None - and self.indent is None): + if (c_make_encoder is not None and self.indent is None): _iterencode = c_make_encoder( markers, self.default, _encoder, self.indent, self.key_separator, self.item_separator, self.sort_keys, @@ -369,7 +370,7 @@ def floatstr(o, allow_nan=self.allow_nan, ignore_nan=self.ignore_nan, _iterencode = _make_iterencode( markers, self.default, _encoder, self.indent, floatstr, self.key_separator, self.item_separator, self.sort_keys, - self.skipkeys, _one_shot, self.use_decimal, + self.skipkeys, self.use_decimal, self.namedtuple_as_object, self.tuple_as_array, int_as_string_bitcount, self.item_sort_key, self.encoding, self.for_json, @@ -397,14 +398,14 @@ class JSONEncoderForHTML(JSONEncoder): def encode(self, o): # Override JSONEncoder.encode because it has hacks for # performance that make things more complicated. - chunks = self.iterencode(o, True) + chunks = self.iterencode(o) if self.ensure_ascii: return ''.join(chunks) else: return u''.join(chunks) - def iterencode(self, o, _one_shot=False): - chunks = super(JSONEncoderForHTML, self).iterencode(o, _one_shot) + def iterencode(self, o): + chunks = super(JSONEncoderForHTML, self).iterencode(o) for chunk in chunks: chunk = chunk.replace('&', '\\u0026') chunk = chunk.replace('<', '\\u003c') @@ -418,7 +419,7 @@ def iterencode(self, o, _one_shot=False): def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, - _key_separator, _item_separator, _sort_keys, _skipkeys, _one_shot, + _key_separator, _item_separator, _sort_keys, _skipkeys, _use_decimal, _namedtuple_as_object, _tuple_as_array, _int_as_string_bitcount, _item_sort_key, _encoding,_for_json, @@ -450,6 +451,15 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, not isinstance(_int_as_string_bitcount, integer_types))): raise TypeError("int_as_string_bitcount must be a positive integer") + def call_method(obj, method_name): + method = getattr(obj, method_name, None) + if callable(method): + try: + return (method(),) + except TypeError: + pass + return None + def _encode_int(value): skip_quoting = ( _int_as_string_bitcount is None @@ -512,15 +522,18 @@ def _iterencode_list(lst, _current_indent_level): yield buf + str(value) else: yield buf - for_json = _for_json and getattr(value, 'for_json', None) - if for_json and callable(for_json): - chunks = _iterencode(for_json(), _current_indent_level) + for_json = _for_json and call_method(value, 'for_json') + if for_json: + chunks = _iterencode(for_json[0], _current_indent_level) elif isinstance(value, list): chunks = _iterencode_list(value, _current_indent_level) else: - _asdict = _namedtuple_as_object and getattr(value, '_asdict', None) - if _asdict and callable(_asdict): - chunks = _iterencode_dict(_asdict(), + _asdict = _namedtuple_as_object and call_method(value, '_asdict') + if _asdict: + dct = _asdict[0] + if not isinstance(dct, dict): + raise TypeError("_asdict() must return a dict, not %s" % (type(dct).__name__,)) + chunks = _iterencode_dict(dct, _current_indent_level) elif _tuple_as_array and isinstance(value, tuple): chunks = _iterencode_list(value, _current_indent_level) @@ -633,15 +646,18 @@ def _iterencode_dict(dct, _current_indent_level): elif _use_decimal and isinstance(value, Decimal): yield str(value) else: - for_json = _for_json and getattr(value, 'for_json', None) - if for_json and callable(for_json): - chunks = _iterencode(for_json(), _current_indent_level) + for_json = _for_json and call_method(value, 'for_json') + if for_json: + chunks = _iterencode(for_json[0], _current_indent_level) elif isinstance(value, list): chunks = _iterencode_list(value, _current_indent_level) else: - _asdict = _namedtuple_as_object and getattr(value, '_asdict', None) - if _asdict and callable(_asdict): - chunks = _iterencode_dict(_asdict(), + _asdict = _namedtuple_as_object and call_method(value, '_asdict') + if _asdict: + dct = _asdict[0] + if not isinstance(dct, dict): + raise TypeError("_asdict() must return a dict, not %s" % (type(dct).__name__,)) + chunks = _iterencode_dict(dct, _current_indent_level) elif _tuple_as_array and isinstance(value, tuple): chunks = _iterencode_list(value, _current_indent_level) @@ -676,18 +692,20 @@ def _iterencode(o, _current_indent_level): elif isinstance(o, float): yield _floatstr(o) else: - for_json = _for_json and getattr(o, 'for_json', None) - if for_json and callable(for_json): - for chunk in _iterencode(for_json(), _current_indent_level): + for_json = _for_json and call_method(o, 'for_json') + if for_json: + for chunk in _iterencode(for_json[0], _current_indent_level): yield chunk elif isinstance(o, list): for chunk in _iterencode_list(o, _current_indent_level): yield chunk else: - _asdict = _namedtuple_as_object and getattr(o, '_asdict', None) - if _asdict and callable(_asdict): - for chunk in _iterencode_dict(_asdict(), - _current_indent_level): + _asdict = _namedtuple_as_object and call_method(o, '_asdict') + if _asdict: + dct = _asdict[0] + if not isinstance(dct, dict): + raise TypeError("_asdict() must return a dict, not %s" % (type(dct).__name__,)) + for chunk in _iterencode_dict(dct, _current_indent_level): yield chunk elif (_tuple_as_array and isinstance(o, tuple)): for chunk in _iterencode_list(o, _current_indent_level): diff --git a/script.module.simplejson/lib/simplejson/scanner.py b/script.module.simplejson/lib/simplejson/scanner.py index 85e385e147..34710d68c6 100644 --- a/script.module.simplejson/lib/simplejson/scanner.py +++ b/script.module.simplejson/lib/simplejson/scanner.py @@ -60,11 +60,11 @@ def _scan_once(string, idx): else: res = parse_int(integer) return res, m.end() - elif nextchar == 'N' and string[idx:idx + 3] == 'NaN': + elif parse_constant and nextchar == 'N' and string[idx:idx + 3] == 'NaN': return parse_constant('NaN'), idx + 3 - elif nextchar == 'I' and string[idx:idx + 8] == 'Infinity': + elif parse_constant and nextchar == 'I' and string[idx:idx + 8] == 'Infinity': return parse_constant('Infinity'), idx + 8 - elif nextchar == '-' and string[idx:idx + 9] == '-Infinity': + elif parse_constant and nextchar == '-' and string[idx:idx + 9] == '-Infinity': return parse_constant('-Infinity'), idx + 9 else: raise JSONDecodeError(errmsg, string, idx) diff --git a/script.module.simplejson/lib/simplejson/tool.py b/script.module.simplejson/lib/simplejson/tool.py deleted file mode 100644 index 062e8e2c18..0000000000 --- a/script.module.simplejson/lib/simplejson/tool.py +++ /dev/null @@ -1,42 +0,0 @@ -r"""Command-line tool to validate and pretty-print JSON - -Usage:: - - $ echo '{"json":"obj"}' | python -m simplejson.tool - { - "json": "obj" - } - $ echo '{ 1.2:3.4}' | python -m simplejson.tool - Expecting property name: line 1 column 2 (char 2) - -""" -from __future__ import with_statement -import sys -import simplejson as json - -def main(): - if len(sys.argv) == 1: - infile = sys.stdin - outfile = sys.stdout - elif len(sys.argv) == 2: - infile = open(sys.argv[1], 'r') - outfile = sys.stdout - elif len(sys.argv) == 3: - infile = open(sys.argv[1], 'r') - outfile = open(sys.argv[2], 'w') - else: - raise SystemExit(sys.argv[0] + " [infile [outfile]]") - with infile: - try: - obj = json.load(infile, - object_pairs_hook=json.OrderedDict, - use_decimal=True) - except ValueError: - raise SystemExit(sys.exc_info()[1]) - with outfile: - json.dump(obj, outfile, sort_keys=True, indent=' ', use_decimal=True) - outfile.write('\n') - - -if __name__ == '__main__': - main()