-
-
Notifications
You must be signed in to change notification settings - Fork 199
Expand file tree
/
Copy pathtypes.py
More file actions
60 lines (45 loc) · 1.56 KB
/
types.py
File metadata and controls
60 lines (45 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import abc
from typing import Any, Awaitable, Callable, Dict, Optional, Tuple, TypeAlias, Union
from starlette.requests import Request
from starlette.responses import Response
from typing_extensions import Protocol
_Func = Callable[..., Any]
class KeyBuilder(Protocol):
def __call__(
self,
__function: _Func,
__namespace: str = ...,
*,
request: Optional[Request] = ...,
response: Optional[Response] = ...,
args: Tuple[Any, ...],
kwargs: Dict[str, Any],
) -> Union[Awaitable[str], str]:
...
class Backend(abc.ABC):
@abc.abstractmethod
async def get_with_ttl(self, key: str) -> Tuple[int, Optional[bytes]]:
raise NotImplementedError
@abc.abstractmethod
async def get(self, key: str) -> Optional[bytes]:
raise NotImplementedError
@abc.abstractmethod
async def set(self, key: str, value: bytes, expire: Optional[int] = None) -> None:
raise NotImplementedError
@abc.abstractmethod
async def clear(self, namespace: Optional[str] = None, key: Optional[str] = None) -> int:
raise NotImplementedError
class _ItemsProviderProtocol(Protocol):
def __call__(self, data: Union[dict, list]):
pass
class _ItemsProviderProtocolWithParams(Protocol):
def __call__(
self,
data: Union[dict, list],
method_args: Optional[tuple] = None,
method_kwargs: Optional[dict] = None,
) -> list[dict]:
pass
ItemsProviderProtocol: TypeAlias = (
_ItemsProviderProtocol | _ItemsProviderProtocolWithParams
)