Choice type¶
-
class
pyasn1.type.univ.Choice(componentType=None, tagSet=tagSet(), subtypeSpec=ConstraintsIntersection(), sizeSpec=ConstraintsIntersection())¶ Create Choice type.
Choice objects are mutable and duck-type Python
dictobjects.Parameters: - componentType (
NamedType) – Object holding named ASN.1 types allowed within this collection - tagSet (
TagSet) – Object representing non-default ASN.1 tag(s) - subtypeSpec (
ConstraintsIntersection) – Object representing non-default ASN.1 subtype constraint(s) - sizeSpec (
ConstraintsIntersection) – Object representing collection size constraint
Note
The Choice type can only hold a single component at a time belonging to the list of allowed types.
-
clone(componentType=None, tagSet=tagSet(), subtypeSpec=ConstraintsIntersection())¶ Create a copy of a Choice type or object.
Any parameters to the clone() method will replace corresponding properties of the Choice object.
Parameters: - tagSet (
TagSet) – Object representing non-default ASN.1 tag(s) - subtypeSpec (
ConstraintsIntersection) – Object representing non-default ASN.1 subtype constraint(s) - sizeSpec (
ConstraintsIntersection) – Object representing non-default ASN.1 size constraint(s)
Returns: new instance of Choice type/value
- tagSet (
-
subtype(componentType=None, implicitTag=Tag(), explicitTag=Tag(), subtypeSpec=ConstraintsIntersection())¶ Create a copy of a Choice type or object.
Any parameters to the subtype() method will be added to the corresponding properties of the Choice object.
Parameters: - tagSet (
TagSet) – Object representing non-default ASN.1 tag(s) - subtypeSpec (
ConstraintsIntersection) – Object representing non-default ASN.1 subtype constraint(s) - sizeSpec (
ConstraintsIntersection) – Object representing non-default ASN.1 size constraint(s)
Returns: new instance of Choice type/value
- tagSet (
-
tagSet= TagSet((), )¶ Set (on class, not on instance) or return a
TagSetobject representing ASN.1 tag(s) associated with Choice type.
-
componentType= NamedTypes()¶ Default collection of ASN.1 types of component (e.g.
NamedType) object representing ASN.1 type allowed within Choice type
-
subtypeSpec= ConstraintsIntersection()¶ Set (on class, not on instance) or return a
ConstraintsIntersectionobject imposing constraints on Choice type initialization values.
-
sizeSpec= ConstraintsIntersection(ValueSizeConstraint(1, 1))¶ Default
ConstraintsIntersectionobject imposing size constraint on Choice objects
-
getComponentByName(name)¶ Returns Choice type component by name.
Equivalent to Python
dictsubscription operation (e.g. []).Parameters: name ( str) – Choice type component nameReturns: PyAsn1Item– Instantiate Choice component type or return existing component value
-
getComponentByType(tagSet, innerFlag=False)¶ Returns Choice type component by ASN.1 tag.
Parameters: tagSet ( TagSet) – Object representing ASN.1 tags to identify one of Choice object componentReturns: PyAsn1Item– a pyasn1 object
-
isSameTypeWith(other, matchTags=True, matchConstraints=True)¶ Examine Choice type for equality with other ASN.1 type.
ASN.1 tags (
tag) and constraints (constraint) are examined when carrying out ASN.1 types comparison.No Python inheritance relationship between PyASN1 objects is considered.
Parameters: other (a pyasn1 type object) – Class instance representing ASN.1 type. Returns: bool–Trueif other is Choice type,Falseotherwise.
-
isSuperTypeOf(other, matchTags=True, matchConstraints=True)¶ Examine Choice type for subtype relationship with other ASN.1 type.
ASN.1 tags (
tag) and constraints (constraint) are examined when carrying out ASN.1 types comparison.No Python inheritance relationship between PyASN1 objects is considered.
Parameters: other (a pyasn1 type object) – Class instance representing ASN.1 type. Returns: bool–Trueif other is a subtype of Choice type,Falseotherwise.
-
setComponentByName(name, value=NoValue(), verifyConstraints=True, matchTags=True, matchConstraints=True)¶ Assign Choice type component by name.
Equivalent to Python
dictitem assignment operation (e.g. []).Parameters: - name (
str) – Choice type component name - value (
objectorPyAsn1Itemderivative) – A Python value to initialize Choice component with (if componentType is set) or ASN.1 value object to assign to Choice component. - verifyConstraints (
bool) – If False, skip constraints validation - matchTags (
bool) – If False, skip component tags matching - matchConstraints (
bool) – If False, skip component constraints matching
Returns: self
- name (
-
setComponentByType(tagSet, value=NoValue(), verifyConstraints=True, matchTags=True, matchConstraints=True, innerFlag=False)¶ Assign Choice type component by ASN.1 tag.
Parameters: - tagSet (
TagSet) – Object representing ASN.1 tags to identify one of Choice object component - value (
objectorPyAsn1Itemderivative) – A Python value to initialize Choice component with (if componentType is set) or ASN.1 value object to assign to Choice component. - verifyConstraints (
bool) – If False, skip constraints validation - matchTags (
bool) – If False, skip component tags matching - matchConstraints (
bool) – If False, skip component constraints matching - innerFlag (
bool) – If True, search for matching tagSet recursively.
Returns: self
- tagSet (
-
setComponentByPosition(idx, value=NoValue(), verifyConstraints=True, matchTags=True, matchConstraints=True)¶ Assign Choice type component by position.
Equivalent to Python sequence item assignment operation (e.g. []).
Parameters: - idx (
int) – Component index (zero-based). Must either refer to existing component or to N+1 component. In the latter case a new component type gets instantiated (if componentType is set, or given ASN.1 object is taken otherwise) and appended to the Choice sequence. - value (
objectorPyAsn1Itemderivative) – A Python value to initialize Choice component with (if componentType is set) or ASN.1 value object to assign to Choice component. Once a new value is set to idx component, previous value is dropped. - verifyConstraints (
bool) – If False, skip constraints validation - matchTags (
bool) – If False, skip component tags matching - matchConstraints (
bool) – If False, skip component constraints matching
Returns: self
- idx (
-
effectiveTagSet¶ Return a
TagSetobject of the currently initialized component or self (if Choice is tagged).
-
getComponent(innerFlag=0)¶ Return currently assigned component of the Choice object.
Returns: PyAsn1Item– a PyASN1 object
-
getName(innerFlag=False)¶ Return the name of currently assigned component of the Choice object.
Returns: str– Choice component name
-
isValue¶ Indicate if Choice component is set and represents ASN.1 type or ASN.1 value.
The PyASN1 type objects can only participate in types comparison and serve as a blueprint for serialization codecs to resolve ambiguous types.
The PyASN1 value objects can additionally participate in most of built-in Python operations.
Returns: bool–Trueif Choice component is set and represent value and type,Falseif Choice component is not set or it represents just ASN.1 type.
- componentType (