rnet 2.4.2__cp313-cp313t-macosx_11_0_arm64.whl → 3.0.0rc10__cp313-cp313t-macosx_11_0_arm64.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.
rnet/__init__.pyi CHANGED
@@ -1,6 +1,8 @@
1
+ import datetime
1
2
  import ipaddress
2
- import typing
3
3
  from typing import (
4
+ AsyncGenerator,
5
+ Generator,
4
6
  Optional,
5
7
  Tuple,
6
8
  Union,
@@ -8,311 +10,1096 @@ from typing import (
8
10
  Dict,
9
11
  List,
10
12
  TypedDict,
13
+ Unpack,
14
+ NotRequired,
15
+ final,
11
16
  )
12
17
  from pathlib import Path
13
18
  from enum import Enum, auto
14
19
 
15
- from .blocking import *
20
+ from .http1 import Http1Options
21
+ from .http2 import Http2Options
16
22
  from .cookie import *
17
- from .exceptions import *
18
23
  from .header import *
19
- from .impersonate import *
24
+ from .emulation import *
25
+ from .tls import *
20
26
 
21
- try:
22
- from typing import Unpack, NotRequired
23
- except ImportError:
24
- from typing_extensions import Unpack, NotRequired
27
+ @final
28
+ class Method(Enum):
29
+ r"""
30
+ An HTTP method.
31
+ """
32
+
33
+ GET = auto()
34
+ HEAD = auto()
35
+ POST = auto()
36
+ PUT = auto()
37
+ DELETE = auto()
38
+ OPTIONS = auto()
39
+ TRACE = auto()
40
+ PATCH = auto()
41
+
42
+ @final
43
+ class Version(Enum):
44
+ r"""
45
+ An HTTP version.
46
+ """
47
+
48
+ HTTP_09 = auto()
49
+ HTTP_10 = auto()
50
+ HTTP_11 = auto()
51
+ HTTP_2 = auto()
52
+ HTTP_3 = auto()
53
+
54
+ @final
55
+ class StatusCode:
56
+ r"""
57
+ HTTP status code.
58
+ """
59
+
60
+ def __str__(self) -> str: ...
61
+ def as_int(self) -> int:
62
+ r"""
63
+ Return the status code as an integer.
64
+ """
65
+ ...
66
+
67
+ def is_informational(self) -> bool:
68
+ r"""
69
+ Check if status is within 100-199.
70
+ """
71
+ ...
72
+
73
+ def is_success(self) -> bool:
74
+ r"""
75
+ Check if status is within 200-299.
76
+ """
77
+ ...
78
+
79
+ def is_redirection(self) -> bool:
80
+ r"""
81
+ Check if status is within 300-399.
82
+ """
83
+ ...
84
+
85
+ def is_client_error(self) -> bool:
86
+ r"""
87
+ Check if status is within 400-499.
88
+ """
89
+ ...
90
+
91
+ def is_server_error(self) -> bool:
92
+ r"""
93
+ Check if status is within 500-599.
94
+ """
95
+ ...
96
+
97
+ @final
98
+ class SocketAddr:
99
+ r"""
100
+ A IP socket address.
101
+ """
102
+
103
+ def __str__(self) -> str: ...
104
+ def ip(self) -> Union[ipaddress.IPv4Address, ipaddress.IPv6Address]:
105
+ r"""
106
+ Returns the IP address of the socket address.
107
+ """
108
+
109
+ def port(self) -> int:
110
+ r"""
111
+ Returns the port number of the socket address.
112
+ """
113
+
114
+ @final
115
+ class Multipart:
116
+ r"""
117
+ A multipart form for a request.
118
+ """
119
+
120
+ def __init__(self, *parts: Part) -> None:
121
+ r"""
122
+ Creates a new multipart form.
123
+ """
124
+ ...
125
+
126
+ @final
127
+ class Part:
128
+ r"""
129
+ A part of a multipart form.
130
+ """
131
+
132
+ def __init__(
133
+ self,
134
+ name: str,
135
+ value: Union[
136
+ str,
137
+ bytes,
138
+ Path,
139
+ Generator[bytes, str, None],
140
+ AsyncGenerator[bytes, str],
141
+ ],
142
+ filename: str | None = None,
143
+ mime: str | None = None,
144
+ length: int | None = None,
145
+ headers: HeaderMap | None = None,
146
+ ) -> None:
147
+ r"""
148
+ Creates a new part.
149
+
150
+ # Arguments
151
+ - `name` - The name of the part.
152
+ - `value` - The value of the part, either text, bytes, a file path, or a async or sync stream.
153
+ - `filename` - The filename of the part.
154
+ - `mime` - The MIME type of the part.
155
+ - `length` - The length of the part when value is a stream (e.g., for file uploads).
156
+ - `headers` - The custom headers for the part.
157
+ """
158
+ ...
159
+
160
+ class ProxyParams(TypedDict):
161
+ username: NotRequired[str]
162
+ r"""Username for proxy authentication."""
163
+
164
+ password: NotRequired[str]
165
+ r"""Password for proxy authentication."""
166
+
167
+ custom_http_auth: NotRequired[str]
168
+ r"""Custom HTTP proxy authentication header value."""
169
+
170
+ custom_http_headers: NotRequired[Union[Dict[str, str], HeaderMap]]
171
+ r"""Custom HTTP proxy headers."""
172
+
173
+ exclusion: NotRequired[str]
174
+ r"""List of domains to exclude from proxying."""
175
+
176
+ @final
177
+ class Proxy:
178
+ r"""
179
+ A proxy server for a request.
180
+ Supports HTTP, HTTPS, SOCKS4, SOCKS4a, SOCKS5, and SOCKS5h protocols.
181
+ """
182
+
183
+ @staticmethod
184
+ def http(url: str, **kwargs: Unpack[ProxyParams]) -> "Proxy":
185
+ r"""
186
+ Creates a new HTTP proxy.
187
+
188
+ This method sets up a proxy server for HTTP requests.
189
+
190
+ # Examples
191
+
192
+ ```python
193
+ import rnet
194
+
195
+ proxy = rnet.Proxy.http("http://proxy.example.com")
196
+ ```
197
+ """
198
+
199
+ @staticmethod
200
+ def https(url: str, **kwargs: Unpack[ProxyParams]) -> "Proxy":
201
+ r"""
202
+ Creates a new HTTPS proxy.
203
+
204
+ This method sets up a proxy server for HTTPS requests.
205
+
206
+ # Examples
207
+
208
+ ```python
209
+ import rnet
210
+
211
+ proxy = rnet.Proxy.https("https://proxy.example.com")
212
+ ```
213
+ """
214
+
215
+ @staticmethod
216
+ def all(url: str, **kwargs: Unpack[ProxyParams]) -> "Proxy":
217
+ r"""
218
+ Creates a new proxy for all protocols.
219
+
220
+ This method sets up a proxy server for all types of requests (HTTP, HTTPS, etc.).
221
+
222
+ # Examples
223
+
224
+ ```python
225
+ import rnet
226
+
227
+ proxy = rnet.Proxy.all("https://proxy.example.com")
228
+ ```
229
+ """
230
+
231
+ class Message:
232
+ r"""
233
+ A WebSocket message.
234
+ """
235
+
236
+ data: Optional[bytes]
237
+ r"""
238
+ Returns the data of the message as bytes.
239
+ """
240
+
241
+ text: Optional[str]
242
+ r"""
243
+ Returns the text content of the message if it is a text message.
244
+ """
245
+
246
+ binary: Optional[bytes]
247
+ r"""
248
+ Returns the binary data of the message if it is a binary message.
249
+ """
250
+
251
+ ping: Optional[bytes]
252
+ r"""
253
+ Returns the ping data of the message if it is a ping message.
254
+ """
255
+
256
+ pong: Optional[bytes]
257
+ r"""
258
+ Returns the pong data of the message if it is a pong message.
259
+ """
260
+
261
+ close: Optional[Tuple[int, Optional[str]]]
262
+ r"""
263
+ Returns the close code and reason of the message if it is a close message.
264
+ """
265
+
266
+ @staticmethod
267
+ def text_from_json(json: Dict[str, Any]) -> "Message":
268
+ r"""
269
+ Creates a new text message from the JSON representation.
270
+
271
+ # Arguments
272
+ * `json` - The JSON representation of the message.
273
+ """
274
+ ...
275
+
276
+ @staticmethod
277
+ def binary_from_json(json: Dict[str, Any]) -> "Message":
278
+ r"""
279
+ Creates a new binary message from the JSON representation.
280
+
281
+ # Arguments
282
+ * `json` - The JSON representation of the message.
283
+ """
284
+
285
+ @staticmethod
286
+ def from_text(text: str) -> "Message":
287
+ r"""
288
+ Creates a new text message.
289
+
290
+ # Arguments
291
+
292
+ * `text` - The text content of the message.
293
+ """
294
+
295
+ @staticmethod
296
+ def from_binary(data: bytes) -> "Message":
297
+ r"""
298
+ Creates a new binary message.
299
+
300
+ # Arguments
301
+
302
+ * `data` - The binary data of the message.
303
+ """
304
+
305
+ @staticmethod
306
+ def from_ping(data: bytes) -> "Message":
307
+ r"""
308
+ Creates a new ping message.
309
+
310
+ # Arguments
311
+
312
+ * `data` - The ping data of the message.
313
+ """
314
+
315
+ @staticmethod
316
+ def from_pong(data: bytes) -> "Message":
317
+ r"""
318
+ Creates a new pong message.
319
+
320
+ # Arguments
321
+
322
+ * `data` - The pong data of the message.
323
+ """
324
+
325
+ @staticmethod
326
+ def from_close(code: int, reason: str | None = None) -> "Message":
327
+ r"""
328
+ Creates a new close message.
329
+
330
+ # Arguments
331
+
332
+ * `code` - The close code.
333
+ * `reason` - An optional reason for closing.
334
+ """
335
+
336
+ def json(self) -> Dict[str, Any]:
337
+ r"""
338
+ Returns the JSON representation of the message.
339
+ """
340
+
341
+ def __str__(self) -> str: ...
342
+
343
+ @final
344
+ class History:
345
+ """
346
+ An entry in the redirect history.
347
+ """
348
+
349
+ status: int
350
+ """Get the status code of the redirect response."""
351
+
352
+ url: str
353
+ """Get the URL of the redirect response."""
354
+
355
+ previous: str
356
+ """Get the previous URL before the redirect response."""
357
+
358
+ headers: HeaderMap
359
+ """Get the headers of the redirect response."""
360
+
361
+ def __str__(self) -> str: ...
362
+
363
+ class Streamer:
364
+ r"""
365
+ A byte stream response.
366
+ An asynchronous iterator yielding data chunks from the response stream.
367
+ Used to stream response content.
368
+ Implemented in the `stream` method of the `Response` class.
369
+ Can be used in an asynchronous for loop in Python.
370
+
371
+ # Examples
372
+
373
+ ```python
374
+ import asyncio
375
+ import rnet
376
+ from rnet import Method, Emulation
377
+
378
+ async def main():
379
+ resp = await rnet.get("https://httpbin.org/stream/20")
380
+ async with resp.stream() as streamer:
381
+ async for chunk in streamer:
382
+ print("Chunk: ", chunk)
383
+ await asyncio.sleep(0.1)
384
+
385
+ if __name__ == "__main__":
386
+ asyncio.run(main())
387
+ ```
388
+ """
389
+
390
+ async def __aiter__(self) -> "Streamer": ...
391
+ async def __anext__(self) -> Optional[bytes]: ...
392
+ async def __aenter__(self) -> Any: ...
393
+ async def __aexit__(
394
+ self, _exc_type: Any, _exc_value: Any, _traceback: Any
395
+ ) -> Any: ...
396
+ def __iter__(self) -> "Streamer": ...
397
+ def __next__(self) -> bytes: ...
398
+ def __enter__(self) -> "Streamer": ...
399
+ def __exit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> None: ...
400
+
401
+ class Response:
402
+ r"""
403
+ A response from a request.
404
+
405
+ # Examples
406
+
407
+ ```python
408
+ import asyncio
409
+ import rnet
410
+
411
+ async def main():
412
+ response = await rnet.get("https://www.rust-lang.org")
413
+ print("Status Code: ", response.status)
414
+ print("Version: ", response.version)
415
+ print("Response URL: ", response.url)
416
+ print("Headers: ", response.headers)
417
+ print("Content-Length: ", response.content_length)
418
+ print("Encoding: ", response.encoding)
419
+ print("Remote Address: ", response.remote_addr)
420
+
421
+ text_content = await response.text()
422
+ print("Text: ", text_content)
423
+
424
+ if __name__ == "__main__":
425
+ asyncio.run(main())
426
+ ```
427
+ """
428
+
429
+ url: str
430
+ r"""
431
+ Get the URL of the response.
432
+ """
433
+
434
+ status: StatusCode
435
+ r"""
436
+ Get the status code of the response.
437
+ """
438
+
439
+ version: Version
440
+ r"""
441
+ Get the HTTP version of the response.
442
+ """
443
+
444
+ headers: HeaderMap
445
+ r"""
446
+ Get the headers of the response.
447
+ """
448
+
449
+ cookies: List[Cookie]
450
+ r"""
451
+ Get the cookies of the response.
452
+ """
453
+
454
+ content_length: Optional[int]
455
+ r"""
456
+ Get the content length of the response.
457
+ """
458
+
459
+ remote_addr: Optional[SocketAddr]
460
+ r"""
461
+ Get the remote address of the response.
462
+ """
463
+
464
+ local_addr: Optional[SocketAddr]
465
+ r"""
466
+ Get the local address of the response.
467
+ """
468
+
469
+ history: List[History]
470
+ r"""
471
+ Get the redirect history of the Response.
472
+ """
473
+
474
+ peer_certificate: Optional[bytes]
475
+ r"""
476
+ Get the DER encoded leaf certificate of the response.
477
+ """
478
+
479
+ def raise_for_status(self) -> None:
480
+ r"""
481
+ Turn a response into an error if the server returned an error.
482
+ """
483
+
484
+ def stream(self) -> Streamer:
485
+ r"""
486
+ Get the response into a `Streamer` of `bytes` from the body.
487
+ """
488
+
489
+ async def text(self) -> str:
490
+ r"""
491
+ Get the text content of the response.
492
+ """
493
+
494
+ async def text_with_charset(self, encoding: str) -> str:
495
+ r"""
496
+ Get the full response text given a specific encoding.
497
+ """
498
+
499
+ async def json(self) -> Any:
500
+ r"""
501
+ Get the JSON content of the response.
502
+ """
503
+
504
+ async def bytes(self) -> bytes:
505
+ r"""
506
+ Get the bytes content of the response.
507
+ """
508
+
509
+ async def close(self) -> None:
510
+ r"""
511
+ Close the response connection.
512
+ """
513
+
514
+ async def __aenter__(self) -> Any: ...
515
+ async def __aexit__(
516
+ self, _exc_type: Any, _exc_value: Any, _traceback: Any
517
+ ) -> Any: ...
518
+
519
+ class WebSocket:
520
+ r"""
521
+ A WebSocket response.
522
+ """
523
+
524
+ status: StatusCode
525
+ r"""
526
+ Get the status code of the response.
527
+ """
528
+
529
+ version: Version
530
+ r"""
531
+ Get the HTTP version of the response.
532
+ """
533
+
534
+ headers: HeaderMap
535
+ r"""
536
+ Get the headers of the response.
537
+ """
538
+
539
+ cookies: List[Cookie]
540
+ r"""
541
+ Get the cookies of the response.
542
+ """
543
+
544
+ remote_addr: Optional[SocketAddr]
545
+ r"""
546
+ Get the remote address of the response.
547
+ """
548
+
549
+ protocol: Optional[str]
550
+ r"""
551
+ Get the WebSocket protocol.
552
+ """
553
+
554
+ async def recv(
555
+ self, timeout: datetime.timedelta | None = None
556
+ ) -> Optional[Message]:
557
+ r"""
558
+ Receive a message from the WebSocket.
559
+ """
560
+
561
+ async def send(self, message: Message) -> None:
562
+ r"""
563
+ Send a message to the WebSocket.
564
+ """
565
+
566
+ async def send_all(self, messages: List[Message]) -> None:
567
+ r"""
568
+ Send multiple messages to the WebSocket.
569
+ """
570
+
571
+ async def close(
572
+ self,
573
+ code: int | None = None,
574
+ reason: str | None = None,
575
+ ) -> None:
576
+ r"""
577
+ Close the WebSocket connection.
578
+ """
579
+
580
+ def __aenter__(self) -> Any: ...
581
+ def __aexit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> Any: ...
582
+
583
+ class ClientParams(TypedDict):
584
+ emulation: NotRequired[Union[Emulation, EmulationOption]]
585
+ """Emulation config."""
586
+
587
+ user_agent: NotRequired[str]
588
+ """
589
+ Default User-Agent string.
590
+ """
591
+
592
+ headers: NotRequired[Union[Dict[str, str], HeaderMap]]
593
+ """
594
+ Default request headers.
595
+ """
596
+
597
+ orig_headers: NotRequired[Union[List[str], OrigHeaderMap]]
598
+ """
599
+ Original request headers (case-sensitive and order).
600
+ """
601
+
602
+ referer: NotRequired[bool]
603
+ """
604
+ Automatically set Referer.
605
+ """
606
+
607
+ history: NotRequired[bool]
608
+ """
609
+ Store redirect history.
610
+ """
611
+
612
+ allow_redirects: NotRequired[bool]
613
+ """
614
+ Allow automatic redirects.
615
+ """
616
+
617
+ max_redirects: NotRequired[int]
618
+ """
619
+ Maximum number of redirects.
620
+ """
621
+
622
+ cookie_store: NotRequired[bool]
623
+ """
624
+ Enable cookie store.
625
+ """
626
+
627
+ cookie_provider: NotRequired[Jar]
628
+ """
629
+ Custom cookie provider.
630
+ """
631
+
632
+ lookup_ip_strategy: NotRequired[str]
633
+ """
634
+ IP lookup strategy.
635
+ """
636
+
637
+ timeout: NotRequired[int]
638
+ """
639
+ Total timeout (seconds).
640
+ """
641
+
642
+ connect_timeout: NotRequired[int]
643
+ """
644
+ Connection timeout (seconds).
645
+ """
646
+
647
+ read_timeout: NotRequired[int]
648
+ """
649
+ Read timeout (seconds).
650
+ """
651
+
652
+ tcp_keepalive: NotRequired[int]
653
+ """
654
+ TCP keepalive time (seconds).
655
+ """
656
+
657
+ tcp_keepalive_interval: NotRequired[int]
658
+ """
659
+ TCP keepalive interval (seconds).
660
+ """
661
+
662
+ tcp_keepalive_retries: NotRequired[int]
663
+ """
664
+ TCP keepalive retry count.
665
+ """
666
+
667
+ tcp_user_timeout: NotRequired[int]
668
+ """
669
+ TCP user timeout (seconds).
670
+ """
671
+
672
+ tcp_nodelay: NotRequired[bool]
673
+ """
674
+ Enable TCP_NODELAY.
675
+ """
676
+
677
+ tcp_reuse_address: NotRequired[bool]
678
+ """
679
+ Enable SO_REUSEADDR.
680
+ """
681
+
682
+ pool_idle_timeout: NotRequired[int]
683
+ """
684
+ Connection pool idle timeout (seconds).
685
+ """
686
+
687
+ pool_max_idle_per_host: NotRequired[int]
688
+ """
689
+ Max idle connections per host.
690
+ """
691
+
692
+ pool_max_size: NotRequired[int]
693
+ """
694
+ Max total connections in pool.
695
+ """
696
+
697
+ http1_only: NotRequired[bool]
698
+ """
699
+ Enable HTTP/1.1 only.
700
+ """
701
+
702
+ http2_only: NotRequired[bool]
703
+ """
704
+ Enable HTTP/2 only.
705
+ """
706
+
707
+ https_only: NotRequired[bool]
708
+ """
709
+ Enable HTTPS only.
710
+ """
711
+
712
+ http1_options: NotRequired[Http1Options]
713
+ """
714
+ Sets the HTTP/1 options.
715
+ """
716
+
717
+ http2_options: NotRequired[Http2Options]
718
+ """
719
+ Sets the HTTP/2 options.
720
+ """
721
+
722
+ verify: NotRequired[Union[bool, Path, CertStore]]
723
+ """
724
+ Verify SSL or specify CA path.
725
+ """
726
+
727
+ verify_hostname: NotRequired[bool]
728
+ """
729
+ Configures the use of hostname verification when connecting.
730
+ """
731
+
732
+ identity: NotRequired[Identity]
733
+ """
734
+ Represents a private key and X509 cert as a client certificate.
735
+ """
736
+
737
+ keylog: NotRequired[KeyLog]
738
+ """
739
+ Key logging policy (environment or file).
740
+ """
741
+
742
+ tls_info: NotRequired[bool]
743
+ """
744
+ Return TLS info.
745
+ """
746
+
747
+ min_tls_version: NotRequired[TlsVersion]
748
+ """
749
+ Minimum TLS version.
750
+ """
751
+
752
+ max_tls_version: NotRequired[TlsVersion]
753
+ """
754
+ Maximum TLS version.
755
+ """
756
+
757
+ tls_options: NotRequired[TlsOptions]
758
+ """
759
+ Sets the TLS options.
760
+ """
761
+
762
+ no_proxy: NotRequired[bool]
763
+ """
764
+ Disable proxy.
765
+ """
766
+
767
+ proxies: NotRequired[List[Proxy]]
768
+ """
769
+ Proxy server list.
770
+ """
771
+
772
+ local_address: NotRequired[Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address]]
773
+ """
774
+ Local bind address.
775
+ """
776
+
777
+ interface: NotRequired[str]
778
+ """
779
+ Local network interface.
780
+ """
781
+
782
+ gzip: NotRequired[bool]
783
+ """
784
+ Enable gzip decompression.
785
+ """
786
+
787
+ brotli: NotRequired[bool]
788
+ """
789
+ Enable brotli decompression.
790
+ """
791
+
792
+ deflate: NotRequired[bool]
793
+ """
794
+ Enable deflate decompression.
795
+ """
796
+
797
+ zstd: NotRequired[bool]
798
+ """
799
+ Enable zstd decompression.
800
+ """
801
+
802
+ class Request(TypedDict):
803
+ emulation: NotRequired[Union[Emulation, EmulationOption]]
804
+ """
805
+ The Emulation settings for the request.
806
+ """
807
+
808
+ proxy: NotRequired[Proxy]
809
+ """
810
+ The proxy to use for the request.
811
+ """
25
812
 
