コード例 #1
0
ファイル: stringobject.py プロジェクト: xx312022850/pypy
def getslice__String_ANY_ANY(space, w_str, w_start, w_stop):
    s = w_str._value
    start, stop = normalize_simple_slice(space, len(s), w_start, w_stop)
    if start == stop:
        return W_StringObject.EMPTY
    else:
        return sliced(space, s, start, stop, w_str)
コード例 #2
0
def getslice__String_ANY_ANY(space, w_str, w_start, w_stop):
    s = w_str._value
    start, stop = normalize_simple_slice(space, len(s), w_start, w_stop)
    if start == stop:
        return W_StringObject.EMPTY
    else:
        return sliced(space, s, start, stop, w_str)
コード例 #3
0
ファイル: stringmethods.py プロジェクト: sota/pypy-old
 def descr_getslice(self, space, w_start, w_stop):
     selfvalue = self._val(space)
     start, stop = normalize_simple_slice(space, len(selfvalue), w_start,
                                          w_stop)
     if start == stop:
         return self._empty()
     else:
         return self._sliced(space, selfvalue, start, stop, self)
コード例 #4
0
def getslice__List_ANY_ANY(space, w_list, w_start, w_stop):
    length = w_list.length()
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)

    slicelength = stop - start
    if slicelength == 0:
        return make_empty_list(space)
    return w_list.getslice(start, stop, 1, stop - start)
コード例 #5
0
ファイル: stringmethods.py プロジェクト: Darriall/pypy
 def descr_getslice(self, space, w_start, w_stop):
     selfvalue = self._val(space)
     start, stop = normalize_simple_slice(space, len(selfvalue), w_start,
                                          w_stop)
     if start == stop:
         return self._empty()
     else:
         return self._sliced(space, selfvalue, start, stop, self)
コード例 #6
0
def getslice__List_ANY_ANY(space, w_list, w_start, w_stop):
    length = w_list.length()
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)

    slicelength = stop - start
    if slicelength == 0:
        return make_empty_list(space)
    return w_list.getslice(start, stop, 1, stop - start)
コード例 #7
0
ファイル: listobject.py プロジェクト: gorakhargosh/pypy
def setslice__List_ANY_ANY_ANY(space, w_list, w_start, w_stop, w_sequence):
    length = len(w_list.wrappeditems)
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)

    sequence2 = space.listview(w_sequence)
    items = w_list.wrappeditems
    _setitem_slice_helper(space, items, start, 1, stop-start, sequence2,
                          empty_elem=None)
コード例 #8
0
def getslice__RopeUnicode_ANY_ANY(space, w_uni, w_start, w_stop):
    node = w_uni._node
    length = node.length()
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    sl = stop - start
    if sl == 0:
        return W_RopeUnicodeObject.EMPTY
    return W_RopeUnicodeObject(rope.getslice(node, start, stop, 1, sl))
コード例 #9
0
def getslice__Rope_ANY_ANY(space, w_str, w_start, w_stop):
    node = w_str._node
    length = node.length()
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    sl = stop - start
    if sl == 0:
        return W_RopeObject.EMPTY
    return W_RopeObject(rope.getslice(node, start, stop, 1, sl))
コード例 #10
0
ファイル: rangeobject.py プロジェクト: e2pluginss/plexnet
def getslice__RangeList_ANY_ANY(space, w_rangelist, w_start, w_stop):
    if w_rangelist.w_list is not None:
        return space.getslice(w_rangelist.w_list, w_start, w_stop)
    length = w_rangelist.length
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    slicelength = stop - start
    assert slicelength >= 0
    rangestart = w_rangelist.getitem_unchecked(start)
    rangestep = w_rangelist.step
    return W_RangeListObject(rangestart, rangestep, slicelength)
コード例 #11
0
def getslice__StringSlice_ANY_ANY(space, w_str, w_start, w_stop):
    length = w_str.stop - w_str.start
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    sl = stop - start
    if sl == 0:
        return W_StringObject.EMPTY
    else:
        s = w_str.str
        start = w_str.start + start
        stop = w_str.start + stop
        return W_StringSliceObject(s, start, stop)
コード例 #12
0
def getslice__StringSlice_ANY_ANY(space, w_str, w_start, w_stop):
    length = w_str.stop - w_str.start
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    sl = stop - start
    if sl == 0:
        return W_StringObject.EMPTY
    else:
        s = w_str.str
        start = w_str.start + start
        stop = w_str.start + stop
        return W_StringSliceObject(s, start, stop)
コード例 #13
0
ファイル: test_sliceobject.py プロジェクト: Darriall/pypy
    def test_normalize_simple_slice(self):
        space = self.space
        w = space.wrap

        def getslice(length, start, stop):
            # returns range(length)[start:stop] but without special
            # support for negative start or stop
            return [i for i in range(length) if start <= i < stop]

        assert getslice(10, 2, 5) == [2, 3, 4]

        for length in range(5):
            for start in range(-2*length-2, 2*length+3):
                for stop in range(-2*length-2, 2*length+3):
                    mystart, mystop = normalize_simple_slice(space, length,
                                                             w(start), w(stop))
                    assert 0 <= mystart <= mystop <= length
                    assert (getslice(length, start, stop) ==
                            getslice(length, mystart, mystop))
