Utils#
Interesting methods that globally helps
- sanitize_secondary_parameters(d, **kw)#
This function is used to sanitize any secondary parameter (meaning not mandatory parameters)
- Parameters
- Returns
a sanitized dictionnary with secondary parameters
- Return type
Examples
>>> d = {"field1": str} >>> kw = {"field1": "value1"} >>> sanitize_secondary_parameters(d=d, **kw) {"field1": "value1"}
>>> d = {"field1": str} >>> kw = {"field1": "value1", "field2": "value2"} >>> sanitize_secondary_parameters(d=d, **kw) {"field1": "value1"}
- sanitize_value(field, t, is_mandatory=False, default=None, **kw)#
This function is used to sanitize the value from a keyword dictionnary (such as default value, type etc.)
- Parameters
field (str) – Name of the field to sanitize
t (type) – Expected type from the given
fieldis_mandatory (bool, optional) – Indicates if
fieldis mandatory. Defaults to Falsedefault (
Any, optional) – Default value forfieldif any. Defaults to None**kw (dict, required) – The
fieldvalue will be extracted from the provided keyword aguments
- Raises
MandatoryFieldMissing – The value is not given as a keyword parameter and it’s mandatory
WrongType – If
tis not equals to the value type for the given field
- Returns
the value for the given field if all checks passed
- Return type
Any
Examples
>>> sanitize_value(field="field1", t=str, is_mandatory=False, default=None, {"field1": "value1"}) "value1"
>>> sanitize_value(field="field1", t=int, is_mandatory=False, default=None, {"field1": "value1"}) # Exception raised as "value1" is not an integer