Unreleased
Generated from the docstrings of Tau 0.16.0-dev (commit c439c401) by scripts/api_docs.py in the Tau repository. Not the 0.15 API.
Writing a frontend¶
A frontend holds a Client, in this process or over the wire, and reads the line a person typed.
Names: Client, CommandFailed, LocalClient, Parsed, RemoteClient, UnknownCommand, commandline.STDIN, commandline.completions, commandline.parse, commandline.value, commandline.values
Client¶
class Client(AsyncIterator[Event], Protocol)
id: str
What a frontend holds. Iterating it yields the events: first a snapshot (a CursorView per
open cursor, a CursorGone per closed one, then Labels), then changes as they happen,
until the driver stops (the stream ends), or the driver fails or the client is CutOff for
falling behind (it raises ConnectionError). Every call raises ConnectionError once the
driver has failed or stopped, or the client has been closed or cut off.
Client.input¶
async def input(self, cursor: int, text: str) -> int
Add text to the cursor's scratchpad as this client's input; returns the item.
Client.send¶
async def send(self, cursor: int, text: str) -> int
input with auto-step on.
Client.step¶
async def step(self, cursor: int) -> None
Start a step on a cursor at rest; Busy otherwise.
Client.go_to¶
async def go_to(self, cursor: int, to: int) -> None
Move the cursor to node to, aborting a busy step (which declines its open
questions).
Client.remove_item¶
async def remove_item(self, cursor: int, item: int) -> None
Take back a pending input this client added to cursor (input or send): it is
removed from the scratchpad before the cursor delivers it. LookupError once it is
delivered, or if there is no such item on the cursor; PermissionError for an item
another client or an extension added. Wakes nothing and does not turn auto-step off.
Client.set_auto¶
async def set_auto(self, cursor: int, on: bool) -> None
Turn cursor's auto-step on or off; on wakes it.
Client.abort¶
async def abort(self, cursor: int) -> None
Abort the cursor's step and decline its open questions.
Client.open¶
async def open(self, at: int) -> int
Open a cursor at node at; it wakes. Returns its id.
Client.close_cursor¶
async def close_cursor(self, cursor: int) -> None
Close the cursor (D17): abort its step as abort does, wait for it to rest, drop its
pending items, and close it. Clients are sent a CursorGone. Its id, last node and
labels stay; reopen restarts from them. CursorClosed if it is already closed.
Client.reopen¶
async def reopen(self, cursor: int) -> int
Open a new cursor at the closed cursor's last node, and move each of its labels
onto it. Returns the new id. ValueError if cursor is open, NoSuchCursor if it was
never opened.
Client.set_label¶
async def set_label(self, cursor: int, label: str) -> None
Put label on cursor; a label set elsewhere moves.
Client.remove_label¶
async def remove_label(self, label: str) -> None
Remove label; NoSuchLabel if there is none.
Client.watch¶
async def watch(self, cursors: Collection[int]) -> None
Hear the Live of exactly these cursors from now on (a call replaces the last),
starting with what each sample in flight has streamed that is not in the tree yet.
Client.answer¶
async def answer(self, question: int, value: object) -> None
Answer an open question with a decoded JSON value; None declines. ValueError if
the value is wrong (the question stays open), LookupError if the question is closed
or unknown (the first good answer wins), PermissionError if it is for another
client.
Client.close¶
async def close(self) -> None
Disconnect: the stream ends and the client is no longer connected.
Client.node¶
async def node(self, id: int) -> Node
The node with this id; NoSuchNode if there is none.
Client.nodes¶
async def nodes(self, start: int, limit: int) -> list[Node]
Up to limit nodes from id start, in id order; none past the end. Ids are dense
and a node never changes, so a tree is read in ranges. ValueError for a negative
start or limit.
Client.walk¶
async def walk(self, id: int) -> list[Node]
The nodes from the root to id.
Client.children¶
async def children(self, id: int) -> list[int]
The ids of the children of node id, in append order.
Client.commands¶
async def commands(self) -> tuple[Form, ...]
Each command's form: its name, description and argument schema (named types with
their "format", each default), fixed until the driver reloads. If some extension has
options there is one more, config, whose one argument is the extension; it is
changed with configure, not run.
Client.run¶
async def run(self, cursor: int, command: str, args: Mapping[str, object]) -> str | None
Run /command ("note", or "a:note", the extension's qualified name) with decoded
JSON args on cursor; returns the command's result
(None if it has none) once it has finished. CommandFailed (its message is the
failure as "Type: msg") if it raised, or was aborted; it is raised as soon as the
command raises, even when the command's step has not yet ended: the cursor may still be
busy for a moment while the step ends, and a retry then gets Busy. A command's progress
and cursor.tell arrive as Notices. LookupError for an unknown command or a bare name
two extensions share ("/note is two commands: /a:note, /b:note"), ValueError
naming the problem for arguments that fit no parameter (the values are checked with the
session, "new" last), Busy for a command that runs as a step of the cursor when it is
not at rest.
Client.options¶
async def options(self, cursor: int, extension: str) -> Form
extension's options as they stand at cursor: a form whose schema has every
option, each default the value now. ConfigError if it has no options.
Client.configure¶
async def configure(
self,
cursor: int,
extension: str,
values: Mapping[str, object],
*,
save: bool = False,
) -> None
Change the options named in values (decoded JSON) of extension on cursor's
branch: a step of the cursor writes a Config node. With save, the server also writes the
user's config file (extensions.<name>), which every session reads: the options in values
and those a Config node on the branch set, wherever they differ from the file's (options
equal to the file's stay untouched; values may be {}; options only the user, project
or command-line layers set are not copied). A client needs no access to that file.
ConfigError
for an extension without options, or values its options type refuses (or, with save,
a driver with no user config), Busy unless the cursor is at rest; nothing is written
then, neither node nor file.
Client.complete¶
async def complete(self, cursor: int, named: str, prefix: str) -> list[str]
The values of a named type ("path", "model", "cursor", "label", "node";
the "format" of a schema) that start with prefix, as cursor sees them. Paths are
the driver's machine's, relative to its working directory.
Client.parse_line¶
async def parse_line(self, cursor: int, line: str) -> Parsed
commandline.parse of line with this driver's forms and the options forms
cursor sees: the command, its arguments, and the required parameters still missing.
UnknownCommand if no command has the name (send the line as text), ValueError for a
line that cannot be read, plain LookupError for a bare name two extensions share.
Client.complete_line¶
async def complete_line(self, cursor: int, line: str) -> list[str]
commandline.completions of line on the driver: what could finish its last
word, in one call.
CommandFailed¶
class CommandFailed(RuntimeError)
A command raised, or returned what is not a str or None. The message is the failure
as "Type: msg". Client.run raises it as soon as the command raises; an aborted one raises
it too. A command raises it itself to refuse (its arguments, say), with a message for the
person: the caller gets that message as written, with no traceback, and a command that takes
a Cursor does not fail its step for it.
LocalClient¶
class LocalClient(Client)
A Client in the driver's process, made by Driver.client: its stream opens with the
snapshot, in one act on the loop, so make it inside the running loop. Each call is
documented on Client.
LocalClient.aiter¶
def __aiter__(self) -> Self
LocalClient.anext¶
async def __anext__(self) -> Event
LocalClient.take¶
def take(self) -> list[Event]
The events the stream holds now, removed, without waiting. A server writes a client's events as batches and sends each response after the events its call caused.
LocalClient.aenter¶
async def __aenter__(self) -> Self
LocalClient.aexit¶
async def __aexit__(self, *exc: object) -> None
Parsed¶
@dataclass(frozen=True)
class Parsed
command: Form
args: dict[str, object]
missing: tuple[str, ...]
extension: str | None = None
save: bool = False
A command line, read: the command form, its args (decoded JSON), and the missing
required parameters, in order, which a frontend asks for. For /config <extension> the
command is the extension's options form, args the options to change and extension
its name; with no args the line asks for the form, which a frontend shows from
Client.options. save is whether --save was typed. run makes the call.
Parsed.run¶
async def run(self, client: 'Client', cursor: int) -> str | None
client.run the command, or client.configure the extension's options; returns the
command's result.
RemoteClient¶
class RemoteClient(Client)
welcome: Welcome
A Client of a session served by tau serve: build one with RemoteClient.connect. Each
call is documented once, on Client. It is also an async context manager that closes.
RemoteClient.connect¶
@classmethod
async def connect(cls, socket: str | PathLike[str], client: str, *, buffer: int = 256) -> Self
Dial the server at socket as client with an event stream of buffer, and say
hello. The snapshot is queued before this returns. ProtocolMismatch if the server
speaks another protocol, OSError if nothing answers at socket.
RemoteClient.aiter¶
def __aiter__(self) -> Self
RemoteClient.anext¶
async def __anext__(self) -> Event
RemoteClient.aenter¶
async def __aenter__(self) -> Self
RemoteClient.aexit¶
async def __aexit__(self, *exc: object) -> None
RemoteClient.request¶
async def request(self, method: str, params: Json) -> object
Send request method and wait for its result, decoded. ConnectionError if the
stream has ended; the exception the error code names if the server answered with
one.
RemoteClient.call¶
async def call(self, method: str, **args: object) -> object
request for a call's arguments: they are encoded by the call's signature, so a
value that is not JSON is a TypeError here, before anything is sent.
UnknownCommand¶
class UnknownCommand(LookupError)
The line names a command there is not. A frontend warns and sends the line as text.
UnknownCommand.init¶
def __init__(self, name: str) -> None
tau.commandline.STDIN¶
STDIN = 'stdin'
A command parameter of this name is never read from the line: tau -p fills it with
standard input.
tau.commandline.completions¶
async def completions(
line: str,
commands: Sequence[Form],
client: 'Client',
cursor: int,
options: Mapping[str, Form] = MappingProxyType({}),
) -> list[str]
What could finish the word being typed at the end of line, each a whole word to
replace it with (quoted if it needs to be): command names after /, then for each
parameter its values; after /config <extension>, the extension's options (--save is
typed, not completed). Nothing for a line that is not a command line, an unknown command, or
a word past the last parameter.
tau.commandline.parse¶
def parse(
line: str,
commands: Sequence[Form],
options: Mapping[str, Form] = MappingProxyType({}),
) -> Parsed
Read a line that starts with /. UnknownCommand if no command has the name, plain
LookupError ("/note is two commands: /a:note, /b:note") if a bare name is several
extensions' commands, ValueError naming the problem for a line that is not a command
line, quotes that do not close, too many words, a word that cannot be the parameter's
value, or /config of an extension not in options (the options forms of
Client.options, by extension).
tau.commandline.value¶
def value(text: str, schema: Json) -> object
The decoded JSON text stands for under schema: a command's argument, or the answer
to a question. ValueError if it stands for none.
tau.commandline.values¶
async def values(schema: Json, prefix: str, client: 'Client', cursor: int) -> list[str]
What could finish prefix as a value of schema, each a whole value to replace it
with (unquoted): a named type's through client.complete (paths on the driver's machine),
the values of a Literal, true and false, the items of a list after its last comma.