Skip to content

sybaritic.uri

SPARTAN_DEFAULT_PORT module-attribute

SPARTAN_DEFAULT_PORT: Final[int] = 300

The default TCP network port for the Spartan protocol.

SPARTAN_PREFIX module-attribute

SPARTAN_PREFIX: Final[str] = f'{SPARTAN_SCHEME}://'

The standard prefix for Spartan URIs.

SPARTAN_SCHEME module-attribute

SPARTAN_SCHEME: Final[str] = 'spartan'

The default URL scheme for the Spartan protocol.

SpartanURI

SpartanURI(
    uri: str | SpartanURI,
    *,
    host: str | None = None,
    port: int | None = None,
    path: str | None = None,
    scheme: str | None = None,
)

Represents a validated Spartan protocol URI.

Parameters:

Name Type Description Default

uri

str | SpartanURI

The raw URI string or an existing SpartanURI to clone.

required

host

str | None

Optional host override.

None

port

int | None

Optional port override.

None

path

str | None

Optional path override.

None

scheme

str | None

Optional scheme override.

None

Raises:

Type Description
URIError

If the URI is empty, scheme is missing or not 'spartan', host is missing, or URI parsing fails.

host property

host: str

The target hostname or IP address.

hostname property

hostname: str

The target hostname or IP address (alias for host).

netloc property

netloc: str

Return the network location portion ('host' or 'host:port' if non-default).

parent property

parent: SpartanURI

Return a new SpartanURI pointing to the parent directory path without query.

path property

path: str

The path portion of the URI, starting with '/'.

port property

port: int

The target port number, defaulting to 300.

punycode_host property

punycode_host: str

Return the host encoded in punycode for IDN compliance.

query property

query: str | None

The query string portion of the URI, or None.

root property

root: SpartanURI

Return a new SpartanURI pointing to the root path '/' without query.

scheme property

scheme: str

The scheme portion of the URI (always 'spartan').

without_query property

without_query: SpartanURI

Return a new SpartanURI with any query string removed.

from_str classmethod

from_str(uri_str: str) -> SpartanURI

Construct a SpartanURI from a string.

parse classmethod

parse(uri_str: str | SpartanURI) -> SpartanURI

Parse a URI string or return a SpartanURI instance.

replace

replace(
    *,
    host: str | _UnsetType = _UNSET,
    port: int | _UnsetType = _UNSET,
    path: str | _UnsetType = _UNSET,
    query: str | None | _UnsetType = _UNSET,
) -> SpartanURI

Return a new SpartanURI with specified fields replaced.

resolve_redirect

resolve_redirect(target_path: str) -> SpartanURI

Return a new SpartanURI for a redirect target on the same host.

with_default_scheme classmethod

with_default_scheme(uri_str: str) -> SpartanURI

Construct a SpartanURI from a string, prepending 'spartan://' if missing.

with_host

with_host(host: str) -> SpartanURI

Return a new SpartanURI with the specified host.

with_path

with_path(path: str) -> SpartanURI

Return a new SpartanURI with the specified path.

with_port

with_port(port: int) -> SpartanURI

Return a new SpartanURI with the specified port.

with_query

with_query(query: str | None) -> SpartanURI

Return a new SpartanURI with the specified query string (or None to clear).