1.1 --- a/lib/__builtins__/sequence.py Sun Jan 29 22:56:43 2017 +0100
1.2 +++ b/lib/__builtins__/sequence.py Mon Jan 30 00:31:25 2017 +0100
1.3 @@ -36,22 +36,6 @@
1.4 if index < 0 or index >= self.__len__():
1.5 raise IndexError(index)
1.6
1.7 - def _confine_index(self, index):
1.8 -
1.9 - """
1.10 - Return the given absolute 'index', confined by the bounds of the
1.11 - sequence.
1.12 - """
1.13 -
1.14 - length = self.__len__()
1.15 -
1.16 - if index < 0:
1.17 - return 0
1.18 - elif index > length:
1.19 - return length
1.20 - else:
1.21 - return index
1.22 -
1.23 def __getitem__(self, index):
1.24
1.25 "Return the item or slice specified by 'index'."
1.26 @@ -153,9 +137,18 @@
1.27
1.28 def __get_multiple_items__(self, start, end, step):
1.29
1.30 - "Method to be overridden by subclasses."
1.31 + """
1.32 + Return items from 'start' until (but excluding) 'end', at 'step'
1.33 + intervals.
1.34 + """
1.35
1.36 - return None
1.37 + result = []
1.38 +
1.39 + while step > 0 and start < end or step < 0 and start > end:
1.40 + result.append(self.__get_single_item__(start))
1.41 + start += step
1.42 +
1.43 + return result
1.44
1.45 def __len__(self):
1.46
1.47 @@ -283,21 +276,6 @@
1.48
1.49 raise StopIteration()
1.50
1.51 - def __get_multiple_items__(self, start, end, step):
1.52 -
1.53 - """
1.54 - Return items from 'start' until (but excluding) 'end', at 'step'
1.55 - intervals.
1.56 - """
1.57 -
1.58 - result = []
1.59 -
1.60 - while step > 0 and start < end or step < 0 and start > end:
1.61 - result.append(self.__get_single_item__(start))
1.62 - start += step
1.63 -
1.64 - return result
1.65 -
1.66 def _get_absolute_index(index, length):
1.67
1.68 """
2.1 --- a/lib/__builtins__/str.py Sun Jan 29 22:56:43 2017 +0100
2.2 +++ b/lib/__builtins__/str.py Mon Jan 30 00:31:25 2017 +0100
2.3 @@ -537,17 +537,16 @@
2.4 intervals.
2.5 """
2.6
2.7 - start = self._confine_index(start)
2.8 - end = self._confine_index(end)
2.9 + if start == end:
2.10 + return ""
2.11 +
2.12 check_int(step)
2.13
2.14 if step == 0:
2.15 raise ValueError(step)
2.16
2.17 - if start == end:
2.18 - return ""
2.19 -
2.20 - return str_substr(self.__data__, start, end, step)
2.21 + l = get_using(basestring.__get_multiple_items__, self)(start, end, step)
2.22 + return "".join(l)
2.23
2.24 def str(obj):
2.25
3.1 --- a/lib/__builtins__/unicode.py Sun Jan 29 22:56:43 2017 +0100
3.2 +++ b/lib/__builtins__/unicode.py Mon Jan 30 00:31:25 2017 +0100
3.3 @@ -179,17 +179,16 @@
3.4 intervals.
3.5 """
3.6
3.7 - start = self._confine_index(start)
3.8 - end = self._confine_index(end)
3.9 + if start == end:
3.10 + return ""
3.11 +
3.12 check_int(step)
3.13
3.14 if step == 0:
3.15 raise ValueError(step)
3.16
3.17 - if start == end:
3.18 - return ""
3.19 -
3.20 - return utf8string(unicode_substr(self.__data__, start, end, step), self.encoding)
3.21 + l = get_using(basestring.__get_multiple_items__, self)(start, end, step)
3.22 + return utf8string("".join(l), self.encoding)
3.23
3.24 def unicode(s, encoding):
3.25