summaryrefslogtreecommitdiffstats
path: root/contrib/python/Flask/py3/flask/json
diff options
context:
space:
mode:
authorrobot-piglet <[email protected]>2024-05-03 00:01:03 +0300
committerrobot-piglet <[email protected]>2024-05-03 00:06:37 +0300
commit38934cfb0b963a0157cf16c13499977ac87f35b9 (patch)
tree124d141726b8a860761a75fe2b597eecce078ee7 /contrib/python/Flask/py3/flask/json
parent616419d508d3ee4a3b07a82e5cae5ab4544bd1e2 (diff)
Intermediate changes
Diffstat (limited to 'contrib/python/Flask/py3/flask/json')
-rw-r--r--contrib/python/Flask/py3/flask/json/__init__.py75
1 files changed, 8 insertions, 67 deletions
diff --git a/contrib/python/Flask/py3/flask/json/__init__.py b/contrib/python/Flask/py3/flask/json/__init__.py
index ccb9efb174c..adefe02dcd2 100644
--- a/contrib/python/Flask/py3/flask/json/__init__.py
+++ b/contrib/python/Flask/py3/flask/json/__init__.py
@@ -1,9 +1,8 @@
+import dataclasses
import decimal
-import io
import json as _json
import typing as t
import uuid
-import warnings
from datetime import date
from jinja2.utils import htmlsafe_json_dumps as _jinja_htmlsafe_dumps
@@ -16,12 +15,6 @@ if t.TYPE_CHECKING:
from ..app import Flask
from ..wrappers import Response
-try:
- import dataclasses
-except ImportError:
- # Python < 3.7
- dataclasses = None # type: ignore
-
class JSONEncoder(_json.JSONEncoder):
"""The default JSON encoder. Handles extra types compared to the
@@ -30,6 +23,7 @@ class JSONEncoder(_json.JSONEncoder):
- :class:`datetime.datetime` and :class:`datetime.date` are
serialized to :rfc:`822` strings. This is the same as the HTTP
date format.
+ - :class:`decimal.Decimal` is serialized to a string.
- :class:`uuid.UUID` is serialized to a string.
- :class:`dataclasses.dataclass` is passed to
:func:`dataclasses.asdict`.
@@ -135,20 +129,7 @@ def dumps(obj: t.Any, app: t.Optional["Flask"] = None, **kwargs: t.Any) -> str:
context for configuration.
"""
_dump_arg_defaults(kwargs, app=app)
- encoding = kwargs.pop("encoding", None)
- rv = _json.dumps(obj, **kwargs)
-
- if encoding is not None:
- warnings.warn(
- "'encoding' is deprecated and will be removed in Flask 2.1.",
- DeprecationWarning,
- stacklevel=2,
- )
-
- if isinstance(rv, str):
- return rv.encode(encoding) # type: ignore
-
- return rv
+ return _json.dumps(obj, **kwargs)
def dump(
@@ -170,27 +151,14 @@ def dump(
deprecated and will be removed in Flask 2.1.
"""
_dump_arg_defaults(kwargs, app=app)
- encoding = kwargs.pop("encoding", None)
- show_warning = encoding is not None
-
- try:
- fp.write("")
- except TypeError:
- show_warning = True
- fp = io.TextIOWrapper(fp, encoding or "utf-8") # type: ignore
-
- if show_warning:
- warnings.warn(
- "Writing to a binary file, and the 'encoding' argument, is"
- " deprecated and will be removed in Flask 2.1.",
- DeprecationWarning,
- stacklevel=2,
- )
-
_json.dump(obj, fp, **kwargs)
-def loads(s: str, app: t.Optional["Flask"] = None, **kwargs: t.Any) -> t.Any:
+def loads(
+ s: t.Union[str, bytes],
+ app: t.Optional["Flask"] = None,
+ **kwargs: t.Any,
+) -> t.Any:
"""Deserialize an object from a string of JSON.
Takes the same arguments as the built-in :func:`json.loads`, with
@@ -210,19 +178,6 @@ def loads(s: str, app: t.Optional["Flask"] = None, **kwargs: t.Any) -> t.Any:
context for configuration.
"""
_load_arg_defaults(kwargs, app=app)
- encoding = kwargs.pop("encoding", None)
-
- if encoding is not None:
- warnings.warn(
- "'encoding' is deprecated and will be removed in Flask 2.1."
- " The data must be a string or UTF-8 bytes.",
- DeprecationWarning,
- stacklevel=2,
- )
-
- if isinstance(s, bytes):
- s = s.decode(encoding)
-
return _json.loads(s, **kwargs)
@@ -242,20 +197,6 @@ def load(fp: t.IO[str], app: t.Optional["Flask"] = None, **kwargs: t.Any) -> t.A
file must be text mode, or binary mode with UTF-8 bytes.
"""
_load_arg_defaults(kwargs, app=app)
- encoding = kwargs.pop("encoding", None)
-
- if encoding is not None:
- warnings.warn(
- "'encoding' is deprecated and will be removed in Flask 2.1."
- " The file must be text mode, or binary mode with UTF-8"
- " bytes.",
- DeprecationWarning,
- stacklevel=2,
- )
-
- if isinstance(fp.read(0), bytes):
- fp = io.TextIOWrapper(fp, encoding) # type: ignore
-
return _json.load(fp, **kwargs)