コード例 #14
0
    def test_normalize_simple_slice(self):
        space = self.space
        w = space.wrap

        def getslice(length, start, stop):
            # returns range(length)[start:stop] but without special
            # support for negative start or stop
            return [i for i in range(length) if start <= i < stop]

        assert getslice(10, 2, 5) == [2, 3, 4]

        for length in range(5):
            for start in range(-2*length-2, 2*length+3):
                for stop in range(-2*length-2, 2*length+3):
                    mystart, mystop = normalize_simple_slice(space, length,
                                                             w(start), w(stop))
                    assert 0 <= mystart <= mystop <= length
                    assert (getslice(length, start, stop) ==
                            getslice(length, mystart, mystop))
コード例 #15
0
ファイル: listobject.py プロジェクト: gorakhargosh/pypy
def delslice__List_ANY_ANY(space, w_list, w_start, w_stop):
    length = len(w_list.wrappeditems)
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    _delitem_slice_helper(space, w_list.wrappeditems, start, 1, stop-start)
コード例 #16
0
ファイル: unicodeobject.py プロジェクト: nipengadmaster/pypy
def getslice__Unicode_ANY_ANY(space, w_uni, w_start, w_stop):
    uni = w_uni._value
    start, stop = normalize_simple_slice(space, len(uni), w_start, w_stop)
    return W_UnicodeObject(uni[start:stop])
コード例 #17
0
ファイル: listobject.py プロジェクト: xx312022850/pypy
def getslice__List_ANY_ANY(space, w_list, w_start, w_stop):
    length = len(w_list.wrappeditems)
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    return W_ListObject(w_list.wrappeditems[start:stop])
コード例 #18
0
ファイル: listobject.py プロジェクト: xx312022850/pypy
def delslice__List_ANY_ANY(space, w_list, w_start, w_stop):
    length = len(w_list.wrappeditems)
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    _delitem_slice_helper(space, w_list, start, 1, stop - start)
コード例 #19
0
ファイル: listobject.py プロジェクト: xx312022850/pypy
def setslice__List_ANY_ANY_ANY(space, w_list, w_start, w_stop, w_sequence):
    length = len(w_list.wrappeditems)
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    _setitem_slice_helper(space, w_list, start, 1, stop - start, w_sequence)
コード例 #20
0
ファイル: tupleobject.py プロジェクト: ieure/pypy
def getslice__Tuple_ANY_ANY(space, w_tuple, w_start, w_stop):
    length = len(w_tuple.wrappeditems)
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    return space.newtuple(w_tuple.wrappeditems[start:stop])
コード例 #21
0
def setslice__List_ANY_ANY_ANY(space, w_list, w_start, w_stop, w_iterable):
    length = w_list.length()
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    sequence_w = space.listview(w_iterable)
    w_other = W_ListObject(space, sequence_w)
    w_list.setslice(start, 1, stop - start, w_other)
コード例 #22
0
def getslice__Tuple_ANY_ANY(space, w_tuple, w_start, w_stop):
    length = len(w_tuple.wrappeditems)
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    return space.newtuple(w_tuple.wrappeditems[start:stop])
コード例 #23
0
ファイル: listobject.py プロジェクト: gorakhargosh/pypy
def getslice__List_ANY_ANY(space, w_list, w_start, w_stop):
    length = len(w_list.wrappeditems)
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    return W_ListObject(w_list.wrappeditems[start:stop])
コード例 #24
0
def setslice__List_ANY_ANY_List(space, w_list, w_start, w_stop, w_other):
    length = w_list.length()
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    w_list.setslice(start, 1, stop-start, w_other)
コード例 #25
0
def setslice__List_ANY_ANY_List(space, w_list, w_start, w_stop, w_other):
    length = w_list.length()
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    w_list.setslice(start, 1, stop - start, w_other)
コード例 #26
0
def delslice__List_ANY_ANY(space, w_list, w_start, w_stop):
    length = w_list.length()
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    w_list.deleteslice(start, 1, stop - start)
コード例 #27
0
def delslice__List_ANY_ANY(space, w_list, w_start, w_stop):
    length = w_list.length()
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    w_list.deleteslice(start, 1, stop-start)
コード例 #28
0
def setslice__List_ANY_ANY_ANY(space, w_list, w_start, w_stop, w_iterable):
    length = w_list.length()
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    sequence_w = space.listview(w_iterable)
    w_other = W_ListObject(space, sequence_w)
    w_list.setslice(start, 1, stop-start, w_other)
コード例 #29
0
 def descr_getslice(self, space, w_start, w_stop):
     length = self.length()
     start, stop = normalize_simple_slice(space, length, w_start, w_stop)
     return space.newtuple(self.tolist()[start:stop])
コード例 #30
0
def setslice__List_ANY_ANY_ANY(space, w_list, w_start, w_stop, w_sequence):
    length = len(w_list.wrappeditems)
    start, stop = normalize_simple_slice(space, length, w_start, w_stop)
    _setitem_slice_helper(space, w_list, start, 1, stop-start, w_sequence)