openc2lib.types.base.enumerated
1import aenum 2 3from openc2lib.types.base.openc2_type import Openc2Type 4 5class Enumerated(Openc2Type, aenum.Enum): 6 """ OpenC2 Enumerated 7 8 Implements OpenC2 Enumerated: 9 >A set of named integral constants. The API value is a name. 10 11 The constants may be anything, including strings, integers, classes. 12 """ 13 14 # Convert enumerations to str 15 def todict(self, e): 16 """ Converts to dictionary 17 18 It is used to convert this object to an intermediary representation during 19 serialization. It takes an `Encoder` argument that is used to recursively 20 serialize inner data and structures (the `Encoder` provides standard methods 21 for converting base types to dictionaries).. 22 23 :param e: The `Encoder` that is being used. 24 :return: A dictionary compliants to the Language Specification's serialization 25 rules. 26 """ 27 return self.name 28 29 @classmethod 30 def fromdict(cls, dic, e): 31 """ Builds instance from dictionary 32 33 It is used during deserialization to create an openc2lib instance from the text message. 34 It takes an `Encoder` instance that is used to recursively build instances of the inner 35 objects (the `Encoder` provides standard methods to create instances of base objects like 36 strings, integers, boolean). 37 38 :param dic: The intermediary dictionary representation from which the object is built. 39 :param e: The `Encoder that is being used. 40 :return: An instance of this class initialized from the dictionary values. 41 """ 42 try: 43 return cls[str(dic)] 44 except: 45 raise TypeError("Unexpected enum value: ", dic) 46
6class Enumerated(Openc2Type, aenum.Enum): 7 """ OpenC2 Enumerated 8 9 Implements OpenC2 Enumerated: 10 >A set of named integral constants. The API value is a name. 11 12 The constants may be anything, including strings, integers, classes. 13 """ 14 15 # Convert enumerations to str 16 def todict(self, e): 17 """ Converts to dictionary 18 19 It is used to convert this object to an intermediary representation during 20 serialization. It takes an `Encoder` argument that is used to recursively 21 serialize inner data and structures (the `Encoder` provides standard methods 22 for converting base types to dictionaries).. 23 24 :param e: The `Encoder` that is being used. 25 :return: A dictionary compliants to the Language Specification's serialization 26 rules. 27 """ 28 return self.name 29 30 @classmethod 31 def fromdict(cls, dic, e): 32 """ Builds instance from dictionary 33 34 It is used during deserialization to create an openc2lib instance from the text message. 35 It takes an `Encoder` instance that is used to recursively build instances of the inner 36 objects (the `Encoder` provides standard methods to create instances of base objects like 37 strings, integers, boolean). 38 39 :param dic: The intermediary dictionary representation from which the object is built. 40 :param e: The `Encoder that is being used. 41 :return: An instance of this class initialized from the dictionary values. 42 """ 43 try: 44 return cls[str(dic)] 45 except: 46 raise TypeError("Unexpected enum value: ", dic)
OpenC2 Enumerated
Implements OpenC2 Enumerated:
A set of named integral constants. The API value is a name.
The constants may be anything, including strings, integers, classes.
16 def todict(self, e): 17 """ Converts to dictionary 18 19 It is used to convert this object to an intermediary representation during 20 serialization. It takes an `Encoder` argument that is used to recursively 21 serialize inner data and structures (the `Encoder` provides standard methods 22 for converting base types to dictionaries).. 23 24 :param e: The `Encoder` that is being used. 25 :return: A dictionary compliants to the Language Specification's serialization 26 rules. 27 """ 28 return self.name
Converts to dictionary
It is used to convert this object to an intermediary representation during
serialization. It takes an Encoder argument that is used to recursively
serialize inner data and structures (the Encoder provides standard methods
for converting base types to dictionaries)..
Parameters
- e: The
Encoderthat is being used.
Returns
A dictionary compliants to the Language Specification's serialization rules.
30 @classmethod 31 def fromdict(cls, dic, e): 32 """ Builds instance from dictionary 33 34 It is used during deserialization to create an openc2lib instance from the text message. 35 It takes an `Encoder` instance that is used to recursively build instances of the inner 36 objects (the `Encoder` provides standard methods to create instances of base objects like 37 strings, integers, boolean). 38 39 :param dic: The intermediary dictionary representation from which the object is built. 40 :param e: The `Encoder that is being used. 41 :return: An instance of this class initialized from the dictionary values. 42 """ 43 try: 44 return cls[str(dic)] 45 except: 46 raise TypeError("Unexpected enum value: ", dic)
Builds instance from dictionary
It is used during deserialization to create an openc2lib instance from the text message.
It takes an Encoder instance that is used to recursively build instances of the inner
objects (the Encoder provides standard methods to create instances of base objects like
strings, integers, boolean).
Parameters
- dic: The intermediary dictionary representation from which the object is built.
- e: The `Encoder that is being used.
Returns
An instance of this class initialized from the dictionary values.
Inherited Members
- aenum._enum.Enum
- name
- value
- values