Skip to content

port1900.uri

Nex URI representation and parsing.

NEX_DEFAULT_PORT module-attribute

NEX_DEFAULT_PORT: Final[int] = 1900

The default TCP network port for the Nex protocol.

NEX_PREFIX module-attribute

NEX_PREFIX: Final[str] = f'{NEX_SCHEME}://'

The standard prefix for Nex URIs.

NEX_SCHEME module-attribute

NEX_SCHEME: Final[str] = 'nex'

The default URL scheme for the Nex protocol.

NexURI

NexURI(uri: str | NexURI)

Represents a validated Nex protocol URI.

Parameters:

Name Type Description Default

uri

str | NexURI

The raw URI string or an existing NexURI to clone.

required

Raises:

Type Description
URIError

If the URI is empty, the scheme is missing or not 'nex', the host is missing or invalid, or if parsing of the URI fails.

host property

host: str

The target hostname or IP address.

is_directory property

is_directory: bool

True if an empty path or a path finishing with '/'.

parent property

parent: Self

Return a NexURI representing the parent directory of this URI's path.

path property

path: str

The resource path portion of the URI (e.g. '/' or '/hello-world.txt').

port property

port: int

The target port (defaults to NEX_DEFAULT_PORT).

request_bytes property

request_bytes: bytes

Return the path payload bytes sent over TCP to the Nex server.

request_path property

request_path: str

The resource path sent to the server (without leading slash).

request_string property

request_string: str

Return the path payload string sent over TCP to the Nex server.

root property

root: Self

Return a NexURI representing the root directory of this URI's host.

scheme property

scheme: str

The URI scheme (always 'nex').

from_string classmethod

from_string(target: str) -> Self

Create a NexURI from a target string or URI.

Parameters:

Name Type Description Default

target

str

The target string or Nex URI.

required

Returns:

Type Description
Self

A new NexURI instance.

Raises:

Type Description
URIError

If parsing fails or required host is missing.

replace

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

Create a new NexURI by replacing specific parts of this URI.

resolve

resolve(relative_uri: str) -> Self

Resolve a relative URI string against this URI as a base.

Parameters:

Name Type Description Default

relative_uri

str

The relative or absolute target URI string.

required

Returns:

Type Description
Self

A new NexURI representing the resolved target.

Raises:

Type Description
URIError

If resolution fails or target is invalid.

with_default_scheme classmethod

with_default_scheme(uri: str) -> Self

Add the Nex scheme to a URI if it is missing.

Parameters:

Name Type Description Default

uri

str

The URI string to check and potentially modify.

required

Returns:

Type Description
Self

A new NexURI instance with the scheme added if it was missing.

Raises:

Type Description
URIError

If the URI is invalid or missing required components.

with_host

with_host(host: str) -> Self

Return a new NexURI with the host replaced.

with_path

with_path(path: str) -> Self

Return a new NexURI with the path replaced.

with_port

with_port(port: int) -> Self

Return a new NexURI with the port replaced.