Skip to content

utils

General utilities.

Functions

extract_regex_flags

extract_regex_flags(regex_pattern: str) -> Tuple[str, str]

Extract the regex flags from the regex pattern.

Parameters:

regex_pattern

The pattern that might start with regex flags

TYPE: str

Returns:

Tuple[str, str]

A tuple of the regex pattern without the flag string and regex flag string

get_nested_value

get_nested_value(d: dict, path: str) -> Any

Retrieves the value of a nested key in a dictionary based on the given path.

Parameters:

d

The dictionary to search.

TYPE: dict

path

A string representing the path to the nested key, separated by periods.

TYPE: str

Returns:

Any

The value of the nested key.

Raises:

KeyError

If a key in the path does not exist.

ValueError

If an element in the path is not a dictionary.

get_overrides

get_overrides(**kwargs) -> dict

Return a dictionary containing only the overridden key-values.

key_val_string

key_val_string(d: dict) -> str

Render the dictionary as a comma-delimited key=value string.

labels_for_format

labels_for_format(serialize_format: str) -> List[str]

Return a list of labels for the given serialize_format.

recursive_sort_dict

recursive_sort_dict(input_value: Any) -> Any

Sort a dictionary recursively.

set_nested_value

set_nested_value(d: dict, value: Any, path: str) -> None

Sets the value of a nested key in a dictionary based on the given path.

Parameters:

d

The dictionary to search.

TYPE: dict

value

The value to set.

TYPE: Any

path

A string representing the path to the nested key, separated by periods.

TYPE: str

Raises:

ValueError

If an element in the path is not a dictionary.