1.1 --- a/lib/__builtins__/sequence.py Sun Jan 29 18:52:35 2017 +0100
1.2 +++ b/lib/__builtins__/sequence.py Sun Jan 29 22:56:43 2017 +0100
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Sequence operations.
1.6
1.7 -Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -36,15 +36,21 @@
1.13 if index < 0 or index >= self.__len__():
1.14 raise IndexError(index)
1.15
1.16 - def _check_end_index(self, index):
1.17 + def _confine_index(self, index):
1.18
1.19 """
1.20 - Check the given absolute end 'index', raising an IndexError if out of
1.21 - bounds.
1.22 + Return the given absolute 'index', confined by the bounds of the
1.23 + sequence.
1.24 """
1.25
1.26 - if index < -1 or index > self.__len__():
1.27 - raise IndexError(index)
1.28 + length = self.__len__()
1.29 +
1.30 + if index < 0:
1.31 + return 0
1.32 + elif index > length:
1.33 + return length
1.34 + else:
1.35 + return index
1.36
1.37 def __getitem__(self, index):
1.38