wasat.client
Gemini Protocol async client implementation.
Client
Client(
*,
verify_mode: Literal["ca", "tofu", "off"] = "ca",
trust_store: TrustStore | None = None,
trust_store_path: str | Path | None = None,
client_cert: str | Path | None = None,
client_key: str | Path | None = None,
on_new_certificate: NewCertCallback | None = None,
follow_redirects: bool = True,
max_redirects: int = 5,
connect_timeout: float = 10.0,
read_timeout: float = 30.0,
ssl_context: SSLContext | None = None,
)
Asynchronous Gemini Protocol Client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Literal['ca', 'tofu', 'off']
|
The certificate verification mode: - 'ca': Trust certificates signed by system CAs. - 'tofu': Trust-On-First-Use validation. - 'off': Disable certificate verification (insecure). |
'ca'
|
|
TrustStore | None
|
Custom TrustStore instance for TOFU mode. |
None
|
|
str | Path | None
|
Filepath for the default FileTrustStore in TOFU mode. |
None
|
|
str | Path | None
|
Path to client TLS certificate (for client auth). |
None
|
|
str | Path | None
|
Path to client TLS private key (optional if in cert file). |
None
|
|
NewCertCallback | None
|
Async callback called when a new certificate is encountered in TOFU mode. Must return True to accept, False to reject. |
None
|
|
bool
|
If True, automatically follow redirects. |
True
|
|
int
|
Maximum number of redirects to follow. |
5
|
|
float
|
Timeout in seconds for establishing a connection. |
10.0
|
|
float
|
Timeout in seconds for reading the response line. |
30.0
|
|
SSLContext | None
|
Pre-configured ssl.SSLContext. Overrides verify_mode/cert config. |
None
|
request
async
Perform a Gemini request and return the response.
Automatically handles redirection if configured.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | GeminiURI
|
The target URI as a string or GeminiURI object. |
required |
Returns:
| Type | Description |
|---|---|
Response
|
The final Gemini Response object. |
Raises:
| Type | Description |
|---|---|
URIError
|
If the URI is invalid. |
ConnectionError
|
If network connection fails or times out. |
SecurityError
|
If TLS/certificate check fails. |
ProtocolError
|
If the server response violates the Gemini protocol. |
RedirectError
|
If redirect limits are exceeded or loops are detected. |
WrappedStreamReader
WrappedStreamReader(
reader: StreamReader, writer: StreamWriter
)
Wraps StreamReader to ensure the StreamWriter is closed upon reaching EOF or on error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
StreamReader
|
The stream reader to wrap. |
required |
|
StreamWriter
|
The stream writer to close on EOF or error. |
required |
close
async
close() -> None
Close the writer transport.