mirror of https://github.com/celery/kombu.git
json.py cleaning from outdated libs (#1533)
* json.py cleaning from outdated libs * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * 1. Removed cjson and simplejson from documentation, as those libraries aren't supported anymore 2. Removed _json_extra_kwargs from json.py Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
7516daf7a7
commit
260823304f
|
@ -44,8 +44,6 @@
|
|||
|
||||
.. autodata:: registry
|
||||
|
||||
.. _`cjson`: https://pypi.org/project/python-cjson/
|
||||
.. _`simplejson`: https://github.com/simplejson/simplejson
|
||||
.. _`Python 2.7+`: https://docs.python.org/library/json.html
|
||||
.. _`PyYAML`: https://pyyaml.org/
|
||||
.. _`msgpack`: https://msgpack.org/
|
||||
|
|
|
@ -32,10 +32,9 @@ The accept argument can also include MIME-types.
|
|||
|
||||
Each option has its advantages and disadvantages.
|
||||
|
||||
`json` -- JSON is supported in many programming languages, is now
|
||||
a standard part of Python (since 2.6), and is fairly fast to
|
||||
decode using the modern Python libraries such as `cjson` or
|
||||
`simplejson`.
|
||||
`json` -- JSON is supported in many programming languages, is
|
||||
a standard part of Python, and is fairly fast to
|
||||
decode.
|
||||
|
||||
The primary disadvantage to `JSON` is that it limits you to
|
||||
the following data types: strings, Unicode, floats, boolean,
|
||||
|
|
|
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||
import base64
|
||||
import datetime
|
||||
import decimal
|
||||
import json as stdjson
|
||||
import json
|
||||
import uuid
|
||||
|
||||
try:
|
||||
|
@ -14,19 +14,9 @@ except ImportError: # pragma: no cover
|
|||
class DjangoPromise:
|
||||
"""Dummy object."""
|
||||
|
||||
try:
|
||||
import json
|
||||
_json_extra_kwargs = {}
|
||||
|
||||
class _DecodeError(Exception):
|
||||
pass
|
||||
except ImportError: # pragma: no cover
|
||||
import simplejson as json
|
||||
from simplejson.decoder import JSONDecodeError as _DecodeError
|
||||
_json_extra_kwargs = {
|
||||
'use_decimal': False,
|
||||
'namedtuple_as_object': False,
|
||||
}
|
||||
class _DecodeError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
_encoder_cls = type(json._default_encoder)
|
||||
|
@ -74,8 +64,7 @@ _default_encoder = JSONEncoder
|
|||
|
||||
def dumps(s, _dumps=json.dumps, cls=None, default_kwargs=None, **kwargs):
|
||||
"""Serialize object to json string."""
|
||||
if not default_kwargs:
|
||||
default_kwargs = _json_extra_kwargs
|
||||
default_kwargs = default_kwargs or {}
|
||||
return _dumps(s, cls=cls or _default_encoder,
|
||||
**dict(default_kwargs, **kwargs))
|
||||
|
||||
|
@ -108,4 +97,4 @@ def loads(s, _loads=json.loads, decode_bytes=True, object_hook=object_hook):
|
|||
return _loads(s, object_hook=object_hook)
|
||||
except _DecodeError:
|
||||
# catch "Unpaired high surrogate" error
|
||||
return stdjson.loads(s)
|
||||
return json.loads(s)
|
||||
|
|
Loading…
Reference in New Issue