tilie_server.routers.files#

The user’s files below the server’s root folder: list, read and write.

GET /api/folders lists one folder, GET /api/files reads a file and PUT /api/files writes one (decisions/0033-server-file-access.md). A path is the query parameter path, POSIX and relative to the root, "" the root itself. Every path is resolved, each symbolic link followed, and refused when it does not lie in the root or names a hidden place below it (a segment starting with .). Only the files TimeLineEditor opens are read and listed, workspace, manifest and table files, and only the one it saves through the server is written, the workspace file.

tilie_server.routers.files.READ_KINDS = ('.tle.json', '.yaml', '.yml', '.json', '.parquet')#

The ends of the names TimeLineEditor lists and reads, matched in any case.

tilie_server.routers.files.WRITTEN_KINDS = ('.tle.json',)#

The ends of the names TimeLineEditor writes, matched in any case: workspace files.

exception tilie_server.routers.files.Refused(refusal)[source]#

Bases: Exception

A request for a path the routes do not serve, with its status and message.

Parameters:

refusal (tuple[int, str])

Return type:

None

response()[source]#

The answer: the status and {"detail": {"path": ["path"], "message"}}.

Return type:

JSONResponse

tilie_server.routers.files.is_kind(name, kinds)[source]#

Whether a file named name ends in one of kinds, in any case.

Parameters:
Return type:

bool

tilie_server.routers.files.is_hidden(parts)[source]#

Whether one of the segments parts starts with . and is not ...

Parameters:

parts (tuple[str, ...])

Return type:

bool

tilie_server.routers.files.resolve(path)[source]#

The absolute path path names, every link followed but one in a loop.

A link in a loop is left in the path unresolved, with the segments after it, on every Python version: Path.resolve does so from Python 3.13 on but raises RuntimeError up to 3.12, so this calls the function it builds on, os.path.realpath, which leaves the loop in place everywhere. status_of then finds the link, or nothing behind it.

Parameters:

path (Path)

Return type:

Path

tilie_server.routers.files.inside(root, path)[source]#

The absolute path path names below root, every link followed.

Parameters:
  • root (Path) – The resolved root folder.

  • path (str) – A POSIX path relative to the root.

Raises:

Refused – path is absolute, holds a NUL character, or resolves to a place that does not lie in the root (through .. or a symbolic link leading out); it has a hidden segment, or resolves to a place with one below the root; or its links form a loop.

Return type:

Path

tilie_server.routers.files.status_of(path, follow=True)[source]#

What lies at path, None for nothing (or links in a loop).

"folder", "file", "other", or "link" when follow is false and the path names a symbolic link itself.

Raises:

Refused – The user may not look at the path (permission denied).

Parameters:
Return type:

str | None

tilie_server.routers.files.file_path(root, path, kinds, refusal)[source]#

The file path names below root, its name and its target’s of kinds.

Raises:

Refused – As inside refuses; the path ends in /; or the name asked for, or the name of the file a link leads to, is not of kinds (refusal).

Parameters:
Return type:

Path

tilie_server.routers.files.listing(root, path)[source]#

The folders, then the files of a kind TimeLineEditor reads, in path.

Hidden names are left out, and so is a symbolic link leading out of the root, into a hidden place, to nothing, or to a file of another kind; a link inside the root is listed as what it leads to. Each group is sorted by code point.

Parameters:
Return type:

dict[str, object]

tilie_server.routers.files.read(root, path)[source]#

The bytes of the file path names.

Parameters:
Return type:

bytes

tilie_server.routers.files.write(root, path, body)[source]#

Write body into the workspace file path names, replacing it whole.

The bytes go to a new file beside it, which then takes the file’s place (os.replace), so the file is never seen half written. A file replaced keeps its mode; a new one is created as open creates it, under the process’s umask.

Raises:

Refused – The path is refused as inside refuses, ends in /, names (or leads through a link to) a file that is no workspace file, lies in no existing folder, names a folder, or names a file or lies in a folder the user may not write.

Parameters:
Return type:

dict[str, object]

tilie_server.routers.files.root_of(request)[source]#

The run’s resolved root folder.

Parameters:

request (Request)

Return type:

Path

tilie_server.routers.files.get_folder(request, path='')[source]#

List the folder path.

Parameters:
  • request (Request)

  • path (str)

Return type:

Response

tilie_server.routers.files.get_file(request, path='')[source]#

Answer the bytes of the file path.

Parameters:
  • request (Request)

  • path (str)

Return type:

Response

tilie_server.routers.files.put_file(request, body, path='')[source]#

Write the request’s body into the file path.

Parameters:
  • request (Request)

  • body (Annotated[bytes, Depends(dependency=~tilie_server.manifests.posted_body, use_cache=True, scope=function)])

  • path (str)

Return type:

Response