def str_replace__Rope_Rope_Rope_ANY(space, w_self, w_sub, w_by, w_maxsplit=-1): node = w_self._node length = node.length() sub = w_sub._node by = w_by._node maxsplit = space.int_w(w_maxsplit) if maxsplit == 0: return w_self.create_if_subclassed() if not sub.length(): upper = node.length() if maxsplit > 0 and maxsplit < upper + 2: upper = maxsplit - 1 assert upper >= 0 substrings = [by] iter = rope.ItemIterator(node) for i in range(upper): substrings.append(iter.nextrope()) substrings.append(by) substrings.append(rope.getslice_one(node, upper, length)) try: return W_RopeObject(rope.rebalance(substrings)) except OverflowError: raise OperationError(space.w_OverflowError, space.wrap("string too long")) substrings = rope.split(node, sub, maxsplit) if not substrings: return w_self.create_if_subclassed() try: return W_RopeObject(rope.join(by, substrings)) except OverflowError: raise OperationError(space.w_OverflowError, space.wrap("string too long"))
def str_split__Rope_Rope_ANY(space, w_self, w_by, w_maxsplit=-1): maxsplit = space.int_w(w_maxsplit) selfnode = w_self._node bynode = w_by._node bylen = bynode.length() if bylen == 0: raise OperationError(space.w_ValueError, space.wrap("empty separator")) res_w = [W_RopeObject(node) for node in rope.split(selfnode, bynode, maxsplit)] return space.newlist(res_w)
def unicode_split__RopeUnicode_RopeUnicode_ANY(space, w_self, w_delim, w_maxsplit): maxsplit = space.int_w(w_maxsplit) start = 0 selfnode = w_self._node delimnode = w_delim._node delimlen = delimnode.length() if delimlen == 0: raise OperationError(space.w_ValueError, space.wrap("empty separator")) res_w = [W_RopeUnicodeObject(node) for node in rope.split(selfnode, delimnode, maxsplit)] return space.newlist(res_w)
def unicode_expandtabs__RopeUnicode_ANY(space, w_self, w_tabsize): from pypy.objspace.std.ropeobject import _tabindent self = w_self._node tabsize = space.int_w(w_tabsize) splitted = rope.split(self, rope.LiteralStringNode.PREBUILT[ord('\t')]) last = splitted[0] expanded = [last] for i in range(1, len(splitted)): expanded.append(rope.multiply(rope.LiteralStringNode.PREBUILT[ord(" ")], _tabindent(last, tabsize))) last = splitted[i] expanded.append(last) return W_RopeUnicodeObject(rope.rebalance(expanded))
def unicode_expandtabs__RopeUnicode_ANY(space, w_self, w_tabsize): from pypy.objspace.std.ropeobject import _tabindent self = w_self._node tabsize = space.int_w(w_tabsize) splitted = rope.split(self, rope.LiteralStringNode.PREBUILT[ord('\t')]) last = splitted[0] expanded = [last] for i in range(1, len(splitted)): expanded.append( rope.multiply(rope.LiteralStringNode.PREBUILT[ord(" ")], _tabindent(last, tabsize))) last = splitted[i] expanded.append(last) return W_RopeUnicodeObject(rope.rebalance(expanded))
def str_expandtabs__Rope_ANY(space, w_self, w_tabsize): node = w_self._node length = node.length() if length == 0: return W_RopeObject.EMPTY tabsize = space.int_w(w_tabsize) splitted = rope.split(node, rope.LiteralStringNode.PREBUILT[ord("\t")]) last = splitted[0] expanded = [last] for i in range(1, len(splitted)): expanded.append(rope.multiply(rope.LiteralStringNode.PREBUILT[ord(" ")], _tabindent(last, tabsize))) last = splitted[i] expanded.append(last) return W_RopeObject(rope.rebalance(expanded))
def unicode_expandtabs__RopeUnicode_ANY(space, w_self, w_tabsize): from pypy.objspace.std.ropeobject import _tabindent self = w_self._node tabsize = space.int_w(w_tabsize) splitted = rope.split(self, rope.LiteralStringNode.PREBUILT[ord("\t")]) last = splitted[0] expanded = [last] for i in range(1, len(splitted)): expanded.append(rope.multiply(rope.LiteralStringNode.PREBUILT[ord(" ")], _tabindent(last, tabsize))) last = splitted[i] expanded.append(last) try: return W_RopeUnicodeObject(rope.rebalance(expanded)) except OverflowError: raise OperationError(space.w_OverflowError, space.wrap("string too long"))
def unicode_expandtabs__RopeUnicode_ANY(space, w_self, w_tabsize): from pypy.objspace.std.ropeobject import _tabindent self = w_self._node tabsize = space.int_w(w_tabsize) splitted = rope.split(self, rope.LiteralStringNode.PREBUILT[ord('\t')]) last = splitted[0] expanded = [last] for i in range(1, len(splitted)): expanded.append(rope.multiply(rope.LiteralStringNode.PREBUILT[ord(" ")], _tabindent(last, tabsize))) last = splitted[i] expanded.append(last) try: return W_RopeUnicodeObject(rope.rebalance(expanded)) except OverflowError: raise OperationError(space.w_OverflowError, space.wrap("string too long"))
def unicode_replace__RopeUnicode_RopeUnicode_RopeUnicode_ANY( space, w_self, w_old, w_new, w_maxsplit): self = w_self._node old = w_old._node maxsplit = space.int_w(w_maxsplit) oldlength = old.length() if not oldlength: parts = _split_into_chars(self, maxsplit) return W_RopeUnicodeObject(rope.join(w_new._node, parts)) substrings = rope.split(self, old, maxsplit) if not substrings: return w_self.create_if_subclassed() try: return W_RopeUnicodeObject(rope.join(w_new._node, substrings)) except OverflowError: raise OperationError(space.w_OverflowError, space.wrap("string too long"))
def str_expandtabs__Rope_ANY(space, w_self, w_tabsize): node = w_self._node length = node.length() if length == 0: return W_RopeObject.EMPTY tabsize = space.int_w(w_tabsize) splitted = rope.split(node, rope.LiteralStringNode.PREBUILT[ord("\t")]) last = splitted[0] expanded = [last] for i in range(1, len(splitted)): expanded.append(rope.multiply(rope.LiteralStringNode.PREBUILT[ord(" ")], _tabindent(last, tabsize))) last = splitted[i] expanded.append(last) try: return W_RopeObject(rope.rebalance(expanded)) except OverflowError: raise OperationError(space.w_OverflowError, space.wrap("new string is too long"))
def str_expandtabs__Rope_ANY(space, w_self, w_tabsize): node = w_self._node length = node.length() if length == 0: return W_RopeObject.EMPTY tabsize = space.int_w(w_tabsize) splitted = rope.split(node, rope.LiteralStringNode.PREBUILT[ord("\t")]) last = splitted[0] expanded = [last] for i in range(1, len(splitted)): expanded.append(rope.multiply(rope.LiteralStringNode.PREBUILT[ord(" ")], _tabindent(last, tabsize))) last = splitted[i] expanded.append(last) try: return W_RopeObject(rope.rebalance(expanded)) except OverflowError: raise OperationError(space.w_OverflowError, space.wrap('new string is too long'))