-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathcookies.pyi
More file actions
189 lines (176 loc) · 6.79 KB
/
cookies.pyi
File metadata and controls
189 lines (176 loc) · 6.79 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
from _typeshed import sentinel
from _typeshed.wsgi import WSGIEnvironment
from collections.abc import Collection, ItemsView, Iterator, KeysView, MutableMapping, ValuesView
from datetime import date, datetime, timedelta
from time import _TimeTuple, struct_time
from typing import Any, Literal, Protocol, TypeVar, overload, type_check_only
from typing_extensions import TypeAlias
from webob._types import AsymmetricProperty
from webob.request import BaseRequest
from webob.response import Response
__all__ = [
"Cookie",
"CookieProfile",
"SignedCookieProfile",
"SignedSerializer",
"JSONSerializer",
"Base64Serializer",
"make_cookie",
]
_T = TypeVar("_T")
# we accept both the official spelling and the one used in the WebOb docs
# the implementation compares after lower() so technically there are more
# valid spellings, but it seems more natural to support these two spellings
_SameSitePolicy: TypeAlias = Literal["Strict", "Lax", "None", "strict", "lax", "none"]
@type_check_only
class _Serializer(Protocol):
def dumps(self, appstruct: Any, /) -> bytes: ...
def loads(self, bstruct: bytes, /) -> Any: ...
class RequestCookies(MutableMapping[str, str]):
def __init__(self, environ: WSGIEnvironment) -> None: ...
def __setitem__(self, name: str, value: str) -> None: ...
def __getitem__(self, name: str) -> str: ...
@overload
def get(self, name: str) -> str | None: ...
@overload
def get(self, name: str, default: _T) -> str | _T: ...
def __delitem__(self, name: str) -> None: ...
def keys(self) -> KeysView[str]: ...
def values(self) -> ValuesView[str]: ...
def items(self) -> ItemsView[str, str]: ...
def __contains__(self, name: object) -> bool: ...
def __iter__(self) -> Iterator[str]: ...
def __len__(self) -> int: ...
def clear(self) -> None: ...
class Cookie(dict[bytes, Morsel]):
def __init__(self, input: str | None = None) -> None: ...
def load(self, data: str) -> None: ...
def add(self, key: str | bytes, val: str | bytes) -> Morsel | dict[bytes, bytes]: ...
def __setitem__(self, key: str | bytes, val: str | bytes) -> Morsel | dict[bytes, bytes]: ... # type: ignore[override]
def serialize(self, full: bool = True) -> str: ...
def values(self) -> list[Morsel]: ... # type: ignore[override]
def __str__(self, full: bool = True) -> str: ...
class Morsel(dict[bytes, bytes | bool | None]):
__slots__ = ("name", "value")
name: bytes
value: bytes
def __init__(self, name: str | bytes, value: str | bytes) -> None: ...
@property
def path(self) -> bytes | None: ...
@path.setter
def path(self, v: bytes | None) -> None: ...
@property
def domain(self) -> bytes | None: ...
@domain.setter
def domain(self, v: bytes | None) -> None: ...
@property
def comment(self) -> bytes | None: ...
@comment.setter
def comment(self, v: bytes | None) -> None: ...
expires: AsymmetricProperty[bytes | None, datetime | date | timedelta | _TimeTuple | struct_time | int | str | bytes | None]
max_age: AsymmetricProperty[bytes | None, timedelta | int | str | bytes | None]
httponly: AsymmetricProperty[bool, bool | None]
secure: AsymmetricProperty[bool, bool | None]
samesite: AsymmetricProperty[bytes, _SameSitePolicy | bytes]
def __setitem__(self, k: str | bytes, v: bytes | bool | None) -> None: ...
def serialize(self, full: bool = True) -> str: ...
def __str__(self, full: bool = True) -> str: ...
def make_cookie(
name: str | bytes,
value: str | bytes | None,
max_age: int | timedelta | None = None,
path: str = "/",
domain: str | None = None,
secure: bool | None = False,
httponly: bool | None = False,
comment: str | None = None,
samesite: _SameSitePolicy | None = None,
) -> str: ...
class JSONSerializer:
def dumps(self, appstruct: Any) -> bytes: ...
def loads(self, bstruct: bytes | str) -> Any: ...
class Base64Serializer:
serializer: _Serializer
def __init__(self, serializer: _Serializer | None = None) -> None: ...
def dumps(self, appstruct: Any) -> bytes: ...
def loads(self, bstruct: bytes) -> Any: ...
class SignedSerializer:
salt: str | bytes
secret: str | bytes
hashalg: str
salted_secret: bytes
digest_size: int
serializer: _Serializer
def __init__(
self, secret: str | bytes, salt: str | bytes, hashalg: str = "sha512", serializer: _Serializer | None = None
) -> None: ...
def dumps(self, appstruct: Any) -> bytes: ...
def loads(self, bstruct: bytes) -> Any: ...
class CookieProfile:
cookie_name: str
secure: bool
max_age: int | timedelta | None
httponly: bool | None
samesite: _SameSitePolicy | None
path: str
domains: Collection[str] | None
serializer: _Serializer
request: BaseRequest | None
def __init__(
self,
cookie_name: str,
secure: bool = False,
max_age: int | timedelta | None = None,
httponly: bool | None = None,
samesite: _SameSitePolicy | None = None,
path: str = "/",
# even though the docs claim any iterable is fine, that is
# clearly not the case judging by the implementation
domains: Collection[str] | None = None,
serializer: _Serializer | None = None,
) -> None: ...
def __call__(self, request: BaseRequest) -> CookieProfile: ...
def bind(self, request: BaseRequest) -> CookieProfile: ...
def get_value(self) -> Any | None: ...
def set_cookies(
self,
response: Response,
value: Any,
domains: Collection[str] = sentinel,
max_age: int | timedelta | None = sentinel,
path: str = sentinel,
secure: bool = sentinel,
httponly: bool = sentinel,
samesite: _SameSitePolicy | None = sentinel,
) -> Response: ...
def get_headers(
self,
value: Any,
domains: Collection[str] = sentinel,
max_age: int | timedelta | None = sentinel,
path: str = sentinel,
secure: bool = sentinel,
httponly: bool = sentinel,
samesite: _SameSitePolicy | None = sentinel,
) -> list[tuple[str, str]]: ...
class SignedCookieProfile(CookieProfile):
secret: str | bytes
salt: str | bytes
hashalg: str
original_serializer: _Serializer
def __init__(
self,
secret: str,
salt: str,
cookie_name: str,
secure: bool = False,
max_age: int | timedelta | None = None,
httponly: bool | None = False,
samesite: _SameSitePolicy | None = None,
path: str = "/",
domains: Collection[str] | None = None,
hashalg: str = "sha512",
serializer: _Serializer | None = None,
) -> None: ...
def __call__(self, request: BaseRequest) -> SignedCookieProfile: ...
def bind(self, request: BaseRequest) -> SignedCookieProfile: ...