-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathproxy_utils.py
More file actions
31 lines (22 loc) · 809 Bytes
/
proxy_utils.py
File metadata and controls
31 lines (22 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import copy
import random
from checkers.base_checker import CheckerResult
from proxy_py import settings
async def check_proxy(proxy_url: str, timeout=None) -> tuple:
if not settings.PROXY_CHECKERS:
raise Exception("add at least one checker")
checkers = copy.copy(settings.PROXY_CHECKERS)
random.shuffle(checkers)
results = []
for checker, _ in zip(
checkers, range(settings.MINIMUM_NUMBER_OF_CHECKERS_PER_PROXY)
):
checker()
result = await checker().check(proxy_url, timeout=timeout)
if not result[0]:
return False, None
results.append(result)
additional_information = CheckerResult()
for result in results:
additional_information.update_from_other(result[1])
return True, additional_information