diff options
author | Ilya Etingof <etingof@gmail.com> | 2019-07-09 00:03:30 +0200 |
---|---|---|
committer | Ilya Etingof <etingof@gmail.com> | 2019-07-09 00:03:30 +0200 |
commit | 5ec40e81ddc81cffe706ae3497bcaa835201ca08 (patch) | |
tree | 02d8ae96bfbcd56323427351eab78b8185b42eb3 /pyasn1/type/opentype.py | |
parent | 954629f0ba38d9ba26744daba36d97b352ebb721 (diff) | |
download | pyasn1-git-improve-open-type-docs.tar.gz |
Add more docs on `OpenType`improve-open-type-docs
This change adds more explanations and examples on ASN.1 ANY
DEFINED BY syntax (OpenType).
Diffstat (limited to 'pyasn1/type/opentype.py')
-rw-r--r-- | pyasn1/type/opentype.py | 45 |
1 files changed, 37 insertions, 8 deletions
diff --git a/pyasn1/type/opentype.py b/pyasn1/type/opentype.py index d37a533..29645f0 100644 --- a/pyasn1/type/opentype.py +++ b/pyasn1/type/opentype.py @@ -11,11 +11,22 @@ __all__ = ['OpenType'] class OpenType(object): """Create ASN.1 type map indexed by a value - The *DefinedBy* object models the ASN.1 *DEFINED BY* clause which maps - values to ASN.1 types in the context of the ASN.1 SEQUENCE/SET type. - - OpenType objects are duck-type a read-only Python :class:`dict` objects, - however the passed `typeMap` is stored by reference. + The *OpenType* object models an untyped field of a constructed ASN.1 + type. In ASN.1 syntax it is usually represented by the + `ANY DEFINED BY` for scalars or `SET OF ANY DEFINED BY`, + `SEQUENCE OF ANY DEFINED BY` for container types clauses. Typically + used together with :class:`~pyasn1.type.univ.Any` object. + + OpenType objects duck-type a read-only Python :class:`dict` objects, + however the passed `typeMap` is not copied, but stored by reference. + That means the user can manipulate `typeMap` at run time having this + reflected on *OpenType* object behavior. + + The |OpenType| class models an untyped field of a constructed ASN.1 + type. In ASN.1 syntax it is usually represented by the + `ANY DEFINED BY` for scalars or `SET OF ANY DEFINED BY`, + `SEQUENCE OF ANY DEFINED BY` for container types clauses. Typically + used with :class:`~pyasn1.type.univ.Any` type. Parameters ---------- @@ -28,12 +39,14 @@ class OpenType(object): Examples -------- + + For untyped scalars: + .. code-block:: python openType = OpenType( - 'id', - {1: Integer(), - 2: OctetString()} + 'id', {1: Integer(), + 2: OctetString()} ) Sequence( componentType=NamedTypes( @@ -41,6 +54,22 @@ class OpenType(object): NamedType('blob', Any(), openType=openType) ) ) + + For untyped `SET OF` or `SEQUENCE OF` vectors: + + .. code-block:: python + + openType = OpenType( + 'id', {1: Integer(), + 2: OctetString()} + ) + Sequence( + componentType=NamedTypes( + NamedType('id', Integer()), + NamedType('blob', SetOf(componentType=Any()), + openType=openType) + ) + ) """ def __init__(self, name, typeMap=None): |