mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-14 07:47:09 +08:00
* Reflect the deprecation of get_response being None. Signed-off-by: Zixuan James Li <p359101898@gmail.com> * Type get_response with a callback protocol. Otherwise, calling `self.get_response(request)` in a subclass of `MiddlewareMixin` runs into `Invalid self argument` error. This is a workaround for https://github.com/python/mypy/issues/5485. Signed-off-by: Zixuan James Li <p359101898@gmail.com> Signed-off-by: Zixuan James Li <p359101898@gmail.com>
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from typing import Any, Callable, Optional, Union
|
|
|
|
from django.core.cache import BaseCache
|
|
from django.http.request import HttpRequest
|
|
from django.http.response import HttpResponse, HttpResponseBase
|
|
from django.utils.deprecation import MiddlewareMixin
|
|
|
|
class UpdateCacheMiddleware(MiddlewareMixin):
|
|
cache_timeout: float = ...
|
|
key_prefix: str = ...
|
|
cache_alias: str = ...
|
|
cache: BaseCache = ...
|
|
def process_response(
|
|
self, request: HttpRequest, response: Union[HttpResponseBase, str]
|
|
) -> Union[HttpResponseBase, str]: ...
|
|
|
|
class FetchFromCacheMiddleware(MiddlewareMixin):
|
|
key_prefix: str = ...
|
|
cache_alias: str = ...
|
|
cache: BaseCache = ...
|
|
def process_request(self, request: HttpRequest) -> Optional[HttpResponse]: ...
|
|
|
|
class CacheMiddleware(UpdateCacheMiddleware, FetchFromCacheMiddleware):
|
|
key_prefix: str = ...
|
|
cache_alias: str = ...
|
|
cache_timeout: float = ...
|
|
cache: BaseCache = ...
|
|
def __init__(
|
|
self,
|
|
get_response: Callable = ...,
|
|
cache_timeout: Optional[float] = ...,
|
|
page_timeout: Optional[float] = ...,
|
|
**kwargs: Any
|
|
) -> None: ...
|