• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zopefoundation / zope.interface / 467 / 7

Source File

0.0
/src/zope/interface/common/sequence.py
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
"""Sequence Interfaces
×
15

16
Importing this module does *not* mark any standard classes
17
as implementing any of these interfaces.
18
"""
19

20
__docformat__ = 'restructuredtext'
×
21
from zope.interface import Interface
×
22

23
class IMinimalSequence(Interface):
24
    """Most basic sequence interface.
25

26
    All sequences are iterable.  This requires at least one of the
27
    following:
28

29
    - a `__getitem__()` method that takes a single argument; integer
30
      values starting at 0 must be supported, and `IndexError` should
31
      be raised for the first index for which there is no value, or
32

33
    - an `__iter__()` method that returns an iterator as defined in
34
      the Python documentation (http://docs.python.org/lib/typeiter.html).
35

36
    """
37

38
    def __getitem__(index):
39
        """``x.__getitem__(index) <==> x[index]``
40

41
        Declaring this interface does not specify whether `__getitem__`
42
        supports slice objects."""
43

44
class IFiniteSequence(IMinimalSequence):
45

46
    def __len__():
47
        """``x.__len__() <==> len(x)``"""
48

49
class IReadSequence(IFiniteSequence):
50
    """read interface shared by tuple and list"""
51

52
    def __contains__(item):
53
        """``x.__contains__(item) <==> item in x``"""
54

55
    def __lt__(other):
56
        """``x.__lt__(other) <==> x < other``"""
57

58
    def __le__(other):
59
        """``x.__le__(other) <==> x <= other``"""
60

61
    def __eq__(other):
62
        """``x.__eq__(other) <==> x == other``"""
63

64
    def __ne__(other):
65
        """``x.__ne__(other) <==> x != other``"""
66

67
    def __gt__(other):
68
        """``x.__gt__(other) <==> x > other``"""
69

70
    def __ge__(other):
71
        """``x.__ge__(other) <==> x >= other``"""
72

73
    def __add__(other):
74
        """``x.__add__(other) <==> x + other``"""
75

76
    def __mul__(n):
77
        """``x.__mul__(n) <==> x * n``"""
78

79
    def __rmul__(n):
80
        """``x.__rmul__(n) <==> n * x``"""
81

82
    def __getslice__(i, j):
83
        """``x.__getslice__(i, j) <==> x[i:j]``
84

85
        Use of negative indices is not supported.
86

87
        Deprecated since Python 2.0 but still a part of `UserList`.
88
        """
89

90
class IExtendedReadSequence(IReadSequence):
91
    """Full read interface for lists"""
92

93
    def count(item):
94
        """Return number of occurrences of value"""
95

96
    def index(item, *args):
97
        """index(value, [start, [stop]]) -> int
98

99
        Return first index of *value*
100
        """
101

102
class IUniqueMemberWriteSequence(Interface):
103
    """The write contract for a sequence that may enforce unique members"""
104

105
    def __setitem__(index, item):
106
        """``x.__setitem__(index, item) <==> x[index] = item``
107

108
        Declaring this interface does not specify whether `__setitem__`
109
        supports slice objects.
110
        """
111

112
    def __delitem__(index):
113
        """``x.__delitem__(index) <==> del x[index]``
114

115
        Declaring this interface does not specify whether `__delitem__`
116
        supports slice objects.
117
        """
118

119
    def __setslice__(i, j, other):
120
        """``x.__setslice__(i, j, other) <==> x[i:j] = other``
121

122
        Use of negative indices is not supported.
123

124
        Deprecated since Python 2.0 but still a part of `UserList`.
125
        """
126

127
    def __delslice__(i, j):
128
        """``x.__delslice__(i, j) <==> del x[i:j]``
129

130
        Use of negative indices is not supported.
131

132
        Deprecated since Python 2.0 but still a part of `UserList`.
133
        """
134
    def __iadd__(y):
135
        """``x.__iadd__(y) <==> x += y``"""
136

137
    def append(item):
138
        """Append item to end"""
139

140
    def insert(index, item):
141
        """Insert item before index"""
142

143
    def pop(index=-1):
144
        """Remove and return item at index (default last)"""
145

146
    def remove(item):
147
        """Remove first occurrence of value"""
148

149
    def reverse():
150
        """Reverse *IN PLACE*"""
151

152
    def sort(cmpfunc=None):
153
        """Stable sort *IN PLACE*; `cmpfunc(x, y)` -> -1, 0, 1"""
154

155
    def extend(iterable):
156
        """Extend list by appending elements from the iterable"""
157

158
class IWriteSequence(IUniqueMemberWriteSequence):
159
    """Full write contract for sequences"""
160

161
    def __imul__(n):
162
        """``x.__imul__(n) <==> x *= n``"""
163

164
class ISequence(IReadSequence, IWriteSequence):
165
    """Full sequence contract"""
  • Back to Build 456
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc