Renamed wrapped functions to wrapper.

All these functions are wrapping another function. They're the wrapper,
while the function they're wrapping is the wrapped.
This commit is contained in:
Aymeric Augustin 2022-05-22 08:20:29 +02:00 committed by Mariusz Felisiak
parent 90aabd730a
commit 6485894157
11 changed files with 28 additions and 28 deletions

View File

@ -18,7 +18,7 @@ def user_passes_test(
def decorator(view_func):
@wraps(view_func)
def _wrapped_view(request, *args, **kwargs):
def _wrapper_view(request, *args, **kwargs):
if test_func(request.user):
return view_func(request, *args, **kwargs)
path = request.build_absolute_uri()
@ -35,7 +35,7 @@ def user_passes_test(
return redirect_to_login(path, resolved_login_url, redirect_field_name)
return _wrapped_view
return _wrapper_view
return decorator

View File

@ -87,7 +87,7 @@ def handle_default_options(options):
def no_translations(handle_func):
"""Decorator that forces a command to run with translations deactivated."""
def wrapped(*args, **kwargs):
def wrapper(*args, **kwargs):
from django.utils import translation
saved_locale = translation.get_language()
@ -99,7 +99,7 @@ def no_translations(handle_func):
translation.activate(saved_locale)
return res
return wrapped
return wrapper
class DjangoHelpFormatter(HelpFormatter):

View File

@ -120,7 +120,7 @@ def make_middleware_decorator(middleware_class):
middleware = middleware_class(view_func, *m_args, **m_kwargs)
@wraps(view_func)
def _wrapped_view(request, *args, **kwargs):
def _wrapper_view(request, *args, **kwargs):
if hasattr(middleware, "process_request"):
result = middleware.process_request(request)
if result is not None:
@ -155,7 +155,7 @@ def make_middleware_decorator(middleware_class):
return middleware.process_response(request, response)
return response
return _wrapped_view
return _wrapper_view
return _decorator

View File

@ -27,7 +27,7 @@ class warn_about_renamed_method:
self.deprecation_warning = deprecation_warning
def __call__(self, f):
def wrapped(*args, **kwargs):
def wrapper(*args, **kwargs):
warnings.warn(
"`%s.%s` is deprecated, use `%s` instead."
% (self.class_name, self.old_method_name, self.new_method_name),
@ -36,7 +36,7 @@ class warn_about_renamed_method:
)
return f(*args, **kwargs)
return wrapped
return wrapper
class RenameMethodsBase(type):

View File

@ -49,10 +49,10 @@ SafeText = SafeString # For backwards compatibility since Django 2.0.
def _safety_decorator(safety_marker, func):
@wraps(func)
def wrapped(*args, **kwargs):
def wrapper(*args, **kwargs):
return safety_marker(func(*args, **kwargs))
return wrapped
return wrapper
@keep_lazy(SafeString)

View File

@ -52,7 +52,7 @@ def never_cache(view_func):
"""
@wraps(view_func)
def _wrapped_view_func(request, *args, **kwargs):
def _wrapper_view_func(request, *args, **kwargs):
# Ensure argument looks like a request.
if not hasattr(request, "META"):
raise TypeError(
@ -63,4 +63,4 @@ def never_cache(view_func):
add_never_cache_headers(response)
return response
return _wrapped_view_func
return _wrapper_view_func

View File

@ -12,13 +12,13 @@ def xframe_options_deny(view_func):
...
"""
def wrapped_view(*args, **kwargs):
def wrapper_view(*args, **kwargs):
resp = view_func(*args, **kwargs)
if resp.get("X-Frame-Options") is None:
resp["X-Frame-Options"] = "DENY"
return resp
return wraps(view_func)(wrapped_view)
return wraps(view_func)(wrapper_view)
def xframe_options_sameorigin(view_func):
@ -32,13 +32,13 @@ def xframe_options_sameorigin(view_func):
...
"""
def wrapped_view(*args, **kwargs):
def wrapper_view(*args, **kwargs):
resp = view_func(*args, **kwargs)
if resp.get("X-Frame-Options") is None:
resp["X-Frame-Options"] = "SAMEORIGIN"
return resp
return wraps(view_func)(wrapped_view)
return wraps(view_func)(wrapper_view)
def xframe_options_exempt(view_func):
@ -51,9 +51,9 @@ def xframe_options_exempt(view_func):
...
"""
def wrapped_view(*args, **kwargs):
def wrapper_view(*args, **kwargs):
resp = view_func(*args, **kwargs)
resp.xframe_options_exempt = True
return resp
return wraps(view_func)(wrapped_view)
return wraps(view_func)(wrapper_view)

View File

@ -8,8 +8,8 @@ def no_append_slash(view_func):
"""
# view_func.should_append_slash = False would also work, but decorators are
# nicer if they don't have side effects, so return a new function.
def wrapped_view(*args, **kwargs):
def wrapper_view(*args, **kwargs):
return view_func(*args, **kwargs)
wrapped_view.should_append_slash = False
return wraps(view_func)(wrapped_view)
wrapper_view.should_append_slash = False
return wraps(view_func)(wrapper_view)

View File

@ -50,8 +50,8 @@ def csrf_exempt(view_func):
"""Mark a view function as being exempt from the CSRF view protection."""
# view_func.csrf_exempt = True would also work, but decorators are nicer
# if they don't have side effects, so return a new function.
def wrapped_view(*args, **kwargs):
def wrapper_view(*args, **kwargs):
return view_func(*args, **kwargs)
wrapped_view.csrf_exempt = True
return wraps(view_func)(wrapped_view)
wrapper_view.csrf_exempt = True
return wraps(view_func)(wrapper_view)

View File

@ -49,7 +49,7 @@ def mock_inputs(inputs):
"""
def inner(test_func):
def wrapped(*args):
def wrapper(*args):
class mock_getpass:
@staticmethod
def getpass(prompt=b"Password: ", stream=None):
@ -90,7 +90,7 @@ def mock_inputs(inputs):
createsuperuser.getpass = old_getpass
builtins.input = old_input
return wrapped
return wrapper
return inner

View File

@ -196,10 +196,10 @@ class ClsDec:
self.myattr = myattr
def __call__(self, f):
def wrapped():
def wrapper():
return f() and self.myattr
return update_wrapper(wrapped, f)
return update_wrapper(wrapper, f)
class MethodDecoratorTests(SimpleTestCase):