26
- class RequestParams(TypedDict, closed=True):
27
- proxy: NotRequired[Union[str, Proxy]]
28
813
  local_address: NotRequired[Union[ipaddress.IPv4Address, ipaddress.IPv6Address]]
814
+ """
815
+ Bind to a local IP Address.
816
+ """
817
+
29
818
  interface: NotRequired[str]
819
+ """
820
+ Bind to an interface by SO_BINDTODEVICE.
821
+ """
822
+
30
823
  timeout: NotRequired[int]
824
+ """
825
+ The timeout to use for the request.
826
+ """
827
+
31
828
  read_timeout: NotRequired[int]
829
+ """
830
+ The read timeout to use for the request.
831
+ """
832
+
32
833
  version: NotRequired[Version]
834
+ """
835
+ The HTTP version to use for the request.
836
+ """
837
+
33
838
  headers: NotRequired[Union[Dict[str, str], HeaderMap]]
839
+ """
840
+ The headers to use for the request.
841
+ """
842
+
843
+ orig_headers: NotRequired[Union[List[str], OrigHeaderMap]]
844
+ """
845
+ The original headers to use for the request.
846
+ """
847
+
848
+ default_headers: NotRequired[bool]
849
+ """
850
+ The option enables default headers.
851
+ """
852
+
34
853
  cookies: NotRequired[Dict[str, str]]
