notify-tls-client 0.1.6__py3-none-any.whl → 0.1.9__py3-none-any.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.
- notify_tls_client/__init__.py +2 -2
- notify_tls_client/core/client/__init__.py +1 -6
- notify_tls_client/core/client/decorators.py +239 -90
- notify_tls_client/core/client_identifiers_manager.py +45 -0
- notify_tls_client/core/notifytlsclient.py +196 -146
- notify_tls_client/core/proxiesmanager/__init__.py +1 -1
- notify_tls_client/core/proxiesmanager/proxiesmanager.py +67 -67
- notify_tls_client/core/proxiesmanager/proxiesmanagerloader.py +33 -33
- notify_tls_client/tls_client/__init__.py +14 -14
- notify_tls_client/tls_client/__version__.py +10 -10
- notify_tls_client/tls_client/cffi.py +38 -62
- notify_tls_client/tls_client/cookies.py +456 -456
- notify_tls_client/tls_client/dependencies/{tls-client-xgo-1.11.0-darwin-arm64.dylib → tls-client-darwin-amd64-1.12.0.dylib} +0 -0
- notify_tls_client/tls_client/dependencies/tls-client-linux-arm64-1.12.0.so +0 -0
- notify_tls_client/tls_client/dependencies/{tls-client-xgo-1.11.0-linux-amd64.so → tls-client-linux-ubuntu-amd64-1.12.0.so} +0 -0
- notify_tls_client/tls_client/dependencies/{tls-client-windows-1.11.0-64.dll → tls-client-windows-64-1.12.0.dll} +0 -0
- notify_tls_client/tls_client/exceptions.py +2 -2
- notify_tls_client/tls_client/response.py +83 -78
- notify_tls_client/tls_client/sessions.py +522 -513
- notify_tls_client/tls_client/settings.py +69 -69
- notify_tls_client/tls_client/structures.py +74 -74
- {notify_tls_client-0.1.6.dist-info → notify_tls_client-0.1.9.dist-info}/METADATA +14 -16
- notify_tls_client-0.1.9.dist-info/RECORD +27 -0
- notify_tls_client-0.1.6.dist-info/RECORD +0 -25
- {notify_tls_client-0.1.6.dist-info → notify_tls_client-0.1.9.dist-info}/WHEEL +0 -0
- {notify_tls_client-0.1.6.dist-info → notify_tls_client-0.1.9.dist-info}/top_level.txt +0 -0
|
@@ -1,146 +1,196 @@
|
|
|
1
|
-
import
|
|
2
|
-
from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
from notify_tls_client.core.client import *
|
|
7
|
-
from notify_tls_client.core.
|
|
8
|
-
|
|
9
|
-
from notify_tls_client.tls_client.response import Response
|
|
10
|
-
from notify_tls_client.tls_client.
|
|
11
|
-
from notify_tls_client.tls_client.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
self.
|
|
35
|
-
self.
|
|
36
|
-
self.
|
|
37
|
-
self.
|
|
38
|
-
self.
|
|
39
|
-
self.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
self.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
self.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
self.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
1
|
+
import logging
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from typing_extensions import TypeAlias, Literal
|
|
5
|
+
|
|
6
|
+
from notify_tls_client.core.client import *
|
|
7
|
+
from notify_tls_client.core.client_identifiers_manager import ClientIdentifiersManager
|
|
8
|
+
from notify_tls_client.core.proxiesmanager import ProxiesManager, Proxy
|
|
9
|
+
from notify_tls_client.tls_client.response import Response
|
|
10
|
+
from notify_tls_client.tls_client.sessions import Session
|
|
11
|
+
from notify_tls_client.tls_client.settings import ClientIdentifiers
|
|
12
|
+
from notify_tls_client.tls_client.structures import CaseInsensitiveDict
|
|
13
|
+
|
|
14
|
+
HttpMethods: TypeAlias = Literal["GET", "POST", "PUT", "DELETE", "PATCH"]
|
|
15
|
+
logger = logging.Logger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class NotifyTLSClient:
|
|
19
|
+
def __init__(self,
|
|
20
|
+
proxies_manager: Optional[ProxiesManager] = None,
|
|
21
|
+
client_identifiers: list[ClientIdentifiers] = None,
|
|
22
|
+
requests_limit_same_proxy: int = 1000,
|
|
23
|
+
random_tls_extension_order: bool = True,
|
|
24
|
+
requests_limit_with_same_client_identifier: int = -1,
|
|
25
|
+
instantiate_new_client_on_forbidden_response: bool = False,
|
|
26
|
+
instantiate_new_client_on_exception: bool = False,
|
|
27
|
+
debug_mode: bool = False,
|
|
28
|
+
status_codes_to_forbidden_response_handle: list[int] = None,
|
|
29
|
+
change_client_identifier_on_forbidden_response: bool = False,
|
|
30
|
+
default_headers: dict = None,
|
|
31
|
+
disable_http3: bool = False
|
|
32
|
+
):
|
|
33
|
+
|
|
34
|
+
self.client: Optional[Session] = None
|
|
35
|
+
self.change_client_identifier_on_forbidden_response = change_client_identifier_on_forbidden_response
|
|
36
|
+
self.client_identifiers_manager = ClientIdentifiersManager(client_identifiers or ["chrome_133"])
|
|
37
|
+
self.status_codes_to_forbidden_response_handle = status_codes_to_forbidden_response_handle or [403]
|
|
38
|
+
self.free = True
|
|
39
|
+
self.requests_amount = 0
|
|
40
|
+
self.requests_amount_with_current_proxy = 0
|
|
41
|
+
self.requests_amount_with_current_client_identifier = 0
|
|
42
|
+
self.last_request_status = 0
|
|
43
|
+
self.headers = default_headers or CaseInsensitiveDict({
|
|
44
|
+
"User-Agent": f"tls-client/1.0.0",
|
|
45
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
46
|
+
"Accept": "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
|
|
47
|
+
"Connection": "keep-alive",
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
self.disable_http3 = disable_http3
|
|
51
|
+
self.proxies_manager = proxies_manager
|
|
52
|
+
self.requests_limit_with_same_proxy = requests_limit_same_proxy
|
|
53
|
+
self.requests_limit_with_same_client_identifier = requests_limit_with_same_client_identifier
|
|
54
|
+
self.debug_mode = debug_mode
|
|
55
|
+
|
|
56
|
+
self.instantiate_new_client_on_forbidden_response = instantiate_new_client_on_forbidden_response
|
|
57
|
+
self.instantiate_new_client_on_exception = instantiate_new_client_on_exception
|
|
58
|
+
|
|
59
|
+
self.current_proxy = None
|
|
60
|
+
self._create_new_client(self.client_identifiers_manager.get_next(),
|
|
61
|
+
random_tls_extension_order,
|
|
62
|
+
proxy=self.proxies_manager.get_next() if self.proxies_manager else None)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _create_new_client(self,
|
|
66
|
+
client_identifier: ClientIdentifiers = 'chrome_133',
|
|
67
|
+
random_tls_extension_order: bool = False,
|
|
68
|
+
proxy: Optional[Proxy] = None):
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
if self.client:
|
|
73
|
+
self.client.close()
|
|
74
|
+
|
|
75
|
+
old_client_identifier = self.client.client_identifier if self.client else None
|
|
76
|
+
|
|
77
|
+
self.client = Session(client_identifier=client_identifier,
|
|
78
|
+
random_tls_extension_order=random_tls_extension_order)
|
|
79
|
+
|
|
80
|
+
if old_client_identifier != client_identifier:
|
|
81
|
+
self.requests_amount_with_current_client_identifier = 0
|
|
82
|
+
|
|
83
|
+
if proxy:
|
|
84
|
+
|
|
85
|
+
self.client.proxies = proxy.to_proxy_dict()
|
|
86
|
+
|
|
87
|
+
if self.current_proxy != proxy:
|
|
88
|
+
self.current_proxy = proxy
|
|
89
|
+
self.requests_amount_with_current_proxy = 0
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def set_requests_limit_same_proxy(self, requests_limit_same_proxy: int):
|
|
93
|
+
self.requests_limit_with_same_proxy = requests_limit_same_proxy
|
|
94
|
+
|
|
95
|
+
def set_proxies_manager(self, proxies_manager: ProxiesManager):
|
|
96
|
+
self.proxies_manager = proxies_manager
|
|
97
|
+
|
|
98
|
+
def change_proxy(self):
|
|
99
|
+
if self.proxies_manager and self.proxies_manager.get_proxies():
|
|
100
|
+
self.current_proxy = self.proxies_manager.get_next()
|
|
101
|
+
self.client.proxies = self.current_proxy.to_proxy_dict()
|
|
102
|
+
self.requests_amount_with_current_proxy = 0
|
|
103
|
+
|
|
104
|
+
def set_proxies(self, proxies: Proxy):
|
|
105
|
+
self.client.proxies = proxies.to_proxy_dict()
|
|
106
|
+
|
|
107
|
+
def set_headers(self, headers: dict):
|
|
108
|
+
self.client.headers = CaseInsensitiveDict(headers)
|
|
109
|
+
|
|
110
|
+
def get_cookies(self):
|
|
111
|
+
return self.client.cookies
|
|
112
|
+
|
|
113
|
+
def get_cookie_by_name(self, name: str) -> Optional[str]:
|
|
114
|
+
try:
|
|
115
|
+
return self.client.cookies.get(name)
|
|
116
|
+
except Exception as e:
|
|
117
|
+
logging.exception(f"Error getting cookie '{name}': {e}")
|
|
118
|
+
|
|
119
|
+
@request_guard_decorator
|
|
120
|
+
def execute_request(self, method: HttpMethods, url: str, **kwargs) -> Optional[Response]:
|
|
121
|
+
method = method.upper()
|
|
122
|
+
if method == "GET":
|
|
123
|
+
return self.client.get(url, **kwargs)
|
|
124
|
+
elif method == "POST":
|
|
125
|
+
return self.client.post(url, **kwargs)
|
|
126
|
+
elif method == "PUT":
|
|
127
|
+
return self.client.put(url, **kwargs)
|
|
128
|
+
elif method == "DELETE":
|
|
129
|
+
return self.client.delete(url, **kwargs)
|
|
130
|
+
elif method == "PATCH":
|
|
131
|
+
return self.client.delete(url, **kwargs)
|
|
132
|
+
else:
|
|
133
|
+
raise ValueError(f"Unsupported HTTP method: {method}")
|
|
134
|
+
|
|
135
|
+
def get(self, url: str, **kwargs) -> Optional[Response]:
|
|
136
|
+
return self.execute_request("GET", url, **kwargs)
|
|
137
|
+
|
|
138
|
+
def post(self, url: str, **kwargs) -> Optional[Response]:
|
|
139
|
+
return self.execute_request("POST", url, **kwargs)
|
|
140
|
+
|
|
141
|
+
def put(self, url: str, **kwargs) -> Optional[Response]:
|
|
142
|
+
return self.execute_request("PUT", url, **kwargs)
|
|
143
|
+
|
|
144
|
+
def delete(self, url: str, **kwargs) -> Optional[Response]:
|
|
145
|
+
return self.execute_request("DELETE", url, **kwargs)
|
|
146
|
+
|
|
147
|
+
def patch(self, url: str, **kwargs) -> Optional[Response]:
|
|
148
|
+
return self.execute_request("PATCH", url, **kwargs)
|
|
149
|
+
|
|
150
|
+
def _change_to_free(self):
|
|
151
|
+
self.free = True
|
|
152
|
+
|
|
153
|
+
def _change_to_busy(self):
|
|
154
|
+
self.free = False
|
|
155
|
+
|
|
156
|
+
def get_cookie_value_by_name(self, name: str):
|
|
157
|
+
return self.client.cookies.get(name)
|
|
158
|
+
|
|
159
|
+
def set_cookie(self, name: str, value: str):
|
|
160
|
+
self.client.cookies.set(name, value)
|
|
161
|
+
|
|
162
|
+
def get_tls(self):
|
|
163
|
+
return self.client
|
|
164
|
+
|
|
165
|
+
def get_current_client_identifier(self) -> ClientIdentifiers:
|
|
166
|
+
return self.client.client_identifier
|
|
167
|
+
|
|
168
|
+
def is_same_proxy_request_limit_reached(self) -> bool:
|
|
169
|
+
if self.requests_limit_with_same_proxy == -1:
|
|
170
|
+
return False
|
|
171
|
+
|
|
172
|
+
return self.requests_amount_with_current_proxy >= self.requests_limit_with_same_proxy
|
|
173
|
+
|
|
174
|
+
def is_same_client_identifier_request_limit_reached(self) -> bool:
|
|
175
|
+
if self.requests_limit_with_same_client_identifier == -1:
|
|
176
|
+
return False
|
|
177
|
+
|
|
178
|
+
return self.requests_amount_with_current_client_identifier >= self.requests_limit_with_same_client_identifier
|
|
179
|
+
|
|
180
|
+
def is_client_identifier_changeable_by_requests_limit_reached(self) -> bool:
|
|
181
|
+
return self.is_same_client_identifier_request_limit_reached() and self.has_multiple_client_identifiers()
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def has_multiple_client_identifiers(self) -> bool:
|
|
185
|
+
return self.client_identifiers_manager.get_total_items() > 1
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def is_forbidden_request_status(self, status_code: int) -> bool:
|
|
189
|
+
return status_code in self.status_codes_to_forbidden_response_handle
|
|
190
|
+
|
|
191
|
+
def has_proxies_manager(self) -> bool:
|
|
192
|
+
return self.proxies_manager is not None and self.proxies_manager.get_proxies()
|
|
193
|
+
|
|
194
|
+
def set_default_headers(self, headers: dict):
|
|
195
|
+
self.headers = headers
|
|
196
|
+
self.client.headers = self.headers
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
from .proxiesmanager import ProxiesManager, Proxy
|
|
1
|
+
from .proxiesmanager import ProxiesManager, Proxy
|
|
2
2
|
from .proxiesmanagerloader import ProxiesManagerLoader
|
|
@@ -1,67 +1,67 @@
|
|
|
1
|
-
from dataclasses import dataclass, field
|
|
2
|
-
from typing import Optional
|
|
3
|
-
|
|
4
|
-
from dataclasses_json import dataclass_json
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@dataclass_json
|
|
8
|
-
@dataclass
|
|
9
|
-
class Proxy:
|
|
10
|
-
host: str
|
|
11
|
-
port: int
|
|
12
|
-
username: Optional[str] = None
|
|
13
|
-
password: Optional[str] = None
|
|
14
|
-
|
|
15
|
-
def to_proxy_dict(self):
|
|
16
|
-
if self.username is None:
|
|
17
|
-
return {
|
|
18
|
-
'http': f'http://{self.host}:{self.port}',
|
|
19
|
-
'https': f'https://{self.host}:{self.port}'
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
'http': f'http://{self.username}:{self.password}@{self.host}:{self.port}',
|
|
24
|
-
'https': f'https://{self.username}:{self.password}@{self.host}:{self.port}'
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
@dataclass_json
|
|
29
|
-
@dataclass
|
|
30
|
-
class ProxiesManager:
|
|
31
|
-
_proxies: list[Proxy] = field(default_factory=list)
|
|
32
|
-
_current_proxy_index: int = 0
|
|
33
|
-
_current_proxy: Optional[Proxy] = None
|
|
34
|
-
|
|
35
|
-
def get_next(self) -> Proxy:
|
|
36
|
-
|
|
37
|
-
if not self._proxies:
|
|
38
|
-
raise Exception('No proxies available')
|
|
39
|
-
|
|
40
|
-
if self._current_proxy_index < len(self._proxies):
|
|
41
|
-
proxy = self._proxies[self._current_proxy_index]
|
|
42
|
-
self._current_proxy_index += 1
|
|
43
|
-
else:
|
|
44
|
-
self._current_proxy_index = 0
|
|
45
|
-
proxy = self._proxies[self._current_proxy_index]
|
|
46
|
-
|
|
47
|
-
return proxy
|
|
48
|
-
|
|
49
|
-
def get_current_proxy(self) -> Optional[Proxy]:
|
|
50
|
-
if not self._current_proxy:
|
|
51
|
-
return None
|
|
52
|
-
|
|
53
|
-
return self._current_proxy
|
|
54
|
-
|
|
55
|
-
def set_proxies(self, proxies: list[Proxy]):
|
|
56
|
-
self._proxies = proxies
|
|
57
|
-
self._current_proxy_index = 0
|
|
58
|
-
self._current_proxy = None
|
|
59
|
-
|
|
60
|
-
def add_proxy(self, proxy: Proxy):
|
|
61
|
-
self._proxies.append(proxy)
|
|
62
|
-
self._current_proxy_index = 0
|
|
63
|
-
def get_proxies(self) -> list[Proxy]:
|
|
64
|
-
return self._proxies
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from dataclasses_json import dataclass_json
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass_json
|
|
8
|
+
@dataclass
|
|
9
|
+
class Proxy:
|
|
10
|
+
host: str
|
|
11
|
+
port: int
|
|
12
|
+
username: Optional[str] = None
|
|
13
|
+
password: Optional[str] = None
|
|
14
|
+
|
|
15
|
+
def to_proxy_dict(self):
|
|
16
|
+
if self.username is None:
|
|
17
|
+
return {
|
|
18
|
+
'http': f'http://{self.host}:{self.port}',
|
|
19
|
+
'https': f'https://{self.host}:{self.port}'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
'http': f'http://{self.username}:{self.password}@{self.host}:{self.port}',
|
|
24
|
+
'https': f'https://{self.username}:{self.password}@{self.host}:{self.port}'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass_json
|
|
29
|
+
@dataclass
|
|
30
|
+
class ProxiesManager:
|
|
31
|
+
_proxies: list[Proxy] = field(default_factory=list)
|
|
32
|
+
_current_proxy_index: int = 0
|
|
33
|
+
_current_proxy: Optional[Proxy] = None
|
|
34
|
+
|
|
35
|
+
def get_next(self) -> Proxy:
|
|
36
|
+
|
|
37
|
+
if not self._proxies:
|
|
38
|
+
raise Exception('No proxies available')
|
|
39
|
+
|
|
40
|
+
if self._current_proxy_index < len(self._proxies):
|
|
41
|
+
proxy = self._proxies[self._current_proxy_index]
|
|
42
|
+
self._current_proxy_index += 1
|
|
43
|
+
else:
|
|
44
|
+
self._current_proxy_index = 0
|
|
45
|
+
proxy = self._proxies[self._current_proxy_index]
|
|
46
|
+
|
|
47
|
+
return proxy
|
|
48
|
+
|
|
49
|
+
def get_current_proxy(self) -> Optional[Proxy]:
|
|
50
|
+
if not self._current_proxy:
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
return self._current_proxy
|
|
54
|
+
|
|
55
|
+
def set_proxies(self, proxies: list[Proxy]):
|
|
56
|
+
self._proxies = proxies
|
|
57
|
+
self._current_proxy_index = 0
|
|
58
|
+
self._current_proxy = None
|
|
59
|
+
|
|
60
|
+
def add_proxy(self, proxy: Proxy):
|
|
61
|
+
self._proxies.append(proxy)
|
|
62
|
+
self._current_proxy_index = 0
|
|
63
|
+
def get_proxies(self) -> list[Proxy]:
|
|
64
|
+
return self._proxies
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import traceback
|
|
2
|
-
from typing import Optional
|
|
3
|
-
|
|
4
|
-
from notify_tls_client.core.proxiesmanager.proxiesmanager import Proxy, ProxiesManager
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class ProxiesManagerLoader:
|
|
8
|
-
|
|
9
|
-
def from_txt(self, path: str) -> Optional[ProxiesManager]:
|
|
10
|
-
try:
|
|
11
|
-
proxies = []
|
|
12
|
-
with open(path, 'r') as f:
|
|
13
|
-
for proxy in f.read().splitlines():
|
|
14
|
-
_proxy = proxy.split(':')
|
|
15
|
-
if len(_proxy) == 2:
|
|
16
|
-
proxies.append(Proxy(host=_proxy[0],
|
|
17
|
-
port=int(_proxy[1])))
|
|
18
|
-
elif len(_proxy) == 4:
|
|
19
|
-
proxy = Proxy(host=_proxy[0],
|
|
20
|
-
port=int(_proxy[1]),
|
|
21
|
-
username=_proxy[2],
|
|
22
|
-
password=_proxy[3])
|
|
23
|
-
|
|
24
|
-
proxies.append(proxy)
|
|
25
|
-
else:
|
|
26
|
-
raise (ValueError('Invalid proxy format'))
|
|
27
|
-
|
|
28
|
-
return ProxiesManager(proxies)
|
|
29
|
-
|
|
30
|
-
except Exception as e:
|
|
31
|
-
print(e)
|
|
32
|
-
print(traceback.format_exc())
|
|
33
|
-
return None
|
|
1
|
+
import traceback
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from notify_tls_client.core.proxiesmanager.proxiesmanager import Proxy, ProxiesManager
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ProxiesManagerLoader:
|
|
8
|
+
|
|
9
|
+
def from_txt(self, path: str) -> Optional[ProxiesManager]:
|
|
10
|
+
try:
|
|
11
|
+
proxies = []
|
|
12
|
+
with open(path, 'r') as f:
|
|
13
|
+
for proxy in f.read().splitlines():
|
|
14
|
+
_proxy = proxy.split(':')
|
|
15
|
+
if len(_proxy) == 2:
|
|
16
|
+
proxies.append(Proxy(host=_proxy[0],
|
|
17
|
+
port=int(_proxy[1])))
|
|
18
|
+
elif len(_proxy) == 4:
|
|
19
|
+
proxy = Proxy(host=_proxy[0],
|
|
20
|
+
port=int(_proxy[1]),
|
|
21
|
+
username=_proxy[2],
|
|
22
|
+
password=_proxy[3])
|
|
23
|
+
|
|
24
|
+
proxies.append(proxy)
|
|
25
|
+
else:
|
|
26
|
+
raise (ValueError('Invalid proxy format'))
|
|
27
|
+
|
|
28
|
+
return ProxiesManager(proxies)
|
|
29
|
+
|
|
30
|
+
except Exception as e:
|
|
31
|
+
print(e)
|
|
32
|
+
print(traceback.format_exc())
|
|
33
|
+
return None
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# _____ __ __ ___ _ _ _
|
|
2
|
-
# /__ \/ / / _\ / __\ (_) ___ _ __ | |_
|
|
3
|
-
# / /\/ / \ \ _____ / / | | |/ _ \ '_ \| __|
|
|
4
|
-
# / / / /____\ \_____/ /___| | | __/ | | | |_
|
|
5
|
-
# \/ \____/\__/ \____/|_|_|\___|_| |_|\__|
|
|
6
|
-
|
|
7
|
-
# Disclaimer:
|
|
8
|
-
# Big shout out to Bogdanfinn for open sourcing his tls-client in Golang.
|
|
9
|
-
# Also to requests, as most of the cookie handling is copied from it. :'D
|
|
10
|
-
# I wanted to keep the syntax as similar as possible to requests, as most people use it and are familiar with it!
|
|
11
|
-
# Links:
|
|
12
|
-
# tls-client: https://github.com/bogdanfinn/tls-client
|
|
13
|
-
# requests: https://github.com/psf/requests
|
|
14
|
-
|
|
1
|
+
# _____ __ __ ___ _ _ _
|
|
2
|
+
# /__ \/ / / _\ / __\ (_) ___ _ __ | |_
|
|
3
|
+
# / /\/ / \ \ _____ / / | | |/ _ \ '_ \| __|
|
|
4
|
+
# / / / /____\ \_____/ /___| | | __/ | | | |_
|
|
5
|
+
# \/ \____/\__/ \____/|_|_|\___|_| |_|\__|
|
|
6
|
+
|
|
7
|
+
# Disclaimer:
|
|
8
|
+
# Big shout out to Bogdanfinn for open sourcing his tls-client in Golang.
|
|
9
|
+
# Also to requests, as most of the cookie handling is copied from it. :'D
|
|
10
|
+
# I wanted to keep the syntax as similar as possible to requests, as most people use it and are familiar with it!
|
|
11
|
+
# Links:
|
|
12
|
+
# tls-client: https://github.com/bogdanfinn/tls-client
|
|
13
|
+
# requests: https://github.com/psf/requests
|
|
14
|
+
|
|
15
15
|
from .sessions import Session
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
# _____ __ __ ___ _ _ _
|
|
2
|
-
# /__ \/ / / _\ / __\ (_) ___ _ __ | |_
|
|
3
|
-
# / /\/ / \ \ _____ / / | | |/ _ \ '_ \| __|
|
|
4
|
-
# / / / /____\ \_____/ /___| | | __/ | | | |_
|
|
5
|
-
# \/ \____/\__/ \____/|_|_|\___|_| |_|\__|
|
|
6
|
-
|
|
7
|
-
__title__ = "tls_client"
|
|
8
|
-
__description__ = "Advanced Python HTTP Client."
|
|
9
|
-
__version__ = "1.0.1"
|
|
10
|
-
__author__ = "Florian Zager"
|
|
1
|
+
# _____ __ __ ___ _ _ _
|
|
2
|
+
# /__ \/ / / _\ / __\ (_) ___ _ __ | |_
|
|
3
|
+
# / /\/ / \ \ _____ / / | | |/ _ \ '_ \| __|
|
|
4
|
+
# / / / /____\ \_____/ /___| | | __/ | | | |_
|
|
5
|
+
# \/ \____/\__/ \____/|_|_|\___|_| |_|\__|
|
|
6
|
+
|
|
7
|
+
__title__ = "tls_client"
|
|
8
|
+
__description__ = "Advanced Python HTTP Client."
|
|
9
|
+
__version__ = "1.0.1"
|
|
10
|
+
__author__ = "Florian Zager"
|
|
11
11
|
__license__ = "MIT"
|