def _convert_idx_params(space, w_self, w_start, w_end, upper_bound=False): self = w_self._value lenself = len(self) start, end = slicetype.unwrap_start_stop( space, lenself, w_start, w_end, upper_bound=upper_bound) return (self, start, end)
def _convert_idx_params(space, w_self, w_start, w_end, upper_bound=False): self = w_self._value lenself = len(self) start, end = slicetype.unwrap_start_stop( space, lenself, w_start, w_end, upper_bound=upper_bound) return (self, start, end)
def tuple_index__Tuple_ANY_ANY_ANY(space, w_tuple, w_obj, w_start, w_stop): length = len(w_tuple.wrappeditems) start, stop = slicetype.unwrap_start_stop(space, length, w_start, w_stop) for i in range(start, min(stop, length)): w_item = w_tuple.wrappeditems[i] if space.eq_w(w_item, w_obj): return space.wrap(i) raise OperationError(space.w_ValueError, space.wrap("tuple.index(x): x not in tuple"))
def _convert_idx_params(space, w_self, w_sub, w_start, w_end, upper_bound=False): self = w_self._node sub = w_sub._node start, end = slicetype.unwrap_start_stop( space, self.length(), w_start, w_end, upper_bound) return (self, sub, start, end)
def _convert_idx_params(space, w_self, w_sub, w_start, w_end, upper_bound=False): self = w_self._node sub = w_sub._node start, end = slicetype.unwrap_start_stop( space, self.length(), w_start, w_end, upper_bound) return (self, sub, start, end)
def tuple_index__Tuple_ANY_ANY_ANY(space, w_tuple, w_obj, w_start, w_stop): length = len(w_tuple.wrappeditems) start, stop = slicetype.unwrap_start_stop(space, length, w_start, w_stop) for i in range(start, min(stop, length)): w_item = w_tuple.wrappeditems[i] if space.eq_w(w_item, w_obj): return space.wrap(i) raise OperationError(space.w_ValueError, space.wrap("tuple.index(x): x not in tuple"))
def _convert_idx_params(space, w_self, w_sub, w_start, w_end): length = w_self.stop - w_self.start sub = w_sub._value start, end = slicetype.unwrap_start_stop(space, length, w_start, w_end, True) assert start >= 0 assert end >= 0 return (w_self.str, sub, w_self.start + start, w_self.start + end)
def _convert_idx_params(space, w_self, w_sub, w_start, w_end): length = w_self.stop - w_self.start sub = w_sub._value start, end = slicetype.unwrap_start_stop( space, length, w_start, w_end, True) assert start >= 0 assert end >= 0 return (w_self.str, sub, w_self.start + start, w_self.start + end)
def list_index__List_ANY_ANY_ANY(space, w_list, w_any, w_start, w_stop): # needs to be safe against eq_w() mutating the w_list behind our back size = w_list.length() i, stop = slicetype.unwrap_start_stop(space, size, w_start, w_stop, True) while i < stop and i < w_list.length(): if space.eq_w(w_list.getitem(i), w_any): return space.wrap(i) i += 1 raise OperationError(space.w_ValueError, space.wrap("list.index(x): x not in list"))
def list_index__List_ANY_ANY_ANY(space, w_list, w_any, w_start, w_stop): # needs to be safe against eq_w() mutating the w_list behind our back size = w_list.length() i, stop = slicetype.unwrap_start_stop( space, size, w_start, w_stop, True) while i < stop and i < w_list.length(): if space.eq_w(w_list.getitem(i), w_any): return space.wrap(i) i += 1 raise OperationError(space.w_ValueError, space.wrap("list.index(x): x not in list"))
def str_count__Bytearray_Int_ANY_ANY(space, w_bytearray, w_char, w_start, w_stop): char = w_char.intval bytearray = w_bytearray.data length = len(bytearray) start, stop = slicetype.unwrap_start_stop(space, length, w_start, w_stop, False) count = 0 for i in range(start, min(stop, length)): c = w_bytearray.data[i] if ord(c) == char: count += 1 return space.wrap(count)
def str_count__Bytearray_Int_ANY_ANY(space, w_bytearray, w_char, w_start, w_stop): char = w_char.intval bytearray = w_bytearray.data length = len(bytearray) start, stop = slicetype.unwrap_start_stop( space, length, w_start, w_stop, False) count = 0 for i in range(start, min(stop, length)): c = w_bytearray.data[i] if ord(c) == char: count += 1 return space.wrap(count)
def descr_index(self, space, w_obj, w_start, w_stop): """index(obj, [start, [stop]]) -> first index that obj appears in the tuple """ length = self.length() start, stop = slicetype.unwrap_start_stop(space, length, w_start, w_stop) for i in range(start, min(stop, length)): w_item = self.tolist()[i] if space.eq_w(w_item, w_obj): return space.wrap(i) raise OperationError(space.w_ValueError, space.wrap("tuple.index(x): x not in tuple"))