854
+ """
855
+ The cookies to use for the request.
856
+ """
857
+
35
858
  allow_redirects: NotRequired[bool]
859
+ """
860
+ Whether to allow redirects.
861
+ """
862
+
36
863
  max_redirects: NotRequired[int]
864
+ """
865
+ The maximum number of redirects to follow.
866
+ """
867
+
868
+ gzip: NotRequired[bool]
869
+ """
870
+ Sets gzip as an accepted encoding.
871
+ """
872
+
873
+ brotli: NotRequired[bool]
874
+ """
875
+ Sets brotli as an accepted encoding.
876
+ """
877
+
878
+ deflate: NotRequired[bool]
879
+ """
880
+ Sets deflate as an accepted encoding.
881
+ """
882
+
883
+ zstd: NotRequired[bool]
884
+ """
885
+ Sets zstd as an accepted encoding.
886
+ """
887
+
37
888
  auth: NotRequired[str]
889
+ """
890
+ The authentication to use for the request.
891
+ """
892
+
38
893
  bearer_auth: NotRequired[str]
894
+ """
895
+ The bearer authentication to use for the request.
896
+ """
897
+
39
898
  basic_auth: NotRequired[Tuple[str, Optional[str]]]
899
+ """
900
+ The basic authentication to use for the request.
901
+ """
902
+
40
903
  query: NotRequired[List[Tuple[str, str]]]
