helperFunctions.data_conversion module

helperFunctions.data_conversion.convert_compare_id_to_list(compare_id)

Convert a compare ID back to a list of UIDs.

Parameters:

compare_id (str) – The compare ID.

Returns:

The according UID list.

Return type:

list[str]

helperFunctions.data_conversion.convert_str_to_bool(string)

Convert a string to a boolean, e.g. “0” to False or “Y” to True. Replaces distutils.util.strtobool which was deprecated in Python 3.10.

Parameters:

string (str) –

Return type:

bool

helperFunctions.data_conversion.convert_time_to_str(time_obj)

Convert a time object to a string. The time object may be a datetime.date object or a string. If it is anything else, the output defaults to “1970-01-01”.

Parameters:

time_obj (Any) – The time object, that is converted to string.

Returns:

The converted time object as string or a default date (if the conversion fails).

Return type:

str

helperFunctions.data_conversion.convert_uid_list_to_compare_id(uid_list)

Convert a list of UIDs to a compare ID (which is a unique string consisting of UIDs separated by semi-colons, used to identify a FACT Firmware or FileObject comparison).

Parameters:

uid_list (Iterable[str]) – A list of FileObject or Firmware UIDs.

Returns:

The compare ID.

Return type:

str

helperFunctions.data_conversion.get_value_of_first_key(input_dict)

Get the value of the first key in a dictionary. If the dict is empty, return None.

Parameters:

input_dict (dict[_KT, _VT]) – The dictionary to get the value from.

Returns:

The value of the first key in the dictionary or None if it is empty.

Return type:

_VT | None

helperFunctions.data_conversion.make_bytes(data)

Convert data into bytes (if necessary).

Parameters:

data (AnyStr | list[int]) – Some sort of data that can be converted to bytes.

Returns:

The data as bytes.

Return type:

bytes

helperFunctions.data_conversion.make_unicode_string(code)

Convert a (byte) string or some arbitrary object into a string.

Parameters:

code (Any) –

Return type:

str

helperFunctions.data_conversion.none_to_none(input_data)

Convert a string to None if it consists of the word “None” or return the input data otherwise. Used to convert a string coming from the web interface to a NoneType object if necessary.

Parameters:

input_data (str | None) – A string that may

Return type:

str | None

helperFunctions.data_conversion.normalize_compare_id(compare_id)

Sort the UIDs in a compare ID (so that it is unique) and return it.

Parameters:

compare_id (str) – The compare ID.

Returns:

The according unique compare ID with reordered UIDs.

Return type:

str