mirror of https://github.com/pallets/flask.git
remove deprecated send_file argument names
This commit is contained in:
parent
9e686d93b6
commit
c2810ffdd2
|
@ -7,7 +7,13 @@ Unreleased
|
||||||
|
|
||||||
- Remove previously deprecated code. :pr:`4337`
|
- Remove previously deprecated code. :pr:`4337`
|
||||||
|
|
||||||
- The ``RequestContext.g`` proxy to ``AppContext.g`` is removed.
|
- Old names for some ``send_file`` parameters have been removed.
|
||||||
|
``download_name`` replaces ``attachment_filename``, ``max_age``
|
||||||
|
replaces ``cache_timeout``, and ``etag`` replaces ``add_etags``.
|
||||||
|
Additionally, ``path`` replaces ``filename`` in
|
||||||
|
``send_from_directory``.
|
||||||
|
- The ``RequestContext.g`` property returning ``AppContext.g`` is
|
||||||
|
removed.
|
||||||
|
|
||||||
- Add new customization points to the ``Flask`` app object for many
|
- Add new customization points to the ``Flask`` app object for many
|
||||||
previously global behaviors.
|
previously global behaviors.
|
||||||
|
|
|
@ -3,7 +3,6 @@ import pkgutil
|
||||||
import socket
|
import socket
|
||||||
import sys
|
import sys
|
||||||
import typing as t
|
import typing as t
|
||||||
import warnings
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from functools import update_wrapper
|
from functools import update_wrapper
|
||||||
|
@ -390,53 +389,12 @@ def get_flashed_messages(
|
||||||
return flashes
|
return flashes
|
||||||
|
|
||||||
|
|
||||||
def _prepare_send_file_kwargs(
|
def _prepare_send_file_kwargs(**kwargs: t.Any) -> t.Dict[str, t.Any]:
|
||||||
download_name: t.Optional[str] = None,
|
if kwargs.get("max_age") is None:
|
||||||
attachment_filename: t.Optional[str] = None,
|
kwargs["max_age"] = current_app.get_send_file_max_age
|
||||||
etag: t.Optional[t.Union[bool, str]] = None,
|
|
||||||
add_etags: t.Optional[t.Union[bool]] = None,
|
|
||||||
max_age: t.Optional[
|
|
||||||
t.Union[int, t.Callable[[t.Optional[str]], t.Optional[int]]]
|
|
||||||
] = None,
|
|
||||||
cache_timeout: t.Optional[int] = None,
|
|
||||||
**kwargs: t.Any,
|
|
||||||
) -> t.Dict[str, t.Any]:
|
|
||||||
if attachment_filename is not None:
|
|
||||||
warnings.warn(
|
|
||||||
"The 'attachment_filename' parameter has been renamed to"
|
|
||||||
" 'download_name'. The old name will be removed in Flask"
|
|
||||||
" 2.2.",
|
|
||||||
DeprecationWarning,
|
|
||||||
stacklevel=3,
|
|
||||||
)
|
|
||||||
download_name = attachment_filename
|
|
||||||
|
|
||||||
if cache_timeout is not None:
|
|
||||||
warnings.warn(
|
|
||||||
"The 'cache_timeout' parameter has been renamed to"
|
|
||||||
" 'max_age'. The old name will be removed in Flask 2.2.",
|
|
||||||
DeprecationWarning,
|
|
||||||
stacklevel=3,
|
|
||||||
)
|
|
||||||
max_age = cache_timeout
|
|
||||||
|
|
||||||
if add_etags is not None:
|
|
||||||
warnings.warn(
|
|
||||||
"The 'add_etags' parameter has been renamed to 'etag'. The"
|
|
||||||
" old name will be removed in Flask 2.2.",
|
|
||||||
DeprecationWarning,
|
|
||||||
stacklevel=3,
|
|
||||||
)
|
|
||||||
etag = add_etags
|
|
||||||
|
|
||||||
if max_age is None:
|
|
||||||
max_age = current_app.get_send_file_max_age
|
|
||||||
|
|
||||||
kwargs.update(
|
kwargs.update(
|
||||||
environ=request.environ,
|
environ=request.environ,
|
||||||
download_name=download_name,
|
|
||||||
etag=etag,
|
|
||||||
max_age=max_age,
|
|
||||||
use_x_sendfile=current_app.use_x_sendfile,
|
use_x_sendfile=current_app.use_x_sendfile,
|
||||||
response_class=current_app.response_class,
|
response_class=current_app.response_class,
|
||||||
_root_path=current_app.root_path, # type: ignore
|
_root_path=current_app.root_path, # type: ignore
|
||||||
|
@ -449,16 +407,13 @@ def send_file(
|
||||||
mimetype: t.Optional[str] = None,
|
mimetype: t.Optional[str] = None,
|
||||||
as_attachment: bool = False,
|
as_attachment: bool = False,
|
||||||
download_name: t.Optional[str] = None,
|
download_name: t.Optional[str] = None,
|
||||||
attachment_filename: t.Optional[str] = None,
|
|
||||||
conditional: bool = True,
|
conditional: bool = True,
|
||||||
etag: t.Union[bool, str] = True,
|
etag: t.Union[bool, str] = True,
|
||||||
add_etags: t.Optional[bool] = None,
|
|
||||||
last_modified: t.Optional[t.Union[datetime, int, float]] = None,
|
last_modified: t.Optional[t.Union[datetime, int, float]] = None,
|
||||||
max_age: t.Optional[
|
max_age: t.Optional[
|
||||||
t.Union[int, t.Callable[[t.Optional[str]], t.Optional[int]]]
|
t.Union[int, t.Callable[[t.Optional[str]], t.Optional[int]]]
|
||||||
] = None,
|
] = None,
|
||||||
cache_timeout: t.Optional[int] = None,
|
) -> "Response":
|
||||||
):
|
|
||||||
"""Send the contents of a file to the client.
|
"""Send the contents of a file to the client.
|
||||||
|
|
||||||
The first argument can be a file path or a file-like object. Paths
|
The first argument can be a file path or a file-like object. Paths
|
||||||
|
@ -560,20 +515,17 @@ def send_file(
|
||||||
|
|
||||||
.. versionadded:: 0.2
|
.. versionadded:: 0.2
|
||||||
"""
|
"""
|
||||||
return werkzeug.utils.send_file(
|
return werkzeug.utils.send_file( # type: ignore[return-value]
|
||||||
**_prepare_send_file_kwargs(
|
**_prepare_send_file_kwargs(
|
||||||
path_or_file=path_or_file,
|
path_or_file=path_or_file,
|
||||||
environ=request.environ,
|
environ=request.environ,
|
||||||
mimetype=mimetype,
|
mimetype=mimetype,
|
||||||
as_attachment=as_attachment,
|
as_attachment=as_attachment,
|
||||||
download_name=download_name,
|
download_name=download_name,
|
||||||
attachment_filename=attachment_filename,
|
|
||||||
conditional=conditional,
|
conditional=conditional,
|
||||||
etag=etag,
|
etag=etag,
|
||||||
add_etags=add_etags,
|
|
||||||
last_modified=last_modified,
|
last_modified=last_modified,
|
||||||
max_age=max_age,
|
max_age=max_age,
|
||||||
cache_timeout=cache_timeout,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -581,7 +533,6 @@ def send_file(
|
||||||
def send_from_directory(
|
def send_from_directory(
|
||||||
directory: t.Union[os.PathLike, str],
|
directory: t.Union[os.PathLike, str],
|
||||||
path: t.Union[os.PathLike, str],
|
path: t.Union[os.PathLike, str],
|
||||||
filename: t.Optional[str] = None,
|
|
||||||
**kwargs: t.Any,
|
**kwargs: t.Any,
|
||||||
) -> "Response":
|
) -> "Response":
|
||||||
"""Send a file from within a directory using :func:`send_file`.
|
"""Send a file from within a directory using :func:`send_file`.
|
||||||
|
@ -617,16 +568,7 @@ def send_from_directory(
|
||||||
|
|
||||||
.. versionadded:: 0.5
|
.. versionadded:: 0.5
|
||||||
"""
|
"""
|
||||||
if filename is not None:
|
return werkzeug.utils.send_from_directory( # type: ignore[return-value]
|
||||||
warnings.warn(
|
|
||||||
"The 'filename' parameter has been renamed to 'path'. The"
|
|
||||||
" old name will be removed in Flask 2.2.",
|
|
||||||
DeprecationWarning,
|
|
||||||
stacklevel=2,
|
|
||||||
)
|
|
||||||
path = filename
|
|
||||||
|
|
||||||
return werkzeug.utils.send_from_directory( # type: ignore
|
|
||||||
directory, path, **_prepare_send_file_kwargs(**kwargs)
|
directory, path, **_prepare_send_file_kwargs(**kwargs)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue