1.1 --- a/lib/__builtins__/sequence.py Wed Nov 23 17:23:52 2016 +0100
1.2 +++ b/lib/__builtins__/sequence.py Wed Nov 23 17:32:58 2016 +0100
1.3 @@ -25,6 +25,27 @@
1.4
1.5 "A common base class for sequence types."
1.6
1.7 + def _str(self, opening, closing):
1.8 +
1.9 + "Serialise this object with the given 'opening' and 'closing' strings."
1.10 +
1.11 + b = buffer()
1.12 + i = 0
1.13 + l = self.__len__()
1.14 + first = True
1.15 +
1.16 + b.append(opening)
1.17 + while i < l:
1.18 + if first:
1.19 + first = False
1.20 + else:
1.21 + b.append(", ")
1.22 + b.append(repr(self.__get_single_item__(i)))
1.23 + i += 1
1.24 + b.append(closing)
1.25 +
1.26 + return str(b)
1.27 +
1.28 def __getitem__(self, index):
1.29
1.30 "Return the item or slice specified by 'index'."
1.31 @@ -46,6 +67,27 @@
1.32 else:
1.33 raise TypeError
1.34
1.35 + def __setitem__(self, index, value):
1.36 +
1.37 + "Set at 'index' the given 'value'."
1.38 +
1.39 + # Normalise any integer indexes, converting negative indexes to positive
1.40 + # ones.
1.41 +
1.42 + if _isinstance(index, int):
1.43 + index = _normalise_index(index, self.__len__())
1.44 + return self.__set_single_item__(index, value)
1.45 +
1.46 + # Handle slices separately.
1.47 +
1.48 + elif _isinstance(index, slice):
1.49 + return self.__setslice__(index.start, index.end, value)
1.50 +
1.51 + # No other kinds of objects are supported as indexes.
1.52 +
1.53 + else:
1.54 + raise TypeError
1.55 +
1.56 def __getslice__(self, start, end=None):
1.57
1.58 "Return a slice starting from 'start', with the optional 'end'."