33from datetime import datetime
44from typing import Optional , Any
55
6- from pydantic import ConfigDict , Field , GetCoreSchemaHandler , computed_field
6+ from pydantic import ConfigDict , Field , GetCoreSchemaHandler , computed_field , constr
77from pydantic_core import CoreSchema , core_schema
8-
98from CoT .utils import CustomModel
109from CoT .xml import unparse
11- from CoT .types import CoTTypes , CoTReservations
12-
10+ from CoT .types import CoTTypes , CoTReservations , CoTHow
11+ from pydantic import BaseModel
12+ KeywordsPattern = constr (pattern = r"^[\w\- ]+(,[\w\- ]+)*$" )
1313
14+ class Remarks (BaseModel ):
15+ text : str
16+
1417# MITRE Definition does not have addition subschema
1518class Detail (CustomModel ):
16- model_config = ConfigDict (extra = "allow" )
17-
19+ model_config = ConfigDict (extras = True , populate_by_name = True )
20+ remarks : Remarks = Optional [ Remarks ]
1821
1922class Point (CustomModel ):
2023 lat : float = Field (ge = - 90 , le = 90 )
@@ -63,7 +66,17 @@ def __get_pydantic_core_schema__(
6366 ) -> CoreSchema :
6467 return core_schema .no_info_after_validator_function (cls , handler (str ))
6568
66-
69+
70+ class How (str ):
71+ value : str
72+
73+ @computed_field
74+ @property
75+ def description (self ) -> str :
76+ if self .value not in CoTHow :
77+ return "Unknown"
78+
79+ return CoTHow [self .value ]
6780
6881class Event (CustomModel ):
6982 version : float = 2.0
@@ -72,7 +85,7 @@ class Event(CustomModel):
7285 time : datetime
7386 start : datetime
7487 stale : datetime
75- how : str = Field (pattern = r"\w-\w" )
88+ how : How = Field (pattern = r"\w-\w" )
7689 opex : Optional [str ] = None
7790 qos : Optional [str ] = None
7891 access : Optional [str ] = None
0 commit comments