Parse a proxy URL into (protocol, host, port, username, password).
(proxy_url: str)
| 1000 | |
| 1001 | |
| 1002 | def _parse_proxy_url(proxy_url: str): |
| 1003 | """Parse a proxy URL into (protocol, host, port, username, password).""" |
| 1004 | if not proxy_url: |
| 1005 | return None, None, None, None, None |
| 1006 | url = proxy_url.strip() |
| 1007 | if not re.match(r'^(http|https|socks5h?|socks5)://', url): |
| 1008 | url = f"http://{url}" |
| 1009 | m = re.match(r'^(socks5h?|socks5|http|https)://(?:([^:]+):([^@]+)@)?([^:]+):(\d+)$', url) |
| 1010 | if not m: |
| 1011 | return None, None, None, None, None |
| 1012 | protocol, username, password, host, port = m.groups() |
| 1013 | if protocol == "socks5h": |
| 1014 | protocol = "socks5" |
| 1015 | return protocol, host, port, username, password |
| 1016 | |
| 1017 | |
| 1018 | def _compose_proxy_url( |
no outgoing calls
no test coverage detected