Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

opentype.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #
  2. # This file is part of pyasn1 software.
  3. #
  4. # Copyright (c) 2005-2018, Ilya Etingof <etingof@gmail.com>
  5. # License: http://snmplabs.com/pyasn1/license.html
  6. #
  7. __all__ = ['OpenType']
  8. class OpenType(object):
  9. """Create ASN.1 type map indexed by a value
  10. The *DefinedBy* object models the ASN.1 *DEFINED BY* clause which maps
  11. values to ASN.1 types in the context of the ASN.1 SEQUENCE/SET type.
  12. OpenType objects are duck-type a read-only Python :class:`dict` objects,
  13. however the passed `typeMap` is stored by reference.
  14. Parameters
  15. ----------
  16. name: :py:class:`str`
  17. Field name
  18. typeMap: :py:class:`dict`
  19. A map of value->ASN.1 type. It's stored by reference and can be
  20. mutated later to register new mappings.
  21. Examples
  22. --------
  23. .. code-block:: python
  24. openType = OpenType(
  25. 'id',
  26. {1: Integer(),
  27. 2: OctetString()}
  28. )
  29. Sequence(
  30. componentType=NamedTypes(
  31. NamedType('id', Integer()),
  32. NamedType('blob', Any(), openType=openType)
  33. )
  34. )
  35. """
  36. def __init__(self, name, typeMap=None):
  37. self.__name = name
  38. if typeMap is None:
  39. self.__typeMap = {}
  40. else:
  41. self.__typeMap = typeMap
  42. @property
  43. def name(self):
  44. return self.__name
  45. # Python dict protocol
  46. def values(self):
  47. return self.__typeMap.values()
  48. def keys(self):
  49. return self.__typeMap.keys()
  50. def items(self):
  51. return self.__typeMap.items()
  52. def __contains__(self, key):
  53. return key in self.__typeMap
  54. def __getitem__(self, key):
  55. return self.__typeMap[key]
  56. def __iter__(self):
  57. return iter(self.__typeMap)