def getitem__String_ANY(space, w_str, w_index): ival = space.getindex_w(w_index, space.w_IndexError, "string index") str = w_str._value slen = len(str) if ival < 0: ival += slen if ival < 0 or ival >= slen: raise OperationError(space.w_IndexError, space.wrap("string index out of range")) return wrapchar(space, str[ival])
def getitem__Rope_ANY(space, w_str, w_index): ival = space.getindex_w(w_index, space.w_IndexError, "string index") node = w_str._node slen = node.length() if ival < 0: ival += slen if ival < 0 or ival >= slen: raise OperationError(space.w_IndexError, space.wrap("string index out of range")) return wrapchar(space, node.getchar(ival))
def getitem__StringSlice_ANY(space, w_str, w_index): ival = space.getindex_w(w_index, space.w_IndexError, "string index") slen = w_str.stop - w_str.start if ival < 0: ival += slen if ival < 0 or ival >= slen: exc = space.call_function(space.w_IndexError, space.wrap("string index out of range")) raise OperationError(space.w_IndexError, exc) return wrapchar(space, w_str.str[w_str.start + ival])
def next__RopeIter(space, w_ropeiter): if w_ropeiter.node is None: raise OperationError(space.w_StopIteration, space.w_None) try: char = w_ropeiter.item_iter.nextchar() w_item = wrapchar(space, char) except StopIteration: w_ropeiter.node = None w_ropeiter.char_iter = None raise OperationError(space.w_StopIteration, space.w_None) w_ropeiter.index += 1 return w_item