Skip to content

Commit

Permalink
Refactor dicts with NS_AAS tags
Browse files Browse the repository at this point in the history
  • Loading branch information
zrgt committed Nov 15, 2023
1 parent 2a49abd commit 05e423d
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions basyx/aas/adapter/xml/xml_deserialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,16 +729,16 @@ def construct_submodel_element(cls, element: etree.Element, **kwargs: Any) -> mo
This function doesn't support the object_class parameter.
Overwrite each individual SubmodelElement/DataElement constructor function instead.
"""
submodel_elements: Dict[str, Callable[..., model.SubmodelElement]] = {NS_AAS + k: v for k, v in {
"annotatedRelationshipElement": cls.construct_annotated_relationship_element,
"basicEventElement": cls.construct_basic_event_element,
"capability": cls.construct_capability,
"entity": cls.construct_entity,
"operation": cls.construct_operation,
"relationshipElement": cls.construct_relationship_element,
"submodelElementCollection": cls.construct_submodel_element_collection,
"submodelElementList": cls.construct_submodel_element_list
}.items()}
submodel_elements: Dict[str, Callable[..., model.SubmodelElement]] = {
f"{NS_AAS}annotatedRelationshipElement": cls.construct_annotated_relationship_element,
f"{NS_AAS}basicEventElement": cls.construct_basic_event_element,
f"{NS_AAS}capability": cls.construct_capability,
f"{NS_AAS}entity": cls.construct_entity,
f"{NS_AAS}operation": cls.construct_operation,
f"{NS_AAS}relationshipElement": cls.construct_relationship_element,
f"{NS_AAS}submodelElementCollection": cls.construct_submodel_element_collection,
f"{NS_AAS}submodelElementList": cls.construct_submodel_element_list
}
if element.tag not in submodel_elements:
return cls.construct_data_element(element, abstract_class_name="SubmodelElement", **kwargs)
return submodel_elements[element.tag](element, **kwargs)
Expand All @@ -750,14 +750,14 @@ def construct_data_element(cls, element: etree.Element, abstract_class_name: str
This function does not support the object_class parameter.
Overwrite each individual DataElement constructor function instead.
"""
data_elements: Dict[str, Callable[..., model.DataElement]] = {NS_AAS + k: v for k, v in {
"blob": cls.construct_blob,
"file": cls.construct_file,
"multiLanguageProperty": cls.construct_multi_language_property,
"property": cls.construct_property,
"range": cls.construct_range,
"referenceElement": cls.construct_reference_element,
}.items()}
data_elements: Dict[str, Callable[..., model.DataElement]] = {
f"{NS_AAS}blob": cls.construct_blob,
f"{NS_AAS}file": cls.construct_file,
f"{NS_AAS}multiLanguageProperty": cls.construct_multi_language_property,
f"{NS_AAS}property": cls.construct_property,
f"{NS_AAS}range": cls.construct_range,
f"{NS_AAS}referenceElement": cls.construct_reference_element,
}
if element.tag not in data_elements:
raise KeyError(_element_pretty_identifier(element) + f" is not a valid {abstract_class_name}!")
return data_elements[element.tag](element, **kwargs)
Expand Down Expand Up @@ -1112,9 +1112,9 @@ def construct_data_specification_content(cls, element: etree.Element, **kwargs:
Overwrite each individual DataSpecificationContent constructor function instead.
"""
data_specification_contents: Dict[str, Callable[..., model.DataSpecificationContent]] = \
{NS_AAS + k: v for k, v in {
"dataSpecificationIec61360": cls.construct_data_specification_iec61360,
}.items()}
{
f"{NS_AAS}dataSpecificationIec61360": cls.construct_data_specification_iec61360,
}
if element.tag not in data_specification_contents:
raise KeyError(f"{_element_pretty_identifier(element)} is not a valid DataSpecificationContent!")
return data_specification_contents[element.tag](element, **kwargs)
Expand Down Expand Up @@ -1435,13 +1435,11 @@ def read_aas_xml_file_into(object_store: model.AbstractObjectStore[model.Identif
decoder_ = _select_decoder(failsafe, stripped, decoder)

element_constructors: Dict[str, Callable[..., model.Identifiable]] = {
"assetAdministrationShell": decoder_.construct_asset_administration_shell,
"conceptDescription": decoder_.construct_concept_description,
"submodel": decoder_.construct_submodel
f"{NS_AAS}assetAdministrationShell": decoder_.construct_asset_administration_shell,
f"{NS_AAS}conceptDescription": decoder_.construct_concept_description,
f"{NS_AAS}submodel": decoder_.construct_submodel
}

element_constructors = {NS_AAS + k: v for k, v in element_constructors.items()}

root = _parse_xml_document(file, failsafe=decoder_.failsafe, **parser_kwargs)

if root is None:
Expand Down

0 comments on commit 05e423d

Please sign in to comment.