120 lines
3.1 KiB
Python
120 lines
3.1 KiB
Python
from __future__ import annotations
|
|
|
|
from collections.abc import Mapping
|
|
from typing import Any, TypeVar, cast
|
|
from uuid import UUID
|
|
|
|
from attrs import define as _attrs_define
|
|
from attrs import field as _attrs_field
|
|
|
|
T = TypeVar("T", bound="Event")
|
|
|
|
|
|
@_attrs_define
|
|
class Event:
|
|
"""
|
|
Attributes:
|
|
label (str):
|
|
data (Any):
|
|
user (None | UUID):
|
|
application (None | UUID):
|
|
"""
|
|
|
|
label: str
|
|
data: Any
|
|
user: None | UUID
|
|
application: None | UUID
|
|
additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)
|
|
|
|
def to_dict(self) -> dict[str, Any]:
|
|
label = self.label
|
|
|
|
data = self.data
|
|
|
|
user: None | str
|
|
if isinstance(self.user, UUID):
|
|
user = str(self.user)
|
|
else:
|
|
user = self.user
|
|
|
|
application: None | str
|
|
if isinstance(self.application, UUID):
|
|
application = str(self.application)
|
|
else:
|
|
application = self.application
|
|
|
|
field_dict: dict[str, Any] = {}
|
|
field_dict.update(self.additional_properties)
|
|
field_dict.update(
|
|
{
|
|
"label": label,
|
|
"data": data,
|
|
"user": user,
|
|
"application": application,
|
|
}
|
|
)
|
|
|
|
return field_dict
|
|
|
|
@classmethod
|
|
def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
|
|
d = dict(src_dict)
|
|
label = d.pop("label")
|
|
|
|
data = d.pop("data")
|
|
|
|
def _parse_user(data: object) -> None | UUID:
|
|
if data is None:
|
|
return data
|
|
try:
|
|
if not isinstance(data, str):
|
|
raise TypeError()
|
|
user_type_0 = UUID(data)
|
|
|
|
return user_type_0
|
|
except (TypeError, ValueError, AttributeError, KeyError):
|
|
pass
|
|
return cast(None | UUID, data)
|
|
|
|
user = _parse_user(d.pop("user"))
|
|
|
|
def _parse_application(data: object) -> None | UUID:
|
|
if data is None:
|
|
return data
|
|
try:
|
|
if not isinstance(data, str):
|
|
raise TypeError()
|
|
application_type_0 = UUID(data)
|
|
|
|
return application_type_0
|
|
except (TypeError, ValueError, AttributeError, KeyError):
|
|
pass
|
|
return cast(None | UUID, data)
|
|
|
|
application = _parse_application(d.pop("application"))
|
|
|
|
event = cls(
|
|
label=label,
|
|
data=data,
|
|
user=user,
|
|
application=application,
|
|
)
|
|
|
|
event.additional_properties = d
|
|
return event
|
|
|
|
@property
|
|
def additional_keys(self) -> list[str]:
|
|
return list(self.additional_properties.keys())
|
|
|
|
def __getitem__(self, key: str) -> Any:
|
|
return self.additional_properties[key]
|
|
|
|
def __setitem__(self, key: str, value: Any) -> None:
|
|
self.additional_properties[key] = value
|
|
|
|
def __delitem__(self, key: str) -> None:
|
|
del self.additional_properties[key]
|
|
|
|
def __contains__(self, key: str) -> bool:
|
|
return key in self.additional_properties
|