| 
									
										
										
										
											2024-11-12 21:51:09 +08:00
										 |  |  | from collections.abc import Sequence | 
					
						
							| 
									
										
										
										
											2024-12-24 18:38:51 +08:00
										 |  |  | from typing import cast | 
					
						
							| 
									
										
										
										
											2024-11-12 21:51:09 +08:00
										 |  |  | from uuid import uuid4 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | from pydantic import Field | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from core.helper import encrypter | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 15:03:56 +08:00
										 |  |  | from .segments import ( | 
					
						
							| 
									
										
										
										
											2024-07-27 14:43:51 +08:00
										 |  |  |     ArrayAnySegment, | 
					
						
							| 
									
										
										
										
											2024-11-12 21:51:09 +08:00
										 |  |  |     ArrayFileSegment, | 
					
						
							| 
									
										
										
										
											2024-07-27 14:43:51 +08:00
										 |  |  |     ArrayNumberSegment, | 
					
						
							|  |  |  |     ArrayObjectSegment, | 
					
						
							| 
									
										
										
										
											2024-12-23 15:52:50 +08:00
										 |  |  |     ArraySegment, | 
					
						
							| 
									
										
										
										
											2024-07-27 14:43:51 +08:00
										 |  |  |     ArrayStringSegment, | 
					
						
							| 
									
										
										
										
											2024-10-21 10:43:49 +08:00
										 |  |  |     FileSegment, | 
					
						
							| 
									
										
										
										
											2024-07-26 15:03:56 +08:00
										 |  |  |     FloatSegment, | 
					
						
							|  |  |  |     IntegerSegment, | 
					
						
							|  |  |  |     NoneSegment, | 
					
						
							|  |  |  |     ObjectSegment, | 
					
						
							|  |  |  |     Segment, | 
					
						
							|  |  |  |     StringSegment, | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | from .types import SegmentType | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Variable(Segment): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     A variable is a segment that has a name. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     id: str = Field( | 
					
						
							| 
									
										
										
										
											2024-11-12 21:51:09 +08:00
										 |  |  |         default=lambda _: str(uuid4()), | 
					
						
							|  |  |  |         description="Unique identity for variable.", | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |     ) | 
					
						
							|  |  |  |     name: str | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  |     description: str = Field(default="", description="Description of the variable.") | 
					
						
							| 
									
										
										
										
											2024-11-12 21:51:09 +08:00
										 |  |  |     selector: Sequence[str] = Field(default_factory=list) | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class StringVariable(StringSegment, Variable): | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 15:03:56 +08:00
										 |  |  | class FloatVariable(FloatSegment, Variable): | 
					
						
							|  |  |  |     pass | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-25 17:06:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 15:03:56 +08:00
										 |  |  | class IntegerVariable(IntegerSegment, Variable): | 
					
						
							|  |  |  |     pass | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-26 15:03:56 +08:00
										 |  |  | class ObjectVariable(ObjectSegment, Variable): | 
					
						
							|  |  |  |     pass | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-25 17:06:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-23 15:52:50 +08:00
										 |  |  | class ArrayVariable(ArraySegment, Variable): | 
					
						
							| 
									
										
										
										
											2024-07-26 15:03:56 +08:00
										 |  |  |     pass | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-23 15:52:50 +08:00
										 |  |  | class ArrayAnyVariable(ArrayAnySegment, ArrayVariable): | 
					
						
							| 
									
										
										
										
											2024-07-27 14:43:51 +08:00
										 |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-23 15:52:50 +08:00
										 |  |  | class ArrayStringVariable(ArrayStringSegment, ArrayVariable): | 
					
						
							| 
									
										
										
										
											2024-07-27 14:43:51 +08:00
										 |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-23 15:52:50 +08:00
										 |  |  | class ArrayNumberVariable(ArrayNumberSegment, ArrayVariable): | 
					
						
							|  |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ArrayObjectVariable(ArrayObjectSegment, ArrayVariable): | 
					
						
							| 
									
										
										
										
											2024-07-27 14:43:51 +08:00
										 |  |  |     pass | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  | class SecretVariable(StringVariable): | 
					
						
							|  |  |  |     value_type: SegmentType = SegmentType.SECRET | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @property | 
					
						
							|  |  |  |     def log(self) -> str: | 
					
						
							| 
									
										
										
										
											2024-12-24 18:38:51 +08:00
										 |  |  |         return cast(str, encrypter.obfuscated_token(self.value)) | 
					
						
							| 
									
										
										
										
											2024-07-23 17:59:32 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-23 21:46:08 +08:00
										 |  |  | class NoneVariable(NoneSegment, Variable): | 
					
						
							| 
									
										
										
										
											2024-07-23 17:59:32 +08:00
										 |  |  |     value_type: SegmentType = SegmentType.NONE | 
					
						
							| 
									
										
										
										
											2024-07-23 21:46:08 +08:00
										 |  |  |     value: None = None | 
					
						
							| 
									
										
										
										
											2024-10-21 10:43:49 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FileVariable(FileSegment, Variable): | 
					
						
							|  |  |  |     pass | 
					
						
							| 
									
										
										
										
											2024-11-12 21:51:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-24 15:56:59 +08:00
										 |  |  | class ArrayFileVariable(ArrayFileSegment, ArrayVariable): | 
					
						
							| 
									
										
										
										
											2024-11-12 21:51:09 +08:00
										 |  |  |     pass |