URL Tools¶
URL parsing, escaping, and scheme resolution helpers conforming to WHATWG URL and RFC standards.
proxy_string.url_tools
¶
URL parsing, escaping, and scheme resolution helpers.
build_url
¶
build_url(
scheme: str,
host: str,
port: int,
username: str | None = None,
password: str | None = None,
) -> str
Constructs a standard URL string from individual proxy components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scheme
|
str
|
The URL scheme/protocol (e.g. 'http', 'socks5h'). |
required |
host
|
str
|
Hostname or IP address (IPv6 will be bracketed if needed). |
required |
port
|
int
|
Connection port number. |
required |
username
|
str | None
|
Optional username credential. |
None
|
password
|
str | None
|
Optional password credential. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Formatted URL string. |
Source code in src/proxy_string/url_tools.py
get_protocol
¶
get_protocol(
scheme: str,
) -> tuple[ProxyServerProtocol, bool | None]
Resolves a scheme name into a ProxyServerProtocol and remote_dns flag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scheme
|
str
|
URL scheme string (e.g. 'socks5h', 'http'). |
required |
Returns:
| Type | Description |
|---|---|
tuple[ProxyServerProtocol, bool | None]
|
tuple[ProxyServerProtocol, bool | None]: Tuple of protocol enum and remote_dns setting. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If scheme is not a recognized proxy protocol. |
Source code in src/proxy_string/url_tools.py
get_scheme
¶
get_scheme(
protocol: ProxyServerProtocol | str,
remote_dns: bool | None,
socks_ext: bool = True,
) -> str
Determines the appropriate URL scheme based on protocol and DNS resolution mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
protocol
|
ProxyServerProtocol | str
|
Proxy protocol enum member or protocol name string. |
required |
remote_dns
|
bool | None
|
Whether remote DNS resolution is enabled. |
required |
socks_ext
|
bool
|
Whether to use extended SOCKS schemes ('socks4a', 'socks5h'). |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Resolved scheme string. |
Source code in src/proxy_string/url_tools.py
quote_all
¶
Percent-encodes all reserved characters in a string.
Encodes every character that is not alphanumeric, without treating any characters as safe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_string
|
str
|
The string to percent-encode. |
required |
encoding
|
str
|
The text encoding to use (defaults to 'utf-8'). |
'utf-8'
|
errors
|
str
|
Error handling scheme for decoding errors. |
'strict'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The fully percent-encoded string. |
Source code in src/proxy_string/url_tools.py
unquote_all
¶
Decodes percent-encoded characters in a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_string
|
str
|
The percent-encoded string. |
required |
encoding
|
str
|
The text encoding to use (defaults to 'utf-8'). |
'utf-8'
|
errors
|
str
|
Error handling scheme for decoding errors. |
'strict'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The decoded string. |
Source code in src/proxy_string/url_tools.py
proxy_string.whatwg_url
¶
WHATWG URL standard backend integration and IDNA decoding.
clear_cache
¶
decode_idna
cached
¶
Decodes a punycode/IDNA domain to Unicode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoded_domain
|
str
|
Punycode-encoded domain name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Unicode representation of the domain name. |
Source code in src/proxy_string/whatwg_url.py
parse_url
¶
Parses a proxy URL into a dictionary of proxy attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Absolute proxy URL string. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Parsed proxy attributes. |
Raises:
| Type | Description |
|---|---|
InvalidProxyURLError
|
If URL has no scheme, missing host, or SOCKS4 is used with IPv6. |