tilie_server.cli#

The tilie command: start the server and open the editor, or serve it publicly.

tilie_server.cli.PUBLIC_BIND = '0.0.0.0'#

The address a public run binds: every interface, so that a proxy or a container’s port mapping reaches it.

tilie_server.cli.free_port()[source]#

A port that was free on the loopback interface a moment ago.

Return type:

int

tilie_server.cli.port_is_free(port)[source]#

Whether port could be bound on the loopback interface a moment ago.

The port is bound as the server binds it: with SO_REUSEADDR outside Windows, so that the connections of a run just stopped do not hold it. On Windows the option would let a second socket share a port in use.

Parameters:

port (int)

Return type:

bool

tilie_server.cli.choose_port(requested, default=8000)[source]#

The port to listen on, and the notice to print about it, if any.

Parameters:
  • requested (int | None) – The port given with --port, taken as it is; None for none.

  • default (int) – The port taken without one, while it is free.

Returns:

The port and None; or, when no port is requested and default is in use, a free port and the notice saying so.

Return type:

tuple[int, str | None]

tilie_server.cli.existing_folder(given)[source]#

The folder --root names; refused unless it exists.

Parameters:

given (str)

Return type:

Path

tilie_server.cli.public_host(given)[source]#

A host name --public-host gives; refused when empty, since an empty name would admit a request with an empty Host header.

Parameters:

given (str)

Return type:

str

tilie_server.cli.EXCLUDED_BY_PUBLIC_HOST = ('check', 'root', 'no_browser')#

The options a public run refuses: it checks nothing, serves no files and opens no browser.

tilie_server.cli.parse_args(argv)[source]#

Parse the command line of tilie; None reads sys.argv.

An option a public run excludes is an error next to --public-host; --root defaults to the home folder only after that check.

Parameters:

argv (Sequence[str] | None)

Return type:

Namespace

tilie_server.cli.settings_for(args, port)[source]#

The settings of the run args asks for, on port.

A public run binds every interface, answers as the given hosts, checks no token, serves no files, bounds request bodies and posted tables, and limits its computations and connections; a local run binds the loopback interface with a new token and serves the files below its root.

Parameters:
Return type:

ServerSettings

tilie_server.cli.uvicorn_config(app, settings, *, check)[source]#

The uvicorn configuration of a run of app with settings.

Parameters:
  • app (FastAPI) – The application.

  • settings (ServerSettings) – The run’s settings, whose connections uvicorn keeps.

  • check (bool) – Whether the run is a --check, which logs only errors and no access lines.

Return type:

Config

tilie_server.cli.public_notice(settings)[source]#

The line a public run prints once it listens.

Parameters:

settings (ServerSettings)

Return type:

str

tilie_server.cli.wait_until_started(server)[source]#

Wait until server listens, requesting shutdown on a timeout.

Parameters:

server (Server)

Return type:

bool

tilie_server.cli.run_server(server, on_started)[source]#

Run uvicorn in the main thread and perform on_started alongside it.

Uvicorn can install its SIGINT and SIGTERM handlers only in the main thread. The short-lived observer does no server work; it waits for startup and then prints or verifies the URL.

Parameters:
  • server (Server)

  • on_started (Callable[[], None])

Return type:

bool

tilie_server.cli.fetch(url, token)[source]#

GET url with the bearer token and return status and body.

Parameters:
Return type:

tuple[int, bytes]

exception tilie_server.cli.CheckFailed[source]#

Bases: Exception

A --check verification step did not pass.

tilie_server.cli.verify(base_url, token)[source]#

Verify the health endpoint and the editor; return the health document.

Parameters:
Return type:

dict[str, str | bool | None]

tilie_server.cli.main(argv=None)[source]#

Run the tilie command and return its exit status.

A public run prints what it serves; a --check run prints the health document once the checks pass, then stops; a local run prints the editor’s URL, the token in its fragment, and opens a browser unless --no-browser is given.

Returns:

0 on success, 1 if the server did not start or a check failed.

Parameters:

argv (Sequence[str] | None)

Return type:

int