notify-tls-client 0.1.1__py3-none-any.whl → 0.1.3__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 +6 -6
- notify_tls_client/core/client/decorators.py +90 -90
- notify_tls_client/core/notifytlsclient.py +146 -144
- 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 +33 -33
- notify_tls_client/tls_client/cookies.py +456 -456
- notify_tls_client/tls_client/exceptions.py +2 -2
- notify_tls_client/tls_client/response.py +78 -78
- notify_tls_client/tls_client/sessions.py +513 -513
- notify_tls_client/tls_client/settings.py +69 -69
- notify_tls_client/tls_client/structures.py +74 -74
- {notify_tls_client-0.1.1.dist-info → notify_tls_client-0.1.3.dist-info}/METADATA +16 -14
- notify_tls_client-0.1.3.dist-info/RECORD +26 -0
- notify_tls_client/tls_client/dependencies/tls-client-amd64.so +0 -0
- notify_tls_client/tls_client/dependencies/tls-client-arm64.so +0 -0
- notify_tls_client/tls_client/dependencies/tls-client-x86.so +0 -0
- notify_tls_client-0.1.1.dist-info/RECORD +0 -29
- {notify_tls_client-0.1.1.dist-info → notify_tls_client-0.1.3.dist-info}/WHEEL +0 -0
- {notify_tls_client-0.1.1.dist-info → notify_tls_client-0.1.3.dist-info}/top_level.txt +0 -0
notify_tls_client/__init__.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
from .core.notifytlsclient import NotifyTLSClient
|
|
2
|
-
from .tls_client import Session
|
|
1
|
+
from .core.notifytlsclient import NotifyTLSClient
|
|
2
|
+
from .tls_client import Session
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
from .decorators import (
|
|
2
|
-
increment_requests_decorator,
|
|
3
|
-
handle_forbidden_requests_decorator,
|
|
4
|
-
print_request_infos_decorator,
|
|
5
|
-
change_state_decorator,
|
|
6
|
-
handle_exception_requests_decorator)
|
|
1
|
+
from .decorators import (
|
|
2
|
+
increment_requests_decorator,
|
|
3
|
+
handle_forbidden_requests_decorator,
|
|
4
|
+
print_request_infos_decorator,
|
|
5
|
+
change_state_decorator,
|
|
6
|
+
handle_exception_requests_decorator)
|
|
@@ -1,90 +1,90 @@
|
|
|
1
|
-
import time
|
|
2
|
-
import traceback
|
|
3
|
-
from datetime import datetime
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def change_state_decorator(callback):
|
|
8
|
-
def wrapper(*args, **kwargs):
|
|
9
|
-
self = args[0]
|
|
10
|
-
self.free = False
|
|
11
|
-
response = callback(*args, **kwargs)
|
|
12
|
-
self.free = True
|
|
13
|
-
return response
|
|
14
|
-
|
|
15
|
-
return wrapper
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def print_request_infos_decorator(callback):
|
|
19
|
-
def wrapper(*args, **kwargs):
|
|
20
|
-
start = time.time()
|
|
21
|
-
response = callback(*args, **kwargs)
|
|
22
|
-
response.elapsed = round((time.time() - start) * 1000, 2)
|
|
23
|
-
self = args[0]
|
|
24
|
-
|
|
25
|
-
print("Date: ", datetime.now().strftime("%d-%m-%Y %H:%M:%S.%f")[:-3])
|
|
26
|
-
print(f"Request URL: {response.url}")
|
|
27
|
-
print(f"Response Status Code: {response.status_code}")
|
|
28
|
-
print(f"Response Headers: {response.headers}")
|
|
29
|
-
print(f"Response Elapsed Time: {response.elapsed} ms")
|
|
30
|
-
|
|
31
|
-
if self.client.proxies:
|
|
32
|
-
print(f"Proxy: {self.client.proxies['http']}")
|
|
33
|
-
|
|
34
|
-
print(f"-")
|
|
35
|
-
|
|
36
|
-
return response
|
|
37
|
-
|
|
38
|
-
return wrapper
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def handle_exception_requests_decorator(callback):
|
|
42
|
-
def wrapper(*args, **kwargs):
|
|
43
|
-
response = None
|
|
44
|
-
try:
|
|
45
|
-
response = callback(*args, **kwargs)
|
|
46
|
-
except Exception as e:
|
|
47
|
-
print(traceback.format_exc())
|
|
48
|
-
self = args[0]
|
|
49
|
-
self.get_tls().close()
|
|
50
|
-
self._create_new_client()
|
|
51
|
-
self.change_proxy()
|
|
52
|
-
|
|
53
|
-
return response
|
|
54
|
-
|
|
55
|
-
return wrapper
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def handle_forbidden_requests_decorator(callback):
|
|
59
|
-
def wrapper(*args, **kwargs):
|
|
60
|
-
response = callback(*args, **kwargs)
|
|
61
|
-
if response.status_code == 403 or response.status_code == 429:
|
|
62
|
-
self = args[0]
|
|
63
|
-
self.get_tls().close()
|
|
64
|
-
self._create_new_client()
|
|
65
|
-
|
|
66
|
-
if self.proxies_manager:
|
|
67
|
-
self.change_proxy()
|
|
68
|
-
|
|
69
|
-
return response
|
|
70
|
-
|
|
71
|
-
return wrapper
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def increment_requests_decorator(callback):
|
|
75
|
-
def wrapper(*args, **kwargs):
|
|
76
|
-
|
|
77
|
-
self = args[0]
|
|
78
|
-
response = callback(*args, **kwargs)
|
|
79
|
-
self.requests_amount += 1
|
|
80
|
-
|
|
81
|
-
if self.requests_amount >= self.requests_limit_same_proxy:
|
|
82
|
-
self.get_tls().close()
|
|
83
|
-
self._create_new_client()
|
|
84
|
-
self.change_proxy()
|
|
85
|
-
|
|
86
|
-
return response
|
|
87
|
-
|
|
88
|
-
return wrapper
|
|
89
|
-
|
|
90
|
-
|
|
1
|
+
import time
|
|
2
|
+
import traceback
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def change_state_decorator(callback):
|
|
8
|
+
def wrapper(*args, **kwargs):
|
|
9
|
+
self = args[0]
|
|
10
|
+
self.free = False
|
|
11
|
+
response = callback(*args, **kwargs)
|
|
12
|
+
self.free = True
|
|
13
|
+
return response
|
|
14
|
+
|
|
15
|
+
return wrapper
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def print_request_infos_decorator(callback):
|
|
19
|
+
def wrapper(*args, **kwargs):
|
|
20
|
+
start = time.time()
|
|
21
|
+
response = callback(*args, **kwargs)
|
|
22
|
+
response.elapsed = round((time.time() - start) * 1000, 2)
|
|
23
|
+
self = args[0]
|
|
24
|
+
|
|
25
|
+
print("Date: ", datetime.now().strftime("%d-%m-%Y %H:%M:%S.%f")[:-3])
|
|
26
|
+
print(f"Request URL: {response.url}")
|
|
27
|
+
print(f"Response Status Code: {response.status_code}")
|
|
28
|
+
print(f"Response Headers: {response.headers}")
|
|
29
|
+
print(f"Response Elapsed Time: {response.elapsed} ms")
|
|
30
|
+
|
|
31
|
+
if self.client.proxies:
|
|
32
|
+
print(f"Proxy: {self.client.proxies['http']}")
|
|
33
|
+
|
|
34
|
+
print(f"-")
|
|
35
|
+
|
|
36
|
+
return response
|
|
37
|
+
|
|
38
|
+
return wrapper
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def handle_exception_requests_decorator(callback):
|
|
42
|
+
def wrapper(*args, **kwargs):
|
|
43
|
+
response = None
|
|
44
|
+
try:
|
|
45
|
+
response = callback(*args, **kwargs)
|
|
46
|
+
except Exception as e:
|
|
47
|
+
print(traceback.format_exc())
|
|
48
|
+
self = args[0]
|
|
49
|
+
self.get_tls().close()
|
|
50
|
+
self._create_new_client(self.client_identifier,self.random_tls_extension_order)
|
|
51
|
+
self.change_proxy()
|
|
52
|
+
|
|
53
|
+
return response
|
|
54
|
+
|
|
55
|
+
return wrapper
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def handle_forbidden_requests_decorator(callback):
|
|
59
|
+
def wrapper(*args, **kwargs):
|
|
60
|
+
response = callback(*args, **kwargs)
|
|
61
|
+
if response.status_code == 403 or response.status_code == 429:
|
|
62
|
+
self = args[0]
|
|
63
|
+
self.get_tls().close()
|
|
64
|
+
self._create_new_client(self.client_identifier,self.random_tls_extension_order)
|
|
65
|
+
|
|
66
|
+
if self.proxies_manager:
|
|
67
|
+
self.change_proxy()
|
|
68
|
+
|
|
69
|
+
return response
|
|
70
|
+
|
|
71
|
+
return wrapper
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def increment_requests_decorator(callback):
|
|
75
|
+
def wrapper(*args, **kwargs):
|
|
76
|
+
|
|
77
|
+
self = args[0]
|
|
78
|
+
response = callback(*args, **kwargs)
|
|
79
|
+
self.requests_amount += 1
|
|
80
|
+
|
|
81
|
+
if self.requests_amount >= self.requests_limit_same_proxy:
|
|
82
|
+
self.get_tls().close()
|
|
83
|
+
self._create_new_client(self.client_identifier,self.random_tls_extension_order)
|
|
84
|
+
self.change_proxy()
|
|
85
|
+
|
|
86
|
+
return response
|
|
87
|
+
|
|
88
|
+
return wrapper
|
|
89
|
+
|
|
90
|
+
|
|
@@ -1,144 +1,146 @@
|
|
|
1
|
-
import time
|
|
2
|
-
from datetime import datetime
|
|
3
|
-
from typing import Optional
|
|
4
|
-
|
|
5
|
-
from notify_tls_client import tls_client
|
|
6
|
-
from notify_tls_client.core.client import *
|
|
7
|
-
from notify_tls_client.core.proxiesmanager import ProxiesManager, Proxy
|
|
8
|
-
|
|
9
|
-
from notify_tls_client.tls_client.response import Response
|
|
10
|
-
from notify_tls_client.tls_client.settings import ClientIdentifiers
|
|
11
|
-
from notify_tls_client.tls_client.structures import CaseInsensitiveDict
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class NotifyTLSClient:
|
|
15
|
-
|
|
16
|
-
def __init__(self,
|
|
17
|
-
proxies_manager: Optional[ProxiesManager] = None,
|
|
18
|
-
requests_limit_same_proxy: int = 1000,
|
|
19
|
-
client_identifier: ClientIdentifiers = "chrome_133",
|
|
20
|
-
random_tls_extension_order: bool = True):
|
|
21
|
-
|
|
22
|
-
self.client = None
|
|
23
|
-
self.free = True
|
|
24
|
-
self.requests_amount = 0
|
|
25
|
-
self.last_request_status = 0
|
|
26
|
-
self.headers = CaseInsensitiveDict({
|
|
27
|
-
"User-Agent": f"tls-client/1.0.0",
|
|
28
|
-
"Accept-Encoding": "gzip, deflate, br",
|
|
29
|
-
"Accept": "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
|
|
30
|
-
"Connection": "keep-alive",
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
self.
|
|
34
|
-
self.
|
|
35
|
-
self.
|
|
36
|
-
self.
|
|
37
|
-
self.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
self.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1
|
+
import time
|
|
2
|
+
from datetime import datetime
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from notify_tls_client import tls_client
|
|
6
|
+
from notify_tls_client.core.client import *
|
|
7
|
+
from notify_tls_client.core.proxiesmanager import ProxiesManager, Proxy
|
|
8
|
+
|
|
9
|
+
from notify_tls_client.tls_client.response import Response
|
|
10
|
+
from notify_tls_client.tls_client.settings import ClientIdentifiers
|
|
11
|
+
from notify_tls_client.tls_client.structures import CaseInsensitiveDict
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class NotifyTLSClient:
|
|
15
|
+
|
|
16
|
+
def __init__(self,
|
|
17
|
+
proxies_manager: Optional[ProxiesManager] = None,
|
|
18
|
+
requests_limit_same_proxy: int = 1000,
|
|
19
|
+
client_identifier: ClientIdentifiers = "chrome_133",
|
|
20
|
+
random_tls_extension_order: bool = True):
|
|
21
|
+
|
|
22
|
+
self.client = None
|
|
23
|
+
self.free = True
|
|
24
|
+
self.requests_amount = 0
|
|
25
|
+
self.last_request_status = 0
|
|
26
|
+
self.headers = CaseInsensitiveDict({
|
|
27
|
+
"User-Agent": f"tls-client/1.0.0",
|
|
28
|
+
"Accept-Encoding": "gzip, deflate, br",
|
|
29
|
+
"Accept": "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8",
|
|
30
|
+
"Connection": "keep-alive",
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
self.client_identifier = client_identifier
|
|
34
|
+
self.proxies_manager = proxies_manager
|
|
35
|
+
self.requests_limit_same_proxy = requests_limit_same_proxy
|
|
36
|
+
self.random_tls_extension_order = random_tls_extension_order
|
|
37
|
+
self.current_proxy = None
|
|
38
|
+
self._create_new_client(self.client_identifier, self.random_tls_extension_order)
|
|
39
|
+
self.change_proxy()
|
|
40
|
+
|
|
41
|
+
def _create_new_client(self, client_identifier: ClientIdentifiers = 'chrome_133', random_tls_extension_order: bool = False):
|
|
42
|
+
self.client = tls_client.Session(client_identifier=client_identifier,
|
|
43
|
+
random_tls_extension_order=random_tls_extension_order)
|
|
44
|
+
|
|
45
|
+
def set_requests_limit_same_proxy(self, requests_limit_same_proxy: int):
|
|
46
|
+
self.requests_limit_same_proxy = requests_limit_same_proxy
|
|
47
|
+
|
|
48
|
+
def set_proxies_manager(self, proxies_manager: ProxiesManager):
|
|
49
|
+
self.proxies_manager = proxies_manager
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def change_proxy(self):
|
|
53
|
+
if self.proxies_manager and self.proxies_manager.get_proxies():
|
|
54
|
+
self.current_proxy = self.proxies_manager.get_next()
|
|
55
|
+
self.client.proxies = self.current_proxy.to_proxy_dict()
|
|
56
|
+
self.requests_amount = 0
|
|
57
|
+
|
|
58
|
+
def set_proxies(self, proxies: Proxy):
|
|
59
|
+
self.client.proxies = proxies.to_proxy_dict()
|
|
60
|
+
|
|
61
|
+
def set_headers(self, headers: dict):
|
|
62
|
+
self.client.headers = CaseInsensitiveDict(headers)
|
|
63
|
+
|
|
64
|
+
def get_cookies(self):
|
|
65
|
+
return self.client.cookies
|
|
66
|
+
|
|
67
|
+
def get_cookie_by_name(self, name: str):
|
|
68
|
+
return self.client.cookies.get(name)
|
|
69
|
+
|
|
70
|
+
@handle_exception_requests_decorator
|
|
71
|
+
@increment_requests_decorator
|
|
72
|
+
@handle_forbidden_requests_decorator
|
|
73
|
+
@print_request_infos_decorator
|
|
74
|
+
@change_state_decorator
|
|
75
|
+
def get(self, url: str, **kwargs) -> Response:
|
|
76
|
+
start = time.time()
|
|
77
|
+
response = self.client.get(url, **kwargs)
|
|
78
|
+
response.elapsed = round((time.time() - start) * 1000, 2)
|
|
79
|
+
self.last_request_status = response.status_code
|
|
80
|
+
return response
|
|
81
|
+
|
|
82
|
+
@handle_exception_requests_decorator
|
|
83
|
+
@increment_requests_decorator
|
|
84
|
+
@handle_forbidden_requests_decorator
|
|
85
|
+
@print_request_infos_decorator
|
|
86
|
+
@change_state_decorator
|
|
87
|
+
def post(self, url: str, **kwargs) -> Response:
|
|
88
|
+
start = time.time()
|
|
89
|
+
response = self.client.post(url, **kwargs)
|
|
90
|
+
response.elapsed = round((time.time() - start) * 1000, 2)
|
|
91
|
+
|
|
92
|
+
self.last_request_status = response.status_code
|
|
93
|
+
return response
|
|
94
|
+
|
|
95
|
+
@handle_exception_requests_decorator
|
|
96
|
+
@increment_requests_decorator
|
|
97
|
+
@handle_forbidden_requests_decorator
|
|
98
|
+
@print_request_infos_decorator
|
|
99
|
+
@change_state_decorator
|
|
100
|
+
def put(self, url: str, **kwargs) -> Response:
|
|
101
|
+
start = datetime.now()
|
|
102
|
+
response = self.client.put(url, **kwargs)
|
|
103
|
+
response.elapsed = datetime.now() - start
|
|
104
|
+
|
|
105
|
+
self.last_request_status = response.status_code
|
|
106
|
+
return response
|
|
107
|
+
|
|
108
|
+
@increment_requests_decorator
|
|
109
|
+
@handle_forbidden_requests_decorator
|
|
110
|
+
@print_request_infos_decorator
|
|
111
|
+
@change_state_decorator
|
|
112
|
+
def delete(self, url: str, **kwargs) -> Response:
|
|
113
|
+
start = time.time()
|
|
114
|
+
response = self.client.delete(url, **kwargs)
|
|
115
|
+
response.elapsed = round((time.time() - start) * 1000, 2)
|
|
116
|
+
|
|
117
|
+
self.last_request_status = response.status_code
|
|
118
|
+
return response
|
|
119
|
+
|
|
120
|
+
@handle_exception_requests_decorator
|
|
121
|
+
@increment_requests_decorator
|
|
122
|
+
@handle_forbidden_requests_decorator
|
|
123
|
+
@print_request_infos_decorator
|
|
124
|
+
@change_state_decorator
|
|
125
|
+
def patch(self, url: str, **kwargs) -> Response:
|
|
126
|
+
start = datetime.now()
|
|
127
|
+
response = self.client.patch(url, **kwargs)
|
|
128
|
+
response.elapsed = datetime.now() - start
|
|
129
|
+
|
|
130
|
+
self.last_request_status = response.status_code
|
|
131
|
+
return response
|
|
132
|
+
|
|
133
|
+
def _change_to_free(self):
|
|
134
|
+
self.free = True
|
|
135
|
+
|
|
136
|
+
def _change_to_busy(self):
|
|
137
|
+
self.free = False
|
|
138
|
+
|
|
139
|
+
def get_cookie_value_by_name(self, name: str):
|
|
140
|
+
return self.client.cookies.get(name)
|
|
141
|
+
|
|
142
|
+
def set_cookie(self, name: str, value: str):
|
|
143
|
+
self.client.cookies.set(name, value)
|
|
144
|
+
|
|
145
|
+
def get_tls(self):
|
|
146
|
+
return self.client
|
|
@@ -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
|
+
|