41
- form: NotRequired[List[Tuple[str, str]]]
904
+ """
905
+ The query parameters to use for the request.
906
+ """
907
+
908
+ form: NotRequired[Union[List[Tuple[str, str]], Dict[str, str]]]
909
+ """
910
+ The form parameters to use for the request.
911
+ """
912
+
42
913
  json: NotRequired[Dict[str, Any]]
914
+ """
915
+ The JSON body to use for the request.
916
+ """
917
+
43
918
  body: NotRequired[
44
919
  Union[
45
920
  str,
46
921
  bytes,
47
- typing.AsyncGenerator[bytes, str],
48
- typing.Generator[bytes, str],
922
+ Generator[bytes, str, None],
923
+ AsyncGenerator[bytes, str],
49
924
  ]
50
925
  ]
926
+ """
927
+ The body to use for the request.
928
+ """
929
+
51
930
  multipart: NotRequired[Multipart]
931
+ """
932
+ The multipart form to use for the request.
933
+ """
52
934
 
53
- class WebSocketParams(TypedDict, closed=True):
54
- proxy: NotRequired[Union[str, Proxy]]
55
- local_address: NotRequired[Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address]]
56
- interface: NotRequired[str]
57
- headers: NotRequired[Union[Dict[str, str], HeaderMap]]
58
- cookies: NotRequired[Dict[str, str]]
59
- protocols: NotRequired[List[str]]
60
- use_http2: NotRequired[bool]
61
- auth: NotRequired[str]
62
- bearer_auth: NotRequired[str]
63
- basic_auth: NotRequired[Tuple[str, Optional[str]]]
64
- query: NotRequired[List[Tuple[str, str]]]
65
- read_buffer_size: NotRequired[int]
66
- write_buffer_size: NotRequired[int]
67
- max_write_buffer_size: NotRequired[int]
68
- max_message_size: NotRequired[int]
69
- max_frame_size: NotRequired[int]
70
- accept_unmasked_frames: NotRequired[bool]
935
+ class WebSocketRequest(TypedDict):
936
+ emulation: NotRequired[Union[Emulation, EmulationOption]]
937
+ """
938
+ The Emulation settings for the request.
939
+ """
71
940
 
72
- class ProxyParams(TypedDict, closed=True):
73
- username: NotRequired[str]
74
- password: NotRequired[str]
75
- custom_http_auth: NotRequired[str]
76
- custom_http_headers: NotRequired[Union[Dict[str, str], HeaderMap]]
77
- exclusion: NotRequired[str]
941
+ proxy: NotRequired[Proxy]
942
+ """
943
+ The proxy to use for the request.
944
+ """
78
945
 
79
- class Client:
80
- r"""
81
- A client for making HTTP requests.
946
+ local_address: NotRequired[Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address]]
947
+ """
948
+ Bind to a local IP Address.
82
949
  """
83
950
 
84
- user_agent: Optional[str]
85
- r"""
86
- Returns the user agent of the client.
87
-
88
- # Examples
89
-
90
- ```python
91
- import rnet
92
-
93
- client = rnet.Client()
94
- user_agent = client.user_agent()
95
- print(user_agent)
96
- ```
951
+ interface: NotRequired[str]
97
952
  """
98
- headers: HeaderMap
99
- r"""
100
- Returns the headers of the client.
101
-
102
- # Examples
103
-
104
- ```python
105
- import rnet
106
-
107
- client = rnet.Client()
108
- headers = client.headers()
109
- print(headers)
110
- ```
953
+ Bind to an interface by SO_BINDTODEVICE.
111
954
  """
112
- def __new__(
113
- cls,
114
- impersonate: Optional[Union[Impersonate, ImpersonateOption]] = None,
115
- user_agent: Optional[str] = None,
116
- default_headers: Optional[Union[Dict[str, str], HeaderMap]] = None,
117
- headers_order: Optional[List[str]] = None,
118
- referer: Optional[bool] = None,
119
- allow_redirects: Optional[bool] = None,
120
- max_redirects: Optional[int] = None,
121
- cookie_store: Optional[bool] = None,
122
- lookup_ip_strategy: Optional[LookupIpStrategy] = None,
123
- timeout: Optional[int] = None,
124
- connect_timeout: Optional[int] = None,
125
- read_timeout: Optional[int] = None,
126
- no_keepalive: Optional[bool] = None,
127
- tcp_keepalive: Optional[int] = None,
128
- tcp_keepalive_interval: Optional[int] = None,
129
- tcp_keepalive_retries: Optional[int] = None,
130
- tcp_user_timeout: Optional[int] = None,
131
- pool_idle_timeout: Optional[int] = None,
132
- pool_max_idle_per_host: Optional[int] = None,
133
- pool_max_size: Optional[int] = None,
134
- http1_only: Optional[bool] = None,
135
- http2_only: Optional[bool] = None,
136
- https_only: Optional[bool] = None,
137
- tcp_nodelay: Optional[bool] = None,
138
- http2_max_retry_count: Optional[int] = None,
139
- verify: Optional[Union[bool, Path]] = None,
140
- tls_info: Optional[bool] = None,
141
- min_tls_version: Optional[TlsVersion] = None,
142
- max_tls_version: Optional[TlsVersion] = None,
143
- no_proxy: Optional[bool] = None,
144
- proxies: Optional[List[Proxy]] = None,
145
- local_address: Optional[
146
- Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address]
147
- ] = None,
148
- interface: Optional[str] = None,
149
- gzip: Optional[bool] = None,
150
- brotli: Optional[bool] = None,
151
- deflate: Optional[bool] = None,
152
- zstd: Optional[bool] = None,
153
- ) -> Client:
154
- r"""
155
- Creates a new Client instance.
156
955
 
157
- Args:
158
- impersonate: Browser fingerprint/impersonation config.
159
- user_agent: Default User-Agent string.
160
- default_headers: Default request headers.
161
- headers_order: Custom header order.
162
- referer: Automatically set Referer.
163
- allow_redirects: Allow automatic redirects.
164
- max_redirects: Maximum number of redirects.
165
- cookie_store: Enable cookie store.
166
- lookup_ip_strategy: IP lookup strategy.
167
- timeout: Total timeout (seconds).
168
- connect_timeout: Connection timeout (seconds).
169
- read_timeout: Read timeout (seconds).
170
- no_keepalive: Disable HTTP keep-alive.
171
- tcp_keepalive: TCP keepalive time (seconds).
172
- tcp_keepalive_interval: TCP keepalive interval (seconds).
173
- tcp_keepalive_retries: TCP keepalive retry count.
174
- tcp_user_timeout: TCP user timeout (seconds).
175
- pool_idle_timeout: Connection pool idle timeout (seconds).
176
- pool_max_idle_per_host: Max idle connections per host.
177
- pool_max_size: Max total connections in pool.
178
- http1_only: Enable HTTP/1.1 only.
179
- http2_only: Enable HTTP/2 only.
180
- https_only: Enable HTTPS only.
181
- tcp_nodelay: Enable TCP_NODELAY.
182
- http2_max_retry_count: Max HTTP/2 retry count.
183
- verify: Verify SSL or specify CA path.
184
- tls_info: Return TLS info.
185
- min_tls_version: Minimum TLS version.
186
- max_tls_version: Maximum TLS version.
187
- no_proxy: Disable proxy.
188
- proxies: Proxy server list.
189
- local_address: Local bind address.
190
- interface: Local network interface.
191
- gzip: Enable gzip decompression.
192
- brotli: Enable brotli decompression.
193
- deflate: Enable deflate decompression.
194
- zstd: Enable zstd decompression.
956
+ headers: NotRequired[Union[Dict[str, str], HeaderMap]]
957
+ """
958
+ The headers to use for the request.
959
+ """
195
960
 
