rnet 3.0.0rc1__cp311-abi3-musllinux_1_2_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of rnet might be problematic. Click here for more details.

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