Skip to content

Commit

Permalink
Merge pull request #81 from strictdoc-project/stanislaw/version
Browse files Browse the repository at this point in the history
XHTML attributes: improve handling of multiline fields
  • Loading branch information
stanislaw authored Feb 8, 2023
2 parents fc797ba + cfc6250 commit 2b5ad01
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 33 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ keywords = [

[tool.poetry.dependencies]
python = "^3.6.2"
beautifulsoup4 = '>= 4.9.3'
lxml = '>= 4.6.2'
jinja2 = ">= 2.11.2"
toml = ">= 0.10.2"
Expand Down
6 changes: 1 addition & 5 deletions reqif/commands/anonymize/anonymize.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,4 @@ def _anonymize_attribute(attribute):
if attribute.attribute_type == SpecObjectAttributeType.STRING:
attribute.value = ANONYMIZED
elif attribute.attribute_type == SpecObjectAttributeType.XHTML:
attribute.value = (
"\n"
f" <xhtml:div>{ANONYMIZED}</xhtml:div>\n"
" "
)
attribute.value = f"<xhtml:div>{ANONYMIZED}</xhtml:div>"
2 changes: 1 addition & 1 deletion reqif/helpers/lxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def dump_xml_node(node):
# when the etree.tostring(...) method is used:
# <reqif-xhtml:div xmlns:reqif-xhtml="http://www.w3.org/1999/xhtml">--</reqif-xhtml:div> # noqa: E501
# FIXME: Would be great to find a better solution for this.
def stringify_namespaced_children(node):
def stringify_namespaced_children(node) -> str:
def _stringify_reqif_ns_node(node):
assert node is not None
nskey = next(iter(node.nsmap.keys()))
Expand Down
39 changes: 21 additions & 18 deletions reqif/models/reqif_spec_hierarchy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional
from typing import List, Optional, Any

from reqif.helpers.debug import auto_described

Expand All @@ -7,34 +7,37 @@
class ReqIFSpecHierarchy: # pylint: disable=too-many-instance-attributes
def __init__( # pylint: disable=too-many-arguments
self,
xml_node,
is_self_closed: bool,
*,
identifier: str,
last_change: Optional[str],
long_name: Optional[str],
editable: Optional[bool],
spec_object: str,
children: Optional[List],
ref_then_children_order: bool,
level: int,
children: Optional[List] = None,
long_name: Optional[str] = None,
ref_then_children_order: bool = True,
last_change: Optional[str] = None,
editable: Optional[bool] = False,
is_self_closed: bool = True,
xml_node: Optional[Any] = None,
):
assert level >= 0

self.xml_node = xml_node
self.is_self_closed = is_self_closed
self.identifier = identifier
self.last_change: Optional[str] = last_change
self.long_name: Optional[str] = long_name
self.editable: Optional[bool] = editable
self.spec_object = spec_object
self.children: Optional[List] = children
# Mandatory fields.
self.identifier: str = identifier
self.spec_object: str = spec_object
# Not part of ReqIF, but helpful to calculate the section depth levels.
self.level = level

# Optional fields.
self.children: Optional[List] = children
self.long_name: Optional[str] = long_name
# Not part of REqIF, but helpful for printing the
# <OBJECT> and <CHILDREN> tags depending on which tool produced the
# ReqIF file.
self.ref_then_children_order: bool = ref_then_children_order
# Not part of ReqIF, but helpful to calculate the section depth levels.
self.level = level
self.last_change: Optional[str] = last_change
self.editable: Optional[bool] = editable
self.is_self_closed: bool = is_self_closed
self.xml_node = xml_node

def add_child(self, spec_hierarchy):
assert (self.level + 1) == spec_hierarchy.level, (
Expand Down
5 changes: 4 additions & 1 deletion reqif/parsers/spec_object_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
<DEFINITION>
<ATTRIBUTE-DEFINITION-XHTML-REF>{definition_ref}</ATTRIBUTE-DEFINITION-XHTML-REF>
</DEFINITION>
<THE-VALUE>{value}</THE-VALUE>
<THE-VALUE>
{value}
</THE-VALUE>
</ATTRIBUTE-VALUE-XHTML>
"""

Expand Down Expand Up @@ -187,6 +189,7 @@ def parse(spec_object_xml) -> ReqIFSpecObject:
elif attribute_xml.tag == "ATTRIBUTE-VALUE-XHTML":
the_value = attribute_xml.find("THE-VALUE")
attribute_value = stringify_namespaced_children(the_value)
attribute_value = attribute_value.strip()
attribute_definition_ref = (
attribute_xml.find("DEFINITION")
.find("ATTRIBUTE-DEFINITION-XHTML-REF")
Expand Down
6 changes: 4 additions & 2 deletions reqif/parsers/spec_types/spec_object_type_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def parse(spec_object_type_xml) -> ReqIFSpecObjectType:
default_value = stringify_namespaced_children(
xml_values
)
default_value = default_value.strip()
else:
raise NotImplementedError
elif (
Expand Down Expand Up @@ -440,8 +441,9 @@ def _unparse_attribute_default_value(
f"{attribute.default_value_definition_ref}"
f"</ATTRIBUTE-DEFINITION-XHTML-REF>\n"
" </DEFINITION>\n"
f" <THE-VALUE>{attribute.default_value}"
"</THE-VALUE>\n"
" <THE-VALUE>\n"
f" {attribute.default_value}\n"
" </THE-VALUE>\n"
" </ATTRIBUTE-VALUE-XHTML>\n"
" </DEFAULT-VALUE>\n"
)
Expand Down
1 change: 1 addition & 0 deletions reqif/parsers/specification_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def parse(specification_xml) -> ReqIFSpecification:
elif xml_attribute.tag == "ATTRIBUTE-VALUE-XHTML":
the_value = xml_attribute.find("THE-VALUE")
attribute_value = stringify_namespaced_children(the_value)
attribute_value = attribute_value.strip()
attribute_name = (
xml_attribute.find("DEFINITION")
.find("ATTRIBUTE-DEFINITION-XHTML-REF")
Expand Down
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def install_local(context):
context,
one_line_command(
"""
tar -xvf dist/*.tar.gz --wildcards --no-anchored '*/setup.py' --strip=1
tar -xvf dist/*.tar.gz '*/setup.py'
"""
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
<ATTRIBUTE-DEFINITION-XHTML-REF>_7f123ed4-98dd-4eed-b96a-edc8828963a8_CREATEDBY-DOORS-MODULE</ATTRIBUTE-DEFINITION-XHTML-REF>
</DEFINITION>
<THE-VALUE>
<reqif-xhtml:div>susan</reqif-xhtml:div>
<reqif-xhtml:div>
A
multiline
text
</reqif-xhtml:div>
</THE-VALUE>
</ATTRIBUTE-VALUE-XHTML>
</VALUES>
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/reqif/parsers/test_spec_object_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def test_02_attributes_xhtml():
spec_object = SpecObjectParser.parse(spec_object_xml)
assert spec_object.identifier == "TEST_SPEC_OBJECT_ID"

expected_xhtml = """
<reqif-xhtml:div>susan</reqif-xhtml:div>\n \
"""
expected_xhtml = "<reqif-xhtml:div>susan</reqif-xhtml:div>"
assert (
spec_object.attribute_map[
"_7f123ed4-98dd-4eed-b96a-edc8828963a8_CREATEDBY"
Expand Down

0 comments on commit 2b5ad01

Please sign in to comment.