Skip to content

Tokens

load_token(path: Path = TOKEN_PATH, encoding: str = DEFAULT_ENCODING, errors: str = DEFAULT_ERRORS) -> str

Loads the token from the given path.

Parameters:

Name Type Description Default
path Path

The path to the token file.

TOKEN_PATH
encoding str

The encoding to use.

DEFAULT_ENCODING
errors str

The error handling of the encoding to use.

DEFAULT_ERRORS

Returns:

Type Description
str

The loaded token.

Raises:

Type Description
TokenNotFound

OSError occured.

Source code in aoc/tokens.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def load_token(
    path: Path = TOKEN_PATH, encoding: str = DEFAULT_ENCODING, errors: str = DEFAULT_ERRORS
) -> str:
    """Loads the token from the given `path`.

    Arguments:
        path: The path to the token file.
        encoding: The encoding to use.
        errors: The error handling of the encoding to use.

    Returns:
        The loaded token.

    Raises:
        TokenNotFound: [`OSError`][OSError] occured."""
    try:
        return path.read_text(encoding, errors).strip()

    except OSError as origin:
        raise TokenNotFound(path) from origin

dump_token(token: str, path: Path = TOKEN_PATH, encoding: str = DEFAULT_ENCODING, errors: str = DEFAULT_ERRORS) -> None

Dumps the token to the given path.

Parameters:

Name Type Description Default
token str

The token to dump.

required
path Path

The path to the token file.

TOKEN_PATH
encoding str

The encoding to use.

DEFAULT_ENCODING
errors str

The error handling of the encoding to use.

DEFAULT_ERRORS
Source code in aoc/tokens.py
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def dump_token(
    token: str,
    path: Path = TOKEN_PATH,
    encoding: str = DEFAULT_ENCODING,
    errors: str = DEFAULT_ERRORS,
) -> None:
    """Dumps the `token` to the given `path`.

    Arguments:
        token: The token to dump.
        path: The path to the token file.
        encoding: The encoding to use.
        errors: The error handling of the encoding to use.
    """
    path.write_text(token + NEW_LINE, encoding, errors)

remove_token(path: Path = TOKEN_PATH) -> None

Removes the token at the given path.

This function does nothing if the path does not exist.

Parameters:

Name Type Description Default
path Path

The path to the token file.

TOKEN_PATH
Source code in aoc/tokens.py
48
49
50
51
52
53
54
55
56
def remove_token(path: Path = TOKEN_PATH) -> None:
    """Removes the token at the given `path`.

    This function does nothing if the `path` does not exist.

    Arguments:
        path: The path to the token file.
    """
    path.unlink(missing_ok=True)