From 71ff951e2211d9b7077b614d0394e66ebbaf1d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20M=C3=B6ller?= Date: Fri, 15 Mar 2024 18:38:40 +0100 Subject: [PATCH] adapter.http: use builtin id_short path resolution --- basyx/aas/adapter/http.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/basyx/aas/adapter/http.py b/basyx/aas/adapter/http.py index e55fddff3..f5dc7bcdd 100644 --- a/basyx/aas/adapter/http.py +++ b/basyx/aas/adapter/http.py @@ -514,17 +514,19 @@ def _resolve_reference(self, reference: model.ModelReference[model.base._RT]) -> @classmethod def _get_nested_submodel_element(cls, namespace: model.UniqueIdShortNamespace, id_shorts: List[str]) \ -> model.SubmodelElement: - current_namespace: Union[model.UniqueIdShortNamespace, model.SubmodelElement] = namespace - for id_short in id_shorts: - current_namespace = cls._expect_namespace(current_namespace, id_short) - next_obj = cls._namespace_submodel_element_op(current_namespace, current_namespace.get_referable, id_short) - if not isinstance(next_obj, model.SubmodelElement): - raise werkzeug.exceptions.InternalServerError(f"{next_obj}, child of {current_namespace!r}, " - f"is not a submodel element!") - current_namespace = next_obj - if not isinstance(current_namespace, model.SubmodelElement): + if not id_shorts: raise ValueError("No id_shorts specified!") - return current_namespace + + try: + ret = namespace.get_referable(id_shorts) + except KeyError as e: + raise NotFound(e.args[0]) + except (TypeError, ValueError) as e: + raise BadRequest(e.args[0]) + + if not isinstance(ret, model.SubmodelElement): + raise BadRequest(f"{ret!r} is not a submodel element!") + return ret @classmethod def _get_submodel_or_nested_submodel_element(cls, submodel: model.Submodel, id_shorts: List[str]) \