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.

sequence.py 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. Sequence 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.ISequence` and
  21. :class:`~zope.interface.common.collections.IMutableSequence`. This
  22. module is occasionally useful for its fine-grained breakdown of interfaces.
  23. The standard library :class:`list`, :class:`tuple` and
  24. :class:`collections.UserList`, among others, implement ``ISequence``
  25. or ``IMutableSequence`` but *do not* implement any of the interfaces
  26. in this module.
  27. """
  28. __docformat__ = 'restructuredtext'
  29. from zope.interface import Interface
  30. from zope.interface.common import collections
  31. class IMinimalSequence(collections.IIterable):
  32. """Most basic sequence interface.
  33. All sequences are iterable. This requires at least one of the
  34. following:
  35. - a `__getitem__()` method that takes a single argument; integer
  36. values starting at 0 must be supported, and `IndexError` should
  37. be raised for the first index for which there is no value, or
  38. - an `__iter__()` method that returns an iterator as defined in
  39. the Python documentation (http://docs.python.org/lib/typeiter.html).
  40. """
  41. def __getitem__(index):
  42. """``x.__getitem__(index) <==> x[index]``
  43. Declaring this interface does not specify whether `__getitem__`
  44. supports slice objects."""
  45. class IFiniteSequence(collections.ISized, IMinimalSequence):
  46. """
  47. A sequence of bound size.
  48. .. versionchanged:: 5.0.0
  49. Extend ``ISized``
  50. """
  51. class IReadSequence(collections.IContainer, IFiniteSequence):
  52. """
  53. read interface shared by tuple and list
  54. This interface is similar to
  55. :class:`~zope.interface.common.collections.ISequence`, but
  56. requires that all instances be totally ordered. Most users
  57. should prefer ``ISequence``.
  58. .. versionchanged:: 5.0.0
  59. Extend ``IContainer``
  60. """
  61. def __contains__(item):
  62. """``x.__contains__(item) <==> item in x``"""
  63. # Optional in IContainer, required here.
  64. def __lt__(other):
  65. """``x.__lt__(other) <==> x < other``"""
  66. def __le__(other):
  67. """``x.__le__(other) <==> x <= other``"""
  68. def __eq__(other):
  69. """``x.__eq__(other) <==> x == other``"""
  70. def __ne__(other):
  71. """``x.__ne__(other) <==> x != other``"""
  72. def __gt__(other):
  73. """``x.__gt__(other) <==> x > other``"""
  74. def __ge__(other):
  75. """``x.__ge__(other) <==> x >= other``"""
  76. def __add__(other):
  77. """``x.__add__(other) <==> x + other``"""
  78. def __mul__(n):
  79. """``x.__mul__(n) <==> x * n``"""
  80. def __rmul__(n):
  81. """``x.__rmul__(n) <==> n * x``"""
  82. class IExtendedReadSequence(IReadSequence):
  83. """Full read interface for lists"""
  84. def count(item):
  85. """Return number of occurrences of value"""
  86. def index(item, *args):
  87. """index(value, [start, [stop]]) -> int
  88. Return first index of *value*
  89. """
  90. class IUniqueMemberWriteSequence(Interface):
  91. """The write contract for a sequence that may enforce unique members"""
  92. def __setitem__(index, item):
  93. """``x.__setitem__(index, item) <==> x[index] = item``
  94. Declaring this interface does not specify whether `__setitem__`
  95. supports slice objects.
  96. """
  97. def __delitem__(index):
  98. """``x.__delitem__(index) <==> del x[index]``
  99. Declaring this interface does not specify whether `__delitem__`
  100. supports slice objects.
  101. """
  102. def __iadd__(y):
  103. """``x.__iadd__(y) <==> x += y``"""
  104. def append(item):
  105. """Append item to end"""
  106. def insert(index, item):
  107. """Insert item before index"""
  108. def pop(index=-1):
  109. """Remove and return item at index (default last)"""
  110. def remove(item):
  111. """Remove first occurrence of value"""
  112. def reverse():
  113. """Reverse *IN PLACE*"""
  114. def sort(cmpfunc=None):
  115. """Stable sort *IN PLACE*; `cmpfunc(x, y)` -> -1, 0, 1"""
  116. def extend(iterable):
  117. """Extend list by appending elements from the iterable"""
  118. class IWriteSequence(IUniqueMemberWriteSequence):
  119. """Full write contract for sequences"""
  120. def __imul__(n):
  121. """``x.__imul__(n) <==> x *= n``"""
  122. class ISequence(IReadSequence, IWriteSequence):
  123. """
  124. Full sequence contract.
  125. New code should prefer
  126. :class:`~zope.interface.common.collections.IMutableSequence`.
  127. Compared to that interface, which is implemented by :class:`list`
  128. (:class:`~zope.interface.common.builtins.IList`), among others,
  129. this interface is missing the following methods:
  130. - clear
  131. - count
  132. - index
  133. This interface adds the following methods:
  134. - sort
  135. """