SequenceOf type

class pyasn1.type.univ.SequenceOf(componentType=NoValue(), tagSet=TagSet(), subtypeSpec=ConstraintsIntersection())

Create SequenceOf schema or value object.

SequenceOf class is based on ConstructedAsn1Type, its objects are mutable and duck-type Python list objects.

Keyword Arguments
  • componentType (PyAsn1Item derivative) – A pyasn1 object representing ASN.1 type allowed within SequenceOf type

  • tagSet (TagSet) – Object representing non-default ASN.1 tag(s)

  • subtypeSpec (ConstraintsIntersection) – Object representing non-default ASN.1 subtype constraint(s). Constraints verification for SequenceOf type can only occur on explicit .isInconsistent call.

Examples

class LotteryDraw(SequenceOf):  #  SetOf is similar
    '''
    ASN.1 specification:

    LotteryDraw ::= SEQUENCE OF INTEGER
    '''
    componentType = Integer()

lotteryDraw = LotteryDraw()
lotteryDraw.extend([123, 456, 789])

Note

The SequenceOf type models a collection of elements of a single ASN.1 type. Ordering of the components is preserved upon de/serialisation.

clone(componentType=NoValue(), tagSet=TagSet(), subtypeSpec=ConstraintsIntersection())

Create a modified version of SequenceOf schema object.

The clone() method accepts the same set arguments as SequenceOf class takes on instantiation except that all arguments of the clone() method are optional.

Whatever arguments are supplied, they are used to create a copy of self taking precedence over the ones used to instantiate self.

Possible values of self are never copied over thus clone() can only create a new schema object.

Returns

new instance of SequenceOf type/value

Note

Due to the mutable nature of the SequenceOf object, even if no arguments are supplied, a new SequenceOf object will be created and returned.

subtype(componentType=NoValue(), implicitTag=Tag(), explicitTag=Tag(), subtypeSpec=ConstraintsIntersection())

Create a specialization of SequenceOf schema object.

The subtype() method accepts the same set arguments as SequenceOf class takes on instantiation except that all parameters of the subtype() method are optional.

With the exception of the arguments described below, the rest of supplied arguments they are used to create a copy of self taking precedence over the ones used to instantiate self.

The following arguments to subtype() create a ASN.1 subtype out of SequenceOf type.

Other Parameters
  • implicitTag (Tag) – Implicitly apply given ASN.1 tag object to self’s TagSet, then use the result as new object’s ASN.1 tag(s).

  • explicitTag (Tag) – Explicitly apply given ASN.1 tag object to self’s TagSet, then use the result as new object’s ASN.1 tag(s).

  • subtypeSpec (ConstraintsIntersection) – Add ASN.1 constraints object to one of the self’s, then use the result as new object’s ASN.1 constraints.

Returns

new instance of SequenceOf type/value

Note

Due to the mutable nature of the SequenceOf object, even if no arguments are supplied, a new SequenceOf object will be created and returned.

tagSet = <TagSet object, tags 0:32:16>

Set (on class, not on instance) or return a TagSet object representing ASN.1 tag(s) associated with SequenceOf type.

componentType = None

Default PyAsn1Item derivative object representing ASN.1 type allowed within SequenceOf type

subtypeSpec = <ConstraintsIntersection object>

Set (on class, not on instance) or return a ConstraintsIntersection object imposing constraints on SequenceOf type initialization values.

property isValue

Indicate that SequenceOf object represents ASN.1 value.

If isValue is False then this object represents just ASN.1 schema.

If isValue is True then, in addition to its ASN.1 schema features, this object can also be used like a Python built-in object (e.g. int, str, dict etc.).

Returns

boolFalse if object represents just ASN.1 schema. True if object represents ASN.1 schema and can be used as a normal value.

Note

There is an important distinction between PyASN1 schema and value objects. The PyASN1 schema objects can only participate in ASN.1 schema-related operations (e.g. defining or testing the structure of the data). Most obvious uses of ASN.1 schema is to guide serialisation codecs whilst encoding/decoding serialised ASN.1 contents.

The PyASN1 value objects can additionally participate in many operations involving regular Python objects (e.g. arithmetic, comprehension etc).

isSameTypeWith(other, matchTags=True, matchConstraints=True)

Examine SequenceOf type for equality with other ASN.1 type.

ASN.1 tags (tag) and constraints (constraint) are examined when carrying out ASN.1 types comparison.

Python class inheritance relationship is NOT considered.

Parameters

other (a pyasn1 type object) – Class instance representing ASN.1 type.

Returns

boolTrue if other is SequenceOf type, False otherwise.

isSuperTypeOf(other, matchTags=True, matchConstraints=True)

Examine SequenceOf 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.

Python class inheritance relationship is NOT considered.

Parameters

other (a pyasn1 type object) – Class instance representing ASN.1 type.

Returns

boolTrue if other is a subtype of SequenceOf type, False otherwise.

property effectiveTagSet

For SequenceOf type is equivalent to tagSet

property tagMap

Return a TagMap object mapping ASN.1 tags to ASN.1 objects within callee object.

getComponentByPosition(idx, default=<NoValue object>, instantiate=True)

Return SequenceOf type component value by position.

Equivalent to Python sequence subscription operation (e.g. []).

Parameters

idx (int) – Component index (zero-based). Must either refer to an existing component or to N+1 component (if componentType is set). In the latter case a new component type gets instantiated and appended to the SequenceOf sequence.

Keyword Arguments
  • default (object) – If set and requested component is a schema object, return the default object instead of the requested component.

  • instantiate (bool) – If True (default), inner component will be automatically instantiated. If False either existing component or the NoValue object will be returned.

Returns

PyAsn1Item – Instantiate SequenceOf component type or return existing component value

Examples

# can also be SetOf
class MySequenceOf(SequenceOf):
    componentType = OctetString()

s = MySequenceOf()

# returns component #0 with `.isValue` property False
s.getComponentByPosition(0)

# returns None
s.getComponentByPosition(0, default=None)

s.clear()

# returns noValue
s.getComponentByPosition(0, instantiate=False)

# sets component #0 to OctetString() ASN.1 schema
# object and returns it
s.getComponentByPosition(0, instantiate=True)

# sets component #0 to ASN.1 value object
s.setComponentByPosition(0, 'ABCD')

# returns OctetString('ABCD') value object
s.getComponentByPosition(0, instantiate=False)

s.clear()

# returns noValue
s.getComponentByPosition(0, instantiate=False)
setComponentByPosition(idx, value=<NoValue object>, verifyConstraints=True, matchTags=True, matchConstraints=True)

Assign SequenceOf type component by position.

Equivalent to Python sequence item assignment operation (e.g. []) or list.append() (when idx == len(self)).

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 SequenceOf sequence.

Keyword Arguments
  • value (object or PyAsn1Item derivative) – A Python value to initialize SequenceOf component with (if componentType is set) or ASN.1 value object to assign to SequenceOf component. If value is not given, schema object will be set as a 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

Raises
clear()

Remove all components and become an empty SequenceOf value object.

Has the same effect on SequenceOf object as it does on list built-in.

reset()

Remove all components and become a SequenceOf schema object.

See isValue() property for more information on the distinction between value and schema objects.

property isInconsistent

Run necessary checks to ensure SequenceOf object consistency.

Default action is to verify SequenceOf object against constraints imposed by subtypeSpec.

Raises

PyAsn1tError