parser_utils
Parser utilities.
Functions
|
Function factory for a simple binary parser |
|
Function factory for a simple binary writer |
|
Function factory for bitfield decompositions. |
|
Function factory for bytes to string converter. |
|
Function factory for failure/error-catching wrapper. |
|
Function factory for float list parsing with adjustable delimiter. |
|
Function factory for string strip and float conversion functions. |
|
Function factory to parse int and map to output value. |
|
Returns bool from '0' or '1'. |
|
Returns float. |
|
Returns int. |
|
Function factory to map str to output value. |
|
Function factory for string to bool conversion functions. |
|
Function factory for string strip and float conversion functions. |
|
Function factory for string strip functions. |
|
Parser factory for truthy verifiers. |
Classes
SimpleBinaryParser
- icicle.utils.parser_utils.SimpleBinaryParser(type_parser, binary_type, num_values=1, offset=0, is_big_endian=False)
Function factory for a simple binary parser
- Parameters:
type_parser – parser function (from ICICLE utils)
binary_type – struct format character
num_values – #items in list or string length, -1: use whole buffer after offset
offset – offset in bytes
is_big_endian – use big endian encoding
SimpleBinaryWriter
- icicle.utils.parser_utils.SimpleBinaryWriter(type_formats, ignore_extra_params=False, is_big_endian=False, encoding='ASCII')
Function factory for a simple binary writer
- Parameters:
type_formats – array of struct format strings, one for each expected value. ‘S’ parses a string of unknown length
ignore_extra_params – writer shall ignore parameters which exceed the number of type_formats entries. Fix for queries which call with extra parameters (channel number, etc). which shall not be sent.
is_big_endian – use big endian encoding
bitfield_bool
- icicle.utils.parser_utils.bitfield_bool(bit)
Function factory for bitfield decompositions.
- Parameters:
bit – which bit should be returned as bool on parsing.
bytes_string
- icicle.utils.parser_utils.bytes_string(max_length=None, encoding='ASCII')
Function factory for bytes to string converter.
- Parameters:
max_length – truncate string after max_length characters.
catch_failure
- icicle.utils.parser_utils.catch_failure(verifier, value_on_error=<class 'icicle.utils.parser_utils.PassOriginalValueOnError'>)
Function factory for failure/error-catching wrapper.
- Parameters:
verifier – verifier to be wrapped by try-catch block.
float_list
- icicle.utils.parser_utils.float_list(delimiter=',')
Function factory for float list parsing with adjustable delimiter.
- Parameters:
delimiter – delimiter to split string on. Defaults to ,.
float_or_strings
- icicle.utils.parser_utils.float_or_strings(*strings, replace=None, case_sensitive=False)
Function factory for string strip and float conversion functions.
- Parameters:
strings... – strings which should be accepted as valid instead of float.
replace – iterable of strings which should be stripped from output prior to float conversion.
case_sensitive – whether strings to be accepted should be tested case- sensitively.
int_map
- icicle.utils.parser_utils.int_map(mapping)
Function factory to parse int and map to output value.
- Parameters:
mapping – callable or dict definiting mapping. If callable, must take 2 arguments: (value: int, setting: str)
numeric_bool
- icicle.utils.parser_utils.numeric_bool(value, _)
Returns bool from ‘0’ or ‘1’.
- Parameters:
value – value to convert.
numeric_float
- icicle.utils.parser_utils.numeric_float(value, _)
Returns float.
- Parameters:
value – value to convert.
numeric_int
- icicle.utils.parser_utils.numeric_int(value, _)
Returns int.
- Parameters:
value – value to convert.
str_map
- icicle.utils.parser_utils.str_map(mapping, uppercase=False)
Function factory to map str to output value.
- Parameters:
mapping – callable or dict definiting mapping. If callable, must take 2 arguments: (value: int, setting: str)
string_bool
- icicle.utils.parser_utils.string_bool(true_string, false_string, case_sensitive=False)
Function factory for string to bool conversion functions.
- Parameters:
true_string – string corresponding to true.
false_string – string corresponding to false.
case_sensitive – whether to respect case sensitivity.
strip_float
- icicle.utils.parser_utils.strip_float(*remove)
Function factory for string strip and float conversion functions.
- Parameters:
remove... – substrings which should be stripped from output prior to float conversion.
strip_str
- icicle.utils.parser_utils.strip_str(*remove)
Function factory for string strip functions.
- Parameters:
remove... – substrings which should be removed (replaced by “”) from output.
truthy_bool
- icicle.utils.parser_utils.truthy_bool(true_like=(True, 1, '1', 'ON', 'Y', 'YES', 'TRUE'), false_like=(False, 0, '0', 'OFF', 'N', 'NO', 'FALSE'))
Parser factory for truthy verifiers. What is truthy is controlled by true_like, false_like lists.
- Parameters:
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.