spdx_tools.spdx3.model.external_identifier

 1# SPDX-FileCopyrightText: 2023 spdx contributors
 2#
 3# SPDX-License-Identifier: Apache-2.0
 4from dataclasses import field
 5from enum import Enum, auto
 6
 7from beartype.typing import List, Optional
 8
 9from spdx_tools.common.typing.dataclass_with_properties import dataclass_with_properties
10from spdx_tools.common.typing.type_checks import check_types_and_set_values
11
12
13class ExternalIdentifierType(Enum):
14    CPE22 = auto()
15    CPE23 = auto()
16    CVE = auto()
17    EMAIL = auto()
18    GITOID = auto()
19    PURL = auto()
20    SECURITY_OTHER = auto()
21    SWHID = auto()
22    SWID = auto()
23    URL_SCHEME = auto()
24    OTHER = auto()
25
26
27@dataclass_with_properties
28class ExternalIdentifier:
29    external_identifier_type: ExternalIdentifierType
30    identifier: str
31    comment: Optional[str] = None
32    identifier_locator: List[str] = field(default_factory=list)
33    issuing_authority: Optional[str] = None
34
35    def __init__(
36        self,
37        external_identifier_type: ExternalIdentifierType,
38        identifier: str,
39        comment: Optional[str] = None,
40        identifier_locator: List[str] = None,
41        issuing_authority: Optional[str] = None,
42    ):
43        identifier_locator = [] if identifier_locator is None else identifier_locator
44        check_types_and_set_values(self, locals())
class ExternalIdentifierType(enum.Enum):
14class ExternalIdentifierType(Enum):
15    CPE22 = auto()
16    CPE23 = auto()
17    CVE = auto()
18    EMAIL = auto()
19    GITOID = auto()
20    PURL = auto()
21    SECURITY_OTHER = auto()
22    SWHID = auto()
23    SWID = auto()
24    URL_SCHEME = auto()
25    OTHER = auto()

Create a collection of name/value pairs.

Example enumeration:

>>> class Color(Enum):
...     RED = 1
...     BLUE = 2
...     GREEN = 3

Access them by:

  • attribute access::
>>> Color.RED
<Color.RED: 1>
  • value lookup:
>>> Color(1)
<Color.RED: 1>
  • name lookup:
>>> Color['RED']
<Color.RED: 1>

Enumerations can be iterated over, and know how many members they have:

>>> len(Color)
3
>>> list(Color)
[<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>]

Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details.

Inherited Members
enum.Enum
name
value
@dataclass_with_properties
class ExternalIdentifier:
28@dataclass_with_properties
29class ExternalIdentifier:
30    external_identifier_type: ExternalIdentifierType
31    identifier: str
32    comment: Optional[str] = None
33    identifier_locator: List[str] = field(default_factory=list)
34    issuing_authority: Optional[str] = None
35
36    def __init__(
37        self,
38        external_identifier_type: ExternalIdentifierType,
39        identifier: str,
40        comment: Optional[str] = None,
41        identifier_locator: List[str] = None,
42        issuing_authority: Optional[str] = None,
43    ):
44        identifier_locator = [] if identifier_locator is None else identifier_locator
45        check_types_and_set_values(self, locals())
ExternalIdentifier( external_identifier_type: ExternalIdentifierType, identifier: str, comment: Optional[str] = None, identifier_locator: list[str] = None, issuing_authority: Optional[str] = None)
36    def __init__(
37        self,
38        external_identifier_type: ExternalIdentifierType,
39        identifier: str,
40        comment: Optional[str] = None,
41        identifier_locator: List[str] = None,
42        issuing_authority: Optional[str] = None,
43    ):
44        identifier_locator = [] if identifier_locator is None else identifier_locator
45        check_types_and_set_values(self, locals())
external_identifier_type: ExternalIdentifierType
47    def get_field(self) -> field_type:
48        return getattr(self, f"_{field_name}")
identifier: str
47    def get_field(self) -> field_type:
48        return getattr(self, f"_{field_name}")
comment: Optional[str]
47    def get_field(self) -> field_type:
48        return getattr(self, f"_{field_name}")
identifier_locator: list[str]
47    def get_field(self) -> field_type:
48        return getattr(self, f"_{field_name}")
issuing_authority: Optional[str]
47    def get_field(self) -> field_type:
48        return getattr(self, f"_{field_name}")