MCPcopy Index your code
hub / github.com/Python3WebSpider/ProxyPool / convert_proxy_or_proxies

Function convert_proxy_or_proxies

proxypool/utils/proxy.py:41–67  ·  view source on GitHub ↗

convert list of str to valid proxies or proxy :param data: :return:

(data)

Source from the content-addressed store, hash-verified

39
40
41def convert_proxy_or_proxies(data):
42 """
43 convert list of str to valid proxies or proxy
44 :param data:
45 :return:
46 """
47 if not data:
48 return None
49 # if list of proxies
50 if isinstance(data, list):
51 result = []
52 for item in data:
53 # skip invalid item
54 item = item.strip()
55 if not is_valid_proxy(item): continue
56 if is_auth_proxy(item):
57 host, port = extract_auth_proxy(item)
58 else:
59 host, port, *_ = item.split(':')
60 result.append(Proxy(host=host, port=int(port)))
61 return result
62 if isinstance(data, str) and is_valid_proxy(data):
63 if is_auth_proxy(data):
64 host, port = extract_auth_proxy(data)
65 else:
66 host, port, *_ = data.split(':')
67 return Proxy(host=host, port=int(port))
68
69
70def is_auth_proxy(data: str) -> bool:

Callers 4

randomMethod · 0.90
randomsMethod · 0.90
allMethod · 0.90
batchMethod · 0.90

Calls 4

ProxyClass · 0.90
is_valid_proxyFunction · 0.85
is_auth_proxyFunction · 0.85
extract_auth_proxyFunction · 0.85

Tested by

no test coverage detected