Parsers¶
Parsing helpers and format auto-detection functions for string-formatted proxies.
proxy_string.parsers
¶
Parsers and regex patterns for text-formatted proxy strings.
detect_possible_formats
¶
detect_possible_formats(
proxy_string: str,
) -> tuple[tuple[ProxyStringFormat, dict[str, Any]], ...]
Detects viable proxy string formats and attempts to parse the string.
Note
When credentials (usernames or passwords) contain only digits and fall into
a valid port range (0..65535), 4-part colon-delimited strings can be ambiguous.
Explicitly passing ProxyStringFormat is recommended in such cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proxy_string
|
str
|
Raw proxy string without scheme. |
required |
Returns:
| Type | Description |
|---|---|
tuple[tuple[ProxyStringFormat, dict[str, Any]], ...]
|
tuple[tuple[ProxyStringFormat, dict[str, Any]], ...]: Parsed formats and data dictionaries. |
Source code in src/proxy_string/parsers.py
parse_proxy_string
¶
parse_proxy_string(
proxy_string: str, proxy_format: ProxyStringFormat
) -> dict[str, Any]
Parses a proxy string according to the specified format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proxy_string
|
str
|
Proxy string to parse. |
required |
proxy_format
|
ProxyStringFormat
|
Expected ProxyStringFormat. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Extracted proxy parameters (host, port, username, password). |
Raises:
| Type | Description |
|---|---|
InvalidProxyStringError
|
If the string does not match the expected format. |