rnet 2.4.2__cp313-cp313t-manylinux_2_34_armv7l.whl → 3.0.0rc10__cp313-cp313t-manylinux_2_34_armv7l.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/blocking.py CHANGED
@@ -1 +1,434 @@
1
- # type: ignore
1
+ import datetime
2
+ from rnet import (
3
+ ClientParams,
4
+ History,
5
+ Message,
6
+ Request,
7
+ Streamer,
8
+ WebSocketRequest,
9
+ Version,
10
+ Method,
11
+ SocketAddr,
12
+ StatusCode,
13
+ )
14
+ from typing import (
15
+ Optional,
16
+ Any,
17
+ List,
18
+ Unpack,
19
+ )
20
+
21
+ from rnet.header import HeaderMap
22
+ from rnet.cookie import Cookie
23
+
24
+
25
+ class Response:
26
+ r"""
27
+ A blocking response from a request.
28
+ """
29
+
30
+ url: str
31
+ r"""
32
+ Get the URL of the response.
33
+ """
34
+
35
+ status: StatusCode
36
+ r"""
37
+ Get the status code of the response.
38
+ """
39
+
40
+ version: Version
41
+ r"""
42
+ Get the HTTP version of the response.
43
+ """
44
+
45
+ headers: HeaderMap
46
+ r"""
47
+ Get the headers of the response.
48
+ """
49
+
50
+ cookies: List[Cookie]
51
+ r"""
52
+ Get the cookies of the response.
53
+ """
54
+
55
+ content_length: Optional[int]
56
+ r"""
57
+ Get the content length of the response.
58
+ """
59
+
60
+ remote_addr: Optional[SocketAddr]
61
+ r"""
62
+ Get the remote address of the response.
63
+ """
64
+
65
+ local_addr: Optional[SocketAddr]
66
+ r"""
67
+ Get the local address of the response.
68
+ """
69
+
70
+ history: List[History]
71
+ r"""
72
+ Get the redirect history of the Response.
73
+ """
74
+
75
+ peer_certificate: Optional[bytes]
76
+ r"""
77
+ Get the DER encoded leaf certificate of the response.
78
+ """
79
+
80
+ def raise_for_status(self) -> None:
81
+ r"""
82
+ Turn a response into an error if the server returned an error.
83
+ """
84
+
85
+ def stream(self) -> Streamer:
86
+ r"""
87
+ Get the response into a `Streamer` of `bytes` from the body.
88
+ """
89
+ ...
90
+
91
+ def text(self) -> str:
92
+ r"""
93
+ Get the text content of the response.
94
+ """
95
+ ...
96
+
97
+ def text_with_charset(self, encoding: str) -> str:
98
+ r"""
99
+ Get the full response text given a specific encoding.
100
+ """
101
+ ...
102
+
103
+ def json(self) -> Any:
104
+ r"""
105
+ Get the JSON content of the response.
106
+ """
107
+
108
+ def bytes(self) -> bytes:
109
+ r"""
110
+ Get the bytes content of the response.
111
+ """
112
+ ...
113
+
114
+ def close(self) -> None:
115
+ r"""
116
+ Close the response connection.
117
+ """
118
+
119
+ def __enter__(self) -> "Response": ...
120
+ def __exit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> None: ...
121
+
122
+
123
+ class WebSocket:
124
+ r"""
125
+ A blocking WebSocket response.
126
+ """
127
+
128
+ status: StatusCode
129
+ r"""
130
+ Get the status code of the response.
131
+ """
132
+
133
+ version: Version
134
+ r"""
135
+ Get the HTTP version of the response.
136
+ """
137
+
138
+ headers: HeaderMap
139
+ r"""
140
+ Get the headers of the response.
141
+ """
142
+
143
+ cookies: List[Cookie]
144
+ r"""
145
+ Get the cookies of the response.
146
+ """
147
+
148
+ remote_addr: Optional[SocketAddr]
149
+ r"""
150
+ Get the remote address of the response.
151
+ """
152
+
153
+ protocol: Optional[str]
154
+ r"""
155
+ Get the WebSocket protocol.
156
+ """
157
+
158
+ def recv(self, timeout: datetime.timedelta | None = None) -> Optional[Message]:
159
+ r"""
160
+ Receive a message from the WebSocket.
161
+ """
162
+
163
+ def send(self, message: Message) -> None:
164
+ r"""
165
+ Send a message to the WebSocket.
166
+
167
+ # Arguments
168
+
169
+ * `message` - The message to send.
170
+ """
171
+
172
+ def send_all(self, messages: List[Message]) -> None:
173
+ r"""
174
+ Send multiple messages to the WebSocket.
175
+
176
+ # Arguments
177
+
178
+ * `messages` - The list of messages to send.
179
+ """
180
+
181
+ def close(
182
+ self,
183
+ code: int | None = None,
184
+ reason: str | None = None,
185
+ ) -> None:
186
+ r"""
187
+ Close the WebSocket connection.
188
+
189
+ # Arguments
190
+
191
+ * `code` - An optional close code.
192
+ * `reason` - An optional reason for closing.
193
+ """
194
+
195
+ def __enter__(self) -> "WebSocket": ...
196
+ def __exit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> None: ...
197
+
198
+
199
+ class Client:
200
+ r"""
201
+ A blocking client for making HTTP requests.
202
+ """
203
+
204
+ def __init__(
205
+ self,
206
+ **kwargs: Unpack[ClientParams],
207
+ ) -> None:
208
+ r"""
209
+ Creates a new blocking Client instance.
210
+
211
+ # Examples
212
+
213
+ ```python
214
+ import asyncio
215
+ import rnet
216
+
217
+ client = rnet.blocking.Client(
218
+ user_agent="Mozilla/5.0",
219
+ timeout=10,
220
+ )
221
+ response = client.get('https://httpbin.org/get')
222
+ print(response.text())
223
+ ```
224
+ """
225
+ ...
226
+
227
+ def request(
228
+ self,
229
+ method: Method,
230
+ url: str,
231
+ **kwargs: Unpack[Request],
232
+ ) -> "Response":
233
+ r"""
234
+ Sends a request with the given method and URL.
235
+
236
+ # Examples
237
+
238
+ ```python
239
+ import rnet
240
+ from rnet import Method
241
+
242
+ client = rnet.blocking.Client()
243
+ response = client.request(Method.GET, "https://httpbin.org/anything")
244
+ ```
245
+ """
246
+ ...
247
+
248
+ def websocket(self, url: str, **kwargs: Unpack[WebSocketRequest]) -> "WebSocket":
249
+ r"""
250
+ Sends a WebSocket request.
251
+
252
+ # Examples
253
+
254
+ ```python
255
+ import rnet
256
+
257
+ client = rnet.blocking.Client()
258
+ ws = client.websocket("wss://echo.websocket.org")
259
+ ws.send(rnet.Message.from_text("Hello, WebSocket!"))
260
+ message = ws.recv()
261
+ print("Received:", message.data)
262
+ ws.close()
263
+ ```
264
+ """
265
+ ...
266
+
267
+ def trace(
268
+ self,
269
+ url: str,
270
+ **kwargs: Unpack[Request],
271
+ ) -> "Response":
272
+ r"""
273
+ Sends a request with the given URL.
274
+
275
+ # Examples
276
+
277
+ ```python
278
+ import rnet
279
+ from rnet import Method
280
+
281
+ client = rnet.blocking.Client()
282
+ response = client.trace("https://httpbin.org/anything")
283
+ print(response.text())
284
+ ```
285
+ """
286
+ ...
287
+
288
+ def options(
289
+ self,
290
+ url: str,
291
+ **kwargs: Unpack[Request],
292
+ ) -> "Response":
293
+ r"""
294
+ Sends a request with the given URL.
295
+
296
+ # Examples
297
+
298
+ ```python
299
+ import rnet
300
+ from rnet import Method
301
+
302
+ client = rnet.blocking.Client()
303
+ response = client.options("https://httpbin.org/anything")
304
+ print(response.text())
305
+ ```
306
+ """
307
+ ...
308
+
309
+ def head(
310
+ self,
311
+ url: str,
312
+ **kwargs: Unpack[Request],
313
+ ) -> "Response":
314
+ r"""
315
+ Sends a request with the given URL.
316
+
317
+ # Examples
318
+
319
+ ```python
320
+ import rnet
321
+ from rnet import Method
322
+
323
+ def main():
324
+ client = rnet.blocking.Client()
325
+ response = client.head("https://httpbin.org/anything")
326
+ print(response.text())
327
+ ```
328
+ """
329
+ ...
330
+
331
+ def delete(
332
+ self,
333
+ url: str,
334
+ **kwargs: Unpack[Request],
335
+ ) -> "Response":
336
+ r"""
337
+ Sends a request with the given URL.
338
+
339
+ # Examples
340
+
341
+ ```python
342
+ import rnet
343
+ from rnet import Method
344
+
345
+ client = rnet.blocking.Client()
346
+ response = client.delete("https://httpbin.org/anything")
347
+ print(response.text())
348
+ ```
349
+ """
350
+ ...
351
+
352
+ def patch(
353
+ self,
354
+ url: str,
355
+ **kwargs: Unpack[Request],
356
+ ) -> "Response":
357
+ r"""
358
+ Sends a request with the given URL.
359
+
360
+ # Examples
361
+
362
+ ```python
363
+ import rnet
364
+ from rnet import Method
365
+
366
+ client = rnet.blocking.Client()
367
+ response = client.patch("https://httpbin.org/anything", json={"key": "value"})
368
+ print(response.text())
369
+ ```
370
+ """
371
+ ...
372
+
373
+ def put(
374
+ self,
375
+ url: str,
376
+ **kwargs: Unpack[Request],
377
+ ) -> "Response":
378
+ r"""
379
+ Sends a request with the given URL.
380
+
381
+ # Examples
382
+
383
+ ```python
384
+ import rnet
385
+ from rnet import Method
386
+
387
+ client = rnet.blocking.Client()
388
+ response = client.put("https://httpbin.org/anything", json={"key": "value"})
389
+ print(response.text())
390
+ ```
391
+ """
392
+ ...
393
+
394
+ def post(
395
+ self,
396
+ url: str,
397
+ **kwargs: Unpack[Request],
398
+ ) -> "Response":
399
+ r"""
400
+ Sends a request with the given URL.
401
+
402
+ # Examples
403
+
404
+ ```python
405
+ import rnet
406
+ from rnet import Method
407
+
408
+ client = rnet.blocking.Client()
409
+ response = client.post("https://httpbin.org/anything", json={"key": "value"})
410
+ print(response.text())
411
+ ```
412
+ """
413
+ ...
414
+
415
+ def get(
416
+ self,
417
+ url: str,
418
+ **kwargs: Unpack[Request],
419
+ ) -> "Response":
420
+ r"""
421
+ Sends a request with the given URL.
422
+
423
+ # Examples
424
+
425
+ ```python
426
+ import rnet
427
+ from rnet import Method
428
+
429
+ client = rnet.blocking.Client()
430
+ response = client.get("https://httpbin.org/anything")
431
+ print(response.text())
432
+ ```
433
+ """
434
+ ...
rnet/cookie.py CHANGED
@@ -1 +1,141 @@
1
- # type: ignore
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 List, Optional, final
12
+
13
+ __all__ = ["SameSite", "Cookie", "Jar"]
14
+
15
+
16
+ @final
17
+ class SameSite(Enum):
18
+ r"""
19
+ The Cookie SameSite attribute.
20
+ """
21
+
22
+ Strict = auto()
23
+ Lax = auto()
24
+ Empty = auto()
25
+
26
+
27
+ class Cookie:
28
+ r"""
29
+ A cookie.
30
+ """
31
+
32
+ name: str
33
+ r"""
34
+ The name of the cookie.
35
+ """
36
+ value: str
37
+ r"""
38
+ The value of the cookie.
39
+ """
40
+ http_only: bool
41
+ r"""
42
+ Returns true if the 'HttpOnly' directive is enabled.
43
+ """
44
+ secure: bool
45
+ r"""
46
+ Returns true if the 'Secure' directive is enabled.
47
+ """
48
+ same_site_lax: bool
49
+ r"""
50
+ Returns true if 'SameSite' directive is 'Lax'.
51
+ """
52
+ same_site_strict: bool
53
+ r"""
54
+ Returns true if 'SameSite' directive is 'Strict'.
55
+ """
56
+ path: Optional[str]
57
+ r"""
58
+ Returns the path directive of the cookie, if set.
59
+ """
60
+ domain: Optional[str]
61
+ r"""
62
+ Returns the domain directive of the cookie, if set.
63
+ """
64
+ max_age: Optional[datetime.timedelta]
65
+ r"""
66
+ Get the Max-Age information.
67
+ """
68
+ expires: Optional[datetime.datetime]
69
+ r"""
70
+ The cookie expiration time.
71
+ """
72
+
73
+ def __init__(
74
+ self,
75
+ name: str,
76
+ value: str,
77
+ domain: str | None = None,
78
+ path: str | None = None,
79
+ max_age: datetime.timedelta | None = None,
80
+ expires: datetime.datetime | None = None,
81
+ http_only: bool | None = None,
82
+ secure: bool | None = None,
83
+ same_site: SameSite | None = None,
84
+ ) -> None:
85
+ r"""
86
+ Create a new cookie.
87
+ """
88
+ ...
89
+
90
+ def __str__(self) -> str: ...
91
+
92
+
93
+ class Jar:
94
+ r"""
95
+ A thread-safe cookie jar for storing and managing HTTP cookies.
96
+
97
+ This cookie jar can be safely shared across multiple threads and is used
98
+ to automatically handle cookies during HTTP requests and responses.
99
+ """
100
+
101
+ def __init__(self) -> None:
102
+ r"""
103
+ Create a new cookie jar.
104
+ """
105
+ ...
106
+
107
+ def get(self, name: str, url: str) -> Optional[Cookie]:
108
+ r"""
109
+ Get a cookie by name and URL.
110
+ """
111
+ ...
112
+
113
+ def get_all(self) -> List[Cookie]:
114
+ r"""
115
+ Get all cookies.
116
+ """
117
+ ...
118
+
119
+ def add_cookie(self, cookie: Cookie, url: str) -> None:
120
+ r"""
121
+ Add a cookie to this jar.
122
+ """
123
+ ...
124
+
125
+ def add_cookie_str(self, cookie: str, url: str) -> None:
126
+ r"""
127
+ Add a cookie str to this jar.
128
+ """
129
+ ...
130
+
131
+ def remove(self, name: str, url: str) -> None:
132
+ r"""
133
+ Remove a cookie from this jar by name and URL.
134
+ """
135
+ ...
136
+
137
+ def clear(self) -> None:
138
+ r"""
139
+ Clear all cookies in this jar.
140
+ """
141
+ ...