From 260823304f487e982ce6ecc660ad12cc7f55c987 Mon Sep 17 00:00:00 2001 From: dobosevych Date: Sat, 16 Apr 2022 13:57:37 +0300 Subject: [PATCH] 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> --- docs/reference/kombu.serialization.rst | 2 -- docs/userguide/serialization.rst | 7 +++---- kombu/utils/json.py | 21 +++++---------------- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/docs/reference/kombu.serialization.rst b/docs/reference/kombu.serialization.rst index 04d7b84a..07ca9bfb 100644 --- a/docs/reference/kombu.serialization.rst +++ b/docs/reference/kombu.serialization.rst @@ -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/ diff --git a/docs/userguide/serialization.rst b/docs/userguide/serialization.rst index e9cc94d3..f5cb8125 100644 --- a/docs/userguide/serialization.rst +++ b/docs/userguide/serialization.rst @@ -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, diff --git a/kombu/utils/json.py b/kombu/utils/json.py index 2fb8d03d..f6429c3f 100644 --- a/kombu/utils/json.py +++ b/kombu/utils/json.py @@ -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)