mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-22 22:23:36 -07:00
Update simplejson==3.18.0
This commit is contained in:
parent
9e169cadb3
commit
520db3dcf7
5 changed files with 60 additions and 22 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.17.6'
|
__version__ = '3.18.0'
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'dump', 'dumps', 'load', 'loads',
|
'dump', 'dumps', 'load', 'loads',
|
||||||
'JSONDecoder', 'JSONDecodeError', 'JSONEncoder',
|
'JSONDecoder', 'JSONDecodeError', 'JSONEncoder',
|
||||||
|
@ -300,7 +300,7 @@ def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
|
||||||
iterable_as_array=False, **kw):
|
iterable_as_array=False, **kw):
|
||||||
"""Serialize ``obj`` to a JSON formatted ``str``.
|
"""Serialize ``obj`` to a JSON formatted ``str``.
|
||||||
|
|
||||||
If ``skipkeys`` is false then ``dict`` keys that are not basic types
|
If ``skipkeys`` is true then ``dict`` keys that are not basic types
|
||||||
(``str``, ``int``, ``long``, ``float``, ``bool``, ``None``)
|
(``str``, ``int``, ``long``, ``float``, ``bool``, ``None``)
|
||||||
will be skipped instead of raising a ``TypeError``.
|
will be skipped instead of raising a ``TypeError``.
|
||||||
|
|
||||||
|
|
|
@ -109,6 +109,8 @@ def py_scanstring(s, end, encoding=None, strict=True,
|
||||||
uni = int(esc, 16)
|
uni = int(esc, 16)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise JSONDecodeError(msg, s, end - 1)
|
raise JSONDecodeError(msg, s, end - 1)
|
||||||
|
if uni < 0 or uni > _maxunicode:
|
||||||
|
raise JSONDecodeError(msg, s, end - 1)
|
||||||
end += 5
|
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
|
||||||
|
|
|
@ -450,6 +450,15 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
|
||||||
not isinstance(_int_as_string_bitcount, integer_types))):
|
not isinstance(_int_as_string_bitcount, integer_types))):
|
||||||
raise TypeError("int_as_string_bitcount must be a positive integer")
|
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):
|
def _encode_int(value):
|
||||||
skip_quoting = (
|
skip_quoting = (
|
||||||
_int_as_string_bitcount is None
|
_int_as_string_bitcount is None
|
||||||
|
@ -512,15 +521,15 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
|
||||||
yield buf + str(value)
|
yield buf + str(value)
|
||||||
else:
|
else:
|
||||||
yield buf
|
yield buf
|
||||||
for_json = _for_json and getattr(value, 'for_json', None)
|
for_json = _for_json and call_method(value, 'for_json')
|
||||||
if for_json and callable(for_json):
|
if for_json:
|
||||||
chunks = _iterencode(for_json(), _current_indent_level)
|
chunks = _iterencode(for_json[0], _current_indent_level)
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
chunks = _iterencode_list(value, _current_indent_level)
|
chunks = _iterencode_list(value, _current_indent_level)
|
||||||
else:
|
else:
|
||||||
_asdict = _namedtuple_as_object and getattr(value, '_asdict', None)
|
_asdict = _namedtuple_as_object and call_method(value, '_asdict')
|
||||||
if _asdict and callable(_asdict):
|
if _asdict:
|
||||||
dct = _asdict()
|
dct = _asdict[0]
|
||||||
if not isinstance(dct, dict):
|
if not isinstance(dct, dict):
|
||||||
raise TypeError("_asdict() must return a dict, not %s" % (type(dct).__name__,))
|
raise TypeError("_asdict() must return a dict, not %s" % (type(dct).__name__,))
|
||||||
chunks = _iterencode_dict(dct,
|
chunks = _iterencode_dict(dct,
|
||||||
|
@ -636,15 +645,15 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
|
||||||
elif _use_decimal and isinstance(value, Decimal):
|
elif _use_decimal and isinstance(value, Decimal):
|
||||||
yield str(value)
|
yield str(value)
|
||||||
else:
|
else:
|
||||||
for_json = _for_json and getattr(value, 'for_json', None)
|
for_json = _for_json and call_method(value, 'for_json')
|
||||||
if for_json and callable(for_json):
|
if for_json:
|
||||||
chunks = _iterencode(for_json(), _current_indent_level)
|
chunks = _iterencode(for_json[0], _current_indent_level)
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
chunks = _iterencode_list(value, _current_indent_level)
|
chunks = _iterencode_list(value, _current_indent_level)
|
||||||
else:
|
else:
|
||||||
_asdict = _namedtuple_as_object and getattr(value, '_asdict', None)
|
_asdict = _namedtuple_as_object and call_method(value, '_asdict')
|
||||||
if _asdict and callable(_asdict):
|
if _asdict:
|
||||||
dct = _asdict()
|
dct = _asdict[0]
|
||||||
if not isinstance(dct, dict):
|
if not isinstance(dct, dict):
|
||||||
raise TypeError("_asdict() must return a dict, not %s" % (type(dct).__name__,))
|
raise TypeError("_asdict() must return a dict, not %s" % (type(dct).__name__,))
|
||||||
chunks = _iterencode_dict(dct,
|
chunks = _iterencode_dict(dct,
|
||||||
|
@ -682,17 +691,17 @@ def _make_iterencode(markers, _default, _encoder, _indent, _floatstr,
|
||||||
elif isinstance(o, float):
|
elif isinstance(o, float):
|
||||||
yield _floatstr(o)
|
yield _floatstr(o)
|
||||||
else:
|
else:
|
||||||
for_json = _for_json and getattr(o, 'for_json', None)
|
for_json = _for_json and call_method(o, 'for_json')
|
||||||
if for_json and callable(for_json):
|
if for_json:
|
||||||
for chunk in _iterencode(for_json(), _current_indent_level):
|
for chunk in _iterencode(for_json[0], _current_indent_level):
|
||||||
yield chunk
|
yield chunk
|
||||||
elif isinstance(o, list):
|
elif isinstance(o, list):
|
||||||
for chunk in _iterencode_list(o, _current_indent_level):
|
for chunk in _iterencode_list(o, _current_indent_level):
|
||||||
yield chunk
|
yield chunk
|
||||||
else:
|
else:
|
||||||
_asdict = _namedtuple_as_object and getattr(o, '_asdict', None)
|
_asdict = _namedtuple_as_object and call_method(o, '_asdict')
|
||||||
if _asdict and callable(_asdict):
|
if _asdict:
|
||||||
dct = _asdict()
|
dct = _asdict[0]
|
||||||
if not isinstance(dct, dict):
|
if not isinstance(dct, dict):
|
||||||
raise TypeError("_asdict() must return a dict, not %s" % (type(dct).__name__,))
|
raise TypeError("_asdict() must return a dict, not %s" % (type(dct).__name__,))
|
||||||
for chunk in _iterencode_dict(dct, _current_indent_level):
|
for chunk in _iterencode_dict(dct, _current_indent_level):
|
||||||
|
|
|
@ -110,22 +110,47 @@ class TestNamedTuple(unittest.TestCase):
|
||||||
|
|
||||||
def test_asdict_not_callable_dump(self):
|
def test_asdict_not_callable_dump(self):
|
||||||
for f in CONSTRUCTORS:
|
for f in CONSTRUCTORS:
|
||||||
self.assertRaises(TypeError,
|
self.assertRaises(
|
||||||
json.dump, f(DeadDuck()), StringIO(), namedtuple_as_object=True)
|
TypeError,
|
||||||
|
json.dump,
|
||||||
|
f(DeadDuck()),
|
||||||
|
StringIO(),
|
||||||
|
namedtuple_as_object=True
|
||||||
|
)
|
||||||
sio = StringIO()
|
sio = StringIO()
|
||||||
json.dump(f(DeadDict()), sio, namedtuple_as_object=True)
|
json.dump(f(DeadDict()), sio, namedtuple_as_object=True)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
json.dumps(f({})),
|
json.dumps(f({})),
|
||||||
sio.getvalue())
|
sio.getvalue())
|
||||||
|
self.assertRaises(
|
||||||
|
TypeError,
|
||||||
|
json.dump,
|
||||||
|
f(Value),
|
||||||
|
StringIO(),
|
||||||
|
namedtuple_as_object=True
|
||||||
|
)
|
||||||
|
|
||||||
def test_asdict_not_callable_dumps(self):
|
def test_asdict_not_callable_dumps(self):
|
||||||
for f in CONSTRUCTORS:
|
for f in CONSTRUCTORS:
|
||||||
self.assertRaises(TypeError,
|
self.assertRaises(TypeError,
|
||||||
json.dumps, f(DeadDuck()), namedtuple_as_object=True)
|
json.dumps, f(DeadDuck()), namedtuple_as_object=True)
|
||||||
|
self.assertRaises(
|
||||||
|
TypeError,
|
||||||
|
json.dumps,
|
||||||
|
f(Value),
|
||||||
|
namedtuple_as_object=True
|
||||||
|
)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
json.dumps(f({})),
|
json.dumps(f({})),
|
||||||
json.dumps(f(DeadDict()), namedtuple_as_object=True))
|
json.dumps(f(DeadDict()), namedtuple_as_object=True))
|
||||||
|
|
||||||
|
def test_asdict_unbound_method_dumps(self):
|
||||||
|
for f in CONSTRUCTORS:
|
||||||
|
self.assertEqual(
|
||||||
|
json.dumps(f(Value), default=lambda v: v.__name__),
|
||||||
|
json.dumps(f(Value.__name__))
|
||||||
|
)
|
||||||
|
|
||||||
def test_asdict_does_not_return_dict(self):
|
def test_asdict_does_not_return_dict(self):
|
||||||
if not mock:
|
if not mock:
|
||||||
if hasattr(unittest, "SkipTest"):
|
if hasattr(unittest, "SkipTest"):
|
||||||
|
|
|
@ -132,6 +132,8 @@ 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)
|
||||||
|
|
||||||
def test_issue3623(self):
|
def test_issue3623(self):
|
||||||
self.assertRaises(ValueError, json.decoder.scanstring, "xxx", 1,
|
self.assertRaises(ValueError, json.decoder.scanstring, "xxx", 1,
|
||||||
"xxx")
|
"xxx")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue