• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2.. _type.namedval:
3
4Enumerating numbers
5-------------------
6
7Some ASN.1 types such as :ref:`Integer <univ.Integer>`,
8:ref:`Enumerated <univ.Enumerated>` and :ref:`BitString <univ.BitString>`
9may enumerate their otherwise numeric values associating them with
10human-friendly labels.
11
12.. code-block:: python
13
14   class ErrorStatus(Integer):
15   """
16   ASN.1 specification:
17
18   error-status
19                 INTEGER {
20                     noError(0),
21                     tooBig(1),
22                     noSuchName(2),
23                     ...
24                  }
25   """
26   namedValues = NamedValues(
27       ('noError', 0), ('tooBig', 1), ('noSuchName', 2)
28   )
29
30The enumerated types behave exactly like the non-enumerated ones but,
31additionally, values can be referred by labels.
32
33.. code-block:: python
34
35   errorStatus = ErrorStatus('tooBig')
36
37   assert errorStatus == 1
38
39
40.. toctree::
41   :maxdepth: 2
42
43   /pyasn1/type/namedval/namedval
44