mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-15 01:32:57 -07:00
Bump simplejson from 3.18.3 to 3.19.1 (#2036)
* Bump simplejson from 3.18.3 to 3.19.1 Bumps [simplejson](https://github.com/simplejson/simplejson) from 3.18.3 to 3.19.1. - [Release notes](https://github.com/simplejson/simplejson/releases) - [Changelog](https://github.com/simplejson/simplejson/blob/master/CHANGES.txt) - [Commits](https://github.com/simplejson/simplejson/compare/v3.18.3...v3.19.1) --- updated-dependencies: - dependency-name: simplejson dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * Update simplejson==3.19.1 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> [skip ci]
This commit is contained in:
parent
70fb00280b
commit
1798594569
9 changed files with 128 additions and 121 deletions
|
@ -118,7 +118,7 @@ Serializing multiple objects to JSON lines (newline-delimited JSON)::
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
__version__ = '3.18.3'
|
__version__ = '3.19.1'
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'dump', 'dumps', 'load', 'loads',
|
'dump', 'dumps', 'load', 'loads',
|
||||||
'JSONDecoder', 'JSONDecodeError', 'JSONEncoder',
|
'JSONDecoder', 'JSONDecodeError', 'JSONEncoder',
|
||||||
|
@ -149,28 +149,10 @@ def _import_c_make_encoder():
|
||||||
except ImportError:
|
except ImportError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
_default_encoder = JSONEncoder(
|
_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,
|
|
||||||
)
|
|
||||||
|
|
||||||
def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
|
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,
|
encoding='utf-8', default=None, use_decimal=True,
|
||||||
namedtuple_as_object=True, tuple_as_array=True,
|
namedtuple_as_object=True, tuple_as_array=True,
|
||||||
bigint_as_string=False, sort_keys=False, item_sort_key=None,
|
bigint_as_string=False, sort_keys=False, item_sort_key=None,
|
||||||
|
@ -187,10 +169,10 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
|
||||||
contain non-ASCII characters, so long as they do not need to be escaped
|
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.
|
by JSON. When it is true, all non-ASCII characters are escaped.
|
||||||
|
|
||||||
If *allow_nan* is false, then it will be a ``ValueError`` to
|
If *allow_nan* is true (default: ``False``), then out of range ``float``
|
||||||
serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``)
|
values (``nan``, ``inf``, ``-inf``) will be serialized to
|
||||||
in strict compliance of the original JSON specification, instead of using
|
their JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``)
|
||||||
the JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``). See
|
instead of raising a ValueError. See
|
||||||
*ignore_nan* for ECMA-262 compliant behavior.
|
*ignore_nan* for ECMA-262 compliant behavior.
|
||||||
|
|
||||||
If *indent* is a string, then JSON array elements and object members
|
If *indent* is a string, then JSON array elements and object members
|
||||||
|
@ -258,7 +240,7 @@ def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,
|
||||||
"""
|
"""
|
||||||
# cached encoder
|
# cached encoder
|
||||||
if (not skipkeys and ensure_ascii and
|
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
|
cls is None and indent is None and separators is None and
|
||||||
encoding == 'utf-8' and default is None and use_decimal
|
encoding == 'utf-8' and default is None and use_decimal
|
||||||
and namedtuple_as_object and tuple_as_array and not iterable_as_array
|
and namedtuple_as_object and tuple_as_array and not iterable_as_array
|
||||||
|
@ -292,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,
|
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,
|
encoding='utf-8', default=None, use_decimal=True,
|
||||||
namedtuple_as_object=True, tuple_as_array=True,
|
namedtuple_as_object=True, tuple_as_array=True,
|
||||||
bigint_as_string=False, sort_keys=False, item_sort_key=None,
|
bigint_as_string=False, sort_keys=False, item_sort_key=None,
|
||||||
|
@ -312,10 +294,11 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
|
||||||
for container types will be skipped and a circular reference will
|
for container types will be skipped and a circular reference will
|
||||||
result in an ``OverflowError`` (or worse).
|
result in an ``OverflowError`` (or worse).
|
||||||
|
|
||||||
If ``allow_nan`` is false, then it will be a ``ValueError`` to
|
If *allow_nan* is true (default: ``False``), then out of range ``float``
|
||||||
serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in
|
values (``nan``, ``inf``, ``-inf``) will be serialized to
|
||||||
strict compliance of the JSON specification, instead of using the
|
their JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``)
|
||||||
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
|
If ``indent`` is a string, then JSON array elements and object members
|
||||||
will be pretty-printed with a newline followed by that string repeated
|
will be pretty-printed with a newline followed by that string repeated
|
||||||
|
@ -383,7 +366,7 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
|
||||||
"""
|
"""
|
||||||
# cached encoder
|
# cached encoder
|
||||||
if (not skipkeys and ensure_ascii and
|
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
|
cls is None and indent is None and separators is None and
|
||||||
encoding == 'utf-8' and default is None and use_decimal
|
encoding == 'utf-8' and default is None and use_decimal
|
||||||
and namedtuple_as_object and tuple_as_array and not iterable_as_array
|
and namedtuple_as_object and tuple_as_array and not iterable_as_array
|
||||||
|
@ -412,14 +395,12 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
|
||||||
**kw).encode(obj)
|
**kw).encode(obj)
|
||||||
|
|
||||||
|
|
||||||
_default_decoder = JSONDecoder(encoding=None, object_hook=None,
|
_default_decoder = JSONDecoder()
|
||||||
object_pairs_hook=None)
|
|
||||||
|
|
||||||
|
|
||||||
def load(fp, encoding=None, cls=None, object_hook=None, parse_float=None,
|
def load(fp, encoding=None, cls=None, object_hook=None, parse_float=None,
|
||||||
parse_int=None, parse_constant=None, object_pairs_hook=None,
|
parse_int=None, parse_constant=None, object_pairs_hook=None,
|
||||||
use_decimal=False, namedtuple_as_object=True, tuple_as_array=True,
|
use_decimal=False, allow_nan=False, **kw):
|
||||||
**kw):
|
|
||||||
"""Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
|
"""Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
|
||||||
a JSON document as `str` or `bytes`) to a Python object.
|
a JSON document as `str` or `bytes`) to a Python object.
|
||||||
|
|
||||||
|
@ -442,23 +423,27 @@ def load(fp, encoding=None, cls=None, object_hook=None, parse_float=None,
|
||||||
takes priority.
|
takes priority.
|
||||||
|
|
||||||
*parse_float*, if specified, will be called with the string of every
|
*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
|
``float(num_str)``. This can be used to use another datatype or parser
|
||||||
for JSON floats (e.g. :class:`decimal.Decimal`).
|
for JSON floats (e.g. :class:`decimal.Decimal`).
|
||||||
|
|
||||||
*parse_int*, if specified, will be called with the string of every
|
*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
|
``int(num_str)``. This can be used to use another datatype or parser
|
||||||
for JSON integers (e.g. :class:`float`).
|
for JSON integers (e.g. :class:`float`).
|
||||||
|
|
||||||
*parse_constant*, if specified, will be called with one of the
|
*allow_nan*, if True (default false), will allow the parser to
|
||||||
following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This
|
accept the non-standard floats ``NaN``, ``Infinity``, and ``-Infinity``
|
||||||
can be used to raise an exception if invalid JSON numbers are
|
and enable the use of the deprecated *parse_constant*.
|
||||||
encountered.
|
|
||||||
|
|
||||||
If *use_decimal* is true (default: ``False``) then it implies
|
If *use_decimal* is true (default: ``False``) then it implies
|
||||||
parse_float=decimal.Decimal for parity with ``dump``.
|
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``
|
To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
|
||||||
kwarg. NOTE: You should use *object_hook* or *object_pairs_hook* instead
|
kwarg. NOTE: You should use *object_hook* or *object_pairs_hook* instead
|
||||||
of subclassing whenever possible.
|
of subclassing whenever possible.
|
||||||
|
@ -468,12 +453,12 @@ def load(fp, encoding=None, cls=None, object_hook=None, parse_float=None,
|
||||||
encoding=encoding, cls=cls, object_hook=object_hook,
|
encoding=encoding, cls=cls, object_hook=object_hook,
|
||||||
parse_float=parse_float, parse_int=parse_int,
|
parse_float=parse_float, parse_int=parse_int,
|
||||||
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook,
|
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,
|
def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
|
||||||
parse_int=None, parse_constant=None, object_pairs_hook=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
|
"""Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON
|
||||||
document) to a Python object.
|
document) to a Python object.
|
||||||
|
|
||||||
|
@ -505,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
|
``int(num_str)``. This can be used to use another datatype or parser
|
||||||
for JSON integers (e.g. :class:`float`).
|
for JSON integers (e.g. :class:`float`).
|
||||||
|
|
||||||
*parse_constant*, if specified, will be called with one of the
|
*allow_nan*, if True (default false), will allow the parser to
|
||||||
following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This
|
accept the non-standard floats ``NaN``, ``Infinity``, and ``-Infinity``
|
||||||
can be used to raise an exception if invalid JSON numbers are
|
and enable the use of the deprecated *parse_constant*.
|
||||||
encountered.
|
|
||||||
|
|
||||||
If *use_decimal* is true (default: ``False``) then it implies
|
If *use_decimal* is true (default: ``False``) then it implies
|
||||||
parse_float=decimal.Decimal for parity with ``dump``.
|
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``
|
To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
|
||||||
kwarg. NOTE: You should use *object_hook* or *object_pairs_hook* instead
|
kwarg. NOTE: You should use *object_hook* or *object_pairs_hook* instead
|
||||||
of subclassing whenever possible.
|
of subclassing whenever possible.
|
||||||
|
@ -521,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
|
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_int is None and parse_float is None and
|
||||||
parse_constant is None and object_pairs_hook is None
|
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)
|
return _default_decoder.decode(s)
|
||||||
if cls is None:
|
if cls is None:
|
||||||
cls = JSONDecoder
|
cls = JSONDecoder
|
||||||
|
@ -539,6 +528,8 @@ def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
|
||||||
if parse_float is not None:
|
if parse_float is not None:
|
||||||
raise TypeError("use_decimal=True implies parse_float=Decimal")
|
raise TypeError("use_decimal=True implies parse_float=Decimal")
|
||||||
kw['parse_float'] = Decimal
|
kw['parse_float'] = Decimal
|
||||||
|
if allow_nan:
|
||||||
|
kw['allow_nan'] = True
|
||||||
return cls(encoding=encoding, **kw).decode(s)
|
return cls(encoding=encoding, **kw).decode(s)
|
||||||
|
|
||||||
|
|
||||||
|
@ -560,22 +551,9 @@ def _toggle_speedups(enabled):
|
||||||
scan.make_scanner = scan.py_make_scanner
|
scan.make_scanner = scan.py_make_scanner
|
||||||
dec.make_scanner = scan.make_scanner
|
dec.make_scanner = scan.make_scanner
|
||||||
global _default_decoder
|
global _default_decoder
|
||||||
_default_decoder = JSONDecoder(
|
_default_decoder = JSONDecoder()
|
||||||
encoding=None,
|
|
||||||
object_hook=None,
|
|
||||||
object_pairs_hook=None,
|
|
||||||
)
|
|
||||||
global _default_encoder
|
global _default_encoder
|
||||||
_default_encoder = JSONEncoder(
|
_default_encoder = JSONEncoder()
|
||||||
skipkeys=False,
|
|
||||||
ensure_ascii=True,
|
|
||||||
check_circular=True,
|
|
||||||
allow_nan=True,
|
|
||||||
indent=None,
|
|
||||||
separators=None,
|
|
||||||
encoding='utf-8',
|
|
||||||
default=None,
|
|
||||||
)
|
|
||||||
|
|
||||||
def simple_first(kv):
|
def simple_first(kv):
|
||||||
"""Helper function to pass to item_sort_key to sort simple
|
"""Helper function to pass to item_sort_key to sort simple
|
||||||
|
|
|
@ -46,9 +46,35 @@ BACKSLASH = {
|
||||||
|
|
||||||
DEFAULT_ENCODING = "utf-8"
|
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,
|
def py_scanstring(s, end, encoding=None, strict=True,
|
||||||
_b=BACKSLASH, _m=STRINGCHUNK.match, _join=u''.join,
|
_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
|
"""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.
|
character in s after the quote that started the JSON string.
|
||||||
Unescapes all valid JSON string escape sequences and raises ValueError
|
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:
|
if chunk is None:
|
||||||
raise JSONDecodeError(
|
raise JSONDecodeError(
|
||||||
"Unterminated string starting at", s, begin)
|
"Unterminated string starting at", s, begin)
|
||||||
|
prev_end = end
|
||||||
end = chunk.end()
|
end = chunk.end()
|
||||||
content, terminator = chunk.groups()
|
content, terminator = chunk.groups()
|
||||||
# Content is contains zero or more unescaped string characters
|
# Content is contains zero or more unescaped string characters
|
||||||
|
@ -81,7 +108,7 @@ def py_scanstring(s, end, encoding=None, strict=True,
|
||||||
elif terminator != '\\':
|
elif terminator != '\\':
|
||||||
if strict:
|
if strict:
|
||||||
msg = "Invalid control character %r at"
|
msg = "Invalid control character %r at"
|
||||||
raise JSONDecodeError(msg, s, end)
|
raise JSONDecodeError(msg, s, prev_end)
|
||||||
else:
|
else:
|
||||||
_append(terminator)
|
_append(terminator)
|
||||||
continue
|
continue
|
||||||
|
@ -100,35 +127,18 @@ def py_scanstring(s, end, encoding=None, strict=True,
|
||||||
end += 1
|
end += 1
|
||||||
else:
|
else:
|
||||||
# Unicode escape sequence
|
# Unicode escape sequence
|
||||||
msg = "Invalid \\uXXXX escape sequence"
|
uni, end = _scan_four_digit_hex(s, end + 1)
|
||||||
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)
|
|
||||||
if uni < 0 or uni > _maxunicode:
|
|
||||||
raise JSONDecodeError(msg, s, end - 1)
|
|
||||||
end += 5
|
|
||||||
# Check for surrogate pair on UCS-4 systems
|
# Check for surrogate pair on UCS-4 systems
|
||||||
# Note that this will join high/low surrogate pairs
|
# Note that this will join high/low surrogate pairs
|
||||||
# but will also pass unpaired surrogates through
|
# but will also pass unpaired surrogates through
|
||||||
if (_maxunicode > 65535 and
|
if (_maxunicode > 65535 and
|
||||||
uni & 0xfc00 == 0xd800 and
|
uni & 0xfc00 == 0xd800 and
|
||||||
s[end:end + 2] == '\\u'):
|
s[end:end + 2] == '\\u'):
|
||||||
esc2 = s[end + 2:end + 6]
|
uni2, end2 = _scan_four_digit_hex(s, end + 2)
|
||||||
escX = esc2[1:2]
|
if uni2 & 0xfc00 == 0xdc00:
|
||||||
if len(esc2) == 4 and not (escX == 'x' or escX == 'X'):
|
uni = 0x10000 + (((uni - 0xd800) << 10) |
|
||||||
try:
|
(uni2 - 0xdc00))
|
||||||
uni2 = int(esc2, 16)
|
end = end2
|
||||||
except ValueError:
|
|
||||||
raise JSONDecodeError(msg, s, end)
|
|
||||||
if uni2 & 0xfc00 == 0xdc00:
|
|
||||||
uni = 0x10000 + (((uni - 0xd800) << 10) |
|
|
||||||
(uni2 - 0xdc00))
|
|
||||||
end += 6
|
|
||||||
char = unichr(uni)
|
char = unichr(uni)
|
||||||
# Append the unescaped character
|
# Append the unescaped character
|
||||||
_append(char)
|
_append(char)
|
||||||
|
@ -169,7 +179,7 @@ def JSONObject(state, encoding, strict, scan_once, object_hook,
|
||||||
return pairs, end + 1
|
return pairs, end + 1
|
||||||
elif nextchar != '"':
|
elif nextchar != '"':
|
||||||
raise JSONDecodeError(
|
raise JSONDecodeError(
|
||||||
"Expecting property name enclosed in double quotes",
|
"Expecting property name enclosed in double quotes or '}'",
|
||||||
s, end)
|
s, end)
|
||||||
end += 1
|
end += 1
|
||||||
while True:
|
while True:
|
||||||
|
@ -296,14 +306,15 @@ class JSONDecoder(object):
|
||||||
| null | None |
|
| 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.
|
their corresponding ``float`` values, which is outside the JSON spec.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, encoding=None, object_hook=None, parse_float=None,
|
def __init__(self, encoding=None, object_hook=None, parse_float=None,
|
||||||
parse_int=None, parse_constant=None, strict=True,
|
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
|
*encoding* determines the encoding used to interpret any
|
||||||
:class:`str` objects decoded by this instance (``'utf-8'`` by
|
:class:`str` objects decoded by this instance (``'utf-8'`` by
|
||||||
|
@ -336,10 +347,13 @@ class JSONDecoder(object):
|
||||||
``int(num_str)``. This can be used to use another datatype or parser
|
``int(num_str)``. This can be used to use another datatype or parser
|
||||||
for JSON integers (e.g. :class:`float`).
|
for JSON integers (e.g. :class:`float`).
|
||||||
|
|
||||||
*parse_constant*, if specified, will be called with one of the
|
*allow_nan*, if True (default false), will allow the parser to
|
||||||
following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This
|
accept the non-standard floats ``NaN``, ``Infinity``, and ``-Infinity``.
|
||||||
can be used to raise an exception if invalid JSON numbers are
|
|
||||||
encountered.
|
*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
|
*strict* controls the parser's behavior when it encounters an
|
||||||
invalid control character in a string. The default setting of
|
invalid control character in a string. The default setting of
|
||||||
|
@ -353,8 +367,8 @@ class JSONDecoder(object):
|
||||||
self.object_hook = object_hook
|
self.object_hook = object_hook
|
||||||
self.object_pairs_hook = object_pairs_hook
|
self.object_pairs_hook = object_pairs_hook
|
||||||
self.parse_float = parse_float or float
|
self.parse_float = parse_float or float
|
||||||
self.parse_int = parse_int or int
|
self.parse_int = parse_int or bounded_int
|
||||||
self.parse_constant = parse_constant or _CONSTANTS.__getitem__
|
self.parse_constant = parse_constant or (allow_nan and _CONSTANTS.__getitem__ or None)
|
||||||
self.strict = strict
|
self.strict = strict
|
||||||
self.parse_object = JSONObject
|
self.parse_object = JSONObject
|
||||||
self.parse_array = JSONArray
|
self.parse_array = JSONArray
|
||||||
|
|
|
@ -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 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():
|
def _import_speedups():
|
||||||
try:
|
try:
|
||||||
from . import _speedups
|
from . import _speedups
|
||||||
|
@ -140,7 +140,7 @@ class JSONEncoder(object):
|
||||||
key_separator = ': '
|
key_separator = ': '
|
||||||
|
|
||||||
def __init__(self, skipkeys=False, ensure_ascii=True,
|
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,
|
indent=None, separators=None, encoding='utf-8', default=None,
|
||||||
use_decimal=True, namedtuple_as_object=True,
|
use_decimal=True, namedtuple_as_object=True,
|
||||||
tuple_as_array=True, bigint_as_string=False,
|
tuple_as_array=True, bigint_as_string=False,
|
||||||
|
@ -161,10 +161,11 @@ class JSONEncoder(object):
|
||||||
prevent an infinite recursion (which would cause an OverflowError).
|
prevent an infinite recursion (which would cause an OverflowError).
|
||||||
Otherwise, no such check takes place.
|
Otherwise, no such check takes place.
|
||||||
|
|
||||||
If allow_nan is true, then NaN, Infinity, and -Infinity will be
|
If allow_nan is true (default: False), then out of range float
|
||||||
encoded as such. This behavior is not JSON specification compliant,
|
values (nan, inf, -inf) will be serialized to
|
||||||
but is consistent with most JavaScript based encoders and decoders.
|
their JavaScript equivalents (NaN, Infinity, -Infinity)
|
||||||
Otherwise, it will be a ValueError to encode such floats.
|
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
|
If sort_keys is true, then the output of dictionaries will be
|
||||||
sorted by key; this is useful for regression tests to ensure
|
sorted by key; this is useful for regression tests to ensure
|
||||||
|
@ -294,7 +295,7 @@ class JSONEncoder(object):
|
||||||
# This doesn't pass the iterator directly to ''.join() because the
|
# This doesn't pass the iterator directly to ''.join() because the
|
||||||
# exceptions aren't as detailed. The list call should be roughly
|
# exceptions aren't as detailed. The list call should be roughly
|
||||||
# equivalent to the PySequence_Fast that ''.join() would do.
|
# 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)):
|
if not isinstance(chunks, (list, tuple)):
|
||||||
chunks = list(chunks)
|
chunks = list(chunks)
|
||||||
if self.ensure_ascii:
|
if self.ensure_ascii:
|
||||||
|
@ -302,7 +303,7 @@ class JSONEncoder(object):
|
||||||
else:
|
else:
|
||||||
return u''.join(chunks)
|
return u''.join(chunks)
|
||||||
|
|
||||||
def iterencode(self, o, _one_shot=False):
|
def iterencode(self, o):
|
||||||
"""Encode the given object and yield each string
|
"""Encode the given object and yield each string
|
||||||
representation as available.
|
representation as available.
|
||||||
|
|
||||||
|
@ -356,8 +357,7 @@ class JSONEncoder(object):
|
||||||
key_memo = {}
|
key_memo = {}
|
||||||
int_as_string_bitcount = (
|
int_as_string_bitcount = (
|
||||||
53 if self.bigint_as_string else self.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
|
if (c_make_encoder is not None and self.indent is None):
|
||||||
and self.indent is None):
|
|
||||||
_iterencode = c_make_encoder(
|
_iterencode = c_make_encoder(
|
||||||
markers, self.default, _encoder, self.indent,
|
markers, self.default, _encoder, self.indent,
|
||||||
self.key_separator, self.item_separator, self.sort_keys,
|
self.key_separator, self.item_separator, self.sort_keys,
|
||||||
|
@ -370,7 +370,7 @@ class JSONEncoder(object):
|
||||||
_iterencode = _make_iterencode(
|
_iterencode = _make_iterencode(
|
||||||
markers, self.default, _encoder, self.indent, floatstr,
|
markers, self.default, _encoder, self.indent, floatstr,
|
||||||
self.key_separator, self.item_separator, self.sort_keys,
|
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,
|
self.namedtuple_as_object, self.tuple_as_array,
|
||||||
int_as_string_bitcount,
|
int_as_string_bitcount,
|
||||||
self.item_sort_key, self.encoding, self.for_json,
|
self.item_sort_key, self.encoding, self.for_json,
|
||||||
|
@ -398,14 +398,14 @@ class JSONEncoderForHTML(JSONEncoder):
|
||||||
def encode(self, o):
|
def encode(self, o):
|
||||||
# Override JSONEncoder.encode because it has hacks for
|
# Override JSONEncoder.encode because it has hacks for
|
||||||
# performance that make things more complicated.
|
# performance that make things more complicated.
|
||||||
chunks = self.iterencode(o, True)
|
chunks = self.iterencode(o)
|
||||||
if self.ensure_ascii:
|
if self.ensure_ascii:
|
||||||
return ''.join(chunks)
|
return ''.join(chunks)
|
||||||
else:
|
else:
|
||||||
return u''.join(chunks)
|
return u''.join(chunks)
|
||||||
|
|
||||||
def iterencode(self, o, _one_shot=False):
|
def iterencode(self, o):
|
||||||
chunks = super(JSONEncoderForHTML, self).iterencode(o, _one_shot)
|
chunks = super(JSONEncoderForHTML, self).iterencode(o)
|
||||||
for chunk in chunks:
|
for chunk in chunks:
|
||||||
chunk = chunk.replace('&', '\\u0026')
|
chunk = chunk.replace('&', '\\u0026')
|
||||||
chunk = chunk.replace('<', '\\u003c')
|
chunk = chunk.replace('<', '\\u003c')
|
||||||
|
@ -419,7 +419,7 @@ class JSONEncoderForHTML(JSONEncoder):
|
||||||
|
|
||||||
|
|
||||||
def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
|
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,
|
_use_decimal, _namedtuple_as_object, _tuple_as_array,
|
||||||
_int_as_string_bitcount, _item_sort_key,
|
_int_as_string_bitcount, _item_sort_key,
|
||||||
_encoding,_for_json,
|
_encoding,_for_json,
|
||||||
|
|
|
@ -60,11 +60,11 @@ def py_make_scanner(context):
|
||||||
else:
|
else:
|
||||||
res = parse_int(integer)
|
res = parse_int(integer)
|
||||||
return res, m.end()
|
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
|
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
|
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
|
return parse_constant('-Infinity'), idx + 9
|
||||||
else:
|
else:
|
||||||
raise JSONDecodeError(errmsg, string, idx)
|
raise JSONDecodeError(errmsg, string, idx)
|
||||||
|
|
|
@ -2,6 +2,7 @@ from __future__ import absolute_import
|
||||||
import decimal
|
import decimal
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
|
import sys
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
from simplejson.compat import StringIO, b, binary_type
|
from simplejson.compat import StringIO, b, binary_type
|
||||||
from simplejson import OrderedDict
|
from simplejson import OrderedDict
|
||||||
|
@ -117,3 +118,10 @@ class TestDecode(TestCase):
|
||||||
diff = id(x) - id(y)
|
diff = id(x) - id(y)
|
||||||
self.assertRaises(ValueError, j.scan_once, y, diff)
|
self.assertRaises(ValueError, j.scan_once, y, diff)
|
||||||
self.assertRaises(ValueError, j.raw_decode, y, i)
|
self.assertRaises(ValueError, j.raw_decode, y, i)
|
||||||
|
|
||||||
|
def test_bounded_int(self):
|
||||||
|
# SJ-PT-23-03, limit quadratic number parsing per Python 3.11
|
||||||
|
max_str_digits = getattr(sys, 'get_int_max_str_digits', lambda: 4300)()
|
||||||
|
s = '1' + '0' * (max_str_digits - 1)
|
||||||
|
self.assertEqual(json.loads(s), int(s))
|
||||||
|
self.assertRaises(ValueError, json.loads, s + '0')
|
||||||
|
|
|
@ -145,7 +145,7 @@ class TestFail(TestCase):
|
||||||
('["spam', 'Unterminated string starting at', 1),
|
('["spam', 'Unterminated string starting at', 1),
|
||||||
('["spam"', "Expecting ',' delimiter", 7),
|
('["spam"', "Expecting ',' delimiter", 7),
|
||||||
('["spam",', 'Expecting value', 8),
|
('["spam",', 'Expecting value', 8),
|
||||||
('{', 'Expecting property name enclosed in double quotes', 1),
|
('{', "Expecting property name enclosed in double quotes or '}'", 1),
|
||||||
('{"', 'Unterminated string starting at', 1),
|
('{"', 'Unterminated string starting at', 1),
|
||||||
('{"spam', 'Unterminated string starting at', 1),
|
('{"spam', 'Unterminated string starting at', 1),
|
||||||
('{"spam"', "Expecting ':' delimiter", 7),
|
('{"spam"', "Expecting ':' delimiter", 7),
|
||||||
|
@ -156,6 +156,8 @@ class TestFail(TestCase):
|
||||||
('"', 'Unterminated string starting at', 0),
|
('"', 'Unterminated string starting at', 0),
|
||||||
('"spam', 'Unterminated string starting at', 0),
|
('"spam', 'Unterminated string starting at', 0),
|
||||||
('[,', "Expecting value", 1),
|
('[,', "Expecting value", 1),
|
||||||
|
('--', 'Expecting value', 0),
|
||||||
|
('"\x18d', "Invalid control character %r", 1),
|
||||||
]
|
]
|
||||||
for data, msg, idx in test_cases:
|
for data, msg, idx in test_cases:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -7,9 +7,9 @@ from simplejson.decoder import NaN, PosInf, NegInf
|
||||||
class TestFloat(TestCase):
|
class TestFloat(TestCase):
|
||||||
def test_degenerates_allow(self):
|
def test_degenerates_allow(self):
|
||||||
for inf in (PosInf, NegInf):
|
for inf in (PosInf, NegInf):
|
||||||
self.assertEqual(json.loads(json.dumps(inf)), inf)
|
self.assertEqual(json.loads(json.dumps(inf, allow_nan=True), allow_nan=True), inf)
|
||||||
# Python 2.5 doesn't have math.isnan
|
# Python 2.5 doesn't have math.isnan
|
||||||
nan = json.loads(json.dumps(NaN))
|
nan = json.loads(json.dumps(NaN, allow_nan=True), allow_nan=True)
|
||||||
self.assertTrue((0 + nan) != nan)
|
self.assertTrue((0 + nan) != nan)
|
||||||
|
|
||||||
def test_degenerates_ignore(self):
|
def test_degenerates_ignore(self):
|
||||||
|
@ -19,6 +19,9 @@ class TestFloat(TestCase):
|
||||||
def test_degenerates_deny(self):
|
def test_degenerates_deny(self):
|
||||||
for f in (PosInf, NegInf, NaN):
|
for f in (PosInf, NegInf, NaN):
|
||||||
self.assertRaises(ValueError, json.dumps, f, allow_nan=False)
|
self.assertRaises(ValueError, json.dumps, f, allow_nan=False)
|
||||||
|
for s in ('Infinity', '-Infinity', 'NaN'):
|
||||||
|
self.assertRaises(ValueError, json.loads, s, allow_nan=False)
|
||||||
|
self.assertRaises(ValueError, json.loads, s)
|
||||||
|
|
||||||
def test_floats(self):
|
def test_floats(self):
|
||||||
for num in [1617161771.7650001, math.pi, math.pi**100,
|
for num in [1617161771.7650001, math.pi, math.pi**100,
|
||||||
|
|
|
@ -132,7 +132,9 @@ class TestScanString(TestCase):
|
||||||
self.assertRaises(ValueError,
|
self.assertRaises(ValueError,
|
||||||
scanstring, '\\ud834\\x0123"', 0, None, True)
|
scanstring, '\\ud834\\x0123"', 0, None, True)
|
||||||
|
|
||||||
self.assertRaises(json.JSONDecodeError, scanstring, "\\u-123", 0, None, True)
|
self.assertRaises(json.JSONDecodeError, scanstring, '\\u-123"', 0, None, True)
|
||||||
|
# SJ-PT-23-01: Invalid Handling of Broken Unicode Escape Sequences
|
||||||
|
self.assertRaises(json.JSONDecodeError, scanstring, '\\u EDD"', 0, None, True)
|
||||||
|
|
||||||
def test_issue3623(self):
|
def test_issue3623(self):
|
||||||
self.assertRaises(ValueError, json.decoder.scanstring, "xxx", 1,
|
self.assertRaises(ValueError, json.decoder.scanstring, "xxx", 1,
|
||||||
|
|
|
@ -39,7 +39,7 @@ pytz==2023.3
|
||||||
requests==2.28.2
|
requests==2.28.2
|
||||||
requests-oauthlib==1.3.1
|
requests-oauthlib==1.3.1
|
||||||
rumps==0.4.0; platform_system == "Darwin"
|
rumps==0.4.0; platform_system == "Darwin"
|
||||||
simplejson==3.18.3
|
simplejson==3.19.1
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
soupsieve==2.4
|
soupsieve==2.4
|
||||||
tempora==5.2.1
|
tempora==5.2.1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue