def test_unpack_string():
    b, proto = gen_proto(b"\x0c\x68\x65\x6c\x6c\x6f"
                         b"\x20\x77\x6f\x72\x6c\x64\x21")
    assert u('hello world!') == proto.read_val(TType.STRING)

    b, proto = gen_proto(b'\x0c\xe4\xbd\xa0\xe5\xa5'
                         b'\xbd\xe4\xb8\x96\xe7\x95\x8c')
    assert u('你好世界') == proto.read_val(TType.STRING)
def test_unpack_container_bool():
    b, proto = gen_proto(b"\x31\x01\x02\x01")
    assert [True, False, True] == proto.read_val(TType.LIST, TType.BOOL)

    b, proto = gen_proto(b"\x01\x81\x01\x61\x01")
    assert {u("a"): True} == proto.read_val(TType.MAP,
                                            (TType.STRING, TType.BOOL))

    b, proto = gen_proto(b"\x01\x89\x01\x61\x21\x01\x02")
    assert {u("a"): [True, False]} == proto.read_val(
        TType.MAP, (TType.STRING, (TType.LIST, TType.BOOL)))

    b, proto = gen_proto(b"\x03\x81\x01\x61\x01\x01\x63\x01\x01\x62\x02")
    bool_hash = proto.read_val(TType.MAP, (TType.STRING, TType.BOOL))
    assert bool_hash['a'] is True
    assert bool_hash['b'] is False
    assert bool_hash['c'] is True
def test_write_string():
    b = TCyMemoryBuffer()
    proto.write_val(b, TType.STRING, "hello world!")
    b.flush()
    assert "00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64 21" == hexlify(b.getvalue())

    b = TCyMemoryBuffer()
    proto.write_val(b, TType.STRING, u("你好世界"))
    b.flush()
    assert "00 00 00 0c e4 bd a0 e5 a5 bd e4 b8 96 e7 95 8c" == hexlify(b.getvalue())
def test_pack_string():
    b = BytesIO()
    proto.write_val(b, TType.STRING, "hello world!")
    assert "00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64 21" == \
        hexlify(b.getvalue())

    b = BytesIO()
    proto.write_val(b, TType.STRING, u("你好世界"))
    assert "00 00 00 0c e4 bd a0 e5 a5 bd e4 b8 96 e7 95 8c" == \
        hexlify(b.getvalue())
示例#5
0
def test_pack_string():
    b = BytesIO()
    proto.write_val(b, TType.STRING, "hello world!")
    assert_equal("00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64 21",
                 hexlify(b.getvalue()))

    b = BytesIO()
    proto.write_val(b, TType.STRING, u("你好世界"))
    assert_equal("00 00 00 0c e4 bd a0 e5 a5 bd e4 b8 96 e7 95 8c",
                 hexlify(b.getvalue()))
示例#6
0
def test_write_string():
    b = TCyMemoryBuffer()
    proto.write_val(b, TType.STRING, "hello world!")
    b.flush()
    assert "00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64 21" == \
        hexlify(b.getvalue())

    b = TCyMemoryBuffer()
    proto.write_val(b, TType.STRING, u("你好世界"))
    b.flush()
    assert "00 00 00 0c e4 bd a0 e5 a5 bd e4 b8 96 e7 95 8c" == \
        hexlify(b.getvalue())
def test_pack_string():
    b = TMemoryBuffer()
    p = proto.TCyBinaryProtocol(b)
    p.write_val(TType.STRING, "hello world!")
    p.write_message_end()
    assert_equal("00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64 21",
                 hexlify(b.getvalue()))

    b = TMemoryBuffer()
    p = proto.TCyBinaryProtocol(b)
    p.write_val(TType.STRING, u("你好世界"))
    p.write_message_end()
    assert_equal("00 00 00 0c e4 bd a0 e5 a5 bd e4 b8 96 e7 95 8c",
                 hexlify(b.getvalue()))
def test_pack_string():
    b = TMemoryBuffer()
    p = proto.TCyBinaryProtocol(b)
    p.write_val(TType.STRING, "hello world!")
    p.write_message_end()
    assert "00 00 00 0c 68 65 6c 6c 6f 20 77 6f 72 6c 64 21" == \
        hexlify(b.getvalue())

    b = TMemoryBuffer()
    p = proto.TCyBinaryProtocol(b)
    p.write_val(TType.STRING, u("你好世界"))
    p.write_message_end()
    assert "00 00 00 0c e4 bd a0 e5 a5 bd e4 b8 96 e7 95 8c" == \
        hexlify(b.getvalue())
