forked from spdx/tools-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactor.py
More file actions
38 lines (31 loc) · 1.44 KB
/
Copy pathactor.py
File metadata and controls
38 lines (31 loc) · 1.44 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
37
38
# Copyright (c) 2022 spdx contributors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from enum import Enum, auto
from typing import Optional
from src.model.typing.dataclass_with_properties import dataclass_with_properties
from src.model.typing.type_checks import check_types_and_set_values
class ActorType(Enum):
PERSON = auto()
ORGANIZATION = auto()
TOOL = auto()
@dataclass_with_properties
class Actor:
actor_type: ActorType
name: str
email: Optional[str] = None
def __init__(self, actor_type: ActorType, name: str, email: Optional[str] = None):
check_types_and_set_values(self, locals())
def to_serialized_string(self) -> str:
"""
All serialization formats use the same representation of an actor, so this method is included in the data model
"""
optional_email = f" ({self.email})" if self.email else ""
return "".join([f"{self.actor_type.name.title()}:", f" {self.name}", optional_email])