Beispiel #1
0
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)
Beispiel #2
0
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)
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
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_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_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)
Beispiel #8
0
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)
Beispiel #9
0
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"))
Beispiel #11
0
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"))
Beispiel #12
0
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"))
Beispiel #13
0
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)
Beispiel #14
0
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)
Beispiel #15
0
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)
Beispiel #16
0
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)
Beispiel #17
0
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)
Beispiel #18
0
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)