Skip to content

Commit 9d74fa2

Browse files
authored
Merge pull request #322 from andlaus/more_small_fixes
More small fixes
2 parents 9623e2e + 5e10797 commit 9d74fa2

9 files changed

+30
-47
lines changed

odxtools/cli/browse.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ def prompt_single_parameter_value(parameter: Parameter) -> Optional[AtomicOdxTyp
112112

113113
def encode_message_interactively(sub_service: Union[Request, Response],
114114
ask_user_confirmation: bool = False) -> None:
115-
if not sys.__stdin__.isatty() or not sys.__stdout__.isatty():
115+
if sys.__stdin__ is None or sys.__stdout__ is None or not sys.__stdin__.isatty(
116+
) or not sys.__stdout__.isatty():
116117
raise SystemError("This command can only be used in an interactive shell!")
117118
param_dict = sub_service.parameter_dict()
118119

@@ -260,7 +261,8 @@ def encode_message_from_string_values(
260261

261262

262263
def browse(odxdb: Database) -> None:
263-
if not sys.__stdin__.isatty() or not sys.__stdout__.isatty():
264+
if sys.__stdin__ is None or sys.__stdout__ is None or not sys.__stdin__.isatty(
265+
) or not sys.__stdout__.isatty():
264266
raise SystemError("This command can only be used in an interactive shell!")
265267
dl_names = [dl.short_name for dl in odxdb.diag_layers]
266268
while True:

odxtools/comparaminstance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def from_et(et_element: ElementTree.Element,
3232
spec_ref = odxrequire(OdxLinkRef.from_et(et_element, doc_frags))
3333

3434
# ODX standard v2.0.0 defined only VALUE. ODX v2.0.1 decided
35-
# to break things and change it to choice between SIMPLE-VALUE
35+
# to break things and change it to a choice between SIMPLE-VALUE
3636
# and COMPLEX-VALUE
3737
value: Union[str, List[Union[str, ComplexValue]]]
3838
if et_element.find("VALUE") is not None:

odxtools/odxlink.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,14 @@
44
from typing import Any, Dict, Iterable, List, Optional, Type, TypeVar, overload
55
from xml.etree import ElementTree
66

7-
from .exceptions import OdxWarning, odxassert, odxraise
7+
from .exceptions import OdxWarning, odxassert, odxraise, odxrequire
88
from .nameditemlist import OdxNamed, TNamed
99

1010

1111
@dataclass(frozen=True)
1212
class OdxDocFragment:
1313
doc_name: str
14-
doc_type: Optional[str]
15-
16-
def __eq__(self, other: Any) -> bool:
17-
if other is None:
18-
# if the other document fragment is not specified, we
19-
# treat it as a wildcard...
20-
return True
21-
22-
if not isinstance(other, OdxDocFragment):
23-
return False
24-
25-
# the ODX spec says that the doctype can be ignored...
26-
return self.doc_name == other.doc_name
27-
28-
def __hash__(self) -> int:
29-
return hash(self.doc_name) + hash(self.doc_type)
14+
doc_type: str
3015

3116

3217
@dataclass(frozen=True)
@@ -121,6 +106,7 @@ def from_et(et: Optional[ElementTree.Element],
121106

122107
id_ref = et.attrib.get("ID-REF")
123108
if id_ref is None:
109+
odxraise(f"Tag {et.tag} is not a ODXLINK reference")
124110
return None
125111

126112
doc_ref = et.attrib.get("DOCREF")
@@ -134,7 +120,7 @@ def from_et(et: Optional[ElementTree.Element],
134120
# reference, use it, else use the document fragment containing
135121
# the reference.
136122
if doc_ref is not None:
137-
doc_frags = [OdxDocFragment(doc_ref, doc_type)]
123+
doc_frags = [OdxDocFragment(doc_ref, odxrequire(doc_type))]
138124
else:
139125
doc_frags = source_doc_frags
140126

@@ -154,9 +140,9 @@ def __str__(self) -> str:
154140

155141
class OdxLinkDatabase:
156142
"""
157-
A database holding all objects which ehibit OdxLinkIds
143+
A database holding all objects which exhibit OdxLinkIds
158144
159-
This can resolve references to such.
145+
This can resolve ODXLINK references.
160146
"""
161147

162148
def __init__(self) -> None:
@@ -182,7 +168,7 @@ def resolve(self, ref: OdxLinkRef, expected_type: Optional[Any] = None) -> Any:
182168
if doc_frag_db is None:
183169
# No object featured by the database uses the document
184170
# fragment mentioned by the reference. This should not
185-
# happen for correct databases...
171+
# happen for correct ODX databases...
186172
warnings.warn(
187173
f"Warning: Unknown document fragment {ref_frag} "
188174
f"when resolving reference {ref}",

odxtools/templates/macros/printComparam.xml.jinja2

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
{{make_xml_attrib("DISPLAY-LEVEL", cp.display_level)}}{#- #}
4545
CPUSAGE="{{cp.cpusage.value}}">
4646
{{ peid.printElementIdSubtags(cp)|indent(1) }}
47-
<PHYSICAL-DEFAULT-VALUE>{{cp.physical_default_value}}</PHYSICAL-DEFAULT-VALUE>
47+
{%- if cp.physical_default_value is not none %}
48+
<PHYSICAL-DEFAULT-VALUE>{{cp.physical_default_value | e}}</PHYSICAL-DEFAULT-VALUE>
49+
{%- endif %}
4850
<DATA-OBJECT-PROP-REF ID-REF="{{cp.dop_ref.ref_id}}" />
4951
</COMPARAM>
5052
{%- endmacro %}
@@ -61,7 +63,7 @@
6163
{%- for sub_cp in cp.subparams %}
6264
{{- printAnyComparam(sub_cp) | indent(1, first=True) }}
6365
{%- endfor %}
64-
{%- if cp.physical_default_value is not none %}
66+
{%- if cp.physical_default_value is not none %}
6567
{{ printComplexValue(cp.physical_default_value, "COMPLEX-PHYSICAL-DEFAULT-VALUE") | indent(1) }}
6668
{%- endif %}
6769
</COMPLEX-COMPARAM>

odxtools/templates/macros/printCompuMethod.xml.jinja2

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,7 @@
1818
{%- if limit_obj.value_raw is none %}
1919
{#- #}/>
2020
{%- else %}
21-
{#- #}>
22-
{%- if hasattr(limit_obj._value, 'hex') -%}
23-
{#- bytes or bytarray limit #}
24-
{{- limit_obj._value.hex().upper() }}
25-
{%- else -%}
26-
{{- limit_obj._value }}
27-
{%- endif -%}
28-
</{{tag_name}}>
21+
{#- #}>{{- limit_obj.value_raw }}</{{tag_name}}>
2922
{%- endif -%}
3023
{%- endif -%}
3124
{%- endmacro -%}

odxtools/templates/macros/printEcuVariantPattern.xml.jinja2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
{%- macro printMatchingParameter(mp) -%}
1111
<MATCHING-PARAMETER>
12-
<EXPECTED-VALUE>{{mp.expected_value}}</EXPECTED-VALUE>
12+
<EXPECTED-VALUE>{{mp.expected_value | e}}</EXPECTED-VALUE>
1313
<DIAG-COMM-SNREF SHORT-NAME="{{mp.diag_comm_snref}}" />
1414
{#- TODO: OUT-PARAM-IF-SNPATHREF #}
1515
<OUT-PARAM-IF-SNREF SHORT-NAME="{{mp.out_param_if}}" />

odxtools/templates/macros/printParam.xml.jinja2

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,27 @@
3535
{%- endif %}
3636
{%- if param.coded_value is defined %}
3737
<CODED-VALUE>{{param.coded_value}}</CODED-VALUE>
38-
{%- elif param.physical_constant_value_raw is defined %}
39-
<PHYS-CONSTANT-VALUE>{{param.physical_constant_value_raw}}</PHYS-CONSTANT-VALUE>
4038
{%- elif param.coded_values is defined %}
4139
<CODED-VALUES>
4240
{%- for coded_value in param.coded_values %}
4341
<CODED-VALUE>{{coded_value}}</CODED-VALUE>
4442
{%- endfor %}
4543
</CODED-VALUES>
4644
{%- endif %}
47-
{%- if param.physical_default_value_raw %}
48-
<PHYSICAL-DEFAULT-VALUE>{{param.physical_default_value_raw}}</PHYSICAL-DEFAULT-VALUE>
45+
{%- if param.physical_constant_value_raw is defined %}
46+
<PHYS-CONSTANT-VALUE>{{param.physical_constant_value_raw}}</PHYS-CONSTANT-VALUE>
47+
{%- endif %}
48+
{%- if param.physical_default_value_raw is defined and param.physical_default_value_raw is not none %}
49+
<PHYSICAL-DEFAULT-VALUE>{{param.physical_default_value_raw | e}}</PHYSICAL-DEFAULT-VALUE>
4950
{%- endif %}
5051
{%- if param.dop_ref %}
5152
<DOP-REF ID-REF="{{param.dop_ref.ref_id}}"/>
5253
{%- elif param.dop_snref %}
5354
<DOP-SNREF SN="{{param.dop_snref}}"/>
5455
{%- elif param.diag_coded_type is defined %}
5556
{{pdop.printDiagCodedType(param.diag_coded_type)|indent(2)}}
56-
{%- elif param.parameter_type != "MATCHING-REQUEST-PARAM" %}
57-
{%- if param.bit_length is defined and param.bit_length is not none %}
58-
<BIT-LENGTH>{{param.bit_length}}</BIT-LENGTH>
59-
{%- endif %}
57+
{%- elif param.bit_length is defined and param.bit_length is not none %}
58+
<BIT-LENGTH>{{param.bit_length}}</BIT-LENGTH>
6059
{%- endif %}
6160
{%- if param.parameter_type == "TABLE-KEY" %}
6261
{%- if param.table_ref %}

odxtools/templates/macros/printService.xml.jinja2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
-#}
55

66
{%- import('macros/printDiagComm.xml.jinja2') as pdc %}
7+
{%- import('macros/printComparamRef.xml.jinja2') as pcom %}
78

89
{%- macro printService(service) -%}
910
<DIAG-SERVICE {{pdc.printDiagCommAttribs(service) | indent(1) }}
@@ -18,8 +19,8 @@
1819
{{pdc.printDiagCommSubtags(service) | indent(1, first=True) }}
1920
{%- if service.comparam_refs %}
2021
<COMPARAM-REFS>
21-
{%- for ref in service.comparam_refs %}
22-
<COMPARAM-REF ID-REF="{{ref.ref_id}}" />
22+
{%- for cpref in service.comparam_refs %}
23+
{{ pcom.printComparamRef(cpref)|indent(4) }}
2324
{%- endfor %}
2425
</COMPARAM-REFS>
2526
{%- endif%}

odxtools/templates/macros/printSingleEcuJob.xml.jinja2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
<INPUT-PARAM {{-make_xml_attrib("OID", param.oid)}}
6666
{{-make_xml_attrib("SEMANTIC", param.semantic)}}>
6767
{{ peid.printElementIdSubtags(param)|indent(1) }}
68-
{%- if param.physical_default_value %}
69-
<PHYSICAL-DEFAULT-VALUE>{{param.physical_default_value}}</PHYSICAL-DEFAULT-VALUE>
68+
{%- if param.physical_default_value is not none %}
69+
<PHYSICAL-DEFAULT-VALUE>{{param.physical_default_value | e}}</PHYSICAL-DEFAULT-VALUE>
7070
{%- endif %}
7171
<DOP-BASE-REF ID-REF="{{param.dop_base_ref.ref_id}}" />
7272
</INPUT-PARAM>

0 commit comments

Comments
 (0)