/
__init__.pyi
334 lines (308 loc) · 9.77 KB
/
__init__.pyi
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
from collections import Sequence, Sized
from typing import (
Any,
Callable,
Iterator,
Mapping,
Optional,
NamedTuple,
Protocol,
TypeVar,
Dict,
List,
Tuple,
Union,
Iterable
)
from io import BufferedReader, BytesIO
from re import Pattern
from requests.adapters import HTTPResponse, PreparedRequest
from requests.cookies import RequestsCookieJar
from typing_extensions import Literal
from unittest import mock as std_mock
from urllib.parse import quote as quote
from urllib3.response import HTTPHeaderDict # type: ignore # Not currently exposed in typestubs.
from .matchers import urlencoded_params_matcher, json_params_matcher
from .registries import FirstMatchRegistry
def _clean_unicode(url: str) -> str: ...
def _cookies_from_headers(headers: Dict[str, str]) -> RequestsCookieJar: ...
def _ensure_str(s: str) -> str: ...
def _ensure_url_default_path(
url: Union[Pattern[str], str]
) -> Union[Pattern[str], str]: ...
def _get_url_and_path(url: str) -> str: ...
def _handle_body(
body: Optional[Union[bytes, BufferedReader, str]]
) -> Union[BufferedReader, BytesIO]: ...
def _has_unicode(s: str) -> bool: ...
def _is_string(s: Union[Pattern[str], str]) -> bool: ...
def get_wrapped(
func: Callable[..., Any], responses: RequestsMock, registry: Optional[Any]
) -> Callable[..., Any]: ...
class Call(NamedTuple):
request: PreparedRequest
response: Any
_Body = Union[str, BaseException, "Response", BufferedReader, bytes]
MatcherIterable = Iterable[Callable[[Any], Callable[..., Any]]]
class CallList(Sequence[Call], Sized):
def __init__(self) -> None:
self._calls = List[Call]
...
def __iter__(self) -> Iterator[Call]: ...
def __len__(self) -> int: ...
def __getitem__(self, idx: int) -> Call: ... # type: ignore [override]
def add(self, request: PreparedRequest, response: _Body) -> None: ...
def reset(self) -> None: ...
class BaseResponse:
passthrough: bool = ...
content_type: Optional[str] = ...
headers: Optional[Mapping[str, str]] = ...
stream: bool = ...
method: Any = ...
url: Any = ...
match_querystring: Any = ...
match: MatcherIterable = ...
call_count: int = ...
def __init__(
self,
method: str,
url: Union[Pattern[str], str],
match_querystring: Union[bool, object] = ...,
match: MatcherIterable = ...,
) -> None: ...
def __eq__(self, other: Any) -> bool: ...
def __ne__(self, other: Any) -> bool: ...
def _req_attr_matches(
self, match: MatcherIterable, request: PreparedRequest
) -> Tuple[bool, str]: ...
def _should_match_querystring(
self, match_querystring_argument: Union[bool, object]
) -> bool: ...
def _url_matches(
self, url: Union[Pattern[str], str], other: str, match_querystring: bool = ...
) -> bool: ...
def _url_matches_strict(self, url: str, other: str) -> bool: ...
def get_headers(self) -> HTTPHeaderDict: ... # type: ignore
def get_response(self, request: PreparedRequest) -> None: ...
def matches(self, request: PreparedRequest) -> Tuple[bool, str]: ...
class Response(BaseResponse):
body: _Body = ...
status: int = ...
headers: Optional[Mapping[str, str]] = ...
stream: bool = ...
content_type: Optional[str] = ...
auto_calculate_content_length: bool = ...
def __init__(
self,
method: str,
url: Union[Pattern[str], str],
body: _Body = ...,
json: Optional[Any] = ...,
status: int = ...,
headers: Optional[Mapping[str, str]] = ...,
stream: bool = ...,
content_type: Optional[str] = ...,
auto_calculate_content_length: bool = ...,
match_querystring: bool = ...,
match: MatcherIterable = ...,
) -> None: ...
def get_response( # type: ignore [override]
self, request: PreparedRequest
) -> HTTPResponse: ...
class CallbackResponse(BaseResponse):
callback: Callable[[Any], Any] = ...
stream: bool = ...
content_type: Optional[str] = ...
def __init__(
self,
method: str,
url: Union[Pattern[str], str],
callback: Callable[[Any], Any],
stream: bool = ...,
content_type: Optional[str] = ...,
match_querystring: bool = ...,
match: MatcherIterable = ...,
) -> None: ...
def get_response( # type: ignore [override]
self, request: PreparedRequest
) -> HTTPResponse: ...
class PassthroughResponse(BaseResponse):
passthrough: bool = ...
class OriginalResponseShim:
msg: Any = ...
def __init__( # type: ignore [no-any-unimported]
self, headers: HTTPHeaderDict
) -> None: ...
def isclosed(self) -> bool: ...
_F = TypeVar("_F", bound=Callable[..., Any])
class RequestsMock:
DELETE: Literal["DELETE"]
GET: Literal["GET"]
HEAD: Literal["HEAD"]
OPTIONS: Literal["OPTIONS"]
PATCH: Literal["PATCH"]
POST: Literal["POST"]
PUT: Literal["PUT"]
response_callback: Optional[Callable[[Any], Any]] = ...
assert_all_requests_are_fired: Any = ...
passthru_prefixes: Tuple[Union[str, Pattern[str]], ...] = ...
target: Any = ...
_matches: List[Any]
def __init__(
self,
assert_all_requests_are_fired: bool = ...,
response_callback: Optional[Callable[[Any], Any]] = ...,
passthru_prefixes: Tuple[str, ...] = ...,
target: str = ...,
registry: Any = ...,
) -> None:
self._patcher = Callable[[Any], Any]
self._calls = CallList
...
def reset(self) -> None: ...
add: _Add
add_passthru: _AddPassthru
def remove(
self,
method_or_response: Optional[Union[str, Response]] = ...,
url: Optional[Union[Pattern[str], str]] = ...,
) -> None: ...
replace: _Replace
upsert: _Upsert
add_callback: _AddCallback
@property
def calls(self) -> CallList: ...
def __enter__(self) -> RequestsMock: ...
def __exit__(self, type: Any, value: Any, traceback: Any) -> bool: ...
def activate(self, func: Optional[_F], registry: Optional[Any]) -> _F: ...
def start(self) -> None: ...
def stop(self, allow_assert: bool = ...) -> None: ...
def assert_call_count(self, url: str, count: int) -> bool: ...
def registered(self) -> List[Any]: ...
def _set_registry(self, registry: Any) -> None: ...
def _get_registry(self) -> Any: ...
HeaderSet = Optional[Union[Mapping[str, str], List[Tuple[str, str]]]]
class _Add(Protocol):
def __call__(
self,
method: Optional[Union[str, BaseResponse]] = ...,
url: Optional[Union[Pattern[str], str]] = ...,
body: _Body = ...,
json: Optional[Any] = ...,
status: int = ...,
headers: HeaderSet = ...,
stream: bool = ...,
content_type: Optional[str] = ...,
auto_calculate_content_length: bool = ...,
adding_headers: HeaderSet = ...,
match_querystring: bool = ...,
match: MatcherIterable = ...,
) -> None: ...
class _AddCallback(Protocol):
def __call__(
self,
method: str,
url: Union[Pattern[str], str],
callback: Callable[[PreparedRequest], Union[Exception, Tuple[int, Mapping[str, str], _Body]]],
match_querystring: bool = ...,
content_type: Optional[str] = ...,
match: MatcherIterable = ...,
) -> None: ...
class _AddPassthru(Protocol):
def __call__(
self, prefix: Union[Pattern[str], str]
) -> None: ...
class _Remove(Protocol):
def __call__(
self,
method_or_response: Optional[Union[str, BaseResponse]] = ...,
url: Optional[Union[Pattern[str], str]] = ...,
) -> None: ...
class _Replace(Protocol):
def __call__(
self,
method_or_response: Optional[Union[str, BaseResponse]] = ...,
url: Optional[Union[Pattern[str], str]] = ...,
body: _Body = ...,
json: Optional[Any] = ...,
status: int = ...,
headers: HeaderSet = ...,
stream: bool = ...,
content_type: Optional[str] = ...,
adding_headers: HeaderSet = ...,
match_querystring: bool = ...,
match: MatcherIterable = ...,
) -> None: ...
class _Upsert(Protocol):
def __call__(
self,
method: Optional[Union[str, BaseResponse]] = ...,
url: Optional[Union[Pattern[str], str]] = ...,
body: _Body = ...,
json: Optional[Any] = ...,
status: int = ...,
headers: HeaderSet = ...,
stream: bool = ...,
content_type: Optional[str] = ...,
adding_headers: HeaderSet = ...,
match_querystring: bool = ...,
match: MatcherIterable = ...,
) -> None: ...
class _Registered(Protocol):
def __call__(self) -> List[Response]: ...
activate: Any
add: _Add
add_callback: _AddCallback
add_passthru: _AddPassthru
assert_all_requests_are_fired: bool
assert_call_count: Callable[[str, int], bool]
calls: CallList
DELETE: Literal["DELETE"]
GET: Literal["GET"]
HEAD: Literal["HEAD"]
mock: RequestsMock
_default_mock: RequestsMock
OPTIONS: Literal["OPTIONS"]
passthru_prefixes: Tuple[str, ...]
PATCH: Literal["PATCH"]
POST: Literal["POST"]
PUT: Literal["PUT"]
registered: _Registered
remove: _Remove
replace: _Replace
reset: Callable[[], None]
response_callback: Callable[[Any], Any]
start: Callable[[], None]
stop: Callable[..., None]
target: Any
upsert: _Upsert
__all__ = [
"CallbackResponse",
"Response",
"RequestsMock",
# Exposed by the RequestsMock class:
"activate",
"add",
"add_callback",
"add_passthru",
"assert_all_requests_are_fired",
"assert_call_count",
"calls",
"DELETE",
"GET",
"HEAD",
"OPTIONS",
"passthru_prefixes",
"PATCH",
"POST",
"PUT",
"registered",
"remove",
"replace",
"reset",
"response_callback",
"start",
"stop",
"target",
"upsert",
]