snip.token.storage.file_store

Functionalities to save and retrieve tokens from ini files.

We implement a simple configparser to read ini files and parse contained tokens. The typical format of the ini file is:

[any_unique_section_name]
deployment = https://snip.roentgen.physik.uni-goettingen.de/
book_id = 123
token = token

Section names can be arbitrary, but should be unique and are parsed as the token name.

We parse the tokens from multiple files sequentially to keep usable error messages and point out the file that is causing the issue. If no files are given we use the default locations:

  • local: [cwd]/.sniprc

  • user: ~/.sniprc

  • global: /etc/snip/.sniprc

  • environment variable: SNIPRC

Functions

get_all_tokens([files])

Get all available tokens from a file or list of files.

get_token(name[, files])

Get a token from a file or list of files given its name.

token_exists(name[, files])

Check if a token with a given name exists in a file or list of files.

Module Functions

snip.token.storage.file_store.get_all_tokens(files: str | PathLike | Sequence[str | PathLike] | None = None) tuple[list[Token], list[str | PathLike]]

Get all available tokens from a file or list of files.

Allows to read tokens from multiple files using the python builtin configparser.

Parameters:

files (str | os.PathLike | Sequence[str] | Sequence[os.PathLike] | None) – The file or list of files to read the tokens from. Defaults to all default locations.

Returns:

The list of tokens and the list of files they were read from.

Return type:

Sequence[Token], Sequence[File]

snip.token.storage.file_store.get_token(name: str, files: str | PathLike | Sequence[str | PathLike] | None = None) Token | None

Get a token from a file or list of files given its name.

Parameters:
  • name (str) – The name of the token.

  • files (str | os.PathLike | Sequence[str] | Sequence[os.PathLike]) – The file or list of files to read the token from. Defaults to all default locations.

snip.token.storage.file_store.token_exists(name: str, files: str | PathLike | Sequence[str | PathLike] | None = None) bool

Check if a token with a given name exists in a file or list of files.

Parameters:
  • name (str) – The name of the token.

  • files (str | os.PathLike | Sequence[str] | Sequence[os.PathLike]) – The file or list of files to read the token from. Defaults to all default locations.