Coverage for lobster/tools/trlc/item_wrapper.py: 91%
21 statements
« prev ^ index » next coverage.py v7.10.7, created at 2026-09-22 04:43 +0000
« prev ^ index » next coverage.py v7.10.7, created at 2026-09-22 04:43 +0000
1# LOBSTER - Lightweight Open BMW Software Traceability Evidence Report
2# Copyright (C) 2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU Affero General Public License as
6# published by the Free Software Foundation, either version 3 of the
7# License, or (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful, but
10# WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12# Affero General Public License for more details.
13#
14# You should have received a copy of the GNU Affero General Public
15# License along with this program. If not, see
16# <https://www.gnu.org/licenses/>.
18from typing import Any
19from trlc import ast
20from lobster.tools.trlc.errors import RecordObjectComponentError
23class ItemWrapper:
24 def __init__(self, n_obj: ast.Record_Object):
25 self._n_obj = n_obj
26 self._item_data = n_obj.to_python_dict()
28 def get_field(self, field_name: str) -> Any:
29 try:
30 return self._item_data[field_name]
31 except KeyError as ex:
32 raise RecordObjectComponentError(field_name, self._n_obj) from ex
34 def get_field_raw(self, field_name: str) -> Any:
35 """Returns the raw TRLC representation of the field."""
36 try:
37 return self._n_obj.field[field_name]
38 except KeyError as ex:
39 raise RecordObjectComponentError(field_name, self._n_obj) from ex
41 def get_field_value_or_none(self, field_name: str) -> Any:
42 if field := self._n_obj.field.get(field_name, None):
43 return field.to_python_object()
44 return None