remove deprecated send_file argument names
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 9e686d9 · Browse files · 2 files·+13 added−65 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+13 added−65 removed
- other:+13 added−65 removed
Provenance
- Commit
c2810ff- Tree
9a5579d- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
9e686d9
2 files changed+13 added−65 removed
modified:src/flask/helpers.py+6 added-64 removed
1 unmodified line2 import pkgutil3 import socket4 import sys5 import typing as t6-import warnings6 from datetime import datetime7 from functools import lru_cache8 from functools import update_wrapper9 from threading import RLock378 unmodified lines388 return [x[1] for x in flashes]389 return flashes390 391 393-def _prepare_send_file_kwargs(394- download_name: t.Optional[str] = None,395- attachment_filename: t.Optional[str] = None,396- etag: t.Optional[t.Union[bool, str]] = None,397- add_etags: t.Optional[t.Union[bool]] = None,398- max_age: t.Optional[399- t.Union[int, t.Callable[[t.Optional[str]], t.Optional[int]]]400- ] = None,401- cache_timeout: t.Optional[int] = None,402- **kwargs: t.Any,403-) -> t.Dict[str, t.Any]:404- if attachment_filename is not None:405- warnings.warn(406- "The 'attachment_filename' parameter has been renamed to"407- " 'download_name'. The old name will be removed in Flask"408- " 2.2.",409- DeprecationWarning,410- stacklevel=3,411- )412- download_name = attachment_filename392+def _prepare_send_file_kwargs(**kwargs: t.Any) -> t.Dict[str, t.Any]:393+ if kwargs.get("max_age") is None:394+ kwargs["max_age"] = current_app.get_send_file_max_age395 414- if cache_timeout is not None:415- warnings.warn(416- "The 'cache_timeout' parameter has been renamed to"417- " 'max_age'. The old name will be removed in Flask 2.2.",418- DeprecationWarning,419- stacklevel=3,420- )421- max_age = cache_timeout422-423- if add_etags is not None:424- warnings.warn(425- "The 'add_etags' parameter has been renamed to 'etag'. The"426- " old name will be removed in Flask 2.2.",427- DeprecationWarning,428- stacklevel=3,429- )430- etag = add_etags431-432- if max_age is None:433- max_age = current_app.get_send_file_max_age434-396 kwargs.update(397 environ=request.environ,437- download_name=download_name,438- etag=etag,439- max_age=max_age,398 use_x_sendfile=current_app.use_x_sendfile,399 response_class=current_app.response_class,400 _root_path=current_app.root_path, # type: ignore401 )4 unmodified lines406 path_or_file: t.Union[os.PathLike, str, t.BinaryIO],407 mimetype: t.Optional[str] = None,408 as_attachment: bool = False,409 download_name: t.Optional[str] = None,452- attachment_filename: t.Optional[str] = None,410 conditional: bool = True,411 etag: t.Union[bool, str] = True,455- add_etags: t.Optional[bool] = None,412 last_modified: t.Optional[t.Union[datetime, int, float]] = None,413 max_age: t.Optional[414 t.Union[int, t.Callable[[t.Optional[str]], t.Optional[int]]]415 ] = None,460- cache_timeout: t.Optional[int] = None,461-):416+) -> "Response":417 """Send the contents of a file to the client.418 419 The first argument can be a file path or a file-like object. Paths420 are preferred in most cases because Werkzeug can manage the file and93 unmodified lines514 parameters were added. The default behavior is to add etags.515 516 .. versionadded:: 0.2517 """563- return werkzeug.utils.send_file(518+ return werkzeug.utils.send_file( # type: ignore[return-value]519 **_prepare_send_file_kwargs(520 path_or_file=path_or_file,521 environ=request.environ,522 mimetype=mimetype,523 as_attachment=as_attachment,524 download_name=download_name,570- attachment_filename=attachment_filename,525 conditional=conditional,526 etag=etag,573- add_etags=add_etags,527 last_modified=last_modified,528 max_age=max_age,576- cache_timeout=cache_timeout,529 )530 )531 532 533 def send_from_directory(534 directory: t.Union[os.PathLike, str],535 path: t.Union[os.PathLike, str],584- filename: t.Optional[str] = None,536 **kwargs: t.Any,537 ) -> "Response":538 """Send a file from within a directory using :func:`send_file`.539 27 unmodified lines567 pass some Flask-specific arguments.568 569 .. versionadded:: 0.5570 """620- if filename is not None:621- warnings.warn(622- "The 'filename' parameter has been renamed to 'path'. The"623- " old name will be removed in Flask 2.2.",624- DeprecationWarning,625- stacklevel=2,626- )627- path = filename628-629- return werkzeug.utils.send_from_directory( # type: ignore571+ return werkzeug.utils.send_from_directory( # type: ignore[return-value]572 directory, path, **_prepare_send_file_kwargs(**kwargs)573 )574 575 111 unmodified linesmodified:CHANGES.rst+7 added-1 removed
5 unmodified lines6 Unreleased7 8 - Remove previously deprecated code. :pr:`4337`9 10- - The ``RequestContext.g`` proxy to ``AppContext.g`` is removed.10+ - Old names for some ``send_file`` parameters have been removed.11+ ``download_name`` replaces ``attachment_filename``, ``max_age``12+ replaces ``cache_timeout``, and ``etag`` replaces ``add_etags``.13+ Additionally, ``path`` replaces ``filename`` in14+ ``send_from_directory``.15+ - The ``RequestContext.g`` property returning ``AppContext.g`` is16+ removed.17 18 - Add new customization points to the ``Flask`` app object for many19 previously global behaviors.20 1341 unmodified lines