forked from spdx/tools-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal_document_ref_converter.py
More file actions
36 lines (29 loc) · 1.54 KB
/
external_document_ref_converter.py
File metadata and controls
36 lines (29 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# SPDX-FileCopyrightText: 2022 spdx contributors
#
# SPDX-License-Identifier: Apache-2.0
from beartype.typing import Any, Type
from spdx_tools.spdx.jsonschema.checksum_converter import ChecksumConverter
from spdx_tools.spdx.jsonschema.converter import TypedConverter
from spdx_tools.spdx.jsonschema.external_document_ref_properties import ExternalDocumentRefProperty
from spdx_tools.spdx.jsonschema.json_property import JsonProperty
from spdx_tools.spdx.model import Document, ExternalDocumentRef
class ExternalDocumentRefConverter(TypedConverter[ExternalDocumentRef]):
checksum_converter: ChecksumConverter
def __init__(self):
self.checksum_converter = ChecksumConverter()
def _get_property_value(
self,
external_document_ref: ExternalDocumentRef,
external_document_ref_property: ExternalDocumentRefProperty,
_document: Document | None = None,
) -> Any:
if external_document_ref_property == ExternalDocumentRefProperty.EXTERNAL_DOCUMENT_ID:
return external_document_ref.document_ref_id
elif external_document_ref_property == ExternalDocumentRefProperty.SPDX_DOCUMENT:
return external_document_ref.document_uri
elif external_document_ref_property == ExternalDocumentRefProperty.CHECKSUM:
return self.checksum_converter.convert(external_document_ref.checksum)
def get_json_type(self) -> Type[JsonProperty]:
return ExternalDocumentRefProperty
def get_data_model_type(self) -> Type[ExternalDocumentRef]:
return ExternalDocumentRef