196
- Examples:
961
+ orig_headers: NotRequired[Union[List[str], OrigHeaderMap]]
962
+ """
963
+ The original headers to use for the request.
964
+ """
197
965
 
198
- ```python
199
- import asyncio
200
- import rnet
966
+ default_headers: NotRequired[bool]
967
+ """
968
+ The option enables default headers.
969
+ """
201
970
 
202
- client = rnet.Client(
203
- user_agent="my-app/0.0.1",
204
- timeout=10,
205
- )
206
- response = await client.get('https://httpbin.org/get')
207
- print(response.text)
208
- ```
209
- """
971
+ cookies: NotRequired[Dict[str, str]]
972
+ """
973
+ The cookies to use for the request.
974
+ """
210
975
 
211
- def get_cookies(self, url: str) -> Optional[bytes]:
212
- r"""
213
- Returns the cookies for the given URL.
976
+ protocols: NotRequired[List[str]]
977
+ """
978
+ The protocols to use for the request.
979
+ """
214
980
 
215
- # Arguments
981
+ force_http2: NotRequired[bool]
982
+ """
983
+ Whether to use HTTP/2 for the websocket.
984
+ """
216
985
 
217
- * `url` - The URL to get the cookies for.
986
+ auth: NotRequired[str]
987
+ """
988
+ The authentication to use for the request.
989
+ """
990
+
991
+ bearer_auth: NotRequired[str]
992
+ """
993
+ The bearer authentication to use for the request.
994
+ """
218
995
 
219
- # Returns
996
+ basic_auth: NotRequired[Tuple[str, Optional[str]]]
997
+ """
998
+ The basic authentication to use for the request.
999
+ """
220
1000
 
221
- A List of cookie strings.
1001
+ query: NotRequired[List[Tuple[str, str]]]
1002
+ """
1003
+ The query parameters to use for the request.
1004
+ """
222
1005
 
223
- # Examples
1006
+ read_buffer_size: NotRequired[int]
1007
+ """
1008
+ Read buffer capacity. This buffer is eagerly allocated and used for receiving messages.
224
1009
 
225
- ```python
226
- import rnet
1010
+ For high read load scenarios a larger buffer, e.g. 128 KiB, improves performance.
227
1011
 
228
- client = rnet.Client(cookie_store=True)
229
- cookies = client.get_cookies("https://example.com")
230
- print(cookies)
231
- ```
232
- """
1012
+ For scenarios where you expect a lot of connections and don't need high read load
1013
+ performance a smaller buffer, e.g. 4 KiB, would be appropriate to lower total
1014
+ memory usage.
233
1015
 
234
- def set_cookie(self, url: str, cookie: Cookie) -> None:
235
- r"""
236
- Sets the cookies for the given URL.
1016
+ The default value is 128 KiB.
1017
+ """
237
1018
 
238
- # Arguments
239
- * `url` - The URL to set the cookies for.
240
- * `cookie` - The cookie to set.
1019
+ write_buffer_size: NotRequired[int]
1020
+ """
1021
+ The target minimum size of the write buffer to reach before writing the data
1022
+ to the underlying stream. The default value is 128 KiB.
241
1023
 
242
- # Examples
1024
+ If set to 0 each message will be eagerly written to the underlying stream.
1025
+ It is often more optimal to allow them to buffer a little, hence the default value.
243
1026
 
244
- ```python
245
- import rnet
1027
+ Note: flush() will always fully write the buffer regardless.
1028
+ """
246
1029
 
247
- client = rnet.Client(cookie_store=True)
248
- client.set_cookie("https://example.com", rnet.Cookie(name="foo", value="bar"))
249
- ```
250
- """
1030
+ max_write_buffer_size: NotRequired[int]
1031
+ """
1032
+ The max size of the write buffer in bytes. Setting this can provide backpressure
1033
+ in the case the write buffer is filling up due to write errors.
1034
+ The default value is unlimited.
251
1035
 
252
- def remove_cookie(self, url: str, name: str) -> None:
253
- r"""
254
- Removes the cookie with the given name for the given URL.
1036
+ Note: The write buffer only builds up past write_buffer_size when writes to the
1037
+ underlying stream are failing. So the write buffer can not fill up if you are not
1038
+ observing write errors even if not flushing.
255
1039
 
256
- # Arguments
257
- * `url` - The URL to remove the cookie from.
258
- * `name` - The name of the cookie to remove.
1040
+ Note: Should always be at least write_buffer_size + 1 message and probably a little
1041
+ more depending on error handling strategy.
1042
+ """
259
1043
 
260
- # Examples
1044
+ max_message_size: NotRequired[int]
1045
+ """
1046
+ The maximum size of an incoming message. None means no size limit.
1047
+ The default value is 64 MiB which should be reasonably big for all normal use-cases
1048
+ but small enough to prevent memory eating by a malicious user.
1049
+ """
261
1050
 
262
- ```python
263
- import rnet
1051
+ max_frame_size: NotRequired[int]
1052
+ """
1053
+ The maximum size of a single incoming message frame. None means no size limit.
1054
+ The limit is for frame payload NOT including the frame header.
1055
+ The default value is 16 MiB which should be reasonably big for all normal use-cases
1056
+ but small enough to prevent memory eating by a malicious user.
1057
+ """
264
1058
 
265
- client = rnet.Client(cookie_store=True)
266
- client.remove_cookie("https://example.com", "foo")
267
- """
1059
+ accept_unmasked_frames: NotRequired[bool]
1060
+ """
1061
+ When set to True, the server will accept and handle unmasked frames from the client.
1062
+ According to RFC 6455, the server must close the connection to the client in such cases,
1063
+ however it seems like there are some popular libraries that are sending unmasked frames,
1064
+ ignoring the RFC. By default this option is set to False, i.e. according to RFC6455.
1065
+ """
268
1066
 
269
- def clear_cookies(self) -> None:
270
- r"""
271
- Clears the cookies for the given URL.
272
- """
1067
+ class Client:
1068
+ r"""
1069
+ A client for making HTTP requests.
1070
+ """
273
1071
 
274
- def update(
1072
+ def __init__(
275
1073
  self,
276
- impersonate: Optional[Union[Impersonate, ImpersonateOption]] = None,
277
- headers: Optional[Union[Dict[str, str], HeaderMap]] = None,
278
- headers_order: Optional[List[str]] = None,
279
- proxies: Optional[List[Proxy]] = None,
280
- local_address: Optional[
281
- Union[ipaddress.IPv4Address, ipaddress.IPv6Address]
282
- ] = None,
283
- interface: Optional[str] = None,
1074
+ **kwargs: Unpack[ClientParams],
284
1075
  ) -> None:
285
1076
  r"""
286
- Updates the client with the given parameters.
287
-
288
- # Arguments
289
-
290
- * `impersonate` - The impersonation settings for the request.
291
- * `headers` - The headers to use for the request.
292
- * `headers_order` - The order of the headers to use for the request.
293
- * `proxies` - The proxy to use for the request.
294
- * `local_address` - The local IP address to bind to.
295
- * `interface` - The interface to bind to.
1077
+ Creates a new Client instance.
296
1078
 
