From d72cfe7e055d7f76fb13553958889c505546ce43 Mon Sep 17 00:00:00 2001 From: JackDandy Date: Fri, 27 Jan 2017 14:38:06 +0000 Subject: [PATCH] Update SimpleJSON library 3.8.1 (6022794) to 3.10.0 (c52efea). --- CHANGES.md | 1 + lib/simplejson/__init__.py | 4 ++-- lib/simplejson/_speedups.c | 24 +++++++++++++++++++++++- lib/simplejson/compat.py | 6 ------ lib/simplejson/decoder.py | 18 +++++++++++------- lib/simplejson/encoder.py | 24 +++++++++++++++++++++++- 6 files changed, 60 insertions(+), 17 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cc891ba6..6b3c0ecc 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -20,6 +20,7 @@ * Update profilehooks 1.8.2.dev0 (ee3f1a8) to 1.9.0 (de7d59b) * Update rarfile to 3.0 (3e54b22) * Update Requests library 2.9.1 (a1c9b84) to 2.13.0 (fc54869) +* Update SimpleJSON library 3.8.1 (6022794) to 3.10.0 (c52efea) [develop changelog] diff --git a/lib/simplejson/__init__.py b/lib/simplejson/__init__.py index c4487421..d4876cd3 100644 --- a/lib/simplejson/__init__.py +++ b/lib/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.8.1' +__version__ = '3.10.0' __all__ = [ 'dump', 'dumps', 'load', 'loads', 'JSONDecoder', 'JSONDecodeError', 'JSONEncoder', @@ -110,7 +110,7 @@ from decimal import Decimal from .scanner import JSONDecodeError from .decoder import JSONDecoder -from .encoder import JSONEncoder, JSONEncoderForHTML +from .encoder import JSONEncoder, JSONEncoderForHTML, RawJSON def _import_OrderedDict(): import collections try: diff --git a/lib/simplejson/_speedups.c b/lib/simplejson/_speedups.c index 173c5e10..2d810636 100644 --- a/lib/simplejson/_speedups.c +++ b/lib/simplejson/_speedups.c @@ -245,6 +245,8 @@ static void encoder_dealloc(PyObject *self); static int encoder_clear(PyObject *self); +static int +is_raw_json(PyObject *obj); static PyObject * encoder_stringify_key(PyEncoderObject *s, PyObject *key); static int @@ -277,6 +279,20 @@ moduleinit(void); #define MIN_EXPANSION 6 +static PyObject* RawJSONType; +static int +is_raw_json(PyObject *obj) +{ + if (RawJSONType == NULL) { + PyObject *encoder_module = PyImport_ImportModule("simplejson.encoder"); + RawJSONType = PyObject_GetAttrString(encoder_module, "RawJSON"); + Py_DECREF(encoder_module); + if (RawJSONType == NULL) + return 0; + } + return PyObject_IsInstance(obj, RawJSONType) ? 1 : 0; +} + static int JSON_Accu_Init(JSON_Accu *acc) { @@ -2654,7 +2670,7 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds) 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 < long_long_bitsize) { + 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); if (s->min_long_size == NULL || s->max_long_size == NULL) { @@ -2868,6 +2884,12 @@ encoder_listencode_obj(PyEncoderObject *s, JSON_Accu *rval, PyObject *obj, Py_ss if (encoded != NULL) rv = _steal_accumulate(rval, encoded); } + else if (is_raw_json(obj)) + { + PyObject *encoded = PyObject_GetAttrString(obj, "encoded_json"); + if (encoded != NULL) + rv = _steal_accumulate(rval, encoded); + } else if (PyInt_Check(obj) || PyLong_Check(obj)) { PyObject *encoded; if (PyInt_CheckExact(obj) || PyLong_CheckExact(obj)) { diff --git a/lib/simplejson/compat.py b/lib/simplejson/compat.py index a0af4a1c..6f945ccc 100644 --- a/lib/simplejson/compat.py +++ b/lib/simplejson/compat.py @@ -15,9 +15,6 @@ if sys.version_info[0] < 3: integer_types = (int, long) unichr = unichr reload_module = reload - def fromhex(s): - return s.decode('hex') - else: PY3 = True if sys.version_info[:2] >= (3, 4): @@ -40,7 +37,4 @@ else: def unichr(s): return u(chr(s)) - def fromhex(s): - return bytes.fromhex(s) - long_type = integer_types[-1] diff --git a/lib/simplejson/decoder.py b/lib/simplejson/decoder.py index 545e6587..29de124f 100644 --- a/lib/simplejson/decoder.py +++ b/lib/simplejson/decoder.py @@ -4,7 +4,7 @@ from __future__ import absolute_import import re import sys import struct -from .compat import fromhex, b, u, text_type, binary_type, PY3, unichr +from .compat import b, u, text_type, binary_type, PY3, unichr from .scanner import make_scanner, JSONDecodeError def _import_c_scanstring(): @@ -22,12 +22,16 @@ __all__ = ['JSONDecoder'] FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL def _floatconstants(): - _BYTES = fromhex('7FF80000000000007FF0000000000000') - # 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) + 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) + else: + nan = float('nan') + inf = float('inf') return nan, inf, -inf NaN, PosInf, NegInf = _floatconstants() diff --git a/lib/simplejson/encoder.py b/lib/simplejson/encoder.py index 5b9bda72..226480f0 100644 --- a/lib/simplejson/encoder.py +++ b/lib/simplejson/encoder.py @@ -5,7 +5,7 @@ import re from operator import itemgetter # Do not import Decimal directly to avoid reload issues import decimal -from .compat import u, unichr, binary_type, string_types, integer_types, PY3 +from .compat import u, unichr, binary_type, text_type, string_types, integer_types, PY3 def _import_speedups(): try: from . import _speedups @@ -39,6 +39,14 @@ for i in [0x2028, 0x2029]: FLOAT_REPR = repr +class RawJSON(object): + """Wrap an encoded JSON document for direct embedding in the output + + """ + def __init__(self, encoded_json): + self.encoded_json = encoded_json + + def encode_basestring(s, _PY3=PY3, _q=u('"')): """Return a JSON representation of a Python string @@ -46,9 +54,13 @@ def encode_basestring(s, _PY3=PY3, _q=u('"')): if _PY3: if isinstance(s, binary_type): s = s.decode('utf-8') + if type(s) is not text_type: + s = text_type(s) else: if isinstance(s, str) and HAS_UTF8.search(s) is not None: s = s.decode('utf-8') + if type(s) not in string_types: + s = text_type(s) def replace(match): return ESCAPE_DCT[match.group(0)] return _q + ESCAPE.sub(replace, s) + _q @@ -61,9 +73,13 @@ def py_encode_basestring_ascii(s, _PY3=PY3): if _PY3: if isinstance(s, binary_type): s = s.decode('utf-8') + if type(s) is not text_type: + s = text_type(s) else: if isinstance(s, str) and HAS_UTF8.search(s) is not None: s = s.decode('utf-8') + if type(s) not in string_types: + s = text_type(s) def replace(match): s = match.group(0) try: @@ -464,6 +480,8 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, if (isinstance(value, string_types) or (_PY3 and isinstance(value, binary_type))): yield buf + _encoder(value) + elif isinstance(value, RawJSON): + yield buf + value.encoded_json elif value is None: yield buf + 'null' elif value is True: @@ -582,6 +600,8 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, if (isinstance(value, string_types) or (_PY3 and isinstance(value, binary_type))): yield _encoder(value) + elif isinstance(value, RawJSON): + yield value.encoded_json elif value is None: yield 'null' elif value is True: @@ -624,6 +644,8 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr, if (isinstance(o, string_types) or (_PY3 and isinstance(o, binary_type))): yield _encoder(o) + elif isinstance(o, RawJSON): + yield o.encoded_json elif o is None: yield 'null' elif o is True: