Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pyasn1/type/opentype.py: 64%
22 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:40 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:40 +0000
1#
2# This file is part of pyasn1 software.
3#
4# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
5# License: https://pyasn1.readthedocs.io/en/latest/license.html
6#
8__all__ = ['OpenType']
11class OpenType(object):
12 """Create ASN.1 type map indexed by a value
14 The *OpenType* object models an untyped field of a constructed ASN.1
15 type. In ASN.1 syntax it is usually represented by the
16 `ANY DEFINED BY` for scalars or `SET OF ANY DEFINED BY`,
17 `SEQUENCE OF ANY DEFINED BY` for container types clauses. Typically
18 used together with :class:`~pyasn1.type.univ.Any` object.
20 OpenType objects duck-type a read-only Python :class:`dict` objects,
21 however the passed `typeMap` is not copied, but stored by reference.
22 That means the user can manipulate `typeMap` at run time having this
23 reflected on *OpenType* object behavior.
25 The |OpenType| class models an untyped field of a constructed ASN.1
26 type. In ASN.1 syntax it is usually represented by the
27 `ANY DEFINED BY` for scalars or `SET OF ANY DEFINED BY`,
28 `SEQUENCE OF ANY DEFINED BY` for container types clauses. Typically
29 used with :class:`~pyasn1.type.univ.Any` type.
31 Parameters
32 ----------
33 name: :py:class:`str`
34 Field name
36 typeMap: :py:class:`dict`
37 A map of value->ASN.1 type. It's stored by reference and can be
38 mutated later to register new mappings.
40 Examples
41 --------
43 For untyped scalars:
45 .. code-block:: python
47 openType = OpenType(
48 'id', {1: Integer(),
49 2: OctetString()}
50 )
51 Sequence(
52 componentType=NamedTypes(
53 NamedType('id', Integer()),
54 NamedType('blob', Any(), openType=openType)
55 )
56 )
58 For untyped `SET OF` or `SEQUENCE OF` vectors:
60 .. code-block:: python
62 openType = OpenType(
63 'id', {1: Integer(),
64 2: OctetString()}
65 )
66 Sequence(
67 componentType=NamedTypes(
68 NamedType('id', Integer()),
69 NamedType('blob', SetOf(componentType=Any()),
70 openType=openType)
71 )
72 )
73 """
75 def __init__(self, name, typeMap=None):
76 self.__name = name
77 if typeMap is None:
78 self.__typeMap = {}
79 else:
80 self.__typeMap = typeMap
82 @property
83 def name(self):
84 return self.__name
86 # Python dict protocol
88 def values(self):
89 return self.__typeMap.values()
91 def keys(self):
92 return self.__typeMap.keys()
94 def items(self):
95 return self.__typeMap.items()
97 def __contains__(self, key):
98 return key in self.__typeMap
100 def __getitem__(self, key):
101 return self.__typeMap[key]
103 def __iter__(self):
104 return iter(self.__typeMap)