otupy.types.base.choice.Choice
- class Choice(obj)
Bases:
Openc2TypeOpenC2 Choice Implements the OpenC2 Choice:
One field selected from a set of named fields. The API value has a name and a type.
It expect all allowed values to be provided in a Register class, which must be defined as class attribute register in all derived classes (see Target and Actuator as examples).
Note that the current implementation requires all possible choices to be of different types. Due to this limitation, it is not currently possible to define, e.g., more than an object of type
str. In such a case, distinct data types must be defined and used for thestrobjects. This limitation should have limited impact, since theChoiceis expected to be used to select between different data types.Methods
Builds instance from dictionary
Get the class corresponding to the current choice
Returns the name of the choice
Returns the objet instance embedded in the register.
Converts to dictionary
Attributes
List of registered name/class options available
Selected name for the Choice
Class corresponding to the choice
- __init__(obj)
Initialize the
ChoiceobjectObjects used as
Choicemust be registered in advance in the register dictionary.- Parameters:
obj – An object among those defined in the
register.
- classmethod fromdict(dic, e)
Builds instance from dictionary
It is used during deserialization to create an otupy instance from the text message. It takes an
Encoderinstance that is used to recursively build instances of the inner objects (theEncoderprovides 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
Encoderthat is being used.
- Returns:
An instance of this class initialized from the dictionary values.
- classmethod getClass(choice)
Get the class corresponding to the current choice
It may be implemented by any derived class, if a different logic than the Register class is followed to store the name/class bindings.
- Parameters:
choice – The name of the alternative that is being looked for.
- Returns:
The class corresponding to the provided choice.
- getName()
Returns the name of the choice
Returns the name of object, which is the selector carried by the Choice element. This does not include the object itself.
- getObj()
Returns the objet instance embedded in the register.
- obj
Class corresponding to the choice
- register = None
List of registered name/class options available
- todict(e)
Converts to dictionary
It is used to convert this object to an intermediary representation during serialization. It takes an
Encoderargument that is used to recursively serialize inner data and structures (theEncoderprovides 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.