def test_unicode_string():
    class Foo(TPayload):
        thrift_spec = {
            1: (TType.STRING, "name")
        }
        default_spec = [("name", None)]

    trans = TMemoryBuffer()
    p = TJSONProtocol(trans)

    foo = Foo(name=u('pão de açúcar'))
    foo.write(p)

    foo2 = Foo()
    foo2.read(p)

    assert foo == foo2
示例#10
0
def test_unicode_string():
    class Foo(TPayload):
        thrift_spec = {
            1: (TType.STRING, "name", False)
        }
        default_spec = [("name", None)]

    trans = TMemoryBuffer()
    p = TJSONProtocol(trans)

    foo = Foo(name=u('pão de açúcar'))
    foo.write(p)

    foo2 = Foo()
    foo2.read(p)

    assert foo == foo2
示例#11
0
def test_read_binary():
    b = TCyMemoryBuffer(b"\x00\x00\x00\x0c"
                        b"\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xb8\x96\xe7\x95\x8c")
    assert u("你好世界").encode("utf-8") == proto.read_val(b,
                                                       TType.STRING,
                                                       decode_response=False)
示例#12
0
def test_read_string():
    b = TCyMemoryBuffer(b"\x00\x00\x00\x0c"
                        b"\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xb8\x96\xe7\x95\x8c")
    assert u("你好世界") == proto.read_val(b, TType.STRING)
def test_unpack_string():
    b = TMemoryBuffer(b'\x00\x00\x00\x0c'
                      b'\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xb8\x96\xe7\x95\x8c')
    p = proto.TCyBinaryProtocol(b)
    assert_equal(u("你好世界"), p.read_val(TType.STRING))
示例#14
0
def test_unpack_string():
    b = TMemoryBuffer(b'\x00\x00\x00\x0c'
                      b'\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xb8\x96\xe7\x95\x8c')
    p = proto.TCyBinaryProtocol(b)
    assert_equal(u("你好世界"), p.read_val(TType.STRING))
def test_unpack_string():
    b = BytesIO(b"\x00\x00\x00\x0c"
                b"\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xb8\x96\xe7\x95\x8c")
    assert u("你好世界") == proto.read_val(b, TType.STRING)
示例#16
0
def test_unpack_string():
    b = TMemoryBuffer(b"\x00\x00\x00\x0c"
                      b"\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xb8\x96\xe7\x95\x8c")
    p = proto.TCyBinaryProtocol(b)
    assert u("你好世界") == p.read_val(TType.STRING)
def test_unpack_string():
    b = BytesIO(b'\x00\x00\x00\x0c'
                b'\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xb8\x96\xe7\x95\x8c')
    assert_equal(u("你好世界"), proto.read_val(b, TType.STRING))
示例#18
0
def test_unpack_binary():
    bs = BytesIO(b"\x00\x00\x00\x0c"
                 b"\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xb8\x96\xe7\x95\x8c")
    assert u("你好世界").encode("utf-8") == proto.read_val(bs,
                                                       TType.STRING,
                                                       decode_response=False)
def test_unpack_binary():
    bs = BytesIO(b"\x00\x00\x00\x0c"
                 b"\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xb8\x96\xe7\x95\x8c")
    assert u("你好世界").encode("utf-8") == proto.read_val(
        bs, TType.STRING, decode_response=False)
示例#20
0
def test_read_binary():
    b = TCyMemoryBuffer(b"\x00\x00\x00\x0c" b"\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xb8\x96\xe7\x95\x8c")
    assert u("你好世界").encode("utf-8") == proto.read_val(b, TType.STRING, decode_response=False)
示例#21
0
def test_read_string():
    b = TMemoryBuffer(b"\x00\x00\x00\x0c"
                      b"\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xb8\x96\xe7\x95\x8c")
    b = TCyBufferedTransport(b)
    assert u("你好世界") == proto.read_val(b, TType.STRING)
def test_unpack_string():
    b = BytesIO(b"\x00\x00\x00\x0c"
                b"\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xb8\x96\xe7\x95\x8c")
    assert u("你好世界") == proto.read_val(b, TType.STRING)
示例#23
0
def test_unpack_string():
    b = BytesIO(b'\x00\x00\x00\x0c'
                b'\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xb8\x96\xe7\x95\x8c')
    assert_equal(u("你好世界"), proto.read_val(b, TType.STRING))
def test_unpack_binary():
    b, proto = gen_proto(b'\x0c\xe4\xbd\xa0\xe5\xa5'
                         b'\xbd\xe4\xb8\x96\xe7\x95\x8c')
    proto.decode_response = False

    assert u('你好世界').encode("utf-8") == proto.read_val(TType.STRING)