verifier_utils
Verifier utilities.
Function taking in unsanitised input value, and coercing or converting to a desired output.
Verifiers may check limits or type validity. Values that cannot be coerced or converted will raise a ValidationError that should be caught if necessary by client code.
This module contains factory functions that return specialised verifier functions that can be used by the SCPIInstrument interface or in other similar cases.
Functions
|
Verifier factory for "in"-type verifiers. |
|
Verifier factory for integer verifiers. |
|
Verifier factory for numeric verifiers. |
|
Verifier factory for "map"-type verifiers. |
|
Verifier factory for truthy verifiers. |
|
Verifier factory to combine multiple verifiers in OR-like behaviour. |
Exceptions
is_in
- icicle.utils.verifier_utils.is_in(*array, to_upper=False)
Verifier factory for “in”-type verifiers.
- Parameters:
array... – items in list of acceptable input values.
- Returns:
Verifier function.
Note
FUNCTION FACTORY
is_integer
- icicle.utils.verifier_utils.is_integer(min=None, max=None, scale=1)
Verifier factory for integer verifiers.
- Parameters:
min – Minimum input number to accept.
max – Maximal input number to accept.
scale – Verifier scales value by parameter.
- Returns:
Verifier function.
Note
FUNCTION FACTORY
is_numeric
- icicle.utils.verifier_utils.is_numeric(min=None, max=None, scale=1, to_int=False)
Verifier factory for numeric verifiers. Resulting verifiers always return float or, if explicitly requested, int.
- Parameters:
min – Minimum input number to accept.
max – Maximal input number to accept.
scale – Verifier scales value by parameter.
to_int – Verifier converts number to integer instead of float.
- Returns:
Verifier function.
Note
FUNCTION FACTORY
map_to
- icicle.utils.verifier_utils.map_to(mapping, to_upper=False)
Verifier factory for “map”-type verifiers.
- Parameters:
mapping – dictionary of acceptable input values and mapped output values.
- Returns:
Verifier function.
Note
FUNCTION FACTORY
truthy
- icicle.utils.verifier_utils.truthy(true_output=1, false_output=0, true_like=(True, 1, '1', 'ON', 'Y', 'YES', 'TRUE'), false_like=(False, 0, '0', 'OFF', 'N', 'NO', 'FALSE'))
Verifier factory for truthy verifiers. What is truthy is controlled by true_like, false_like lists.
- Parameters:
true_output – What to return if input is “truthy”.
false_output – What to return if input is NOT “truthy”.
true_like – List of things that should resolve to true_output.
false_like – List of things that should resolve to false_output.
- Returns:
Verifier function.
Note
FUNCTION FACTORY
verifier_or
- icicle.utils.verifier_utils.verifier_or(*verifiers)
Verifier factory to combine multiple verifiers in OR-like behaviour.
- Parameters:
verifiers... – multiple verifiers (functions) to combined.
- Returns:
Verifier function.
Note
FUNCTION FACTORY
ValidationError
- icicle.utils.verifier_utils.ValidationError()
Unspecified run-time error.