rtm_wrapper.util#

Misc utilities.

Module Contents#

Functions#

setup_debug_root_logging(→ None)

Configure the root logger with a basic debugging configuration.

partition_dict(→ tuple[dict[_H, _T], dict[_H, _T]])

Partition the given dictionary based on the provided predicate.

build_version(→ str)

Return the version of this distribution with local build number, if available.

platform_summary(→ str)

Return a platform summary string.

first_or(→ _T | None)

Return the first element of the iterable, or the given default if the iterable

trap(→ Callable[Ellipsis, typing_extensions.Never])

Return a trap callable that raises when called.

exception TrapCalledError(message: str, args: tuple[Any, Ellipsis], kwargs: dict[str, Any])[source]#

Bases: RuntimeError

Raised when a trap callable is invoked.

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • message (str) –

  • args (tuple[Any, Ellipsis]) –

  • kwargs (dict[str, Any]) –

__str__() str[source]#

Return str(self).

Return type:

str

setup_debug_root_logging(level: int = logging.NOTSET) None[source]#

Configure the root logger with a basic debugging configuration.

All records at the given level or above will be written to stdout.

This function should be called once near the start of an application entry point, BEFORE any calls to logging.getLogger are made.

Disables any existing loggers.

Parameters:

level (int) –

Return type:

None

partition_dict(dictionary: dict[_H, _T], predicate: Callable[[_H], bool]) tuple[dict[_H, _T], dict[_H, _T]][source]#

Partition the given dictionary based on the provided predicate.

>>> d = {i: i**2 for i in range(6)}
>>> partition_dict(d, lambda x: x % 2 == 0)
({0: 0, 2: 4, 4: 16}, {1: 1, 3: 9, 5: 25})
Parameters:
  • dictionary (dict[_H, _T]) –

  • predicate (Callable[[_H], bool]) –

Return type:

tuple[dict[_H, _T], dict[_H, _T]]

build_version() str[source]#

Return the version of this distribution with local build number, if available.

Return type:

str

platform_summary() str[source]#

Return a platform summary string.

Return type:

str

first_or(iterable: Iterable[_T], default: _T | None = None) _T | None[source]#

Return the first element of the iterable, or the given default if the iterable is empty.

Parameters:
  • iterable (Iterable[_T]) –

  • default (_T | None) –

Return type:

_T | None

trap(message: str) Callable[Ellipsis, typing_extensions.Never][source]#

Return a trap callable that raises when called.

Parameters:

message (str) –

Return type:

Callable[Ellipsis, typing_extensions.Never]