Skip to content

Commit 7f711f6

Browse files
committed
Adding an XML de-serializer
Oddly enough, the number of tests failed did not change.
1 parent 5d35e81 commit 7f711f6

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

cyclonedx/model/tool.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from xml.etree.ElementTree import Element # nosec B405
55

66
import serializable
7-
from serializable import ViewType
7+
from serializable import ObjectMetadataLibrary, ViewType
88
from serializable.helpers import BaseHelper
99
from sortedcontainers import SortedSet
1010

@@ -17,6 +17,7 @@
1717
from ..schema.schema import SchemaVersion1Dot4, SchemaVersion1Dot5, SchemaVersion1Dot6
1818

1919

20+
2021
@serializable.serializable_class
2122
class Tool:
2223
"""
@@ -327,7 +328,24 @@ def xml_normalize(cls, o: ToolsRepository, *,
327328
return elem
328329

329330
@classmethod
330-
def xml_denormalize(cls, o: Element,
331+
def xml_denormalize(cls, o: Element, *,
331332
default_ns: Optional[str],
332-
**__: Any) -> ToolsRepository:
333-
return ToolsRepository()
333+
prop_info: ObjectMetadataLibrary.SerializableProperty,
334+
ctx: Type[Any],
335+
**kwargs: Any) -> ToolsRepository:
336+
tools: list[Tool] = []
337+
components: list[Component] = []
338+
services: list[Service] = []
339+
340+
for e in o:
341+
tag = e.tag if default_ns is None else e.tag.replace(f'{{{default_ns}}}', '')
342+
if tag == 'tool':
343+
tools.append(Tool.from_xml(e))
344+
if tag == 'components':
345+
for c in e:
346+
components.append(Component.from_xml(c))
347+
if tag == 'services':
348+
for s in e:
349+
services.append(Service.from_xml(s))
350+
351+
return ToolsRepository(tools=tools, components=components, services=services)

0 commit comments

Comments
 (0)