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
valueand 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
datatypeand value to convert asvalue_raw. Supported data types are hardcoded here but there are onTYPESconstant 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.