rnet 3.0.0rc11__cp314-cp314t-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/emulation.py ADDED
@@ -0,0 +1,200 @@
1
+ """
2
+ This module provides functionality for emulating various browsers and HTTP clients
3
+ to bypass detection and fingerprinting. It supports emulating Chrome, Firefox, Edge,
4
+ Safari, Opera, and OkHttp clients across different operating systems and versions.
5
+
6
+ The emulation system modifies HTTP/2 settings, TLS fingerprints, and request headers
7
+ to match the behavior of real browsers and clients, making requests appear more
8
+ authentic and less likely to be blocked by anti-bot systems.
9
+ """
10
+
11
+ from enum import Enum, auto
12
+ from typing import final
13
+
14
+ __all__ = ["Emulation", "EmulationOS", "EmulationOption"]
15
+
16
+
17
+ @final
18
+ class Emulation(Enum):
19
+ r"""
20
+ An emulation.
21
+ """
22
+
23
+ # Chrome versions
24
+ Chrome100 = auto()
25
+ Chrome101 = auto()
26
+ Chrome104 = auto()
27
+ Chrome105 = auto()
28
+ Chrome106 = auto()
29
+ Chrome107 = auto()
30
+ Chrome108 = auto()
31
+ Chrome109 = auto()
32
+ Chrome110 = auto()
33
+ Chrome114 = auto()
34
+ Chrome116 = auto()
35
+ Chrome117 = auto()
36
+ Chrome118 = auto()
37
+ Chrome119 = auto()
38
+ Chrome120 = auto()
39
+ Chrome123 = auto()
40
+ Chrome124 = auto()
41
+ Chrome126 = auto()
42
+ Chrome127 = auto()
43
+ Chrome128 = auto()
44
+ Chrome129 = auto()
45
+ Chrome130 = auto()
46
+ Chrome131 = auto()
47
+ Chrome132 = auto()
48
+ Chrome133 = auto()
49
+ Chrome134 = auto()
50
+ Chrome135 = auto()
51
+ Chrome136 = auto()
52
+ Chrome137 = auto()
53
+ Chrome138 = auto()
54
+ Chrome139 = auto()
55
+ Chrome140 = auto()
56
+ Chrome141 = auto()
57
+ Chrome142 = auto()
58
+
59
+ # Microsoft Edge versions
60
+ Edge101 = auto()
61
+ Edge122 = auto()
62
+ Edge127 = auto()
63
+ Edge131 = auto()
64
+ Edge134 = auto()
65
+
66
+ # Firefox versions
67
+ Firefox109 = auto()
68
+ Firefox117 = auto()
69
+ Firefox128 = auto()
70
+ Firefox133 = auto()
71
+ Firefox135 = auto()
72
+ FirefoxPrivate135 = auto()
73
+ FirefoxAndroid135 = auto()
74
+ Firefox136 = auto()
75
+ FirefoxPrivate136 = auto()
76
+ Firefox139 = auto()
77
+ Firefox142 = auto()
78
+ Firefox143 = auto()
79
+
80
+ # Safari versions
81
+ SafariIos17_2 = auto()
82
+ SafariIos17_4_1 = auto()
83
+ SafariIos16_5 = auto()
84
+ Safari15_3 = auto()
85
+ Safari15_5 = auto()
86
+ Safari15_6_1 = auto()
87
+ Safari16 = auto()
88
+ Safari16_5 = auto()
89
+ Safari17_0 = auto()
90
+ Safari17_2_1 = auto()
91
+ Safari17_4_1 = auto()
92
+ Safari17_5 = auto()
93
+ Safari18 = auto()
94
+ SafariIPad18 = auto()
95
+ Safari18_2 = auto()
96
+ Safari18_3 = auto()
97
+ Safari18_3_1 = auto()
98
+ SafariIos18_1_1 = auto()
99
+ Safari18_5 = auto()
100
+ Safari26 = auto()
101
+ SafariIos26 = auto()
102
+ SafariIPad26 = auto()
103
+
104
+ # OkHttp versions
105
+ OkHttp3_9 = auto()
106
+ OkHttp3_11 = auto()
107
+ OkHttp3_13 = auto()
108
+ OkHttp3_14 = auto()
109
+ OkHttp4_9 = auto()
110
+ OkHttp4_10 = auto()
111
+ OkHttp4_12 = auto()
112
+ OkHttp5 = auto()
113
+
114
+ # Opera versions
115
+ Opera116 = auto()
116
+ Opera117 = auto()
117
+ Opera118 = auto()
118
+ Opera119 = auto()
119
+
120
+
121
+ @final
122
+ class EmulationOS(Enum):
123
+ """
124
+ Operating systems that can be emulated.
125
+
126
+ This enum defines the operating systems that can be combined with
127
+ browser emulations to create more specific fingerprints.
128
+ """
129
+
130
+ Windows = auto() # Windows (any version)
131
+ MacOS = auto() # macOS (any version)
132
+ Linux = auto() # Linux (any distribution)
133
+ Android = auto() # Android (mobile)
134
+ IOS = auto() # iOS (iPhone/iPad)
135
+
136
+
137
+ @final
138
+ class EmulationOption:
139
+ """
140
+ Configuration options for browser and client emulation.
141
+
142
+ This class allows fine-grained control over emulation behavior,
143
+ including the ability to disable specific features or combine
144
+ browser types with specific operating systems.
145
+ """
146
+
147
+ def __init__(
148
+ self,
149
+ emulation: Emulation,
150
+ emulation_os: EmulationOS | None = None,
151
+ skip_http2: bool | None = None,
152
+ skip_headers: bool | None = None,
153
+ ) -> None:
154
+ """
155
+ Create a new emulation configuration.
156
+
157
+ Args:
158
+ emulation: The browser/client type to emulate
159
+ emulation_os: The operating system to emulate (optional)
160
+ skip_http2: Whether to disable HTTP/2 emulation (default: False)
161
+ skip_headers: Whether to skip default browser headers (default: False)
162
+
163
+ Returns:
164
+ A configured EmulationOption instance
165
+
166
+ Example:
167
+ ```python
168
+ # Basic Chrome emulation
169
+ option = EmulationOption(Emulation.Chrome137)
170
+
171
+ # Chrome on Windows with HTTP/2 disabled
172
+ option = EmulationOption(
173
+ emulation=Emulation.Chrome137,
174
+ emulation_os=EmulationOS.Windows,
175
+ skip_http2=True
176
+ )
177
+ ```
178
+ """
179
+ ...
180
+
181
+ @staticmethod
182
+ def random() -> "EmulationOption":
183
+ """
184
+ Generate a random emulation configuration.
185
+
186
+ This method creates a randomized emulation setup using a random
187
+ browser/client type and operating system combination. Useful for
188
+ scenarios where you want to vary your fingerprint across requests.
189
+
190
+ Returns:
191
+ A randomly configured EmulationOption instance
192
+
193
+ Example:
194
+ ```python
195
+ # Use different random emulation for each client
196
+ client1 = rnet.Client(emulation=EmulationOption.random())
197
+ client2 = rnet.Client(emulation=EmulationOption.random())
198
+ ```
199
+ """
200
+ ...
rnet/exceptions.py ADDED
@@ -0,0 +1,224 @@
1
+ """
2
+ HTTP Client Exceptions
3
+
4
+ This module defines all exceptions that can be raised by the rnet HTTP client.
5
+ The exceptions are organized into logical categories based on their cause and
6
+ severity, making it easier to handle specific types of errors appropriately.
7
+ """
8
+
9
+ __all__ = [
10
+ "DNSResolverError",
11
+ "TlsError",
12
+ "ConnectionError",
13
+ "ConnectionResetError",
14
+ "BodyError",
15
+ "BuilderError",
16
+ "DecodingError",
17
+ "StatusError",
18
+ "RequestError",
19
+ "RedirectError",
20
+ "UpgradeError",
21
+ "WebSocketError",
22
+ "URLParseError",
23
+ "TimeoutError",
24
+ ]
25
+
26
+ # ========================================
27
+ # Network and System-Level Errors
28
+ # ========================================
29
+
30
+
31
+ class RustPanic(Exception):
32
+ r"""
33
+ A panic occurred in the underlying Rust code.
34
+ """
35
+
36
+
37
+ class DNSResolverError(RuntimeError):
38
+ r"""
39
+ An error occurred while resolving a DNS name.
40
+
41
+ This exception is raised when the DNS resolver fails to resolve
42
+ a hostname to an IP address. This is typically due to network
43
+ issues, invalid hostnames, or DNS server problems.
44
+
45
+ Since this is a system-level issue that usually cannot be resolved
46
+ by retrying the request, it inherits from RuntimeError.
47
+ """
48
+
49
+
50
+ class TlsError(Exception):
51
+ r"""
52
+ An error occurred in the TLS security layer.
53
+
54
+ This exception covers TLS/SSL related issues such as:
55
+ - Certificate verification failures
56
+ - TLS handshake failures
57
+ - Protocol version mismatches
58
+ - Cipher suite negotiations
59
+ """
60
+
61
+
62
+ class ConnectionError(Exception):
63
+ r"""
64
+ An error occurred while establishing a connection.
65
+
66
+ This exception is raised when the client cannot establish a
67
+ TCP connection to the remote server. Common causes include:
68
+ - Server is unreachable
69
+ - Port is closed or blocked
70
+ - Network connectivity issues
71
+ - Firewall blocking the connection
72
+ """
73
+
74
+
75
+ class ConnectionResetError(Exception):
76
+ r"""
77
+ The connection was reset by the remote peer.
78
+
79
+ This exception occurs when an established connection is
80
+ unexpectedly closed by the remote server. This can happen
81
+ due to server overload, network issues, or server-side
82
+ connection limits.
83
+ """
84
+
85
+
86
+ # ========================================
87
+ # Request/Response Processing Errors
88
+ # ========================================
89
+
90
+
91
+ class BodyError(Exception):
92
+ r"""
93
+ An error occurred while processing the body of a request or response.
94
+
95
+ This exception covers issues with reading, writing, or processing
96
+ HTTP message bodies, including:
97
+ - Invalid content encoding
98
+ - Incomplete body data
99
+ - Body size limit exceeded
100
+ """
101
+
102
+
103
+ class BuilderError(Exception):
104
+ r"""
105
+ An error occurred while building a request or response.
106
+
107
+ This exception is raised when there are issues constructing
108
+ HTTP requests or responses, such as:
109
+ - Invalid header combinations
110
+ - Malformed request parameters
111
+ - Configuration conflicts
112
+ """
113
+
114
+
115
+ class DecodingError(Exception):
116
+ r"""
117
+ An error occurred while decoding a response.
118
+
119
+ This exception covers failures in decoding response content,
120
+ including:
121
+ - Character encoding issues (UTF-8, Latin-1, etc.)
122
+ - Compression decompression failures (gzip, deflate, etc.)
123
+ - Content format parsing errors
124
+ """
125
+
126
+
127
+ class StatusError(Exception):
128
+ r"""
129
+ An error occurred while processing the status code of a response.
130
+
131
+ This exception is typically raised for HTTP error status codes
132
+ (4xx, 5xx) when automatic error handling is enabled, or when
133
+ there are issues interpreting the status line.
134
+ """
135
+
136
+
137
+ class RequestError(Exception):
138
+ r"""
139
+ An error occurred while making a request.
140
+
141
+ This is a general exception for request-related issues that
142
+ don't fit into more specific categories. It covers various
143
+ problems during the request lifecycle.
144
+ """
145
+
146
+
147
+ # ========================================
148
+ # HTTP Protocol and Navigation Errors
149
+ # ========================================
150
+
151
+
152
+ class RedirectError(Exception):
153
+ r"""
154
+ An error occurred while following a redirect.
155
+
156
+ This exception is raised when there are issues with HTTP
157
+ redirects, such as:
158
+ - Too many redirects (redirect loop)
159
+ - Invalid redirect location
160
+ - Cross-protocol redirects when not allowed
161
+ - Redirect limit exceeded
162
+ """
163
+
164
+
165
+ class UpgradeError(Exception):
166
+ r"""
167
+ An error occurred while upgrading a connection.
168
+
169
+ This exception covers failures when upgrading HTTP connections
170
+ to other protocols, such as:
171
+ - WebSocket upgrade failures
172
+ - HTTP/2 upgrade issues
173
+ - Protocol negotiation errors
174
+ """
175
+
176
+
177
+ class WebSocketError(Exception):
178
+ r"""
179
+ An error occurred while handling a WebSocket connection.
180
+
181
+ This exception covers WebSocket-specific issues including:
182
+ - WebSocket handshake failures
183
+ - Frame parsing errors
184
+ - Connection state violations
185
+ - Message sending/receiving errors
186
+ """
187
+
188
+
189
+ # ========================================
190
+ # Parsing and Validation Errors
191
+ # ========================================
192
+
193
+
194
+ class URLParseError(Exception):
195
+ r"""
196
+ An error occurred while parsing a URL.
197
+
198
+ This exception is raised when a provided URL cannot be parsed
199
+ or is malformed. Common issues include:
200
+ - Invalid URL schemes
201
+ - Malformed hostnames or ports
202
+ - Invalid characters in URL components
203
+ - Missing required URL components
204
+ """
205
+
206
+
207
+ # ========================================
208
+ # Timeout Errors
209
+ # ========================================
210
+
211
+
212
+ class TimeoutError(Exception):
213
+ r"""
214
+ A timeout occurred while waiting for a response.
215
+
216
+ This exception is raised when operations exceed their configured
217
+ time limits, including:
218
+ - Connection timeout (time to establish connection)
219
+ - Read timeout (time to receive response)
220
+ - Total request timeout (entire request lifecycle)
221
+
222
+ Timeouts can often be resolved by increasing timeout values
223
+ or retrying the request.
224
+ """