Generic utilities#

async commons.sleep_with_condition(seconds: float, condition: partial | Callable[[Any], bool] | Callable[[Any], Coroutine[Any, Any, bool]], *, interval: float = 5) None#

Sleep until either condition is True or we run out of seconds

Parameters:
  • seconds (float) – How long to sleep for up to

  • condition

    Pass either: - A sync function to call which returns a bool - An async function to call which returns a bool

    Note

    If you wish to use arguments in you functions, pass an instance of functools.partial

  • interval (float) –

    How long to sleep in-between each condition check.

    Defaults to 5 seconds.

commons.exception_as_string(error: Exception) str#

Given an exception, return the traceback as a string.

commons.exceptions_as_string(errors: Sequence[Exception]) str#
Given a sequence of exceptions,

return the tracebacks as a string seperated by

— .

commons.value_to_bool(value: str | bool | int | None) bool#

Convert a string representation of truth to true (1) or false (0). True values are ‘y’, ‘yes’, ‘t’, ‘true’, ‘on’, and ‘1’; false values are ‘n’, ‘no’, ‘f’, ‘false’, ‘off’, and ‘0’.

Also handles the case the value is a bool or None

Raises ValueError if ‘val’ is anything else.

async commons.hibp.has_password_been_pwned(password: str) bool#

Lookup the password in ‘have i been pwned’

Returns:

True if pwned, false in all other cases

Return type:

bool

Notes

Fails safely in the sense that a failed lookup returns False