forked from spdx/tools-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannotation_converter.py
More file actions
30 lines (25 loc) · 1.32 KB
/
annotation_converter.py
File metadata and controls
30 lines (25 loc) · 1.32 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
# SPDX-FileCopyrightText: 2022 spdx contributors
#
# SPDX-License-Identifier: Apache-2.0
from beartype.typing import Any, Type
from spdx_tools.spdx.datetime_conversions import datetime_to_iso_string
from spdx_tools.spdx.jsonschema.annotation_properties import AnnotationProperty
from spdx_tools.spdx.jsonschema.converter import TypedConverter
from spdx_tools.spdx.jsonschema.json_property import JsonProperty
from spdx_tools.spdx.model import Annotation, Document
class AnnotationConverter(TypedConverter[Annotation]):
def _get_property_value(
self, annotation: Annotation, annotation_property: AnnotationProperty, document: Document | None = None
) -> Any:
if annotation_property == AnnotationProperty.ANNOTATION_DATE:
return datetime_to_iso_string(annotation.annotation_date)
elif annotation_property == AnnotationProperty.ANNOTATION_TYPE:
return annotation.annotation_type.name
elif annotation_property == AnnotationProperty.ANNOTATOR:
return annotation.annotator.to_serialized_string()
elif annotation_property == AnnotationProperty.COMMENT:
return annotation.annotation_comment
def get_json_type(self) -> Type[JsonProperty]:
return AnnotationProperty
def get_data_model_type(self) -> Type[Annotation]:
return Annotation