def repr__Rope(space, w_str): node = w_str._node length = node.length() i = 0 buf = [' '] * (length * 4 + 2) # safely overallocate quote = "'" if (rope.find_int(node, ord(quote)) != -1 and rope.find_int(node, ord('"')) == -1): quote = '"' buf[0] = quote iter = rope.ItemIterator(node) while 1: try: c = iter.nextchar() i += 1 except StopIteration: break bs_char = None # character quoted by backspace if c == '\\' or c == quote: bs_char = c elif c == '\t': bs_char = 't' elif c == '\r': bs_char = 'r' elif c == '\n': bs_char = 'n' elif not '\x20' <= c < '\x7f': n = ord(c) buf[i] = '\\' i += 1 buf[i] = 'x' i += 1 buf[i] = "0123456789abcdef"[n >> 4] i += 1 buf[i] = "0123456789abcdef"[n & 0xF] else: buf[i] = c if bs_char is not None: buf[i] = '\\' i += 1 buf[i] = bs_char i += 1 buf[i] = quote return W_RopeObject(rope.rope_from_charlist(buf[:i + 1]))
def repr__Rope(space, w_str): node = w_str._node length = node.length() i = 0 buf = [" "] * (length * 4 + 2) # safely overallocate quote = "'" if rope.find_int(node, ord(quote)) != -1 and rope.find_int(node, ord('"')) == -1: quote = '"' buf[0] = quote iter = rope.ItemIterator(node) while 1: try: c = iter.nextchar() i += 1 except StopIteration: break bs_char = None # character quoted by backspace if c == "\\" or c == quote: bs_char = c elif c == "\t": bs_char = "t" elif c == "\r": bs_char = "r" elif c == "\n": bs_char = "n" elif not "\x20" <= c < "\x7f": n = ord(c) buf[i] = "\\" i += 1 buf[i] = "x" i += 1 buf[i] = "0123456789abcdef"[n >> 4] i += 1 buf[i] = "0123456789abcdef"[n & 0xF] else: buf[i] = c if bs_char is not None: buf[i] = "\\" i += 1 buf[i] = bs_char i += 1 buf[i] = quote return W_RopeObject(rope.rope_from_charlist(buf[: i + 1]))
def repr__Rope(space, w_str): node = w_str._node length = node.length() i = 0 buf = [' '] * (length * 4 + 2) # safely overallocate quote = "'" if (rope.find_int(node, ord(quote)) != -1 and rope.find_int(node, ord('"')) == -1): quote = '"' buf[0] = quote iter = rope.ItemIterator(node) while 1: try: c = iter.nextchar() i += 1 except StopIteration: break bs_char = None # character quoted by backspace if c == '\\' or c == quote: bs_char = c elif c == '\t': bs_char = 't' elif c == '\r': bs_char = 'r' elif c == '\n': bs_char = 'n' elif not '\x20' <= c < '\x7f': n = ord(c) buf[i] = '\\' i += 1 buf[i] = 'x' i += 1 buf[i] = "0123456789abcdef"[n>>4] i += 1 buf[i] = "0123456789abcdef"[n&0xF] else: buf[i] = c if bs_char is not None: buf[i] = '\\' i += 1 buf[i] = bs_char i += 1 buf[i] = quote return W_RopeObject(rope.rope_from_charlist(buf[:i+1]))