测试gitnore
This commit is contained in:
@@ -5,21 +5,19 @@ import warnings
|
||||
from asgiref.sync import sync_to_async
|
||||
|
||||
|
||||
class RemovedInDjango41Warning(DeprecationWarning):
|
||||
class RemovedInDjango40Warning(DeprecationWarning):
|
||||
pass
|
||||
|
||||
|
||||
class RemovedInDjango50Warning(PendingDeprecationWarning):
|
||||
class RemovedInDjango41Warning(PendingDeprecationWarning):
|
||||
pass
|
||||
|
||||
|
||||
RemovedInNextVersionWarning = RemovedInDjango41Warning
|
||||
RemovedInNextVersionWarning = RemovedInDjango40Warning
|
||||
|
||||
|
||||
class warn_about_renamed_method:
|
||||
def __init__(
|
||||
self, class_name, old_method_name, new_method_name, deprecation_warning
|
||||
):
|
||||
def __init__(self, class_name, old_method_name, new_method_name, deprecation_warning):
|
||||
self.class_name = class_name
|
||||
self.old_method_name = old_method_name
|
||||
self.new_method_name = new_method_name
|
||||
@@ -28,13 +26,10 @@ class warn_about_renamed_method:
|
||||
def __call__(self, f):
|
||||
def wrapped(*args, **kwargs):
|
||||
warnings.warn(
|
||||
"`%s.%s` is deprecated, use `%s` instead."
|
||||
% (self.class_name, self.old_method_name, self.new_method_name),
|
||||
self.deprecation_warning,
|
||||
2,
|
||||
)
|
||||
"`%s.%s` is deprecated, use `%s` instead." %
|
||||
(self.class_name, self.old_method_name, self.new_method_name),
|
||||
self.deprecation_warning, 2)
|
||||
return f(*args, **kwargs)
|
||||
|
||||
return wrapped
|
||||
|
||||
|
||||
@@ -68,11 +63,9 @@ class RenameMethodsBase(type):
|
||||
# Define the new method if missing and complain about it
|
||||
if not new_method and old_method:
|
||||
warnings.warn(
|
||||
"`%s.%s` method should be renamed `%s`."
|
||||
% (class_name, old_method_name, new_method_name),
|
||||
deprecation_warning,
|
||||
2,
|
||||
)
|
||||
"`%s.%s` method should be renamed `%s`." %
|
||||
(class_name, old_method_name, new_method_name),
|
||||
deprecation_warning, 2)
|
||||
setattr(base, new_method_name, old_method)
|
||||
setattr(base, old_method_name, wrapper(old_method))
|
||||
|
||||
@@ -87,8 +80,7 @@ class DeprecationInstanceCheck(type):
|
||||
def __instancecheck__(self, instance):
|
||||
warnings.warn(
|
||||
"`%s` is deprecated, use `%s` instead." % (self.__name__, self.alternative),
|
||||
self.deprecation_warning,
|
||||
2,
|
||||
self.deprecation_warning, 2
|
||||
)
|
||||
return super().__instancecheck__(instance)
|
||||
|
||||
@@ -97,23 +89,14 @@ class MiddlewareMixin:
|
||||
sync_capable = True
|
||||
async_capable = True
|
||||
|
||||
def __init__(self, get_response):
|
||||
if get_response is None:
|
||||
raise ValueError("get_response must be provided.")
|
||||
# RemovedInDjango40Warning: when the deprecation ends, replace with:
|
||||
# def __init__(self, get_response):
|
||||
def __init__(self, get_response=None):
|
||||
self._get_response_none_deprecation(get_response)
|
||||
self.get_response = get_response
|
||||
self._async_check()
|
||||
super().__init__()
|
||||
|
||||
def __repr__(self):
|
||||
return "<%s get_response=%s>" % (
|
||||
self.__class__.__qualname__,
|
||||
getattr(
|
||||
self.get_response,
|
||||
"__qualname__",
|
||||
self.get_response.__class__.__name__,
|
||||
),
|
||||
)
|
||||
|
||||
def _async_check(self):
|
||||
"""
|
||||
If get_response is a coroutine function, turns us into async mode so
|
||||
@@ -129,10 +112,10 @@ class MiddlewareMixin:
|
||||
if asyncio.iscoroutinefunction(self.get_response):
|
||||
return self.__acall__(request)
|
||||
response = None
|
||||
if hasattr(self, "process_request"):
|
||||
if hasattr(self, 'process_request'):
|
||||
response = self.process_request(request)
|
||||
response = response or self.get_response(request)
|
||||
if hasattr(self, "process_response"):
|
||||
if hasattr(self, 'process_response'):
|
||||
response = self.process_response(request, response)
|
||||
return response
|
||||
|
||||
@@ -142,15 +125,23 @@ class MiddlewareMixin:
|
||||
is running.
|
||||
"""
|
||||
response = None
|
||||
if hasattr(self, "process_request"):
|
||||
if hasattr(self, 'process_request'):
|
||||
response = await sync_to_async(
|
||||
self.process_request,
|
||||
thread_sensitive=True,
|
||||
)(request)
|
||||
response = response or await self.get_response(request)
|
||||
if hasattr(self, "process_response"):
|
||||
if hasattr(self, 'process_response'):
|
||||
response = await sync_to_async(
|
||||
self.process_response,
|
||||
thread_sensitive=True,
|
||||
)(request, response)
|
||||
return response
|
||||
|
||||
def _get_response_none_deprecation(self, get_response):
|
||||
if get_response is None:
|
||||
warnings.warn(
|
||||
'Passing None for the middleware get_response argument is '
|
||||
'deprecated.',
|
||||
RemovedInDjango40Warning, stacklevel=3,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user