openc2lib.types.base.enumerated_id
1from openc2lib.types.base.openc2_type import Openc2Type 2from openc2lib.types.base.enumerated import Enumerated 3 4# This class should check the names are integers. 5# The enum syntax only allows to define <str = int> pairs, 6# so to use this class it is necessary to define mnemonic label 7# TODO: Test this code 8class EnumeratedID(Enumerated): 9 """ OpenC2 EnumeratedID 10 11 Implements OpenC2 EnumeratedID: 12 >A set of unnamed integral constants. The API value is an id. 13 14 The current implementation does not check the values to be integer. 15 However, coversion to/from integer is explicitly done during the 16 intermediary dictionary serialization, hence throwing an Exception if 17 the IDs are not integers. 18 """ 19 20 def todict(self, e): 21 """ Converts to dictionary 22 23 It is used to convert this object to an intermediary representation during 24 serialization. It takes an `Encoder` argument that is used to recursively 25 serialize inner data and structures (the `Encoder` provides standard methods 26 for converting base types to dictionaries).. 27 28 :param e: The `Encoder` that is being used. 29 :return: A dictionary compliants to the Language Specification's serialization 30 rules. 31 """ 32 return int(self.value) 33 34 @classmethod 35 def fromdict(cls, dic, e): 36 """ Builds instance from dictionary 37 38 It is used during deserialization to create an openc2lib instance from the text message. 39 It takes an `Encoder` instance that is used to recursively build instances of the inner 40 objects (the `Encoder` provides standard methods to create instances of base objects like 41 strings, integers, boolean). 42 43 :param dic: The intermediary dictionary representation from which the object is built. 44 :param e: The `Encoder that is being used. 45 :return: An instance of this class initialized from the dictionary values. 46 """ 47 try: 48 return cls(int(dic)) 49 except: 50 raise TypeError("Unexpected enum value: ", dic)
9class EnumeratedID(Enumerated): 10 """ OpenC2 EnumeratedID 11 12 Implements OpenC2 EnumeratedID: 13 >A set of unnamed integral constants. The API value is an id. 14 15 The current implementation does not check the values to be integer. 16 However, coversion to/from integer is explicitly done during the 17 intermediary dictionary serialization, hence throwing an Exception if 18 the IDs are not integers. 19 """ 20 21 def todict(self, e): 22 """ Converts to dictionary 23 24 It is used to convert this object to an intermediary representation during 25 serialization. It takes an `Encoder` argument that is used to recursively 26 serialize inner data and structures (the `Encoder` provides standard methods 27 for converting base types to dictionaries).. 28 29 :param e: The `Encoder` that is being used. 30 :return: A dictionary compliants to the Language Specification's serialization 31 rules. 32 """ 33 return int(self.value) 34 35 @classmethod 36 def fromdict(cls, dic, e): 37 """ Builds instance from dictionary 38 39 It is used during deserialization to create an openc2lib instance from the text message. 40 It takes an `Encoder` instance that is used to recursively build instances of the inner 41 objects (the `Encoder` provides standard methods to create instances of base objects like 42 strings, integers, boolean). 43 44 :param dic: The intermediary dictionary representation from which the object is built. 45 :param e: The `Encoder that is being used. 46 :return: An instance of this class initialized from the dictionary values. 47 """ 48 try: 49 return cls(int(dic)) 50 except: 51 raise TypeError("Unexpected enum value: ", dic)
OpenC2 EnumeratedID
Implements OpenC2 EnumeratedID:
A set of unnamed integral constants. The API value is an id.
The current implementation does not check the values to be integer. However, coversion to/from integer is explicitly done during the intermediary dictionary serialization, hence throwing an Exception if the IDs are not integers.
21 def todict(self, e): 22 """ Converts to dictionary 23 24 It is used to convert this object to an intermediary representation during 25 serialization. It takes an `Encoder` argument that is used to recursively 26 serialize inner data and structures (the `Encoder` provides standard methods 27 for converting base types to dictionaries).. 28 29 :param e: The `Encoder` that is being used. 30 :return: A dictionary compliants to the Language Specification's serialization 31 rules. 32 """ 33 return int(self.value)
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.
35 @classmethod 36 def fromdict(cls, dic, e): 37 """ Builds instance from dictionary 38 39 It is used during deserialization to create an openc2lib instance from the text message. 40 It takes an `Encoder` instance that is used to recursively build instances of the inner 41 objects (the `Encoder` provides standard methods to create instances of base objects like 42 strings, integers, boolean). 43 44 :param dic: The intermediary dictionary representation from which the object is built. 45 :param e: The `Encoder that is being used. 46 :return: An instance of this class initialized from the dictionary values. 47 """ 48 try: 49 return cls(int(dic)) 50 except: 51 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