297
- # Examples
1079
+ Examples:
298
1080
 
299
1081
  ```python
1082
+ import asyncio
300
1083
  import rnet
301
1084
 
302
- client = rnet.Client()
303
- client.update(
304
- impersonate=rnet.Impersonate.Firefox135,
305
- headers={"X-My-Header": "value"},
306
- proxies=[rnet.Proxy.all("http://proxy.example.com:8080")],
307
- )
1085
+ async def main():
1086
+ client = rnet.Client(
1087
+ user_agent="Mozilla/5.0",
1088
+ timeout=10,
1089
+ )
1090
+ response = await client.get('https://httpbin.org/get')
1091
+ print(await response.text())
1092
+
1093
+ asyncio.run(main())
308
1094
  ```
309
1095
  """
1096
+ ...
310
1097
 
311
1098
  async def request(
312
1099
  self,
313
1100
  method: Method,
314
1101
  url: str,
315
- **kwargs: Unpack[RequestParams],
1102
+ **kwargs: Unpack[Request],
316
1103
  ) -> Response:
317
1104
  r"""
318
1105
  Sends a request with the given method and URL.
@@ -336,7 +1123,7 @@ class Client:
336
1123
  async def websocket(
337
1124
  self,
338
1125
  url: str,
339
- **kwargs: Unpack[WebSocketParams],
1126
+ **kwargs: Unpack[WebSocketRequest],
340
1127
  ) -> WebSocket:
341
1128
  r"""
342
1129
  Sends a WebSocket request.
@@ -362,7 +1149,7 @@ class Client:
362
1149
  async def trace(
363
1150
  self,
364
1151
  url: str,
365
- **kwargs: Unpack[RequestParams],
1152
+ **kwargs: Unpack[Request],
366
1153
  ) -> Response:
367
1154
  r"""
368
1155
  Sends a request with the given URL
@@ -386,7 +1173,7 @@ class Client:
386
1173
  async def options(
387
1174
  self,
388
1175
  url: str,
389
- **kwargs: Unpack[RequestParams],
1176
+ **kwargs: Unpack[Request],
390
1177
  ) -> Response:
391
1178
  r"""
392
1179
  Sends a request with the given URL
@@ -410,7 +1197,7 @@ class Client:
410
1197
  async def patch(
411
1198
  self,
412
1199
  url: str,
413
- **kwargs: Unpack[RequestParams],
1200
+ **kwargs: Unpack[Request],
414
1201
  ) -> Response:
415
1202
  r"""
416
1203
  Sends a request with the given URL
@@ -434,7 +1221,7 @@ class Client:
434
1221
  async def delete(
435
1222
  self,
436
1223
  url: str,
437
- **kwargs: Unpack[RequestParams],
1224
+ **kwargs: Unpack[Request],
438
1225
  ) -> Response:
439
1226
  r"""
440
1227
  Sends a request with the given URL
@@ -458,7 +1245,7 @@ class Client:
458
1245
  async def put(
459
1246
  self,
460
1247
  url: str,
461
- **kwargs: Unpack[RequestParams],
1248
+ **kwargs: Unpack[Request],
462
1249
  ) -> Response:
463
1250
  r"""
464
1251
  Sends a request with the given URL
@@ -482,7 +1269,7 @@ class Client:
482
1269
  async def post(
483
1270
  self,
484
1271
  url: str,
485
- **kwargs: Unpack[RequestParams],
1272
+ **kwargs: Unpack[Request],
486
1273
  ) -> Response:
487
1274
  r"""
488
1275
  Sends a request with the given URL
@@ -506,7 +1293,7 @@ class Client:
506
1293
  async def head(
507
1294
  self,
508
1295
  url: str,
509
- **kwargs: Unpack[RequestParams],
1296
+ **kwargs: Unpack[Request],
510
1297
  ) -> Response:
511
1298
  r"""
512
1299
  Sends a request with the given URL
@@ -530,7 +1317,7 @@ class Client:
530
1317
  async def get(
531
1318
  self,
532
1319
  url: str,
533
- **kwargs: Unpack[RequestParams],
1320
+ **kwargs: Unpack[Request],
534
1321
  ) -> Response:
