1.1 --- a/lib/__builtins__/sequence.py Thu Dec 01 19:09:28 2016 +0100
1.2 +++ b/lib/__builtins__/sequence.py Thu Dec 01 19:48:31 2016 +0100
1.3 @@ -21,9 +21,9 @@
1.4
1.5 from native import _isinstance
1.6
1.7 -class sequence:
1.8 +class itemaccess:
1.9
1.10 - "A common base class for sequence types."
1.11 + "An abstract class providing item access."
1.12
1.13 def _check_index(self, index):
1.14
1.15 @@ -35,56 +35,6 @@
1.16 if index < 0 or index >= len(self):
1.17 raise IndexError(index)
1.18
1.19 - def _str(self, opening, closing):
1.20 -
1.21 - "Serialise this object with the given 'opening' and 'closing' strings."
1.22 -
1.23 - b = buffer()
1.24 - i = 0
1.25 - l = self.__len__()
1.26 - first = True
1.27 -
1.28 - b.append(opening)
1.29 - while i < l:
1.30 - if first:
1.31 - first = False
1.32 - else:
1.33 - b.append(", ")
1.34 - b.append(repr(self.__get_single_item__(i)))
1.35 - i += 1
1.36 - b.append(closing)
1.37 -
1.38 - return str(b)
1.39 -
1.40 - def __contains__(self, value):
1.41 -
1.42 - "Return whether the list contains 'value'."
1.43 -
1.44 - # Perform a linear search of the sequence contents.
1.45 -
1.46 - for v in self:
1.47 -
1.48 - # Return True if the current value is equal to the specified one.
1.49 - # Note that this is not an identity test, but an equality test.
1.50 -
1.51 - if v == value:
1.52 - return True
1.53 -
1.54 - return False
1.55 -
1.56 - def index(self, value):
1.57 -
1.58 - "Return the index of 'value' or raise ValueError."
1.59 -
1.60 - i = 0
1.61 - l = len(self)
1.62 - while i < l:
1.63 - if self[i] == value:
1.64 - return i
1.65 - i += 1
1.66 -
1.67 - raise ValueError(value)
1.68 -
1.69 def __getitem__(self, index):
1.70
1.71 "Return the item or slice specified by 'index'."
1.72 @@ -157,6 +107,60 @@
1.73
1.74 return result
1.75
1.76 +class sequence(itemaccess):
1.77 +
1.78 + "A common base class for sequence types."
1.79 +
1.80 + def _str(self, opening, closing):
1.81 +
1.82 + "Serialise this object with the given 'opening' and 'closing' strings."
1.83 +
1.84 + b = buffer()
1.85 + i = 0
1.86 + l = self.__len__()
1.87 + first = True
1.88 +
1.89 + b.append(opening)
1.90 + while i < l:
1.91 + if first:
1.92 + first = False
1.93 + else:
1.94 + b.append(", ")
1.95 + b.append(repr(self.__get_single_item__(i)))
1.96 + i += 1
1.97 + b.append(closing)
1.98 +
1.99 + return str(b)
1.100 +
1.101 + def __contains__(self, value):
1.102 +
1.103 + "Return whether the list contains 'value'."
1.104 +
1.105 + # Perform a linear search of the sequence contents.
1.106 +
1.107 + for v in self:
1.108 +
1.109 + # Return True if the current value is equal to the specified one.
1.110 + # Note that this is not an identity test, but an equality test.
1.111 +
1.112 + if v == value:
1.113 + return True
1.114 +
1.115 + return False
1.116 +
1.117 + def index(self, value):
1.118 +
1.119 + "Return the index of 'value' or raise ValueError."
1.120 +
1.121 + i = 0
1.122 + l = len(self)
1.123 + while i < l:
1.124 + if self[i] == value:
1.125 + return i
1.126 + i += 1
1.127 +
1.128 + raise ValueError(value)
1.129 +
1.130 def __eq__(self, other):
1.131
1.132 "Return whether this sequence is equal to 'other'."
1.133 @@ -211,6 +215,4 @@
1.134 else:
1.135 return y
1.136
1.137 -def _tuple(l): pass
1.138 -
1.139 # vim: tabstop=4 expandtab shiftwidth=4