Skip to content

Commit

Permalink
Merge pull request pallets#4667 from pallets/remove-deprecated-code
Browse files Browse the repository at this point in the history
Remove deprecated code
  • Loading branch information
davidism authored Jul 1, 2022
2 parents 96d39c8 + c2810ff commit c99f07d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 90 deletions.
10 changes: 10 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ Version 2.2.0

Unreleased

- Remove previously deprecated code. :pr:`4337`

- 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
previously global behaviors.

Expand Down
26 changes: 0 additions & 26 deletions src/flask/ctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,32 +327,6 @@ def __init__(
# functions.
self._after_request_functions: t.List[ft.AfterRequestCallable] = []

@property
def g(self) -> _AppCtxGlobals:
import warnings

warnings.warn(
"Accessing 'g' on the request context is deprecated and"
" will be removed in Flask 2.2. Access `g` directly or from"
"the application context instead.",
DeprecationWarning,
stacklevel=2,
)
return _app_ctx_stack.top.g

@g.setter
def g(self, value: _AppCtxGlobals) -> None:
import warnings

warnings.warn(
"Setting 'g' on the request context is deprecated and"
" will be removed in Flask 2.2. Set it on the application"
" context instead.",
DeprecationWarning,
stacklevel=2,
)
_app_ctx_stack.top.g = value

def copy(self) -> "RequestContext":
"""Creates a copy of this request context with the same request object.
This can be used to move a request context to a different greenlet.
Expand Down
70 changes: 6 additions & 64 deletions src/flask/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import socket
import sys
import typing as t
import warnings
from datetime import datetime
from functools import lru_cache
from functools import update_wrapper
Expand Down Expand Up @@ -390,53 +389,12 @@ def get_flashed_messages(
return flashes


def _prepare_send_file_kwargs(
download_name: t.Optional[str] = None,
attachment_filename: t.Optional[str] = None,
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
def _prepare_send_file_kwargs(**kwargs: t.Any) -> t.Dict[str, t.Any]:
if kwargs.get("max_age") is None:
kwargs["max_age"] = current_app.get_send_file_max_age

kwargs.update(
environ=request.environ,
download_name=download_name,
etag=etag,
max_age=max_age,
use_x_sendfile=current_app.use_x_sendfile,
response_class=current_app.response_class,
_root_path=current_app.root_path, # type: ignore
Expand All @@ -449,16 +407,13 @@ def send_file(
mimetype: t.Optional[str] = None,
as_attachment: bool = False,
download_name: t.Optional[str] = None,
attachment_filename: t.Optional[str] = None,
conditional: bool = True,
etag: t.Union[bool, str] = True,
add_etags: t.Optional[bool] = None,
last_modified: t.Optional[t.Union[datetime, int, float]] = None,
max_age: t.Optional[
t.Union[int, t.Callable[[t.Optional[str]], t.Optional[int]]]
] = None,
cache_timeout: t.Optional[int] = None,
):
) -> "Response":
"""Send the contents of a file to the client.
The first argument can be a file path or a file-like object. Paths
Expand Down Expand Up @@ -560,28 +515,24 @@ def send_file(
.. versionadded:: 0.2
"""
return werkzeug.utils.send_file(
return werkzeug.utils.send_file( # type: ignore[return-value]
**_prepare_send_file_kwargs(
path_or_file=path_or_file,
environ=request.environ,
mimetype=mimetype,
as_attachment=as_attachment,
download_name=download_name,
attachment_filename=attachment_filename,
conditional=conditional,
etag=etag,
add_etags=add_etags,
last_modified=last_modified,
max_age=max_age,
cache_timeout=cache_timeout,
)
)


def send_from_directory(
directory: t.Union[os.PathLike, str],
path: t.Union[os.PathLike, str],
filename: t.Optional[str] = None,
**kwargs: t.Any,
) -> "Response":
"""Send a file from within a directory using :func:`send_file`.
Expand Down Expand Up @@ -617,16 +568,7 @@ def download_file(name):
.. 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.2.",
DeprecationWarning,
stacklevel=2,
)
path = filename

return werkzeug.utils.send_from_directory( # type: ignore
return werkzeug.utils.send_from_directory( # type: ignore[return-value]
directory, path, **_prepare_send_file_kwargs(**kwargs)
)

Expand Down

0 comments on commit c99f07d

Please sign in to comment.