rnet 3.0.0rc1__cp311-abi3-win_amd64.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__.pyi ADDED
@@ -0,0 +1,1174 @@
1
+ import ipaddress
2
+ import typing
3
+ from typing import (
4
+ Optional,
5
+ Tuple,
6
+ Union,
7
+ Any,
8
+ Dict,
9
+ List,
10
+ TypedDict,
11
+ )
12
+ from pathlib import Path
13
+ from enum import Enum, auto
14
+
15
+ from .cookie import *
16
+ from .exceptions import *
17
+ from .header import *
18
+ from .emulation import *
19
+ from .tls import *
20
+
21
+ try:
22
+ from typing import Unpack, NotRequired
23
+ except ImportError:
24
+ from typing_extensions import Unpack, NotRequired
25
+
26
+ class Request(TypedDict, closed=True):
27
+ emulation: NotRequired[Union[Emulation, EmulationOption]]
28
+ proxy: NotRequired[Union[str, Proxy]]
29
+ local_address: NotRequired[Union[ipaddress.IPv4Address, ipaddress.IPv6Address]]
30
+ interface: NotRequired[str]
31
+ timeout: NotRequired[int]
32
+ read_timeout: NotRequired[int]
33
+ version: NotRequired[Version]
34
+ headers: NotRequired[Union[Dict[str, str], HeaderMap]]
35
+ orig_headers: NotRequired[Union[List[str], OrigHeaderMap]]
36
+ default_headers: NotRequired[bool]
37
+ cookies: NotRequired[Dict[str, str]]
38
+ allow_redirects: NotRequired[bool]
39
+ max_redirects: NotRequired[int]
40
+ gzip: NotRequired[bool]
41
+ brotli: NotRequired[bool]
42
+ deflate: NotRequired[bool]
43
+ zstd: NotRequired[bool]
44
+ auth: NotRequired[str]
45
+ bearer_auth: NotRequired[str]
46
+ basic_auth: NotRequired[Tuple[str, Optional[str]]]
47
+ query: NotRequired[List[Tuple[str, str]]]
48
+ form: NotRequired[List[Tuple[str, str]]]
49
+ json: NotRequired[Dict[str, Any]]
50
+ body: NotRequired[
51
+ Union[
52
+ str,
53
+ bytes,
54
+ typing.AsyncGenerator[bytes, str],
55
+ typing.Generator[bytes, str],
56
+ ]
57
+ ]
58
+ multipart: NotRequired[Multipart]
59
+
60
+ class WebSocketRequest(TypedDict, closed=True):
61
+ emulation: NotRequired[Union[Emulation, EmulationOption]]
62
+ proxy: NotRequired[Union[str, Proxy]]
63
+ local_address: NotRequired[Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address]]
64
+ interface: NotRequired[str]
65
+ headers: NotRequired[Union[Dict[str, str], HeaderMap]]
66
+ orig_headers: NotRequired[Union[List[str], OrigHeaderMap]]
67
+ default_headers: NotRequired[bool]
68
+ cookies: NotRequired[Dict[str, str]]
69
+ protocols: NotRequired[List[str]]
70
+ force_http2: NotRequired[bool]
71
+ auth: NotRequired[str]
72
+ bearer_auth: NotRequired[str]
73
+ basic_auth: NotRequired[Tuple[str, Optional[str]]]
74
+ query: NotRequired[List[Tuple[str, str]]]
75
+ read_buffer_size: NotRequired[int]
76
+ write_buffer_size: NotRequired[int]
77
+ max_write_buffer_size: NotRequired[int]
78
+ max_message_size: NotRequired[int]
79
+ max_frame_size: NotRequired[int]
80
+ accept_unmasked_frames: NotRequired[bool]
81
+
82
+ class ProxyParams(TypedDict, closed=True):
83
+ username: NotRequired[str]
84
+ password: NotRequired[str]
85
+ custom_http_auth: NotRequired[str]
86
+ custom_http_headers: NotRequired[Union[Dict[str, str], HeaderMap]]
87
+ exclusion: NotRequired[str]
88
+
89
+ class Client:
90
+ r"""
91
+ A client for making HTTP requests.
92
+ """
93
+
94
+ def __new__(
95
+ cls,
96
+ emulation: Optional[Union[Emulation, EmulationOption]] = None,
97
+ user_agent: Optional[str] = None,
98
+ headers: Optional[Union[Dict[str, str], HeaderMap]] = None,
99
+ orig_headers: Optional[Union[List[str], OrigHeaderMap]] = None,
100
+ referer: Optional[bool] = None,
101
+ allow_redirects: Optional[bool] = None,
102
+ max_redirects: Optional[int] = None,
103
+ cookie_store: Optional[bool] = None,
104
+ cookie_provider: Optional[Jar] = None,
105
+ timeout: Optional[int] = None,
106
+ connect_timeout: Optional[int] = None,
107
+ read_timeout: Optional[int] = None,
108
+ no_keepalive: Optional[bool] = None,
109
+ tcp_keepalive: Optional[int] = None,
110
+ tcp_keepalive_interval: Optional[int] = None,
111
+ tcp_keepalive_retries: Optional[int] = None,
112
+ tcp_user_timeout: Optional[int] = None,
113
+ tcp_nodelay: Optional[bool] = None,
114
+ tcp_reuse_address: Optional[bool] = None,
115
+ pool_idle_timeout: Optional[int] = None,
116
+ pool_max_idle_per_host: Optional[int] = None,
117
+ pool_max_size: Optional[int] = None,
118
+ http1_only: Optional[bool] = None,
119
+ http2_only: Optional[bool] = None,
120
+ https_only: Optional[bool] = None,
121
+ http2_max_retry_count: Optional[int] = None,
122
+ verify: Optional[Union[bool, Path, CertStore]] = None,
123
+ identity: Optional[Identity] = None,
124
+ keylog: Optional[KeyLogPolicy] = None,
125
+ tls_info: Optional[bool] = None,
126
+ min_tls_version: Optional[TlsVersion] = None,
127
+ max_tls_version: Optional[TlsVersion] = None,
128
+ no_proxy: Optional[bool] = None,
129
+ proxies: Optional[List[Proxy]] = None,
130
+ local_address: Optional[
131
+ Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address]
132
+ ] = None,
133
+ interface: Optional[str] = None,
134
+ gzip: Optional[bool] = None,
135
+ brotli: Optional[bool] = None,
136
+ deflate: Optional[bool] = None,
137
+ zstd: Optional[bool] = None,
138
+ ) -> Client:
139
+ r"""
140
+ Creates a new Client instance.
141
+
142
+ Args:
143
+ emulation: Browser fingerprint/Emulation config.
144
+ user_agent: Default User-Agent string.
145
+ headers: Default request headers.
146
+ orig_headers: Original request headers (case-sensitive and order).
147
+ referer: Automatically set Referer.
148
+ allow_redirects: Allow automatic redirects.
149
+ max_redirects: Maximum number of redirects.
150
+ cookie_store: Enable cookie store.
151
+ lookup_ip_strategy: IP lookup strategy.
152
+ timeout: Total timeout (seconds).
153
+ connect_timeout: Connection timeout (seconds).
154
+ read_timeout: Read timeout (seconds).
155
+ no_keepalive: Disable HTTP keep-alive.
156
+ tcp_keepalive: TCP keepalive time (seconds).
157
+ tcp_keepalive_interval: TCP keepalive interval (seconds).
158
+ tcp_keepalive_retries: TCP keepalive retry count.
159
+ tcp_user_timeout: TCP user timeout (seconds).
160
+ tcp_nodelay: Enable TCP_NODELAY.
161
+ tcp_reuse_address: Enable SO_REUSEADDR.
162
+ pool_idle_timeout: Connection pool idle timeout (seconds).
163
+ pool_max_idle_per_host: Max idle connections per host.
164
+ pool_max_size: Max total connections in pool.
165
+ http1_only: Enable HTTP/1.1 only.
166
+ http2_only: Enable HTTP/2 only.
167
+ https_only: Enable HTTPS only.
168
+ http2_max_retry_count: Max HTTP/2 retry count.
169
+ verify: Verify SSL or specify CA path.
170
+ identity: Represents a private key and X509 cert as a client certificate.
171
+ keylog: Key logging policy (environment or file).
172
+ tls_info: Return TLS info.
173
+ min_tls_version: Minimum TLS version.
174
+ max_tls_version: Maximum TLS version.
175
+ no_proxy: Disable proxy.
176
+ proxies: Proxy server list.
177
+ local_address: Local bind address.
178
+ interface: Local network interface.
179
+ gzip: Enable gzip decompression.
180
+ brotli: Enable brotli decompression.
181
+ deflate: Enable deflate decompression.
182
+ zstd: Enable zstd decompression.
183
+
184
+ Examples:
185
+
186
+ ```python
187
+ import asyncio
188
+ import rnet
189
+
190
+ client = rnet.Client(
191
+ user_agent="my-app/0.0.1",
192
+ timeout=10,
193
+ )
194
+ response = await client.get('https://httpbin.org/get')
195
+ print(response.text)
196
+ ```
197
+ """
198
+
199
+ async def request(
200
+ self,
201
+ method: Method,
202
+ url: str,
203
+ **kwargs: Unpack[Request],
204
+ ) -> Response:
205
+ r"""
206
+ Sends a request with the given method and URL.
207
+
208
+ # Examples
209
+
210
+ ```python
211
+ import rnet
212
+ import asyncio
213
+ from rnet import Method
214
+
215
+ async def main():
216
+ client = rnet.Client()
217
+ response = await client.request(Method.GET, "https://httpbin.org/anything")
218
+ print(await response.text())
219
+
220
+ asyncio.run(main())
221
+ ```
222
+ """
223
+
224
+ async def websocket(
225
+ self,
226
+ url: str,
227
+ **kwargs: Unpack[WebSocketRequest],
228
+ ) -> WebSocket:
229
+ r"""
230
+ Sends a WebSocket request.
231
+
232
+ # Examples
233
+
234
+ ```python
235
+ import rnet
236
+ import asyncio
237
+
238
+ async def main():
239
+ client = rnet.Client()
240
+ ws = await client.websocket("wss://echo.websocket.org")
241
+ await ws.send(rnet.Message.from_text("Hello, WebSocket!"))
242
+ message = await ws.recv()
243
+ print("Received:", message.data)
244
+ await ws.close()
245
+
246
+ asyncio.run(main())
247
+ ```
248
+ """
249
+
250
+ async def trace(
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.Client()
267
+ response = await client.trace("https://httpbin.org/anything")
268
+ print(await response.text())
269
+
270
+ asyncio.run(main())
271
+ ```
272
+ """
273
+
274
+ async def options(
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.Client()
291
+ response = await client.options("https://httpbin.org/anything")
292
+ print(await response.text())
293
+
294
+ asyncio.run(main())
295
+ ```
296
+ """
297
+
298
+ async def patch(
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.Client()
315
+ response = await client.patch("https://httpbin.org/anything", json={"key": "value"})
316
+ print(await response.text())
317
+
318
+ asyncio.run(main())
319
+ ```
320
+ """
321
+
322
+ async def delete(
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.Client()
339
+ response = await client.delete("https://httpbin.org/anything")
340
+ print(await response.text())
341
+
342
+ asyncio.run(main())
343
+ ```
344
+ """
345
+
346
+ async def put(
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.Client()
363
+ response = await client.put("https://httpbin.org/anything", json={"key": "value"})
364
+ print(await response.text())
365
+
366
+ asyncio.run(main())
367
+ ```
368
+ """
369
+
370
+ async def post(
371
+ self,
372
+ url: str,
373
+ **kwargs: Unpack[Request],
374
+ ) -> Response:
375
+ r"""
376
+ Sends a request with the given URL
377
+
378
+ # Examples
379
+
380
+ ```python
381
+ import rnet
382
+ import asyncio
383
+ from rnet import Method
384
+
385
+ async def main():
386
+ client = rnet.Client()
387
+ response = await client.post("https://httpbin.org/anything", json={"key": "value"})
388
+ print(await response.text())
389
+
390
+ asyncio.run(main())
391
+ ```
392
+ """
393
+
394
+ async def head(
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
+ import asyncio
407
+ from rnet import Method
408
+
409
+ async def main():
410
+ client = rnet.Client()
411
+ response = await client.head("https://httpbin.org/anything")
412
+ print(response.status)
413
+
414
+ asyncio.run(main())
415
+ ```
416
+ """
417
+
418
+ async def get(
419
+ self,
420
+ url: str,
421
+ **kwargs: Unpack[Request],
422
+ ) -> Response:
423
+ r"""
424
+ Sends a request with the given URL
425
+
426
+ # Examples
427
+
428
+ ```python
429
+ import rnet
430
+ import asyncio
431
+ from rnet import Method
432
+
433
+ async def main():
434
+ client = rnet.Client()
435
+ response = await client.get("https://httpbin.org/anything")
436
+ print(await response.text())
437
+
438
+ asyncio.run(main())
439
+ ```
440
+ """
441
+
442
+ class Multipart:
443
+ r"""
444
+ A multipart form for a request.
445
+ """
446
+
447
+ def __new__(cls, *parts) -> Multipart:
448
+ r"""
449
+ Creates a new multipart form.
450
+ """
451
+
452
+ class Part:
453
+ r"""
454
+ A part of a multipart form.
455
+ """
456
+
457
+ def __new__(
458
+ cls,
459
+ name: str,
460
+ value: Union[
461
+ str,
462
+ bytes,
463
+ Path,
464
+ typing.AsyncGenerator[bytes, str],
465
+ typing.Generator[bytes, str],
466
+ ],
467
+ filename: Optional[str] = None,
468
+ mime: Optional[str] = None,
469
+ ) -> Part:
470
+ r"""
471
+ Creates a new part.
472
+
473
+ # Arguments
474
+ - `name` - The name of the part.
475
+ - `value` - The value of the part, either text, bytes, a file path, or a async or sync stream.
476
+ - `filename` - The filename of the part.
477
+ - `mime` - The MIME type of the part.
478
+ """
479
+
480
+ class Response:
481
+ r"""
482
+ A response from a request.
483
+
484
+ # Examples
485
+
486
+ ```python
487
+ import asyncio
488
+ import rnet
489
+
490
+ async def main():
491
+ response = await rnet.get("https://www.rust-lang.org")
492
+ print("Status Code: ", response.status)
493
+ print("Version: ", response.version)
494
+ print("Response URL: ", response.url)
495
+ print("Headers: ", response.headers)
496
+ print("Content-Length: ", response.content_length)
497
+ print("Encoding: ", response.encoding)
498
+ print("Remote Address: ", response.remote_addr)
499
+
500
+ text_content = await response.text()
501
+ print("Text: ", text_content)
502
+
503
+ if __name__ == "__main__":
504
+ asyncio.run(main())
505
+ ```
506
+ """
507
+
508
+ url: str
509
+ r"""
510
+ Returns the URL of the response.
511
+ """
512
+ status: StatusCode
513
+ r"""
514
+ Returns the status code of the response.
515
+ """
516
+ version: Version
517
+ r"""
518
+ Returns the HTTP version of the response.
519
+ """
520
+ headers: HeaderMap
521
+ r"""
522
+ Returns the headers of the response.
523
+ """
524
+ cookies: List[Cookie]
525
+ r"""
526
+ Returns the cookies of the response.
527
+ """
528
+ content_length: int
529
+ r"""
530
+ Returns the content length of the response.
531
+ """
532
+ remote_addr: Optional[SocketAddr]
533
+ r"""
534
+ Returns the remote address of the response.
535
+ """
536
+ encoding: str
537
+ r"""
538
+ Encoding to decode with when accessing text.
539
+ """
540
+ def __aenter__(self) -> Any: ...
541
+ def __aexit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> Any: ...
542
+ def peer_certificate(self) -> Optional[bytes]:
543
+ r"""
544
+ Returns the TLS peer certificate of the response.
545
+ """
546
+
547
+ async def text(self) -> str:
548
+ r"""
549
+ Returns the text content of the response.
550
+ """
551
+
552
+ async def text_with_charset(self, encoding: str) -> str:
553
+ r"""
554
+ Returns the text content of the response with a specific charset.
555
+
556
+ # Arguments
557
+
558
+ * `encoding` - The default encoding to use if the charset is not specified.
559
+ """
560
+
561
+ async def json(self) -> Any:
562
+ r"""
563
+ Returns the JSON content of the response.
564
+ """
565
+
566
+ async def bytes(self) -> bytes:
567
+ r"""
568
+ Returns the bytes content of the response.
569
+ """
570
+
571
+ def stream(self) -> Streamer:
572
+ r"""
573
+ Convert the response into a `Stream` of `Bytes` from the body.
574
+ """
575
+
576
+ async def close(self) -> None:
577
+ r"""
578
+ Closes the response connection.
579
+ """
580
+
581
+ class SocketAddr:
582
+ r"""
583
+ A IP socket address.
584
+ """
585
+
586
+ def __str__(self) -> str: ...
587
+ def ip(self) -> Union[ipaddress.IPv4Address, ipaddress.IPv6Address]:
588
+ r"""
589
+ Returns the IP address of the socket address.
590
+ """
591
+
592
+ def port(self) -> int:
593
+ r"""
594
+ Returns the port number of the socket address.
595
+ """
596
+
597
+ class StatusCode:
598
+ r"""
599
+ HTTP status code.
600
+ """
601
+
602
+ def __str__(self) -> str: ...
603
+ def as_int(self) -> int:
604
+ r"""
605
+ Return the status code as an integer.
606
+ """
607
+
608
+ def is_informational(self) -> bool:
609
+ r"""
610
+ Check if status is within 100-199.
611
+ """
612
+
613
+ def is_success(self) -> bool:
614
+ r"""
615
+ Check if status is within 200-299.
616
+ """
617
+
618
+ def is_redirection(self) -> bool:
619
+ r"""
620
+ Check if status is within 300-399.
621
+ """
622
+
623
+ def is_client_error(self) -> bool:
624
+ r"""
625
+ Check if status is within 400-499.
626
+ """
627
+
628
+ def is_server_error(self) -> bool:
629
+ r"""
630
+ Check if status is within 500-599.
631
+ """
632
+
633
+ class Streamer:
634
+ r"""
635
+ A byte stream response.
636
+ An asynchronous iterator yielding data chunks from the response stream.
637
+ Used to stream response content.
638
+ Implemented in the `stream` method of the `Response` class.
639
+ Can be used in an asynchronous for loop in Python.
640
+
641
+ # Examples
642
+
643
+ ```python
644
+ import asyncio
645
+ import rnet
646
+ from rnet import Method, Emulation
647
+
648
+ async def main():
649
+ resp = await rnet.get("https://httpbin.org/stream/20")
650
+ print("Status Code: ", resp.status)
651
+ print("Version: ", resp.version)
652
+ print("Response URL: ", resp.url)
653
+ print("Headers: ", resp.headers)
654
+ print("Content-Length: ", resp.content_length)
655
+ print("Encoding: ", resp.encoding)
656
+ print("Remote Address: ", resp.remote_addr)
657
+
658
+ async with resp.stream() as streamer:
659
+ async for chunk in streamer:
660
+ print("Chunk: ", chunk)
661
+ await asyncio.sleep(0.1)
662
+
663
+ if __name__ == "__main__":
664
+ asyncio.run(main())
665
+ ```
666
+ """
667
+
668
+ def __aiter__(self) -> Streamer: ...
669
+ def __anext__(self) -> Any: ...
670
+ def __aenter__(self) -> Any: ...
671
+ def __aexit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> Any: ...
672
+ def __iter__(self) -> Streamer: ...
673
+ def __next__(self) -> Any: ...
674
+ def __enter__(self) -> Streamer: ...
675
+ def __exit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> None: ...
676
+
677
+ async def delete(
678
+ url: str,
679
+ **kwargs: Unpack[Request],
680
+ ) -> Response:
681
+ r"""
682
+ Shortcut method to quickly make a request.
683
+
684
+ # Examples
685
+
686
+ ```python
687
+ import rnet
688
+ import asyncio
689
+
690
+ async def run():
691
+ response = await rnet.delete("https://httpbin.org/anything")
692
+ body = await response.text()
693
+ print(body)
694
+
695
+ asyncio.run(run())
696
+ ```
697
+ """
698
+
699
+ async def get(
700
+ url: str,
701
+ **kwargs: Unpack[Request],
702
+ ) -> Response:
703
+ r"""
704
+ Shortcut method to quickly make a request.
705
+
706
+ # Examples
707
+
708
+ ```python
709
+ import rnet
710
+ import asyncio
711
+
712
+ async def run():
713
+ response = await rnet.get("https://httpbin.org/anything")
714
+ body = await response.text()
715
+ print(body)
716
+
717
+ asyncio.run(run())
718
+ ```
719
+ """
720
+
721
+ async def head(
722
+ url: str,
723
+ **kwargs: Unpack[Request],
724
+ ) -> Response:
725
+ r"""
726
+ Shortcut method to quickly make a request.
727
+
728
+ # Examples
729
+
730
+ ```python
731
+ import rnet
732
+ import asyncio
733
+
734
+ async def run():
735
+ response = await rnet.head("https://httpbin.org/anything")
736
+ print(response.status)
737
+
738
+ asyncio.run(run())
739
+ ```
740
+ """
741
+
742
+ async def options(
743
+ url: str,
744
+ **kwargs: Unpack[Request],
745
+ ) -> Response:
746
+ r"""
747
+ Shortcut method to quickly make a request.
748
+
749
+ # Examples
750
+
751
+ ```python
752
+ import rnet
753
+ import asyncio
754
+
755
+ async def run():
756
+ response = await rnet.options("https://httpbin.org/anything")
757
+ print(response.status)
758
+
759
+ asyncio.run(run())
760
+ ```
761
+ """
762
+
763
+ async def patch(
764
+ url: str,
765
+ **kwargs: Unpack[Request],
766
+ ) -> Response:
767
+ r"""
768
+ Shortcut method to quickly make a request.
769
+
770
+ # Examples
771
+
772
+ ```python
773
+ import rnet
774
+ import asyncio
775
+
776
+ async def run():
777
+ response = await rnet.patch("https://httpbin.org/anything")
778
+ body = await response.text()
779
+ print(body)
780
+
781
+ asyncio.run(run())
782
+ ```
783
+ """
784
+
785
+ async def post(
786
+ url: str,
787
+ **kwargs: Unpack[Request],
788
+ ) -> Response:
789
+ r"""
790
+ Shortcut method to quickly make a request.
791
+
792
+ # Examples
793
+
794
+ ```python
795
+ import rnet
796
+ import asyncio
797
+
798
+ async def run():
799
+ response = await rnet.post("https://httpbin.org/anything")
800
+ body = await response.text()
801
+ print(body)
802
+
803
+ asyncio.run(run())
804
+ ```
805
+ """
806
+
807
+ async def put(
808
+ url: str,
809
+ **kwargs: Unpack[Request],
810
+ ) -> Response:
811
+ r"""
812
+ Shortcut method to quickly make a request.
813
+
814
+ # Examples
815
+
816
+ ```python
817
+ import rnet
818
+ import asyncio
819
+
820
+ async def run():
821
+ response = await rnet.put("https://httpbin.org/anything")
822
+ body = await response.text()
823
+ print(body)
824
+
825
+ asyncio.run(run())
826
+ ```
827
+ """
828
+
829
+ async def request(
830
+ method: Method,
831
+ url: str,
832
+ **kwargs: Unpack[Request],
833
+ ) -> Response:
834
+ r"""
835
+ Make a request with the given parameters.
836
+
837
+ # Arguments
838
+
839
+ * `method` - The method to use for the request.
840
+ * `url` - The URL to send the request to.
841
+ * `**kwargs` - Additional request parameters.
842
+
843
+ # Examples
844
+
845
+ ```python
846
+ import rnet
847
+ import asyncio
848
+ from rnet import Method
849
+
850
+ async def run():
851
+ response = await rnet.request(Method.GET, "https://www.rust-lang.org")
852
+ body = await response.text()
853
+ print(body)
854
+
855
+ asyncio.run(run())
856
+ ```
857
+ """
858
+
859
+ async def trace(
860
+ url: str,
861
+ **kwargs: Unpack[Request],
862
+ ) -> Response:
863
+ r"""
864
+ Shortcut method to quickly make a request.
865
+
866
+ # Examples
867
+
868
+ ```python
869
+ import rnet
870
+ import asyncio
871
+
872
+ async def run():
873
+ response = await rnet.trace("https://httpbin.org/anything")
874
+ print(response.status)
875
+
876
+ asyncio.run(run())
877
+ ```
878
+ """
879
+
880
+ async def websocket(
881
+ url: str,
882
+ **kwargs: Unpack[WebSocketRequest],
883
+ ) -> WebSocket:
884
+ r"""
885
+ Make a WebSocket connection with the given parameters.
886
+
887
+ # Examples
888
+
889
+ ```python
890
+ import rnet
891
+ import asyncio
892
+ from rnet import Message
893
+
894
+ async def run():
895
+ ws = await rnet.websocket("wss://echo.websocket.org")
896
+ await ws.send(Message.from_text("Hello, World!"))
897
+ message = await ws.recv()
898
+ print("Received:", message.data)
899
+ await ws.close()
900
+
901
+ asyncio.run(run())
902
+ ```
903
+ """
904
+
905
+ class Proxy:
906
+ r"""
907
+ A proxy server for a request.
908
+ Supports HTTP, HTTPS, SOCKS4, SOCKS4a, SOCKS5, and SOCKS5h protocols.
909
+ """
910
+
911
+ @staticmethod
912
+ def http(url: str, **kwargs: Unpack[ProxyParams]) -> Proxy:
913
+ r"""
914
+ Creates a new HTTP proxy.
915
+
916
+ This method sets up a proxy server for HTTP requests.
917
+
918
+ # Arguments
919
+
920
+ * `url` - The URL of the proxy server.
921
+ * `username` - Optional username for proxy authentication.
922
+ * `password` - Optional password for proxy authentication.
923
+ * `custom_http_auth` - Optional custom HTTP proxy authentication header value.
924
+ * `custom_http_headers` - Optional custom HTTP proxy headers.
925
+ * `exclusion` - Optional List of domains to exclude from proxying.
926
+
927
+ # Examples
928
+
929
+ ```python
930
+ import rnet
931
+
932
+ proxy = rnet.Proxy.http("http://proxy.example.com")
933
+ ```
934
+ """
935
+
936
+ @staticmethod
937
+ def https(url: str, **kwargs: Unpack[ProxyParams]) -> Proxy:
938
+ r"""
939
+ Creates a new HTTPS proxy.
940
+
941
+ This method sets up a proxy server for HTTPS requests.
942
+
943
+ # Arguments
944
+
945
+ * `url` - The URL of the proxy server.
946
+ * `username` - Optional username for proxy authentication.
947
+ * `password` - Optional password for proxy authentication.
948
+ * `custom_http_auth` - Optional custom HTTP proxy authentication header value.
949
+ * `custom_http_headers` - Optional custom HTTP proxy headers.
950
+ * `exclusion` - Optional List of domains to exclude from proxying.
951
+
952
+ # Examples
953
+
954
+ ```python
955
+ import rnet
956
+
957
+ proxy = rnet.Proxy.https("https://proxy.example.com")
958
+ ```
959
+ """
960
+
961
+ @staticmethod
962
+ def all(url: str, **kwargs: Unpack[ProxyParams]) -> Proxy:
963
+ r"""
964
+ Creates a new proxy for all protocols.
965
+
966
+ This method sets up a proxy server for all types of requests (HTTP, HTTPS, etc.).
967
+
968
+ # Arguments
969
+
970
+ * `url` - The URL of the proxy server.
971
+ * `username` - Optional username for proxy authentication.
972
+ * `password` - Optional password for proxy authentication.
973
+ * `custom_http_auth` - Optional custom HTTP proxy authentication header value.
974
+ * `custom_http_headers` - Optional custom HTTP proxy headers.
975
+ * `exclusion` - Optional List of domains to exclude from proxying.
976
+
977
+ # Examples
978
+
979
+ ```python
980
+ import rnet
981
+
982
+ proxy = rnet.Proxy.all("https://proxy.example.com")
983
+ ```
984
+ """
985
+
986
+ class Message:
987
+ r"""
988
+ A WebSocket message.
989
+ """
990
+
991
+ data: Optional[bytes]
992
+ r"""
993
+ Returns the data of the message as bytes.
994
+ """
995
+ text: Optional[str]
996
+ r"""
997
+ Returns the text content of the message if it is a text message.
998
+ """
999
+ binary: Optional[bytes]
1000
+ r"""
1001
+ Returns the binary data of the message if it is a binary message.
1002
+ """
1003
+ ping: Optional[bytes]
1004
+ r"""
1005
+ Returns the ping data of the message if it is a ping message.
1006
+ """
1007
+ pong: Optional[bytes]
1008
+ r"""
1009
+ Returns the pong data of the message if it is a pong message.
1010
+ """
1011
+ close: Optional[Tuple[int, Optional[str]]]
1012
+ r"""
1013
+ Returns the close code and reason of the message if it is a close message.
1014
+ """
1015
+ def __str__(self) -> str: ...
1016
+ @staticmethod
1017
+ def text_from_json(json: Dict[str, Any]) -> Message:
1018
+ r"""
1019
+ Creates a new text message from the JSON representation.
1020
+
1021
+ # Arguments
1022
+ * `json` - The JSON representation of the message.
1023
+ """
1024
+
1025
+ @staticmethod
1026
+ def binary_from_json(json: Dict[str, Any]) -> Message:
1027
+ r"""
1028
+ Creates a new binary message from the JSON representation.
1029
+
1030
+ # Arguments
1031
+ * `json` - The JSON representation of the message.
1032
+ """
1033
+
1034
+ @staticmethod
1035
+ def from_text(text: str) -> Message:
1036
+ r"""
1037
+ Creates a new text message.
1038
+
1039
+ # Arguments
1040
+
1041
+ * `text` - The text content of the message.
1042
+ """
1043
+
1044
+ @staticmethod
1045
+ def from_binary(data: bytes) -> Message:
1046
+ r"""
1047
+ Creates a new binary message.
1048
+
1049
+ # Arguments
1050
+
1051
+ * `data` - The binary data of the message.
1052
+ """
1053
+
1054
+ @staticmethod
1055
+ def from_ping(data: bytes) -> Message:
1056
+ r"""
1057
+ Creates a new ping message.
1058
+
1059
+ # Arguments
1060
+
1061
+ * `data` - The ping data of the message.
1062
+ """
1063
+
1064
+ @staticmethod
1065
+ def from_pong(data: bytes) -> Message:
1066
+ r"""
1067
+ Creates a new pong message.
1068
+
1069
+ # Arguments
1070
+
1071
+ * `data` - The pong data of the message.
1072
+ """
1073
+
1074
+ @staticmethod
1075
+ def from_close(code: int, reason: Optional[str] = None) -> Message:
1076
+ r"""
1077
+ Creates a new close message.
1078
+
1079
+ # Arguments
1080
+
1081
+ * `code` - The close code.
1082
+ * `reason` - An optional reason for closing.
1083
+ """
1084
+
1085
+ def json(self) -> Dict[str, Any]:
1086
+ r"""
1087
+ Returns the JSON representation of the message.
1088
+ """
1089
+
1090
+ class WebSocket:
1091
+ r"""
1092
+ A WebSocket response.
1093
+ """
1094
+
1095
+ status: StatusCode
1096
+ r"""
1097
+ Returns the status code of the response.
1098
+ """
1099
+ version: Version
1100
+ r"""
1101
+ Returns the HTTP version of the response.
1102
+ """
1103
+ headers: HeaderMap
1104
+ r"""
1105
+ Returns the headers of the response.
1106
+ """
1107
+ cookies: List[Cookie]
1108
+ r"""
1109
+ Returns the cookies of the response.
1110
+ """
1111
+ remote_addr: Optional[SocketAddr]
1112
+ r"""
1113
+ Returns the remote address of the response.
1114
+ """
1115
+ protocol: Optional[str]
1116
+ r"""
1117
+ Returns the WebSocket protocol.
1118
+ """
1119
+ def __aiter__(self) -> WebSocket: ...
1120
+ def __anext__(self) -> Any: ...
1121
+ def __aenter__(self) -> Any: ...
1122
+ def __aexit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> Any: ...
1123
+ async def recv(self) -> Optional[Message]:
1124
+ r"""
1125
+ Receives a message from the WebSocket.
1126
+ """
1127
+
1128
+ async def send(self, message: Message) -> None:
1129
+ r"""
1130
+ Sends a message to the WebSocket.
1131
+
1132
+ # Arguments
1133
+
1134
+ * `message` - The message to send.
1135
+ """
1136
+
1137
+ async def close(
1138
+ self,
1139
+ code: Optional[int] = None,
1140
+ reason: Optional[str] = None,
1141
+ ) -> None:
1142
+ r"""
1143
+ Closes the WebSocket connection.
1144
+
1145
+ # Arguments
1146
+
1147
+ * `code` - An optional close code.
1148
+ * `reason` - An optional reason for closing.
1149
+ """
1150
+
1151
+ class Method(Enum):
1152
+ r"""
1153
+ An HTTP method.
1154
+ """
1155
+
1156
+ GET = auto()
1157
+ HEAD = auto()
1158
+ POST = auto()
1159
+ PUT = auto()
1160
+ DELETE = auto()
1161
+ OPTIONS = auto()
1162
+ TRACE = auto()
1163
+ PATCH = auto()
1164
+
1165
+ class Version(Enum):
1166
+ r"""
1167
+ An HTTP version.
1168
+ """
1169
+
1170
+ HTTP_09 = auto()
1171
+ HTTP_10 = auto()
1172
+ HTTP_11 = auto()
1173
+ HTTP_2 = auto()
1174
+ HTTP_3 = auto()