wasat.uri
Gemini URI representation and parsing.
GEMINI_DEFAULT_PORT
module-attribute
The default network port for the Gemini protocol.
GEMINI_PREFIX
module-attribute
GEMINI_PREFIX: Final[str] = f'{GEMINI_SCHEME}://'
The standard prefix for Gemini URIs.
GEMINI_SCHEME
module-attribute
The default URL scheme for the Gemini protocol.
GeminiURI
Represents a validated Gemini protocol URI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | GeminiURI
|
The raw URI string or an existing GeminiURI to clone. |
required |
Raises:
| Type | Description |
|---|---|
URIError
|
If the URI is empty, the scheme is missing or is not 'gemini', the host is missing or invalid, or if parsing of the URI fails. |
MAXIMUM_LENGTH
class-attribute
instance-attribute
The maximum length of a Gemini URI string.
bytes_left
cached
property
bytes_left: int
The number of left left before reaching the maximum URI length.
parent
property
parent: Self
The URI representing the parent directory of this URI's path.
Note
Any query will be removed.
root
property
root: Self
The URI representing the root directory of this URI's host.
Note
Any query will be removed.
without_query
property
without_query: Self
replace
replace(
*,
host: str | _UnsetType = _UNSET,
port: int | _UnsetType = _UNSET,
path: str | None | _UnsetType = _UNSET,
query: str | None | _UnsetType = _UNSET,
) -> Self
Create a new GeminiURI by replacing specific parts of this URI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | _UnsetType
|
The new hostname, or _UNSET to keep the current host. |
_UNSET
|
|
int | _UnsetType
|
The new port number, or _UNSET to keep the current port. |
_UNSET
|
|
str | None | _UnsetType
|
The new path, None to clear the path, or _UNSET to keep current. |
_UNSET
|
|
str | None | _UnsetType
|
The new query string, None to clear the query, or _UNSET to keep current. |
_UNSET
|
Returns:
| Type | Description |
|---|---|
Self
|
A new GeminiURI instance with the replaced components. |
Raises:
| Type | Description |
|---|---|
URIError
|
If the resulting URI is invalid (e.g., if the replaced host or port is invalid). |
resolve
resolve(relative_uri: str) -> Self
Resolve a relative URI string against this URI as a base.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The relative or absolute target URI string. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new GeminiURI representing the resolved target. |
Raises:
| Type | Description |
|---|---|
URIError
|
If the resolved target URI is invalid, or if the relative URI cannot be parsed or resolved against the base URI. |
with_default_scheme
classmethod
Add the Gemini scheme to a URI if it is missing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The URI string to check and potentially modify. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new GeminiURI instance with the scheme added if it was missing. |
Raises:
| Type | Description |
|---|---|
URIError
|
If the URI is empty, the scheme is not 'gemini', the host is missing or invalid, or if parsing of the URI fails. |
with_host
with_path
Return a new GeminiURI with the path replaced or cleared.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | None
|
The new path, or None to clear/reset the path. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new GeminiURI instance with the updated path. |
Raises:
| Type | Description |
|---|---|
URIError
|
If the resulting URI path is invalid. |
with_port
with_query
Return a new GeminiURI with the query parameter replaced, set or cleared.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | None
|
The new query string (will be URL-encoded), or None to clear. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
A new GeminiURI instance with the updated query. |
Raises:
| Type | Description |
|---|---|
URIError
|
If the resulting URI query is invalid. |