Skip to content

syshttp.jar

syshttp.jar

File-backed cookie/token jars, keyed by host.

Jars live under one root, :func:store_root: SYSHTTP_HOME (under the prefixes of :mod:syshttp.env), else the platform's per-user state directory. Cookies go under <root>/cookies/<host>.txt (Netscape format), tokens under <root>/tokens/<host>.token.

Token values are secrets: this module never logs or prints them. Files are written 0o600 (directories 0o700) and replaced whole, with LF line ends; a directory is created at the first write, not when a jar is built.

default_root(*, env=None)

The per-user state directory for jars when SYSHTTP_HOME is unset, a directory syshttp under: %LOCALAPPDATA% on Windows, ~/Library/Application Support on macOS, $XDG_STATE_HOME (else ~/.local/state) elsewhere.

Source code in src/syshttp/jar.py
48
49
50
51
52
53
54
55
56
57
58
59
60
def default_root(*, env: Optional[HTTPEnv] = None) -> Path:
    """The per-user state directory for jars when ``SYSHTTP_HOME`` is unset, a
    directory ``syshttp`` under: ``%LOCALAPPDATA%`` on Windows,
    ``~/Library/Application Support`` on macOS, ``$XDG_STATE_HOME`` (else
    ``~/.local/state``) elsewhere."""
    env = HTTPEnv() if env is None else env
    if sys.platform == "win32":
        base = (env.environ.get("LOCALAPPDATA") or "").strip()
        return (Path(base) if base else Path.home() / "AppData" / "Local") / "syshttp"
    if sys.platform == "darwin":
        return Path.home() / "Library" / "Application Support" / "syshttp"
    base = (env.environ.get("XDG_STATE_HOME") or "").strip()
    return (Path(base) if base else Path.home() / ".local" / "state") / "syshttp"

safe_name(key)

A jar file name for a host: characters no filesystem takes (: of an IPv6 literal on Windows, a /) become _.

Source code in src/syshttp/jar.py
42
43
44
45
def safe_name(key: str) -> str:
    """A jar file name for a host: characters no filesystem takes (``:`` of an
    IPv6 literal on Windows, a ``/``) become ``_``."""
    return "".join("_" if ch in _UNSAFE else ch for ch in key)

store_root(*, env=None)

The jar root: SYSHTTP_HOME, else :func:default_root.

Source code in src/syshttp/jar.py
63
64
65
66
67
def store_root(*, env: Optional[HTTPEnv] = None) -> Path:
    """The jar root: ``SYSHTTP_HOME``, else :func:`default_root`."""
    env = HTTPEnv() if env is None else env
    home = env.get(HOME)
    return Path(home).expanduser() if home else default_root(env=env)