535
1322
  r"""
536
1323
  Sends a request with the given URL
@@ -540,261 +1327,20 @@ class Client:
540
1327
  ```python
541
1328
  import rnet
542
1329
  import asyncio
543
- from rnet import Method
544
-
545
- async def main():
546
- client = rnet.Client()
547
- response = await client.get("https://httpbin.org/anything")
548
- print(await response.text())
549
-
550
- asyncio.run(main())
551
- ```
552
- """
553
-
554
- class Multipart:
555
- r"""
556
- A multipart form for a request.
557
- """
558
-
559
- def __new__(cls, *parts) -> Multipart:
560
- r"""
561
- Creates a new multipart form.
562
- """
563
-
564
- class Part:
565
- r"""
566
- A part of a multipart form.
567
- """
568
-
569
- def __new__(
570
- cls,
571
- name: str,
572
- value: Union[
573
- str,
574
- bytes,
575
- Path,
576
- typing.AsyncGenerator[bytes, str],
577
- typing.Generator[bytes, str],
578
- ],
579
- filename: Optional[str] = None,
580
- mime: Optional[str] = None,
581
- ) -> Part:
582
- r"""
583
- Creates a new part.
584
-
585
- # Arguments
586
- - `name` - The name of the part.
587
- - `value` - The value of the part, either text, bytes, a file path, or a async or sync stream.
588
- - `filename` - The filename of the part.
589
- - `mime` - The MIME type of the part.
590
- """
591
-
592
- class Response:
593
- r"""
594
- A response from a request.
595
-
596
- # Examples
597
-
598
- ```python
599
- import asyncio
600
- import rnet
601
-
602
- async def main():
603
- response = await rnet.get("https://www.rust-lang.org")
604
- print("Status Code: ", response.status_code)
605
- print("Version: ", response.version)
606
- print("Response URL: ", response.url)
607
- print("Headers: ", response.headers)
608
- print("Content-Length: ", response.content_length)
609
- print("Encoding: ", response.encoding)
610
- print("Remote Address: ", response.remote_addr)
611
-
612
- text_content = await response.text()
613
- print("Text: ", text_content)
614
-
615
- if __name__ == "__main__":
616
- asyncio.run(main())
617
- ```
618
- """
619
-
620
- url: str
621
- r"""
622
- Returns the URL of the response.
623
- """
624
- ok: bool
625
- r"""
626
- Returns whether the response is successful.
627
- """
628
- status: int
629
- r"""
630
- Returns the status code as integer of the response.
631
- """
632
- status_code: StatusCode
633
- r"""
634
- Returns the status code of the response.
635
- """
636
- version: Version
637
- r"""
638
- Returns the HTTP version of the response.
639
- """
640
- headers: HeaderMap
641
- r"""
642
- Returns the headers of the response.
643
- """
644
- cookies: List[Cookie]
645
- r"""
646
- Returns the cookies of the response.
647
- """
648
- content_length: int
649
- r"""
650
- Returns the content length of the response.
651
- """
652
- remote_addr: Optional[SocketAddr]
653
- r"""
654
- Returns the remote address of the response.
655
- """
656
- encoding: str
657
- r"""
658
- Encoding to decode with when accessing text.
659
- """
660
- def __aenter__(self) -> Any: ...
661
- def __aexit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> Any: ...
662
- def peer_certificate(self) -> Optional[bytes]:
663
- r"""
664
- Returns the TLS peer certificate of the response.
665
- """
666
-
667
- async def text(self) -> str:
668
- r"""
669
- Returns the text content of the response.
670
- """
671
-
672
- async def text_with_charset(self, encoding: str) -> str:
673
- r"""
674
- Returns the text content of the response with a specific charset.
675
-
676
- # Arguments
677
-
678
- * `encoding` - The default encoding to use if the charset is not specified.
679
- """
680
-
681
- async def json(self) -> Any:
682
- r"""
683
- Returns the JSON content of the response.
684
- """
685
-
686
- async def bytes(self) -> bytes:
687
- r"""
688
- Returns the bytes content of the response.
689
- """
690
-
691
- def stream(self) -> Streamer:
692
- r"""
693
- Convert the response into a `Stream` of `Bytes` from the body.
694
- """
695
-
696
- async def close(self) -> None:
697
- r"""
698
- Closes the response connection.
699
- """
700
-
701
- class SocketAddr:
702
- r"""
703
- A IP socket address.
704
- """
705
-
706
- def __str__(self) -> str: ...
707
- def __repr__(self) -> str: ...
708
- def ip(self) -> Union[ipaddress.IPv4Address, ipaddress.IPv6Address]:
709
- r"""
710
- Returns the IP address of the socket address.
711
- """
712
-
713
- def port(self) -> int:
714
- r"""
715
- Returns the port number of the socket address.
716
- """
717
-
718
- class StatusCode:
719
- r"""
720
- HTTP status code.
721
- """
722
-
723
- def __str__(self) -> str: ...
724
- def __repr__(self) -> str: ...
725
- def as_int(self) -> int:
726
- r"""
727
- Return the status code as an integer.
728
- """
729
-
730
- def is_informational(self) -> bool:
731
- r"""
732
- Check if status is within 100-199.
733
- """
734
-
735
- def is_success(self) -> bool:
736
- r"""
737
- Check if status is within 200-299.
738
- """
739
-
740
- def is_redirection(self) -> bool:
741
- r"""
742
- Check if status is within 300-399.
743
- """
744
-
745
- def is_client_error(self) -> bool:
746
- r"""
747
- Check if status is within 400-499.
748
- """
749
-
750
- def is_server_error(self) -> bool:
751
- r"""
752
- Check if status is within 500-599.
753
- """
754
-
755
- class Streamer:
756
- r"""
757
- A byte stream response.
758
- An asynchronous iterator yielding data chunks from the response stream.
759
- Used to stream response content.
760
- Implemented in the `stream` method of the `Response` class.
761
- Can be used in an asynchronous for loop in Python.
762
-
763
- # Examples
764
-
765
- ```python
766
- import asyncio
767
- import rnet
768
- from rnet import Method, Impersonate
769
-
770
- async def main():
771
- resp = await rnet.get("https://httpbin.org/stream/20")
772
- print("Status Code: ", resp.status_code)
773
- print("Version: ", resp.version)
774
- print("Response URL: ", resp.url)
775
- print("Headers: ", resp.headers)
776
- print("Content-Length: ", resp.content_length)
777
- print("Encoding: ", resp.encoding)
778
- print("Remote Address: ", resp.remote_addr)
1330
+ from rnet import Method
779
1331
 
780
- async with resp.stream() as streamer:
781
- async for chunk in streamer:
782
- print("Chunk: ", chunk)
783
- await asyncio.sleep(0.1)
1332
+ async def main():
1333
+ client = rnet.Client()
1334
+ response = await client.get("https://httpbin.org/anything")
1335
+ print(await response.text())
784
1336
 
785
- if __name__ == "__main__":
786
1337
  asyncio.run(main())
787
- ```
788
- """
789
-
790
- def __aiter__(self) -> Streamer: ...
791
- def __anext__(self) -> Any: ...
792
- def __aenter__(self) -> Any: ...
793
- def __aexit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> Any: ...
1338
+ ```
1339
+ """
794
1340
 
795
1341
  async def delete(
796
1342
  url: str,
797
- **kwargs: Unpack[RequestParams],
1343
+ **kwargs: Unpack[Request],
798
1344
  ) -> Response:
799
1345
  r"""
800
1346
  Shortcut method to quickly make a request.
@@ -816,7 +1362,7 @@ async def delete(
816
1362
 
817
1363
  async def get(
818
1364
  url: str,
819
- **kwargs: Unpack[RequestParams],
1365
+ **kwargs: Unpack[Request],
820
1366
  ) -> Response:
821
1367
  r"""
822
1368
  Shortcut method to quickly make a request.
@@ -838,7 +1384,7 @@ async def get(
838
1384
 
839
1385
  async def head(
840
1386
  url: str,
841
- **kwargs: Unpack[RequestParams],
1387
+ **kwargs: Unpack[Request],
842
1388
  ) -> Response:
843
1389
  r"""
844
1390
  Shortcut method to quickly make a request.
@@ -859,7 +1405,7 @@ async def head(
859
1405
 
860
1406
  async def options(
861
1407
  url: str,
862
- **kwargs: Unpack[RequestParams],
1408
+ **kwargs: Unpack[Request],
863
1409
  ) -> Response:
864
1410
  r"""
865
1411
  Shortcut method to quickly make a request.
@@ -880,7 +1426,7 @@ async def options(
880
1426
 
881
1427
  async def patch(
882
1428
  url: str,
883
- **kwargs: Unpack[RequestParams],
1429
+ **kwargs: Unpack[Request],
884
1430
  ) -> Response:
885
1431
  r"""
886
1432
  Shortcut method to quickly make a request.
@@ -902,7 +1448,7 @@ async def patch(
902
1448
 
903
1449
  async def post(
904
1450
  url: str,
905
- **kwargs: Unpack[RequestParams],
1451
+ **kwargs: Unpack[Request],
906
1452
  ) -> Response:
907
1453
  r"""
908
1454
  Shortcut method to quickly make a request.
@@ -924,7 +1470,7 @@ async def post(
924
1470
 
925
1471
  async def put(
926
1472
  url: str,
927
- **kwargs: Unpack[RequestParams],
1473
+ **kwargs: Unpack[Request],
928
1474
  ) -> Response:
929
1475
  r"""
930
1476
  Shortcut method to quickly make a request.
@@ -947,7 +1493,7 @@ async def put(
947
1493
  async def request(
948
1494
  method: Method,
949
1495
  url: str,
950
- **kwargs: Unpack[RequestParams],
1496
+ **kwargs: Unpack[Request],
951
1497
  ) -> Response:
952
1498
  r"""
953
1499
  Make a request with the given parameters.
@@ -976,7 +1522,7 @@ async def request(
976
1522
 
977
1523
  async def trace(
978
1524
  url: str,
979
- **kwargs: Unpack[RequestParams],
1525
+ **kwargs: Unpack[Request],
980
1526
  ) -> Response:
981
1527
  r"""
982
1528
  Shortcut method to quickly make a request.
@@ -997,7 +1543,7 @@ async def trace(
997
1543
 
998
1544
  async def websocket(
999
1545
  url: str,
1000
- **kwargs: Unpack[WebSocketParams],
1546
+ **kwargs: Unpack[WebSocketRequest],
1001
1547
  ) -> WebSocket:
1002
1548
  r"""
1003
1549
  Make a WebSocket connection with the given parameters.
@@ -1019,304 +1565,3 @@ async def websocket(
1019
1565
  asyncio.run(run())
1020
1566
  ```
