Module tomatic.tools
Tools classes and routines.
Functions
def fix(value, default_value)
-
Force a correct behavior for boolean and other empty values, get retrieved value as
value
and default value asdefault_value
. Return retrieved value if isnt'sNone
, otherwise use default value. def get_type(key_raw)
-
Check if there is a data type enconded on KEY as
key_raw
, extract data type if exist and check. Return KEY without data type encoded and type decoded (if exists) in a tuple.To avoid mistakes handling with boolean or even empty values, use
Tomatic.fix()
function. def type_cast(datatype, value_raw)
-
Convert a given string to a specific data type, receive type to use as
datatype
and value to convert asvalue_raw
. Supported data types are hardcoded here but there are onTYPES
constant as well.There are the following data types supported by buckets:
__bool__
to convert VALUE to a boolean;__float__
to convert VALUE to a floating point number;__int__
to convert VALUE to a integer number;__json__
to convert VALUE to dictionaries or lists and__str__
to convert VALUE to a string (default bahavior).
Don't forget to keep "type" in lower case. All unrecognized data types are treated as string.