def _convert_idx_params(space, w_self, w_start, w_end): self = w_self._value start = slicetype.adapt_bound(space, len(self), w_start) end = slicetype.adapt_bound(space, len(self), w_end) assert start >= 0 assert end >= 0 return (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 = slicetype.adapt_bound(space, length, w_start) end = slicetype.adapt_bound(space, length, w_end) 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, upper_bound=False): self = w_self._value sub = w_sub._value if upper_bound: start = slicetype.adapt_bound(space, len(self), w_start) end = slicetype.adapt_bound(space, len(self), w_end) else: start = slicetype.adapt_lower_bound(space, len(self), w_start) end = slicetype.adapt_lower_bound(space, len(self), w_end) return (self, sub, start, end)
def _convert_idx_params(space, w_self, w_start, w_end): self = w_self._node length = w_self._node.length() start = slicetype.adapt_bound(space, length, w_start) end = slicetype.adapt_bound(space, length, w_end) assert start >= 0 assert end >= 0 return (self, start, end)
def _convert_idx_params(space, w_self, w_sub, w_start, w_end): self = w_self._node sub = w_sub._node start = slicetype.adapt_bound(space, self.length(), w_start) assert start >= 0 end = slicetype.adapt_bound(space, self.length(), w_end) assert end >= 0 return (self, sub, start, end)
def list_index__ListMulti_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 length = w_list.implementation.length() i = slicetype.adapt_bound(space, length, w_start) stop = slicetype.adapt_bound(space, length, w_stop) while i < stop and i < w_list.implementation.length(): if space.eq_w(w_list.implementation.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 items = w_list.wrappeditems size = len(items) i = slicetype.adapt_bound(space, size, w_start) stop = slicetype.adapt_bound(space, size, w_stop) while i < stop and i < len(items): if space.eq_w(items[i], w_any): return space.wrap(i) i += 1 raise OperationError(space.w_ValueError, space.wrap("list.index(x): x not in list"))
def _convert_idx_params(space, w_self, w_start, w_end): self = w_self._node length = w_self._node.length() if space.is_w(w_start, space.w_None): w_start = space.wrap(0) if space.is_w(w_end, space.w_None): w_end = space.len(w_self) start = slicetype.adapt_bound(space, length, w_start) end = slicetype.adapt_bound(space, length, w_end) assert start >= 0 assert end >= 0 return (self, 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 if space.is_w(w_start, space.w_None): w_start = space.wrap(0) if space.is_w(w_end, space.w_None): w_end = space.len(w_self) if upper_bound: start = slicetype.adapt_bound(space, self.length(), w_start) end = slicetype.adapt_bound(space, self.length(), w_end) else: start = slicetype.adapt_lower_bound(space, self.length(), w_start) end = slicetype.adapt_lower_bound(space, self.length(), w_end) return (self, sub, start, end)
def _convert_idx_params(space, w_self, w_sub, w_start, w_end, upper_bound=False): assert isinstance(w_sub, W_UnicodeObject) self = w_self._value sub = w_sub._value if space.is_w(w_start, space.w_None): w_start = space.wrap(0) if space.is_w(w_end, space.w_None): w_end = space.len(w_self) if upper_bound: start = slicetype.adapt_bound(space, len(self), w_start) end = slicetype.adapt_bound(space, len(self), w_end) else: start = slicetype.adapt_lower_bound(space, len(self), w_start) end = slicetype.adapt_lower_bound(space, len(self), w_end) return (self, sub, start, end)
def str_count__Rope_Rope_ANY_ANY(space, w_self, w_arg, w_start, w_end): selfnode = w_self._node length = selfnode.length() argnode = w_arg._node u_start = slicetype.adapt_bound(space, length, w_start) u_end = slicetype.adapt_bound(space, length, w_end) assert u_start >= 0 assert u_end >= 0 iter = rope.FindIterator(selfnode, argnode, u_start, u_end) i = 0 while 1: try: index = iter.next() except StopIteration: break i += 1 return wrapint(space, i)