proxy-reader 2.1.2__tar.gz → 2.1.4__tar.gz
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.
- {proxy_reader-2.1.2/proxy_reader.egg-info → proxy_reader-2.1.4}/PKG-INFO +1 -1
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/proxy_reader/__init__.py +1 -1
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/proxy_reader/reader.py +27 -29
- {proxy_reader-2.1.2 → proxy_reader-2.1.4/proxy_reader.egg-info}/PKG-INFO +1 -1
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/proxy_reader.egg-info/SOURCES.txt +1 -2
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/pyproject.toml +2 -2
- proxy_reader-2.1.4/tests/test_checker.py +17 -0
- proxy_reader-2.1.2/proxy_reader/protocols/__init__.py +0 -0
- proxy_reader-2.1.2/proxy_reader/protocols/reader.py +0 -74
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/LICENSE +0 -0
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/MANIFEST.in +0 -0
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/README.md +0 -0
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/proxy_reader/_types.py +0 -0
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/proxy_reader/domains.py +0 -0
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/proxy_reader/logs_config.py +0 -0
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/proxy_reader/proxy.py +0 -0
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/proxy_reader/py.typed +0 -0
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/proxy_reader/utils.py +0 -0
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/proxy_reader.egg-info/dependency_links.txt +0 -0
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/proxy_reader.egg-info/requires.txt +0 -0
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/proxy_reader.egg-info/top_level.txt +0 -0
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/setup.cfg +0 -0
- {proxy_reader-2.1.2 → proxy_reader-2.1.4}/tests/test_reader.py +0 -0
|
@@ -12,19 +12,19 @@ from aiohttp_socks import ProxyConnector
|
|
|
12
12
|
|
|
13
13
|
from ._types import ProxiesList, ProxyDictT, ProxyiesGen
|
|
14
14
|
from .logs_config import logger
|
|
15
|
-
from .protocols.reader import ProxiesReaderProtocol
|
|
16
15
|
from .proxy import Proxy
|
|
17
16
|
from .utils import parse_proxy_line
|
|
18
17
|
|
|
19
18
|
|
|
20
|
-
class ProxiesReader
|
|
19
|
+
class ProxiesReader:
|
|
21
20
|
def __init__(
|
|
22
21
|
self,
|
|
23
22
|
proxies_file: str,
|
|
24
23
|
check_proxies: bool = False,
|
|
25
24
|
proxy_checking_threads: int = 50,
|
|
26
|
-
max_response_time: int =
|
|
25
|
+
max_response_time: int = 10,
|
|
27
26
|
shuffle: bool = False,
|
|
27
|
+
check_urls: list[str] = [],
|
|
28
28
|
) -> None:
|
|
29
29
|
self._raw_proxies = open(proxies_file, encoding="utf-8", mode="r").readlines()
|
|
30
30
|
|
|
@@ -50,7 +50,7 @@ class ProxiesReader(ProxiesReaderProtocol):
|
|
|
50
50
|
self._timeout_count = 0
|
|
51
51
|
self._proxies_checked = False
|
|
52
52
|
|
|
53
|
-
self._check_urls = [
|
|
53
|
+
self._check_urls = check_urls or [
|
|
54
54
|
# New
|
|
55
55
|
"http://checkip.amazonaws.com",
|
|
56
56
|
"http://ipinfo.io/ip",
|
|
@@ -66,6 +66,8 @@ class ProxiesReader(ProxiesReaderProtocol):
|
|
|
66
66
|
# "http://api.thecatapi.com/v1/images/search",
|
|
67
67
|
# "http://dog.ceo/api/breeds/image/random",
|
|
68
68
|
]
|
|
69
|
+
self._connectins_limit = 60 if "win" in sys.platform else 100
|
|
70
|
+
self._connector = aiohttp.TCPConnector(limit=self._connectins_limit)
|
|
69
71
|
|
|
70
72
|
@classmethod
|
|
71
73
|
def load_list(
|
|
@@ -75,6 +77,7 @@ class ProxiesReader(ProxiesReaderProtocol):
|
|
|
75
77
|
proxy_checking_threads: int = 50,
|
|
76
78
|
max_response_time: int = 60,
|
|
77
79
|
shuffle: bool = False,
|
|
80
|
+
check_urls: list[str] = [],
|
|
78
81
|
) -> "ProxiesReader":
|
|
79
82
|
"""Load proxies from a list"""
|
|
80
83
|
proxies_file = tempfile.NamedTemporaryFile(
|
|
@@ -89,6 +92,7 @@ class ProxiesReader(ProxiesReaderProtocol):
|
|
|
89
92
|
proxy_checking_threads,
|
|
90
93
|
max_response_time,
|
|
91
94
|
shuffle,
|
|
95
|
+
check_urls,
|
|
92
96
|
)
|
|
93
97
|
|
|
94
98
|
finally:
|
|
@@ -172,48 +176,42 @@ class ProxiesReader(ProxiesReaderProtocol):
|
|
|
172
176
|
async def _check_proxy(
|
|
173
177
|
self, proxy: Proxy, response_time: int | None = None
|
|
174
178
|
) -> bool:
|
|
175
|
-
connectins_limit = 60 if "win" in sys.platform else 100
|
|
176
|
-
connector = aiohttp.TCPConnector(limit=connectins_limit)
|
|
177
|
-
session = aiohttp.ClientSession(connector=connector)
|
|
178
|
-
url = self._random_proxy_check_url()
|
|
179
|
-
p = proxy.http
|
|
180
|
-
|
|
181
179
|
async with self._thread_control:
|
|
182
|
-
|
|
180
|
+
session = aiohttp.ClientSession(connector=self._connector)
|
|
181
|
+
logger.debug(f"Checking proxy {proxy} ..")
|
|
183
182
|
try:
|
|
184
183
|
# resp = await asyncio.wait_for(session.get(url, proxy=p), timeout=self._max_response_time)
|
|
185
184
|
resp = await session.get(
|
|
186
|
-
|
|
187
|
-
timeout=aiohttp.ClientTimeout(
|
|
188
|
-
|
|
185
|
+
self._random_proxy_check_url(),
|
|
186
|
+
timeout=aiohttp.ClientTimeout(
|
|
187
|
+
total=response_time or self._max_response_time
|
|
188
|
+
),
|
|
189
|
+
proxy=proxy.http,
|
|
189
190
|
ssl=False,
|
|
190
191
|
)
|
|
191
|
-
|
|
192
|
+
|
|
193
|
+
if resp.status in range(200, 299):
|
|
194
|
+
logger.debug(f"{proxy}: Working")
|
|
195
|
+
self._working_proxies.append(proxy)
|
|
196
|
+
return True
|
|
197
|
+
|
|
198
|
+
else:
|
|
199
|
+
logger.debug(f"{proxy}: Not Working. Response code: {resp.status}")
|
|
200
|
+
self._bad_proxies.append(proxy)
|
|
192
201
|
|
|
193
202
|
except asyncio.TimeoutError as e:
|
|
194
203
|
self._timeout_count += 1
|
|
195
|
-
logger.debug(f"{
|
|
204
|
+
logger.debug(f"{proxy} : TIMEOUT {e}.")
|
|
196
205
|
self._bad_proxies.append(proxy)
|
|
197
|
-
await connector.close()
|
|
198
|
-
await session.close()
|
|
199
|
-
return False
|
|
200
206
|
|
|
201
207
|
except Exception as e:
|
|
202
208
|
logger.debug(f"Bad proxy raised. {e}", exc_info=True)
|
|
203
|
-
|
|
209
|
+
self._bad_proxies.append(proxy)
|
|
204
210
|
|
|
205
211
|
finally:
|
|
206
212
|
await session.close()
|
|
207
213
|
|
|
208
|
-
|
|
209
|
-
logger.debug(f"{p}: Working")
|
|
210
|
-
self._working_proxies.append(proxy)
|
|
211
|
-
|
|
212
|
-
else:
|
|
213
|
-
logger.debug(f"{p}: Not Working. Response code: {resp.status}")
|
|
214
|
-
self._bad_proxies.append(proxy)
|
|
215
|
-
|
|
216
|
-
return True
|
|
214
|
+
return False
|
|
217
215
|
|
|
218
216
|
async def check_all_proxies(self, max_resp_time: int = 30) -> None:
|
|
219
217
|
"""Run this to check all proxies at once."""
|
|
@@ -15,6 +15,5 @@ proxy_reader.egg-info/SOURCES.txt
|
|
|
15
15
|
proxy_reader.egg-info/dependency_links.txt
|
|
16
16
|
proxy_reader.egg-info/requires.txt
|
|
17
17
|
proxy_reader.egg-info/top_level.txt
|
|
18
|
-
|
|
19
|
-
proxy_reader/protocols/reader.py
|
|
18
|
+
tests/test_checker.py
|
|
20
19
|
tests/test_reader.py
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "proxy-reader"
|
|
3
|
-
version = "2.1.
|
|
3
|
+
version = "2.1.4"
|
|
4
4
|
description = "Proxy reader for Python"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.12"
|
|
@@ -28,7 +28,7 @@ github = "https://github.com/runetech0/proxy-reader"
|
|
|
28
28
|
|
|
29
29
|
[tool.bumpver]
|
|
30
30
|
|
|
31
|
-
current_version = "2.1.
|
|
31
|
+
current_version = "2.1.4"
|
|
32
32
|
version_pattern = "MAJOR.MINOR.PATCH"
|
|
33
33
|
commit_message = "bump version {old_version} -> {new_version}"
|
|
34
34
|
tag_message = "{new_version}"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
3
|
+
from proxy_reader.reader import ProxiesReader
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
async def main() -> None:
|
|
7
|
+
check_urls = ["https://proxy-check.queuetools.com"]
|
|
8
|
+
reader = ProxiesReader("proxies.txt", check_proxies=True, check_urls=check_urls)
|
|
9
|
+
await reader.check_all_proxies(max_resp_time=3)
|
|
10
|
+
|
|
11
|
+
print("Total working proxies:", reader.total_working)
|
|
12
|
+
print("Total bad proxies:", reader.total_bad)
|
|
13
|
+
print("Total proxies:", reader.total)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
if __name__ == "__main__":
|
|
17
|
+
asyncio.run(main())
|
|
File without changes
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
from typing import List, Optional, Dict, Any, Protocol
|
|
2
|
-
from .._types import ProxiesList
|
|
3
|
-
from ..proxy import Proxy
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class ProxiesReaderProtocol(Protocol):
|
|
7
|
-
@property
|
|
8
|
-
def total(self) -> int: ...
|
|
9
|
-
|
|
10
|
-
@property
|
|
11
|
-
def total_working(self) -> int: ...
|
|
12
|
-
|
|
13
|
-
@property
|
|
14
|
-
def total_bad(self) -> int: ...
|
|
15
|
-
|
|
16
|
-
@property
|
|
17
|
-
def proxies(self) -> ProxiesList: ...
|
|
18
|
-
|
|
19
|
-
@property
|
|
20
|
-
def bad_proxies(self) -> ProxiesList: ...
|
|
21
|
-
|
|
22
|
-
@property
|
|
23
|
-
def working_proxies(self) -> ProxiesList: ...
|
|
24
|
-
|
|
25
|
-
@working_proxies.setter
|
|
26
|
-
def working_proxies(self, working_proxies: List[Proxy]) -> None: ...
|
|
27
|
-
|
|
28
|
-
def _random_proxy_check_url(self) -> str: ...
|
|
29
|
-
|
|
30
|
-
def read_with_auth(self) -> None: ...
|
|
31
|
-
|
|
32
|
-
def read_authless(self) -> None: ...
|
|
33
|
-
|
|
34
|
-
async def _check_proxy(
|
|
35
|
-
self, proxy: Proxy, response_time: Optional[int] = None
|
|
36
|
-
) -> bool: ...
|
|
37
|
-
|
|
38
|
-
async def check_all_proxies(self, max_resp_time: int = 30) -> None: ...
|
|
39
|
-
|
|
40
|
-
async def _check_proxy_socks(
|
|
41
|
-
self, proxy: Proxy, response_time: Optional[int] = None
|
|
42
|
-
) -> bool: ...
|
|
43
|
-
|
|
44
|
-
async def check_all_proxies_socks5(self, max_resp_time: int = 5) -> None: ...
|
|
45
|
-
|
|
46
|
-
def get_working_proxies_list_http(self) -> List[str]: ...
|
|
47
|
-
|
|
48
|
-
def write_working_proxies(self, filename: str) -> None: ...
|
|
49
|
-
|
|
50
|
-
def get_random_http(self) -> Optional[str]: ...
|
|
51
|
-
|
|
52
|
-
def get_random_socks5(self) -> Optional[str]: ...
|
|
53
|
-
|
|
54
|
-
def get_random_socks5_telegram(self) -> Optional[Dict[str, Any]]: ...
|
|
55
|
-
|
|
56
|
-
def next_http_from_list(self) -> Optional[str]: ...
|
|
57
|
-
|
|
58
|
-
def next_http_from_cycle(self) -> str: ...
|
|
59
|
-
|
|
60
|
-
def next_socks5_from_list(self) -> str: ...
|
|
61
|
-
|
|
62
|
-
def next_socks5_from_cycle(self) -> str: ...
|
|
63
|
-
|
|
64
|
-
def next_http_telegram_from_list(self) -> Dict[str, Any]: ...
|
|
65
|
-
|
|
66
|
-
def next_http_telegram_from_cycle(self) -> Dict[str, Any]: ...
|
|
67
|
-
|
|
68
|
-
def next_socks5_telegram_from_cycle(self) -> Dict[str, Any]: ...
|
|
69
|
-
|
|
70
|
-
def next_socks5_telegram_from_list(self) -> Dict[str, Any]: ...
|
|
71
|
-
|
|
72
|
-
def next_https_from_list(self) -> str: ...
|
|
73
|
-
|
|
74
|
-
def next_https_from_cycle(self) -> str: ...
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|