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 = 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.newint(i)
     raise oefmt(space.w_ValueError, "tuple.index(x): x not in tuple")
Exemple #2
0
 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 = 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 oefmt(space.w_ValueError, "tuple.index(x): x not in tuple")
Exemple #3
0
    def index(self, w_x, w_start, w_stop):
        space = self.space
        w_iter = space.iter(self)
        _len = self.len
        lock = self.getlock()

        start, stop = unwrap_start_stop(space, _len, w_start, w_stop)

        for i in range(0, min(_len, stop)):
            try:
                w_obj = space.next(w_iter)
                if i < start:
                    continue
                if space.eq_w(w_obj, w_x):
                    return space.newint(i)
                self.checklock(lock)
            except OperationError as e:
                if not e.match(space, space.w_StopIteration):
                    raise
        raise oefmt(space.w_ValueError, "%R is not in deque", w_x)
Exemple #4
0
 def _convert_idx_params(self, space, w_start, w_end):
     value = self._val(space)
     lenself = len(value)
     start, end = unwrap_start_stop(space, lenself, w_start, w_end)
     return (value, start, end)
Exemple #5
0
 def _convert_idx_params(self, space, w_start, w_end):
     # optimization: this version doesn't force getdata()
     start, end = unwrap_start_stop(space, self._len(), w_start, w_end)
     ofs = self._offset
     return (self._data, start + ofs, end + ofs, ofs)
Exemple #6
0
 def _convert_idx_params(self, space, w_start, w_end):
     value = self._val(space)
     lenself = len(value)
     start, end = unwrap_start_stop(space, lenself, w_start, w_end)
     # the None means "no offset"; see bytearrayobject.py
     return (value, start, end, None)
Exemple #7
0
 def _convert_idx_params(self, space, w_start, w_end, upper_bound=False):
     value = self._val(space)
     lenself = len(value)
     start, end = unwrap_start_stop(space, lenself, w_start, w_end,
                                    upper_bound=upper_bound)
     return (value, start, end)