示例#1
0
def decode_string(space, w_str, encoding, errors):
    from pypy.objspace.std.unicodetype import decode_object
    if errors is None or errors == "strict":
        node = w_str._node
        if encoding == 'ascii':
            result = rope.str_decode_ascii(node)
            if result is not None:
                return W_RopeUnicodeObject(result)
        elif encoding == 'latin-1':
            assert node.is_bytestring()
            return W_RopeUnicodeObject(node)
        elif encoding == "utf-8":
            result = rope.str_decode_utf8(node)
            if result is not None:
                return W_RopeUnicodeObject(result)
    w_result = decode_object(space, w_str, encoding, errors)
    return w_result
示例#2
0
def decode_string(space, w_str, encoding, errors):
    from pypy.objspace.std.unicodetype import decode_object
    if errors is None or errors == "strict":
        node = w_str._node
        if encoding == 'ascii':
            result = rope.str_decode_ascii(node)
            if result is not None:
                return W_RopeUnicodeObject(result)
        elif encoding == 'latin-1':
            assert node.is_bytestring()
            return W_RopeUnicodeObject(node)
        elif encoding == "utf-8":
            result = rope.str_decode_utf8(node)
            if result is not None:
                return W_RopeUnicodeObject(result)
    w_result = decode_object(space, w_str, encoding, errors)
    return w_result