Re-add filename param for send_from_directory

Add a deprecation warning for the old name
This commit is contained in:
Grey Li 2021-05-12 19:04:20 +08:00 committed by David Lord
parent 80d9519a9c
commit fc82dd50e3
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
2 changed files with 19 additions and 1 deletions

View file

@ -5,6 +5,10 @@ Version 2.0.1
Unreleased
- Re-add the ``filename`` parameter in ``send_from_directory``. The
``filename`` parameter has been renamed to ``path``, the old name
is deprecated. :pr:`4019`
Version 2.0.0
-------------

View file

@ -642,7 +642,9 @@ def safe_join(directory: str, *pathnames: str) -> str:
return path
def send_from_directory(directory: str, path: str, **kwargs: t.Any) -> "Response":
def send_from_directory(
directory: str, path: str, filename: t.Optional[str] = None, **kwargs: t.Any
) -> "Response":
"""Send a file from within a directory using :func:`send_file`.
.. code-block:: python
@ -666,12 +668,24 @@ def send_from_directory(directory: str, path: str, **kwargs: t.Any) -> "Response
``directory``.
:param kwargs: Arguments to pass to :func:`send_file`.
.. versionchanged:: 2.0
``path`` replaces the ``filename`` parameter.
.. versionadded:: 2.0
Moved the implementation to Werkzeug. This is now a wrapper to
pass some Flask-specific arguments.
.. versionadded:: 0.5
"""
if filename is not None:
warnings.warn(
"The 'filename' parameter has been renamed to 'path'. The"
" old name will be removed in Flask 2.1.",
DeprecationWarning,
stacklevel=2,
)
path = filename
return werkzeug.utils.send_from_directory( # type: ignore
directory, path, **_prepare_send_file_kwargs(**kwargs)
)