1021
1567
  """
1022
-
1023
- class Proxy:
1024
- r"""
1025
- A proxy server for a request.
1026
- Supports HTTP, HTTPS, SOCKS4, SOCKS4a, SOCKS5, and SOCKS5h protocols.
1027
- """
1028
-
1029
- @staticmethod
1030
- def http(url: str, **kwargs: Unpack[ProxyParams]) -> Proxy:
1031
- r"""
1032
- Creates a new HTTP proxy.
1033
-
1034
- This method sets up a proxy server for HTTP requests.
1035
-
1036
- # Arguments
1037
-
1038
- * `url` - The URL of the proxy server.
1039
- * `username` - Optional username for proxy authentication.
1040
- * `password` - Optional password for proxy authentication.
1041
- * `custom_http_auth` - Optional custom HTTP proxy authentication header value.
1042
- * `custom_http_headers` - Optional custom HTTP proxy headers.
1043
- * `exclusion` - Optional List of domains to exclude from proxying.
1044
-
1045
- # Examples
1046
-
1047
- ```python
1048
- import rnet
1049
-
1050
- proxy = rnet.Proxy.http("http://proxy.example.com")
1051
- ```
1052
- """
1053
-
1054
- @staticmethod
1055
- def https(url: str, **kwargs: Unpack[ProxyParams]) -> Proxy:
1056
- r"""
1057
- Creates a new HTTPS proxy.
1058
-
1059
- This method sets up a proxy server for HTTPS requests.
1060
-
1061
- # Arguments
1062
-
1063
- * `url` - The URL of the proxy server.
1064
- * `username` - Optional username for proxy authentication.
1065
- * `password` - Optional password for proxy authentication.
1066
- * `custom_http_auth` - Optional custom HTTP proxy authentication header value.
1067
- * `custom_http_headers` - Optional custom HTTP proxy headers.
1068
- * `exclusion` - Optional List of domains to exclude from proxying.
1069
-
1070
- # Examples
1071
-
1072
- ```python
1073
- import rnet
1074
-
1075
- proxy = rnet.Proxy.https("https://proxy.example.com")
1076
- ```
1077
- """
1078
-
1079
- @staticmethod
1080
- def all(url: str, **kwargs: Unpack[ProxyParams]) -> Proxy:
1081
- r"""
1082
- Creates a new proxy for all protocols.
1083
-
1084
- This method sets up a proxy server for all types of requests (HTTP, HTTPS, etc.).
1085
-
1086
- # Arguments
1087
-
1088
- * `url` - The URL of the proxy server.
1089
- * `username` - Optional username for proxy authentication.
1090
- * `password` - Optional password for proxy authentication.
1091
- * `custom_http_auth` - Optional custom HTTP proxy authentication header value.
1092
- * `custom_http_headers` - Optional custom HTTP proxy headers.
1093
- * `exclusion` - Optional List of domains to exclude from proxying.
1094
-
1095
- # Examples
1096
-
1097
- ```python
1098
- import rnet
1099
-
1100
- proxy = rnet.Proxy.all("https://proxy.example.com")
1101
- ```
1102
- """
1103
-
1104
- class Message:
1105
- r"""
1106
- A WebSocket message.
1107
- """
1108
-
1109
- data: Optional[bytes]
1110
- r"""
1111
- Returns the data of the message as bytes.
1112
- """
1113
- text: Optional[str]
1114
- r"""
1115
- Returns the text content of the message if it is a text message.
1116
- """
1117
- binary: Optional[bytes]
1118
- r"""
1119
- Returns the binary data of the message if it is a binary message.
1120
- """
1121
- ping: Optional[bytes]
1122
- r"""
1123
- Returns the ping data of the message if it is a ping message.
1124
- """
1125
- pong: Optional[bytes]
1126
- r"""
1127
- Returns the pong data of the message if it is a pong message.
1128
- """
1129
- close: Optional[Tuple[int, Optional[str]]]
1130
- r"""
1131
- Returns the close code and reason of the message if it is a close message.
1132
- """
1133
- def __str__(self) -> str: ...
1134
- def __repr__(self) -> str: ...
1135
- @staticmethod
1136
- def text_from_json(json: Dict[str, Any]) -> Message:
1137
- r"""
1138
- Creates a new text message from the JSON representation.
1139
-
1140
- # Arguments
1141
- * `json` - The JSON representation of the message.
1142
- """
1143
-
1144
- @staticmethod
1145
- def binary_from_json(json: Dict[str, Any]) -> Message:
1146
- r"""
1147
- Creates a new binary message from the JSON representation.
1148
-
1149
- # Arguments
1150
- * `json` - The JSON representation of the message.
1151
- """
1152
-
1153
- @staticmethod
1154
- def from_text(text: str) -> Message:
1155
- r"""
1156
- Creates a new text message.
1157
-
1158
- # Arguments
1159
-
1160
- * `text` - The text content of the message.
1161
- """
1162
-
1163
- @staticmethod
1164
- def from_binary(data: bytes) -> Message:
1165
- r"""
1166
- Creates a new binary message.
1167
-
1168
- # Arguments
1169
-
1170
- * `data` - The binary data of the message.
1171
- """
1172
-
1173
- @staticmethod
1174
- def from_ping(data: bytes) -> Message:
1175
- r"""
1176
- Creates a new ping message.
1177
-
1178
- # Arguments
1179
-
1180
- * `data` - The ping data of the message.
1181
- """
1182
-
1183
- @staticmethod
1184
- def from_pong(data: bytes) -> Message:
1185
- r"""
1186
- Creates a new pong message.
1187
-
1188
- # Arguments
1189
-
1190
- * `data` - The pong data of the message.
1191
- """
1192
-
1193
- @staticmethod
1194
- def from_close(code: int, reason: Optional[str] = None) -> Message:
1195
- r"""
1196
- Creates a new close message.
1197
-
1198
- # Arguments
1199
-
1200
- * `code` - The close code.
1201
- * `reason` - An optional reason for closing.
1202
- """
1203
-
1204
- def json(self) -> Dict[str, Any]:
1205
- r"""
1206
- Returns the JSON representation of the message.
1207
- """
1208
-
1209
- class WebSocket:
1210
- r"""
1211
- A WebSocket response.
1212
- """
1213
-
1214
- ok: bool
1215
- r"""
1216
- Returns whether the response is successful.
1217
- """
1218
- status: int
1219
- r"""
1220
- Returns the status code as integer of the response.
1221
- """
1222
- status_code: StatusCode
1223
- r"""
1224
- Returns the status code of the response.
1225
- """
1226
- version: Version
1227
- r"""
1228
- Returns the HTTP version of the response.
1229
- """
1230
- headers: HeaderMap
1231
- r"""
1232
- Returns the headers of the response.
1233
- """
1234
- cookies: List[Cookie]
1235
- r"""
1236
- Returns the cookies of the response.
1237
- """
1238
- remote_addr: Optional[SocketAddr]
1239
- r"""
1240
- Returns the remote address of the response.
1241
- """
1242
- protocol: Optional[str]
1243
- r"""
1244
- Returns the WebSocket protocol.
1245
- """
1246
- def __aiter__(self) -> WebSocket: ...
1247
- def __anext__(self) -> Any: ...
1248
- def __aenter__(self) -> Any: ...
1249
- def __aexit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> Any: ...
1250
- async def recv(self) -> Optional[Message]:
1251
- r"""
1252
- Receives a message from the WebSocket.
1253
- """
1254
-
1255
- async def send(self, message: Message) -> None:
1256
- r"""
1257
- Sends a message to the WebSocket.
1258
-
1259
- # Arguments
1260
-
1261
- * `message` - The message to send.
1262
- """
1263
-
1264
- async def close(
1265
- self,
1266
- code: Optional[int] = None,
1267
- reason: Optional[str] = None,
1268
- ) -> None:
1269
- r"""
1270
- Closes the WebSocket connection.
1271
-
1272
- # Arguments
1273
-
1274
- * `code` - An optional close code.
1275
- * `reason` - An optional reason for closing.
1276
- """
1277
-
1278
- class LookupIpStrategy(Enum):
1279
- r"""
1280
- The lookup ip strategy.
1281
- """
1282
-
1283
- Ipv4Only = auto()
1284
- Ipv6Only = auto()
1285
- Ipv4AndIpv6 = auto()
1286
- Ipv6thenIpv4 = auto()
1287
- Ipv4thenIpv6 = auto()
1288
-
1289
- class Method(Enum):
1290
- r"""
1291
- An HTTP method.
1292
- """
1293
-
1294
- GET = auto()
1295
- HEAD = auto()
1296
- POST = auto()
1297
- PUT = auto()
1298
- DELETE = auto()
1299
- OPTIONS = auto()
1300
- TRACE = auto()
1301
- PATCH = auto()
1302
-
1303
- class TlsVersion(Enum):
1304
- r"""
1305
- The TLS version.
1306
- """
1307
-
1308
- TLS_1_0 = auto()
1309
- TLS_1_1 = auto()
1310
- TLS_1_2 = auto()
1311
- TLS_1_3 = auto()
1312
-
1313
- class Version(Enum):
1314
- r"""
1315
- An HTTP version.
1316
- """
1317
-
1318
- HTTP_09 = auto()
1319
- HTTP_10 = auto()
1320
- HTTP_11 = auto()
1321
- HTTP_2 = auto()
1322
- HTTP_3 = auto()