convert list of str to valid proxies or proxy :param data: :return:
(data)
| 39 | |
| 40 | |
| 41 | def 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 | |
| 70 | def is_auth_proxy(data: str) -> bool: |
no test coverage detected