rnet 3.0.0rc1__cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rnet might be problematic. Click here for more details.
- rnet/__init__.py +19 -0
- rnet/__init__.pyi +1174 -0
- rnet/blocking.py +511 -0
- rnet/cookie.py +130 -0
- rnet/emulation.py +185 -0
- rnet/exceptions.py +214 -0
- rnet/header.py +431 -0
- rnet/py.typed +0 -0
- rnet/rnet.abi3.so +0 -0
- rnet/tls.py +161 -0
- rnet-3.0.0rc1.dist-info/METADATA +188 -0
- rnet-3.0.0rc1.dist-info/RECORD +14 -0
- rnet-3.0.0rc1.dist-info/WHEEL +4 -0
- rnet-3.0.0rc1.dist-info/licenses/LICENSE +674 -0
rnet/blocking.py
ADDED
|
@@ -0,0 +1,511 @@
|
|
|
1
|
+
from typing import Unpack
|
|
2
|
+
from rnet import Message, Proxy, Request, Streamer, WebSocketRequest
|
|
3
|
+
import ipaddress
|
|
4
|
+
from typing import (
|
|
5
|
+
Optional,
|
|
6
|
+
Union,
|
|
7
|
+
Any,
|
|
8
|
+
Dict,
|
|
9
|
+
List,
|
|
10
|
+
Unpack,
|
|
11
|
+
)
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
from rnet import Version, Method, SocketAddr, StatusCode
|
|
15
|
+
from rnet.tls import CertStore, KeyLogPolicy, TlsVersion, Identity
|
|
16
|
+
from rnet.header import HeaderMap, OrigHeaderMap
|
|
17
|
+
from rnet.cookie import Cookie, Jar
|
|
18
|
+
from rnet.emulation import EmulationOption, Emulation
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class Client:
|
|
22
|
+
r"""
|
|
23
|
+
A blocking client for making HTTP requests.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __new__(
|
|
27
|
+
cls,
|
|
28
|
+
emulation: Optional[Union[Emulation, EmulationOption]] = None,
|
|
29
|
+
user_agent: Optional[str] = None,
|
|
30
|
+
headers: Optional[Union[Dict[str, str], HeaderMap]] = None,
|
|
31
|
+
orig_headers: Optional[Union[List[str], OrigHeaderMap]] = None,
|
|
32
|
+
referer: Optional[bool] = None,
|
|
33
|
+
allow_redirects: Optional[bool] = None,
|
|
34
|
+
max_redirects: Optional[int] = None,
|
|
35
|
+
cookie_store: Optional[bool] = None,
|
|
36
|
+
cookie_provider: Optional[Jar] = None,
|
|
37
|
+
timeout: Optional[int] = None,
|
|
38
|
+
connect_timeout: Optional[int] = None,
|
|
39
|
+
read_timeout: Optional[int] = None,
|
|
40
|
+
no_keepalive: Optional[bool] = None,
|
|
41
|
+
tcp_keepalive: Optional[int] = None,
|
|
42
|
+
tcp_keepalive_interval: Optional[int] = None,
|
|
43
|
+
tcp_keepalive_retries: Optional[int] = None,
|
|
44
|
+
tcp_user_timeout: Optional[int] = None,
|
|
45
|
+
tcp_nodelay: Optional[bool] = None,
|
|
46
|
+
tcp_reuse_address: Optional[bool] = None,
|
|
47
|
+
pool_idle_timeout: Optional[int] = None,
|
|
48
|
+
pool_max_idle_per_host: Optional[int] = None,
|
|
49
|
+
pool_max_size: Optional[int] = None,
|
|
50
|
+
http1_only: Optional[bool] = None,
|
|
51
|
+
http2_only: Optional[bool] = None,
|
|
52
|
+
https_only: Optional[bool] = None,
|
|
53
|
+
http2_max_retry_count: Optional[int] = None,
|
|
54
|
+
verify: Optional[Union[bool, Path, CertStore]] = None,
|
|
55
|
+
identity: Optional[Identity] = None,
|
|
56
|
+
keylog: Optional[KeyLogPolicy] = None,
|
|
57
|
+
tls_info: Optional[bool] = None,
|
|
58
|
+
min_tls_version: Optional[TlsVersion] = None,
|
|
59
|
+
max_tls_version: Optional[TlsVersion] = None,
|
|
60
|
+
no_proxy: Optional[bool] = None,
|
|
61
|
+
proxies: Optional[List[Proxy]] = None,
|
|
62
|
+
local_address: Optional[
|
|
63
|
+
Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address]
|
|
64
|
+
] = None,
|
|
65
|
+
interface: Optional[str] = None,
|
|
66
|
+
gzip: Optional[bool] = None,
|
|
67
|
+
brotli: Optional[bool] = None,
|
|
68
|
+
deflate: Optional[bool] = None,
|
|
69
|
+
zstd: Optional[bool] = None,
|
|
70
|
+
) -> "Client":
|
|
71
|
+
r"""
|
|
72
|
+
Creates a new blocking Client instance.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
emulation: Browser fingerprint/Emulation config.
|
|
76
|
+
user_agent: Default User-Agent string.
|
|
77
|
+
headers: Default request headers.
|
|
78
|
+
orig_headers: Original request headers (case-sensitive and order).
|
|
79
|
+
referer: Automatically set Referer.
|
|
80
|
+
allow_redirects: Allow automatic redirects.
|
|
81
|
+
max_redirects: Maximum number of redirects.
|
|
82
|
+
cookie_store: Enable cookie store.
|
|
83
|
+
lookup_ip_strategy: IP lookup strategy.
|
|
84
|
+
timeout: Total timeout (seconds).
|
|
85
|
+
connect_timeout: Connection timeout (seconds).
|
|
86
|
+
read_timeout: Read timeout (seconds).
|
|
87
|
+
no_keepalive: Disable HTTP keep-alive.
|
|
88
|
+
tcp_keepalive: TCP keepalive time (seconds).
|
|
89
|
+
tcp_keepalive_interval: TCP keepalive interval (seconds).
|
|
90
|
+
tcp_keepalive_retries: TCP keepalive retry count.
|
|
91
|
+
tcp_user_timeout: TCP user timeout (seconds).
|
|
92
|
+
tcp_nodelay: Enable TCP_NODELAY.
|
|
93
|
+
tcp_reuse_address: Enable SO_REUSEADDR.
|
|
94
|
+
pool_idle_timeout: Connection pool idle timeout (seconds).
|
|
95
|
+
pool_max_idle_per_host: Max idle connections per host.
|
|
96
|
+
pool_max_size: Max total connections in pool.
|
|
97
|
+
http1_only: Enable HTTP/1.1 only.
|
|
98
|
+
http2_only: Enable HTTP/2 only.
|
|
99
|
+
https_only: Enable HTTPS only.
|
|
100
|
+
http2_max_retry_count: Max HTTP/2 retry count.
|
|
101
|
+
verify: Verify SSL or specify CA path.
|
|
102
|
+
identity: Represents a private key and X509 cert as a client certificate.
|
|
103
|
+
keylog: Key logging policy (environment or file).
|
|
104
|
+
tls_info: Return TLS info.
|
|
105
|
+
min_tls_version: Minimum TLS version.
|
|
106
|
+
max_tls_version: Maximum TLS version.
|
|
107
|
+
no_proxy: Disable proxy.
|
|
108
|
+
proxies: Proxy server list.
|
|
109
|
+
local_address: Local bind address.
|
|
110
|
+
interface: Local network interface.
|
|
111
|
+
gzip: Enable gzip decompression.
|
|
112
|
+
brotli: Enable brotli decompression.
|
|
113
|
+
deflate: Enable deflate decompression.
|
|
114
|
+
zstd: Enable zstd decompression.
|
|
115
|
+
|
|
116
|
+
# Examples
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
import asyncio
|
|
120
|
+
import rnet
|
|
121
|
+
|
|
122
|
+
client = rnet.blocking.Client(
|
|
123
|
+
user_agent="my-app/0.0.1",
|
|
124
|
+
timeout=10,
|
|
125
|
+
)
|
|
126
|
+
response = client.get('https://httpbin.org/get')
|
|
127
|
+
print(response.text())
|
|
128
|
+
```
|
|
129
|
+
"""
|
|
130
|
+
|
|
131
|
+
def request(
|
|
132
|
+
self,
|
|
133
|
+
method: Method,
|
|
134
|
+
url: str,
|
|
135
|
+
**kwargs: Unpack[Request],
|
|
136
|
+
) -> "Response":
|
|
137
|
+
r"""
|
|
138
|
+
Sends a request with the given method and URL.
|
|
139
|
+
|
|
140
|
+
# Examples
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
import rnet
|
|
144
|
+
import asyncio
|
|
145
|
+
from rnet import Method
|
|
146
|
+
|
|
147
|
+
async def main():
|
|
148
|
+
client = rnet.blocking.Client()
|
|
149
|
+
response = client.request(Method.GET, "https://httpbin.org/anything")
|
|
150
|
+
print(response.text())
|
|
151
|
+
|
|
152
|
+
asyncio.run(main())
|
|
153
|
+
```
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
def websocket(self, url: str, **kwargs: Unpack[WebSocketRequest]) -> "WebSocket":
|
|
157
|
+
r"""
|
|
158
|
+
Sends a WebSocket request.
|
|
159
|
+
|
|
160
|
+
# Examples
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
import rnet
|
|
164
|
+
import asyncio
|
|
165
|
+
|
|
166
|
+
async def main():
|
|
167
|
+
client = rnet.blocking.Client()
|
|
168
|
+
ws = client.websocket("wss://echo.websocket.org")
|
|
169
|
+
ws.send(rnet.Message.from_text("Hello, WebSocket!"))
|
|
170
|
+
message = ws.recv()
|
|
171
|
+
print("Received:", message.data)
|
|
172
|
+
ws.close()
|
|
173
|
+
|
|
174
|
+
asyncio.run(main())
|
|
175
|
+
```
|
|
176
|
+
"""
|
|
177
|
+
|
|
178
|
+
def trace(
|
|
179
|
+
self,
|
|
180
|
+
url: str,
|
|
181
|
+
**kwargs: Unpack[Request],
|
|
182
|
+
) -> "Response":
|
|
183
|
+
r"""
|
|
184
|
+
Sends a request with the given URL.
|
|
185
|
+
|
|
186
|
+
# Examples
|
|
187
|
+
|
|
188
|
+
```python
|
|
189
|
+
import rnet
|
|
190
|
+
import asyncio
|
|
191
|
+
from rnet import Method
|
|
192
|
+
|
|
193
|
+
async def main():
|
|
194
|
+
client = rnet.blocking.Client()
|
|
195
|
+
response = client.trace("https://httpbin.org/anything")
|
|
196
|
+
print(response.text())
|
|
197
|
+
|
|
198
|
+
asyncio.run(main())
|
|
199
|
+
```
|
|
200
|
+
"""
|
|
201
|
+
|
|
202
|
+
def options(
|
|
203
|
+
self,
|
|
204
|
+
url: str,
|
|
205
|
+
**kwargs: Unpack[Request],
|
|
206
|
+
) -> "Response":
|
|
207
|
+
r"""
|
|
208
|
+
Sends a request with the given URL.
|
|
209
|
+
|
|
210
|
+
# Examples
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
import rnet
|
|
214
|
+
import asyncio
|
|
215
|
+
from rnet import Method
|
|
216
|
+
|
|
217
|
+
async def main():
|
|
218
|
+
client = rnet.blocking.Client()
|
|
219
|
+
response = client.options("https://httpbin.org/anything")
|
|
220
|
+
print(response.text())
|
|
221
|
+
|
|
222
|
+
asyncio.run(main())
|
|
223
|
+
```
|
|
224
|
+
"""
|
|
225
|
+
|
|
226
|
+
def head(
|
|
227
|
+
self,
|
|
228
|
+
url: str,
|
|
229
|
+
**kwargs: Unpack[Request],
|
|
230
|
+
) -> "Response":
|
|
231
|
+
r"""
|
|
232
|
+
Sends a request with the given URL.
|
|
233
|
+
|
|
234
|
+
# Examples
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
import rnet
|
|
238
|
+
import asyncio
|
|
239
|
+
from rnet import Method
|
|
240
|
+
|
|
241
|
+
async def main():
|
|
242
|
+
client = rnet.blocking.Client()
|
|
243
|
+
response = client.head("https://httpbin.org/anything")
|
|
244
|
+
print(response.text())
|
|
245
|
+
|
|
246
|
+
asyncio.run(main())
|
|
247
|
+
```
|
|
248
|
+
"""
|
|
249
|
+
|
|
250
|
+
def delete(
|
|
251
|
+
self,
|
|
252
|
+
url: str,
|
|
253
|
+
**kwargs: Unpack[Request],
|
|
254
|
+
) -> "Response":
|
|
255
|
+
r"""
|
|
256
|
+
Sends a request with the given URL.
|
|
257
|
+
|
|
258
|
+
# Examples
|
|
259
|
+
|
|
260
|
+
```python
|
|
261
|
+
import rnet
|
|
262
|
+
import asyncio
|
|
263
|
+
from rnet import Method
|
|
264
|
+
|
|
265
|
+
async def main():
|
|
266
|
+
client = rnet.blocking.Client()
|
|
267
|
+
response = client.delete("https://httpbin.org/anything")
|
|
268
|
+
print(response.text())
|
|
269
|
+
|
|
270
|
+
asyncio.run(main())
|
|
271
|
+
```
|
|
272
|
+
"""
|
|
273
|
+
|
|
274
|
+
def patch(
|
|
275
|
+
self,
|
|
276
|
+
url: str,
|
|
277
|
+
**kwargs: Unpack[Request],
|
|
278
|
+
) -> "Response":
|
|
279
|
+
r"""
|
|
280
|
+
Sends a request with the given URL.
|
|
281
|
+
|
|
282
|
+
# Examples
|
|
283
|
+
|
|
284
|
+
```python
|
|
285
|
+
import rnet
|
|
286
|
+
import asyncio
|
|
287
|
+
from rnet import Method
|
|
288
|
+
|
|
289
|
+
async def main():
|
|
290
|
+
client = rnet.blocking.Client()
|
|
291
|
+
response = client.patch("https://httpbin.org/anything", json={"key": "value"})
|
|
292
|
+
print(response.text())
|
|
293
|
+
|
|
294
|
+
asyncio.run(main())
|
|
295
|
+
```
|
|
296
|
+
"""
|
|
297
|
+
|
|
298
|
+
def put(
|
|
299
|
+
self,
|
|
300
|
+
url: str,
|
|
301
|
+
**kwargs: Unpack[Request],
|
|
302
|
+
) -> "Response":
|
|
303
|
+
r"""
|
|
304
|
+
Sends a request with the given URL.
|
|
305
|
+
|
|
306
|
+
# Examples
|
|
307
|
+
|
|
308
|
+
```python
|
|
309
|
+
import rnet
|
|
310
|
+
import asyncio
|
|
311
|
+
from rnet import Method
|
|
312
|
+
|
|
313
|
+
async def main():
|
|
314
|
+
client = rnet.blocking.Client()
|
|
315
|
+
response = client.put("https://httpbin.org/anything", json={"key": "value"})
|
|
316
|
+
print(response.text())
|
|
317
|
+
|
|
318
|
+
asyncio.run(main())
|
|
319
|
+
```
|
|
320
|
+
"""
|
|
321
|
+
|
|
322
|
+
def post(
|
|
323
|
+
self,
|
|
324
|
+
url: str,
|
|
325
|
+
**kwargs: Unpack[Request],
|
|
326
|
+
) -> "Response":
|
|
327
|
+
r"""
|
|
328
|
+
Sends a request with the given URL.
|
|
329
|
+
|
|
330
|
+
# Examples
|
|
331
|
+
|
|
332
|
+
```python
|
|
333
|
+
import rnet
|
|
334
|
+
import asyncio
|
|
335
|
+
from rnet import Method
|
|
336
|
+
|
|
337
|
+
async def main():
|
|
338
|
+
client = rnet.blocking.Client()
|
|
339
|
+
response = client.post("https://httpbin.org/anything", json={"key": "value"})
|
|
340
|
+
print(response.text())
|
|
341
|
+
|
|
342
|
+
asyncio.run(main())
|
|
343
|
+
```
|
|
344
|
+
"""
|
|
345
|
+
|
|
346
|
+
def get(
|
|
347
|
+
self,
|
|
348
|
+
url: str,
|
|
349
|
+
**kwargs: Unpack[Request],
|
|
350
|
+
) -> "Response":
|
|
351
|
+
r"""
|
|
352
|
+
Sends a request with the given URL.
|
|
353
|
+
|
|
354
|
+
# Examples
|
|
355
|
+
|
|
356
|
+
```python
|
|
357
|
+
import rnet
|
|
358
|
+
import asyncio
|
|
359
|
+
from rnet import Method
|
|
360
|
+
|
|
361
|
+
async def main():
|
|
362
|
+
client = rnet.blocking.Client()
|
|
363
|
+
response = client.get("https://httpbin.org/anything")
|
|
364
|
+
print(response.text())
|
|
365
|
+
|
|
366
|
+
asyncio.run(main())
|
|
367
|
+
```
|
|
368
|
+
"""
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
class Response:
|
|
372
|
+
r"""
|
|
373
|
+
A blocking response from a request.
|
|
374
|
+
"""
|
|
375
|
+
|
|
376
|
+
url: str
|
|
377
|
+
r"""
|
|
378
|
+
Returns the URL of the response.
|
|
379
|
+
"""
|
|
380
|
+
status: StatusCode
|
|
381
|
+
r"""
|
|
382
|
+
Returns the status code of the response.
|
|
383
|
+
"""
|
|
384
|
+
version: Version
|
|
385
|
+
r"""
|
|
386
|
+
Returns the HTTP version of the response.
|
|
387
|
+
"""
|
|
388
|
+
headers: HeaderMap
|
|
389
|
+
r"""
|
|
390
|
+
Returns the headers of the response.
|
|
391
|
+
"""
|
|
392
|
+
cookies: List[Cookie]
|
|
393
|
+
r"""
|
|
394
|
+
Returns the cookies of the response.
|
|
395
|
+
"""
|
|
396
|
+
content_length: int
|
|
397
|
+
r"""
|
|
398
|
+
Returns the content length of the response.
|
|
399
|
+
"""
|
|
400
|
+
remote_addr: Optional[SocketAddr]
|
|
401
|
+
r"""
|
|
402
|
+
Returns the remote address of the response.
|
|
403
|
+
"""
|
|
404
|
+
encoding: str
|
|
405
|
+
r"""
|
|
406
|
+
Encoding to decode with when accessing text.
|
|
407
|
+
"""
|
|
408
|
+
|
|
409
|
+
def __enter__(self) -> "Response": ...
|
|
410
|
+
def __exit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> None: ...
|
|
411
|
+
def peer_certificate(self) -> Optional[bytes]:
|
|
412
|
+
r"""
|
|
413
|
+
Returns the TLS peer certificate of the response.
|
|
414
|
+
"""
|
|
415
|
+
|
|
416
|
+
def text(self) -> str:
|
|
417
|
+
r"""
|
|
418
|
+
Returns the text content of the response.
|
|
419
|
+
"""
|
|
420
|
+
|
|
421
|
+
def text_with_charset(self, encoding: str) -> str:
|
|
422
|
+
r"""
|
|
423
|
+
Returns the text content of the response with a specific charset.
|
|
424
|
+
|
|
425
|
+
# Arguments
|
|
426
|
+
|
|
427
|
+
* `encoding` - The default encoding to use if the charset is not specified.
|
|
428
|
+
"""
|
|
429
|
+
|
|
430
|
+
def json(self) -> Any:
|
|
431
|
+
r"""
|
|
432
|
+
Returns the JSON content of the response.
|
|
433
|
+
"""
|
|
434
|
+
|
|
435
|
+
def bytes(self) -> bytes:
|
|
436
|
+
r"""
|
|
437
|
+
Returns the bytes content of the response.
|
|
438
|
+
"""
|
|
439
|
+
|
|
440
|
+
def stream(self) -> Streamer:
|
|
441
|
+
r"""
|
|
442
|
+
Convert the response into a `Stream` of `Bytes` from the body.
|
|
443
|
+
"""
|
|
444
|
+
|
|
445
|
+
def close(self) -> None:
|
|
446
|
+
r"""
|
|
447
|
+
Closes the response connection.
|
|
448
|
+
"""
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
class WebSocket:
|
|
452
|
+
r"""
|
|
453
|
+
A blocking WebSocket response.
|
|
454
|
+
"""
|
|
455
|
+
|
|
456
|
+
status: StatusCode
|
|
457
|
+
r"""
|
|
458
|
+
Returns the status code of the response.
|
|
459
|
+
"""
|
|
460
|
+
version: Version
|
|
461
|
+
r"""
|
|
462
|
+
Returns the HTTP version of the response.
|
|
463
|
+
"""
|
|
464
|
+
headers: HeaderMap
|
|
465
|
+
r"""
|
|
466
|
+
Returns the headers of the response.
|
|
467
|
+
"""
|
|
468
|
+
cookies: List[Cookie]
|
|
469
|
+
r"""
|
|
470
|
+
Returns the cookies of the response.
|
|
471
|
+
"""
|
|
472
|
+
remote_addr: Optional[SocketAddr]
|
|
473
|
+
r"""
|
|
474
|
+
Returns the remote address of the response.
|
|
475
|
+
"""
|
|
476
|
+
protocol: Optional[str]
|
|
477
|
+
r"""
|
|
478
|
+
Returns the WebSocket protocol.
|
|
479
|
+
"""
|
|
480
|
+
|
|
481
|
+
def __iter__(self) -> "WebSocket": ...
|
|
482
|
+
def __next__(self) -> Message: ...
|
|
483
|
+
def __enter__(self) -> "WebSocket": ...
|
|
484
|
+
def __exit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> None: ...
|
|
485
|
+
def recv(self) -> Optional[Message]:
|
|
486
|
+
r"""
|
|
487
|
+
Receives a message from the WebSocket.
|
|
488
|
+
"""
|
|
489
|
+
|
|
490
|
+
def send(self, message: Message) -> None:
|
|
491
|
+
r"""
|
|
492
|
+
Sends a message to the WebSocket.
|
|
493
|
+
|
|
494
|
+
# Arguments
|
|
495
|
+
|
|
496
|
+
* `message` - The message to send.
|
|
497
|
+
"""
|
|
498
|
+
|
|
499
|
+
def close(
|
|
500
|
+
self,
|
|
501
|
+
code: Optional[int] = None,
|
|
502
|
+
reason: Optional[str] = None,
|
|
503
|
+
) -> None:
|
|
504
|
+
r"""
|
|
505
|
+
Closes the WebSocket connection.
|
|
506
|
+
|
|
507
|
+
# Arguments
|
|
508
|
+
|
|
509
|
+
* `code` - An optional close code.
|
|
510
|
+
* `reason` - An optional reason for closing.
|
|
511
|
+
"""
|
rnet/cookie.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""
|
|
2
|
+
HTTP Cookie Management
|
|
3
|
+
|
|
4
|
+
This module provides classes for creating, managing, and storing HTTP cookies
|
|
5
|
+
in a thread-safe manner. It includes support for all standard cookie attributes
|
|
6
|
+
and provides a cookie jar for automatic cookie handling during HTTP requests.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import datetime
|
|
10
|
+
from enum import Enum, auto
|
|
11
|
+
from typing import Optional
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SameSite(Enum):
|
|
15
|
+
r"""
|
|
16
|
+
The Cookie SameSite attribute.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
Strict = auto()
|
|
20
|
+
Lax = auto()
|
|
21
|
+
Empty = auto()
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class Cookie:
|
|
25
|
+
r"""
|
|
26
|
+
A cookie.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
name: str
|
|
30
|
+
r"""
|
|
31
|
+
The name of the cookie.
|
|
32
|
+
"""
|
|
33
|
+
value: str
|
|
34
|
+
r"""
|
|
35
|
+
The value of the cookie.
|
|
36
|
+
"""
|
|
37
|
+
http_only: bool
|
|
38
|
+
r"""
|
|
39
|
+
Returns true if the 'HttpOnly' directive is enabled.
|
|
40
|
+
"""
|
|
41
|
+
secure: bool
|
|
42
|
+
r"""
|
|
43
|
+
Returns true if the 'Secure' directive is enabled.
|
|
44
|
+
"""
|
|
45
|
+
same_site_lax: bool
|
|
46
|
+
r"""
|
|
47
|
+
Returns true if 'SameSite' directive is 'Lax'.
|
|
48
|
+
"""
|
|
49
|
+
same_site_strict: bool
|
|
50
|
+
r"""
|
|
51
|
+
Returns true if 'SameSite' directive is 'Strict'.
|
|
52
|
+
"""
|
|
53
|
+
path: Optional[str]
|
|
54
|
+
r"""
|
|
55
|
+
Returns the path directive of the cookie, if set.
|
|
56
|
+
"""
|
|
57
|
+
domain: Optional[str]
|
|
58
|
+
r"""
|
|
59
|
+
Returns the domain directive of the cookie, if set.
|
|
60
|
+
"""
|
|
61
|
+
max_age: Optional[datetime.timedelta]
|
|
62
|
+
r"""
|
|
63
|
+
Get the Max-Age information.
|
|
64
|
+
"""
|
|
65
|
+
expires: Optional[datetime.datetime]
|
|
66
|
+
r"""
|
|
67
|
+
The cookie expiration time.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
def __new__(
|
|
71
|
+
cls,
|
|
72
|
+
name: str,
|
|
73
|
+
value: str,
|
|
74
|
+
domain: Optional[str] = None,
|
|
75
|
+
path: Optional[str] = None,
|
|
76
|
+
max_age: Optional[datetime.timedelta] = None,
|
|
77
|
+
expires: Optional[datetime.datetime] = None,
|
|
78
|
+
http_only: bool = False,
|
|
79
|
+
secure: bool = False,
|
|
80
|
+
same_site: Optional[SameSite] = None,
|
|
81
|
+
) -> "Cookie":
|
|
82
|
+
r"""
|
|
83
|
+
Create a new cookie.
|
|
84
|
+
"""
|
|
85
|
+
|
|
86
|
+
def __str__(self) -> str: ...
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class Jar:
|
|
90
|
+
r"""
|
|
91
|
+
A thread-safe cookie jar for storing and managing HTTP cookies.
|
|
92
|
+
|
|
93
|
+
This cookie jar can be safely shared across multiple threads and is used
|
|
94
|
+
to automatically handle cookies during HTTP requests and responses.
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
def __new__(cls) -> "Jar":
|
|
98
|
+
r"""
|
|
99
|
+
Create a new cookie jar.
|
|
100
|
+
"""
|
|
101
|
+
|
|
102
|
+
def get(self, name: str, url: str) -> Optional[Cookie]:
|
|
103
|
+
r"""
|
|
104
|
+
Get a cookie by name and URL.
|
|
105
|
+
"""
|
|
106
|
+
|
|
107
|
+
def get_all(self) -> list[Cookie]:
|
|
108
|
+
r"""
|
|
109
|
+
Get all cookies.
|
|
110
|
+
"""
|
|
111
|
+
|
|
112
|
+
def add(self, cookie: Cookie, url: str) -> None:
|
|
113
|
+
r"""
|
|
114
|
+
Add a cookie to this jar.
|
|
115
|
+
"""
|
|
116
|
+
|
|
117
|
+
def add_cookie_str(self, cookie: str, url: str) -> None:
|
|
118
|
+
r"""
|
|
119
|
+
Add a cookie str to this jar.
|
|
120
|
+
"""
|
|
121
|
+
|
|
122
|
+
def remove(self, name: str, url: str) -> None:
|
|
123
|
+
r"""
|
|
124
|
+
Remove a cookie from this jar by name and URL.
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
def clear(self) -> None:
|
|
128
|
+
r"""
|
|
129
|
+
Clear all cookies in this jar.
|
|
130
|
+
"""
|