+ def clip_index(self, index):
+ """
+ Make sure the given index fits within the bounds of this
+ list. If it doesn't, clip it off at the ends of the list (e.g,
+ -1 becomes 0).
+ """
+ max_index = len(self.items_cache) - 1
+ return max (0, min(max_index, index))
+
+ def wrap_index(self, index):
+ """
+ Make sure the given index fits within the bounds of this
+ list. If it doesn't, wrap it around (e.g., -1 becomes 5 in a
+ 6-element list).
+ """
+ count = len(self.items_cache)
+ return index % count
+