Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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.

mapping.py 4.6KB

1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. ##############################################################################
  2. #
  3. # Copyright (c) 2001, 2002 Zope Foundation and Contributors.
  4. # All Rights Reserved.
  5. #
  6. # This software is subject to the provisions of the Zope Public License,
  7. # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
  8. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
  9. # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  10. # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
  11. # FOR A PARTICULAR PURPOSE.
  12. #
  13. ##############################################################################
  14. """
  15. Mapping Interfaces.
  16. Importing this module does *not* mark any standard classes as
  17. implementing any of these interfaces.
  18. While this module is not deprecated, new code should generally use
  19. :mod:`zope.interface.common.collections`, specifically
  20. :class:`~zope.interface.common.collections.IMapping` and
  21. :class:`~zope.interface.common.collections.IMutableMapping`. This
  22. module is occasionally useful for its extremely fine grained breakdown
  23. of interfaces.
  24. The standard library :class:`dict` and :class:`collections.UserDict`
  25. implement ``IMutableMapping``, but *do not* implement any of the
  26. interfaces in this module.
  27. """
  28. from zope.interface import Interface
  29. from zope.interface.common import collections
  30. class IItemMapping(Interface):
  31. """Simplest readable mapping object
  32. """
  33. def __getitem__(key):
  34. """Get a value for a key
  35. A `KeyError` is raised if there is no value for the key.
  36. """
  37. class IReadMapping(collections.IContainer, IItemMapping):
  38. """
  39. Basic mapping interface.
  40. .. versionchanged:: 5.0.0
  41. Extend ``IContainer``
  42. """
  43. def get(key, default=None):
  44. """Get a value for a key
  45. The default is returned if there is no value for the key.
  46. """
  47. def __contains__(key):
  48. """Tell if a key exists in the mapping."""
  49. # Optional in IContainer, required by this interface.
  50. class IWriteMapping(Interface):
  51. """Mapping methods for changing data"""
  52. def __delitem__(key):
  53. """Delete a value from the mapping using the key."""
  54. def __setitem__(key, value):
  55. """Set a new item in the mapping."""
  56. class IEnumerableMapping(collections.ISized, IReadMapping):
  57. """
  58. Mapping objects whose items can be enumerated.
  59. .. versionchanged:: 5.0.0
  60. Extend ``ISized``
  61. """
  62. def keys():
  63. """Return the keys of the mapping object.
  64. """
  65. def __iter__():
  66. """Return an iterator for the keys of the mapping object.
  67. """
  68. def values():
  69. """Return the values of the mapping object.
  70. """
  71. def items():
  72. """Return the items of the mapping object.
  73. """
  74. class IMapping(IWriteMapping, IEnumerableMapping):
  75. ''' Simple mapping interface '''
  76. class IIterableMapping(IEnumerableMapping):
  77. """A mapping that has distinct methods for iterating
  78. without copying.
  79. """
  80. class IClonableMapping(Interface):
  81. """Something that can produce a copy of itself.
  82. This is available in `dict`.
  83. """
  84. def copy():
  85. "return copy of dict"
  86. class IExtendedReadMapping(IIterableMapping):
  87. """
  88. Something with a particular method equivalent to ``__contains__``.
  89. On Python 2, `dict` provided the ``has_key`` method, but it was removed
  90. in Python 3.
  91. """
  92. class IExtendedWriteMapping(IWriteMapping):
  93. """Additional mutation methods.
  94. These are all provided by `dict`.
  95. """
  96. def clear():
  97. "delete all items"
  98. def update(d):
  99. " Update D from E: for k in E.keys(): D[k] = E[k]"
  100. def setdefault(key, default=None):
  101. "D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D"
  102. def pop(k, default=None):
  103. """
  104. pop(k[,default]) -> value
  105. Remove specified key and return the corresponding value.
  106. If key is not found, *default* is returned if given, otherwise
  107. `KeyError` is raised. Note that *default* must not be passed by
  108. name.
  109. """
  110. def popitem():
  111. """remove and return some (key, value) pair as a
  112. 2-tuple; but raise KeyError if mapping is empty"""
  113. class IFullMapping(
  114. collections.IMutableMapping,
  115. IExtendedReadMapping, IExtendedWriteMapping, IClonableMapping, IMapping,):
  116. """
  117. Full mapping interface.
  118. Most uses of this interface should instead use
  119. :class:`~zope.interface.commons.collections.IMutableMapping` (one of the
  120. bases of this interface). The required methods are the same.
  121. .. versionchanged:: 5.0.0
  122. Extend ``IMutableMapping``
  123. """