mirror of https://github.com/pallets/flask.git
remove deprecated json encoding parameter
This commit is contained in:
parent
2bd7aed1a4
commit
218534a9f2
|
@ -12,6 +12,7 @@ Unreleased
|
||||||
- The CLI does not pass ``script_info`` to app factory functions.
|
- The CLI does not pass ``script_info`` to app factory functions.
|
||||||
- ``config.from_json`` is replaced by
|
- ``config.from_json`` is replaced by
|
||||||
``config.from_file(name, load=json.load)``.
|
``config.from_file(name, load=json.load)``.
|
||||||
|
- ``json`` functions no longer take an ``encoding`` parameter.
|
||||||
|
|
||||||
|
|
||||||
Version 2.0.2
|
Version 2.0.2
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
import dataclasses
|
import dataclasses
|
||||||
import decimal
|
import decimal
|
||||||
import io
|
|
||||||
import json as _json
|
import json as _json
|
||||||
import typing as t
|
import typing as t
|
||||||
import uuid
|
import uuid
|
||||||
import warnings
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from jinja2.utils import htmlsafe_json_dumps as _jinja_htmlsafe_dumps
|
from jinja2.utils import htmlsafe_json_dumps as _jinja_htmlsafe_dumps
|
||||||
|
@ -124,20 +122,7 @@ def dumps(obj: t.Any, app: t.Optional["Flask"] = None, **kwargs: t.Any) -> str:
|
||||||
context for configuration.
|
context for configuration.
|
||||||
"""
|
"""
|
||||||
_dump_arg_defaults(kwargs, app=app)
|
_dump_arg_defaults(kwargs, app=app)
|
||||||
encoding = kwargs.pop("encoding", None)
|
return _json.dumps(obj, **kwargs)
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
def dump(
|
def dump(
|
||||||
|
@ -159,23 +144,6 @@ def dump(
|
||||||
deprecated and will be removed in Flask 2.1.
|
deprecated and will be removed in Flask 2.1.
|
||||||
"""
|
"""
|
||||||
_dump_arg_defaults(kwargs, app=app)
|
_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)
|
_json.dump(obj, fp, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -199,19 +167,6 @@ def loads(s: str, app: t.Optional["Flask"] = None, **kwargs: t.Any) -> t.Any:
|
||||||
context for configuration.
|
context for configuration.
|
||||||
"""
|
"""
|
||||||
_load_arg_defaults(kwargs, app=app)
|
_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)
|
return _json.loads(s, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -231,20 +186,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.
|
file must be text mode, or binary mode with UTF-8 bytes.
|
||||||
"""
|
"""
|
||||||
_load_arg_defaults(kwargs, app=app)
|
_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)
|
return _json.load(fp, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue