def from_xml(cls, tag: ET.Element, field_types_by_type_id=None): lbl = super().from_xml(tag, field_types_by_type_id) result = cls.from_label(lbl) result.data_ranges = ast.literal_eval(tag.get("data_ranges", "[]")) result.category = cls.Category[tag.get("category", "generic")] crc_tag = tag.find("crc") if crc_tag is not None: result.checksum = GenericCRC.from_xml(crc_tag) wsp_tag = tag.find("wsp_checksum") if wsp_tag is not None: result.checksum = WSPChecksum.from_xml(wsp_tag) return result
def from_xml(cls, tag: ET.Element, field_types_by_caption=None): lbl = super().from_xml(tag, field_types_by_caption) if lbl.field_type is None or lbl.field_type.function != FieldType.Function.CHECKSUM: checksum_field_type = next( (ft for ft in field_types_by_caption.values() if ft.function == FieldType.Function.CHECKSUM), FieldType("checksum", FieldType.Function.CHECKSUM, display_format_index=1)) lbl.field_type = checksum_field_type result = cls.from_label(lbl) result.data_ranges = ast.literal_eval(tag.get("data_ranges", "[]")) result.category = cls.Category[tag.get("category", "generic")] crc_tag = tag.find("crc") if crc_tag is not None: result.checksum = GenericCRC.from_xml(crc_tag) wsp_tag = tag.find("wsp_checksum") if wsp_tag is not None: result.checksum = WSPChecksum.from_xml(wsp_tag) return result