core.utils.parse

ViUR utility functions regarding parsing.

Module Contents

Functions

bool(value[, truthy_values])

Parse a value into a boolean based on accepted truthy values.

timedelta(value)

Parse a value into a timedelta object.

core.utils.parse.bool(value, truthy_values=('true', 'yes', '1'))

Parse a value into a boolean based on accepted truthy values.

This method takes a value, converts it to a lowercase string, removes whitespace, and checks if it matches any of the provided truthy values. :param value: The value to be parsed into a boolean. :param truthy_values: An iterable of strings representing truthy values.

Default is (“true”, “yes”, “1”).

Returns:

True if the value matches any of the truthy values, False otherwise.

Parameters:
  • value (Any) –

  • truthy_values (Iterable[str]) –

Return type:

bool

core.utils.parse.timedelta(value)

Parse a value into a timedelta object.

This method takes a seconds value and converts it into a timedelta object, if it is not already one. :param value: The value to be parsed into a timedelta. :returns: A timedelta object.

Parameters:

value (datetime.timedelta | int | float | str) –

Return type:

datetime.timedelta