本文整理汇总了Python中pypy.objspace.std.sliceobject.normalize_simple_slice函数的典型用法代码示例。如果您正苦于以下问题:Python normalize_simple_slice函数的具体用法?Python normalize_simple_slice怎么用?Python normalize_simple_slice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了normalize_simple_slice函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setslice__List_ANY_ANY_ANY
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)
示例2: descr_getslice
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)
示例3: getslice__RangeList_ANY_ANY
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)
示例4: getslice__StringSlice_ANY_ANY
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)
示例5: test_normalize_simple_slice
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))
示例6: getslice__List_ANY_ANY
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])
示例7: delslice__List_ANY_ANY
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)
示例8: getslice__Tuple_ANY_ANY
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])
示例9: descr_getslice
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])
示例10: getslice__Unicode_ANY_ANY
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])
示例11: setslice__List_ANY_ANY_ANY
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)