_templates
_templates
¶
Sandbox-specific template helpers — systemd argv escaping.
Unit-file rendering uses Jinja2 directly at each callsite (gate,
vault.daemon); only the ExecStart= argv-quoting helpers live
here. They're sandbox-specific (systemd has a quoting dialect that
diverges from POSIX shell where shlex.join lives).
systemd_escape(arg)
¶
Escape arg for a systemd unit-file value position (e.g. ExecStart=).
Three systemd-parser hazards a POSIX-style quoter (shlex.join)
handles wrong:
%introduces specifier expansion — escaped as%%.- Whitespace separates
ExecStart=tokens. Systemd treats both space and tab as separators (persystemd.syntax(7)); escape both as\x20/\x09so a path containing either stays one argv element.
Common Python paths (/usr/bin/python3.12) round-trip unchanged.
Atypical paths (pipx-on-macOS framework prefixes, multi-Python
rootfs layouts with % in directory names, custom build trees
with tabs in names) survive instead of silently mis-parsing.
Source code in src/terok_sandbox/_util/_templates.py
systemd_exec_argv(prefix)
¶
Join prefix into a single ExecStart= value, each element escaped.
Use this instead of :func:shlex.join for unit-file ExecStart,
ExecStartPre, etc. — POSIX shell quoting and systemd unit
quoting diverge enough that shlex.join mis-renders paths that
contain % or whitespace.