Optimized MiddlewareMixin coroutine check.
This commit is contained in:
parent
cc752c1c3a
commit
33401cba93
|
@ -112,10 +112,12 @@ class MiddlewareMixin:
|
||||||
# Mark the class as async-capable, but do the actual switch
|
# Mark the class as async-capable, but do the actual switch
|
||||||
# inside __call__ to avoid swapping out dunder methods
|
# inside __call__ to avoid swapping out dunder methods
|
||||||
self._is_coroutine = asyncio.coroutines._is_coroutine
|
self._is_coroutine = asyncio.coroutines._is_coroutine
|
||||||
|
else:
|
||||||
|
self._is_coroutine = None
|
||||||
|
|
||||||
def __call__(self, request):
|
def __call__(self, request):
|
||||||
# Exit out to async mode, if needed
|
# Exit out to async mode, if needed
|
||||||
if asyncio.iscoroutinefunction(self.get_response):
|
if self._is_coroutine:
|
||||||
return self.__acall__(request)
|
return self.__acall__(request)
|
||||||
response = None
|
response = None
|
||||||
if hasattr(self, 'process_request'):
|
if hasattr(self, 'process_request'):
|
||||||
|
|
Loading…
Reference in New Issue