Update SimpleJSON library 3.8.1 (6022794) to 3.10.0 (c52efea).

This commit is contained in:
JackDandy 2017-01-27 14:38:06 +00:00
parent d8923df521
commit d72cfe7e05
6 changed files with 60 additions and 17 deletions

View file

@ -20,6 +20,7 @@
* Update profilehooks 1.8.2.dev0 (ee3f1a8) to 1.9.0 (de7d59b) * Update profilehooks 1.8.2.dev0 (ee3f1a8) to 1.9.0 (de7d59b)
* Update rarfile to 3.0 (3e54b22) * Update rarfile to 3.0 (3e54b22)
* Update Requests library 2.9.1 (a1c9b84) to 2.13.0 (fc54869) * 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] [develop changelog]

View file

@ -97,7 +97,7 @@ Using simplejson.tool from the shell to validate and pretty-print::
Expecting property name: line 1 column 3 (char 2) Expecting property name: line 1 column 3 (char 2)
""" """
from __future__ import absolute_import from __future__ import absolute_import
__version__ = '3.8.1' __version__ = '3.10.0'
__all__ = [ __all__ = [
'dump', 'dumps', 'load', 'loads', 'dump', 'dumps', 'load', 'loads',
'JSONDecoder', 'JSONDecodeError', 'JSONEncoder', 'JSONDecoder', 'JSONDecodeError', 'JSONEncoder',
@ -110,7 +110,7 @@ from decimal import Decimal
from .scanner import JSONDecodeError from .scanner import JSONDecodeError
from .decoder import JSONDecoder from .decoder import JSONDecoder
from .encoder import JSONEncoder, JSONEncoderForHTML from .encoder import JSONEncoder, JSONEncoderForHTML, RawJSON
def _import_OrderedDict(): def _import_OrderedDict():
import collections import collections
try: try:

View file

@ -245,6 +245,8 @@ static void
encoder_dealloc(PyObject *self); encoder_dealloc(PyObject *self);
static int static int
encoder_clear(PyObject *self); encoder_clear(PyObject *self);
static int
is_raw_json(PyObject *obj);
static PyObject * static PyObject *
encoder_stringify_key(PyEncoderObject *s, PyObject *key); encoder_stringify_key(PyEncoderObject *s, PyObject *key);
static int static int
@ -277,6 +279,20 @@ moduleinit(void);
#define MIN_EXPANSION 6 #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 static int
JSON_Accu_Init(JSON_Accu *acc) 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)) { if (PyInt_Check(int_as_string_bitcount) || PyLong_Check(int_as_string_bitcount)) {
static const unsigned int long_long_bitsize = SIZEOF_LONG_LONG * 8; static const unsigned int long_long_bitsize = SIZEOF_LONG_LONG * 8;
int int_as_string_bitcount_val = (int)PyLong_AsLong(int_as_string_bitcount); 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->max_long_size = PyLong_FromUnsignedLongLong(1ULL << int_as_string_bitcount_val);
s->min_long_size = PyLong_FromLongLong(-1LL << 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) { 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) if (encoded != NULL)
rv = _steal_accumulate(rval, encoded); 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)) { else if (PyInt_Check(obj) || PyLong_Check(obj)) {
PyObject *encoded; PyObject *encoded;
if (PyInt_CheckExact(obj) || PyLong_CheckExact(obj)) { if (PyInt_CheckExact(obj) || PyLong_CheckExact(obj)) {

View file

@ -15,9 +15,6 @@ if sys.version_info[0] < 3:
integer_types = (int, long) integer_types = (int, long)
unichr = unichr unichr = unichr
reload_module = reload reload_module = reload
def fromhex(s):
return s.decode('hex')
else: else:
PY3 = True PY3 = True
if sys.version_info[:2] >= (3, 4): if sys.version_info[:2] >= (3, 4):
@ -40,7 +37,4 @@ else:
def unichr(s): def unichr(s):
return u(chr(s)) return u(chr(s))
def fromhex(s):
return bytes.fromhex(s)
long_type = integer_types[-1] long_type = integer_types[-1]

View file

@ -4,7 +4,7 @@ from __future__ import absolute_import
import re import re
import sys import sys
import struct 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 from .scanner import make_scanner, JSONDecodeError
def _import_c_scanstring(): def _import_c_scanstring():
@ -22,12 +22,16 @@ __all__ = ['JSONDecoder']
FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL FLAGS = re.VERBOSE | re.MULTILINE | re.DOTALL
def _floatconstants(): def _floatconstants():
_BYTES = fromhex('7FF80000000000007FF0000000000000') if sys.version_info < (2, 6):
# The struct module in Python 2.4 would get frexp() out of range here _BYTES = '7FF80000000000007FF0000000000000'.decode('hex')
# when an endian is specified in the format string. Fixed in Python 2.5+ # The struct module in Python 2.4 would get frexp() out of range here
if sys.byteorder != 'big': # when an endian is specified in the format string. Fixed in Python 2.5+
_BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1] if sys.byteorder != 'big':
nan, inf = struct.unpack('dd', _BYTES) _BYTES = _BYTES[:8][::-1] + _BYTES[8:][::-1]
nan, inf = struct.unpack('dd', _BYTES)
else:
nan = float('nan')
inf = float('inf')
return nan, inf, -inf return nan, inf, -inf
NaN, PosInf, NegInf = _floatconstants() NaN, PosInf, NegInf = _floatconstants()

View file

@ -5,7 +5,7 @@ import re
from operator import itemgetter from operator import itemgetter
# Do not import Decimal directly to avoid reload issues # Do not import Decimal directly to avoid reload issues
import decimal 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(): def _import_speedups():
try: try:
from . import _speedups from . import _speedups
@ -39,6 +39,14 @@ for i in [0x2028, 0x2029]:
FLOAT_REPR = repr 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('"')): def encode_basestring(s, _PY3=PY3, _q=u('"')):
"""Return a JSON representation of a Python string """Return a JSON representation of a Python string
@ -46,9 +54,13 @@ def encode_basestring(s, _PY3=PY3, _q=u('"')):
if _PY3: if _PY3:
if isinstance(s, binary_type): if isinstance(s, binary_type):
s = s.decode('utf-8') s = s.decode('utf-8')
if type(s) is not text_type:
s = text_type(s)
else: else:
if isinstance(s, str) and HAS_UTF8.search(s) is not None: if isinstance(s, str) and HAS_UTF8.search(s) is not None:
s = s.decode('utf-8') s = s.decode('utf-8')
if type(s) not in string_types:
s = text_type(s)
def replace(match): def replace(match):
return ESCAPE_DCT[match.group(0)] return ESCAPE_DCT[match.group(0)]
return _q + ESCAPE.sub(replace, s) + _q return _q + ESCAPE.sub(replace, s) + _q
@ -61,9 +73,13 @@ def py_encode_basestring_ascii(s, _PY3=PY3):
if _PY3: if _PY3:
if isinstance(s, binary_type): if isinstance(s, binary_type):
s = s.decode('utf-8') s = s.decode('utf-8')
if type(s) is not text_type:
s = text_type(s)
else: else:
if isinstance(s, str) and HAS_UTF8.search(s) is not None: if isinstance(s, str) and HAS_UTF8.search(s) is not None:
s = s.decode('utf-8') s = s.decode('utf-8')
if type(s) not in string_types:
s = text_type(s)
def replace(match): def replace(match):
s = match.group(0) s = match.group(0)
try: try:
@ -464,6 +480,8 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
if (isinstance(value, string_types) or if (isinstance(value, string_types) or
(_PY3 and isinstance(value, binary_type))): (_PY3 and isinstance(value, binary_type))):
yield buf + _encoder(value) yield buf + _encoder(value)
elif isinstance(value, RawJSON):
yield buf + value.encoded_json
elif value is None: elif value is None:
yield buf + 'null' yield buf + 'null'
elif value is True: elif value is True:
@ -582,6 +600,8 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
if (isinstance(value, string_types) or if (isinstance(value, string_types) or
(_PY3 and isinstance(value, binary_type))): (_PY3 and isinstance(value, binary_type))):
yield _encoder(value) yield _encoder(value)
elif isinstance(value, RawJSON):
yield value.encoded_json
elif value is None: elif value is None:
yield 'null' yield 'null'
elif value is True: elif value is True:
@ -624,6 +644,8 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
if (isinstance(o, string_types) or if (isinstance(o, string_types) or
(_PY3 and isinstance(o, binary_type))): (_PY3 and isinstance(o, binary_type))):
yield _encoder(o) yield _encoder(o)
elif isinstance(o, RawJSON):
yield o.encoded_json
elif o is None: elif o is None:
yield 'null' yield 'null'
elif o is True: elif o is True: