port70.uri
Gopher URI representation and parsing.
DEFAULT_ITEM_TYPE
module-attribute
The default Gopher item type (directory/gophermap).
GOPHER_DEFAULT_PORT
module-attribute
The default TCP network port for the Gopher protocol.
GOPHER_PREFIX
module-attribute
GOPHER_PREFIX: Final[str] = f'{GOPHER_SCHEME}://'
The standard prefix for Gopher URIs.
GOPHER_SCHEME
module-attribute
The default URL scheme for the Gopher protocol.
GopherURI
Represents a validated Gopher protocol URI following RFC 4266 / RFC 1436.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | GopherURI
|
The raw URI string or an existing GopherURI to clone. |
required |
Raises:
| Type | Description |
|---|---|
URIError
|
If the URI is empty, the scheme is missing or is not 'gopher', the host is missing or invalid, or if parsing of the URI fails. |
MAXIMUM_LENGTH
class-attribute
instance-attribute
The maximum length of a Gopher URI string.
bytes_left
cached
property
bytes_left: int
The number of bytes left before reaching the maximum URI length.
is_search
property
is_search: bool
True if the item type is search ('7') or a search query is provided.
parent
property
parent: Self
Return a GopherURI representing the parent directory of this URI's selector path.
request_bytes
property
request_bytes: bytes
Return selector payload bytes sent over TCP to the Gopher server.
request_string
property
request_string: str
Return the selector payload string sent over TCP to the Gopher server.
from_string
classmethod
replace
replace(
*,
host: str | _UnsetType = _UNSET,
port: int | _UnsetType = _UNSET,
item_type: str | _UnsetType = _UNSET,
selector: str | _UnsetType = _UNSET,
query: str | None | _UnsetType = _UNSET,
) -> Self
Create a new GopherURI by replacing specific parts of this URI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | _UnsetType
|
The new hostname, or _UNSET to keep current host. |
_UNSET
|
|
int | _UnsetType
|
The new port number, or _UNSET to keep current port. |
_UNSET
|
|
str | _UnsetType
|
The new item type character, or _UNSET to keep current. |
_UNSET
|
|
str | _UnsetType
|
The new selector, or _UNSET to keep current. |
_UNSET
|
|
str | None | _UnsetType
|
The new query string, None to clear, or _UNSET to keep current. |
_UNSET
|
Returns:
| Type | Description |
|---|---|
Self
|
A new GopherURI instance with updated components. |
Raises:
| Type | Description |
|---|---|
URIError
|
If the resulting URI 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 GopherURI representing the resolved target. |
Raises:
| Type | Description |
|---|---|
URIError
|
If resolution fails or target is invalid. |
with_default_scheme
classmethod
Add the Gopher 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 GopherURI instance with the scheme added if it was missing. |
Raises:
| Type | Description |
|---|---|
URIError
|
If the URI is invalid or missing required components. |
with_item_type
Return a new GopherURI with the item type replaced.
with_query
Return a new GopherURI with the query parameter replaced or cleared.