当前位置: 首页>>代码示例>>Python>>正文


Python Unpacker.unpack方法代码示例

本文整理汇总了Python中msgpack.Unpacker.unpack方法的典型用法代码示例。如果您正苦于以下问题:Python Unpacker.unpack方法的具体用法?Python Unpacker.unpack怎么用?Python Unpacker.unpack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在msgpack.Unpacker的用法示例。


在下文中一共展示了Unpacker.unpack方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_foobar

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import unpack [as 别名]
def test_foobar():
    unpacker = Unpacker(read_size=3)
    unpacker.feed(b'foobar')
    assert unpacker.unpack() == ord(b'f')
    assert unpacker.unpack() == ord(b'o')
    assert unpacker.unpack() == ord(b'o')
    assert unpacker.unpack() == ord(b'b')
    assert unpacker.unpack() == ord(b'a')
    assert unpacker.unpack() == ord(b'r')
    try:
        o = unpacker.unpack()
        print(("Oops!", o))
        assert 0
    except StopIteration:
        assert 1
    else:
        assert 0
    unpacker.feed(b'foo')
    unpacker.feed(b'bar')

    k = 0
    for o, e in zip(unpacker, b'foobarbaz'):
        assert o == e
        k += 1
    assert k == len(b'foobar')
开发者ID:Keith-Redding,项目名称:msgpack,代码行数:27,代码来源:test_sequnpack.py

示例2: test_foobar

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import unpack [as 别名]
def test_foobar():
    unpacker = Unpacker(read_size=3)
    unpacker.feed('foobar')
    assert_equal(unpacker.unpack(), ord('f'))
    assert_equal(unpacker.unpack(), ord('o'))
    assert_equal(unpacker.unpack(), ord('o'))
    assert_equal(unpacker.unpack(), ord('b'))
    assert_equal(unpacker.unpack(), ord('a'))
    assert_equal(unpacker.unpack(), ord('r'))
    try:
        o = unpacker.unpack()
        print "Oops!", o
        assert 0
    except StopIteration:
        assert 1
    else:
        assert 0
    unpacker.feed('foo')
    unpacker.feed('bar')

    k = 0
    for o, e in zip(unpacker, 'foobarbaz'):
        assert o == ord(e)
        k += 1
    assert k == len('foobar')
开发者ID:keisukefukuda,项目名称:msgpack-python-pure,代码行数:27,代码来源:test_sequnpack.py

示例3: test_foobar

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import unpack [as 别名]
def test_foobar():
    unpacker = Unpacker(read_size=3)
    unpacker.feed("foobar")
    assert unpacker.unpack() == ord(b"f")
    assert unpacker.unpack() == ord(b"o")
    assert unpacker.unpack() == ord(b"o")
    assert unpacker.unpack() == ord(b"b")
    assert unpacker.unpack() == ord(b"a")
    assert unpacker.unpack() == ord(b"r")
    try:
        o = unpacker.unpack()
        print "Oops!", o
        assert 0
    except StopIteration:
        assert 1
    else:
        assert 0
    unpacker.feed(b"foo")
    unpacker.feed(b"bar")

    k = 0
    for o, e in zip(unpacker, b"foobarbaz"):
        assert o == ord(e)
        k += 1
    assert k == len(b"foobar")
开发者ID:TSnake41,项目名称:msgpack,代码行数:27,代码来源:test_sequnpack.py

示例4: test_auto_max_array_len

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import unpack [as 别名]
def test_auto_max_array_len():
    packed = b'\xde\x00\x06zz'
    with pytest.raises(UnpackValueError):
        unpackb(packed, raw=False)

    unpacker = Unpacker(max_buffer_size=5, raw=False)
    unpacker.feed(packed)
    with pytest.raises(UnpackValueError):
        unpacker.unpack()
开发者ID:msgpack,项目名称:msgpack-python,代码行数:11,代码来源:test_limits.py

示例5: test_unpack_array_header_from_file

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import unpack [as 别名]
def test_unpack_array_header_from_file():
    f = BytesIO(packb([1,2,3,4]))
    unpacker = Unpacker(f)
    assert unpacker.read_array_header() == 4
    assert unpacker.unpack() == 1
    assert unpacker.unpack() == 2
    assert unpacker.unpack() == 3
    assert unpacker.unpack() == 4
    with raises(OutOfData):
        unpacker.unpack()
开发者ID:Crazy4Tech,项目名称:msgpack-python,代码行数:12,代码来源:test_unpack.py

示例6: test_auto_max_map_len

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import unpack [as 别名]
def test_auto_max_map_len():
    # len(packed) == 6 -> max_map_len == 3
    packed = b'\xde\x00\x04zzz'
    with pytest.raises(UnpackValueError):
        unpackb(packed, raw=False)

    unpacker = Unpacker(max_buffer_size=6, raw=False)
    unpacker.feed(packed)
    with pytest.raises(UnpackValueError):
        unpacker.unpack()
开发者ID:msgpack,项目名称:msgpack-python,代码行数:12,代码来源:test_limits.py

示例7: test_read_map_header

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import unpack [as 别名]
def test_read_map_header():
    unpacker = Unpacker()
    unpacker.feed(packb({"a": "A"}))
    assert unpacker.read_map_header() == 1
    assert unpacker.unpack() == b"a"
    assert unpacker.unpack() == b"A"
    try:
        unpacker.unpack()
        assert 0, "should raise exception"
    except StopIteration:
        assert 1, "okay"
开发者ID:seliopou,项目名称:msgpack-python,代码行数:13,代码来源:test_read_size.py

示例8: test_foobar_skip

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import unpack [as 别名]
def test_foobar_skip():
    unpacker = Unpacker(read_size=3, use_list=1)
    unpacker.feed(b"foobar")
    assert unpacker.unpack() == ord(b"f")
    unpacker.skip()
    assert unpacker.unpack() == ord(b"o")
    unpacker.skip()
    assert unpacker.unpack() == ord(b"a")
    unpacker.skip()
    with raises(OutOfData):
        unpacker.unpack()
开发者ID:Crazy4Tech,项目名称:msgpack-python,代码行数:13,代码来源:test_sequnpack.py

示例9: test_read_map_header

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import unpack [as 别名]
def test_read_map_header():
    unpacker = Unpacker()
    unpacker.feed(packb({'a': 'A'}))
    assert unpacker.read_map_header() == 1
    assert unpacker.unpack() == B'a'
    assert unpacker.unpack() == B'A'
    try:
        unpacker.unpack()
        assert 0, 'should raise exception'
    except OutOfData:
        assert 1, 'okay'
开发者ID:Crazy4Tech,项目名称:msgpack-python,代码行数:13,代码来源:test_read_size.py

示例10: test_max_str_len

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import unpack [as 别名]
def test_max_str_len():
    d = 'x' * 3
    packed = packb(d)

    unpacker = Unpacker(max_str_len=3, raw=False)
    unpacker.feed(packed)
    assert unpacker.unpack() == d

    unpacker = Unpacker(max_str_len=2, raw=False)
    with pytest.raises(UnpackValueError):
        unpacker.feed(packed)
        unpacker.unpack()
开发者ID:msgpack,项目名称:msgpack-python,代码行数:14,代码来源:test_limits.py

示例11: test_read_array_header

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import unpack [as 别名]
def test_read_array_header():
    unpacker = Unpacker()
    unpacker.feed(packb(['a', 'b', 'c']))
    assert unpacker.read_array_header() == 3
    assert unpacker.unpack() == b'a'
    assert unpacker.unpack() == b'b'
    assert unpacker.unpack() == b'c'
    try:
        unpacker.unpack()
        assert 0, 'should raise exception'
    except OutOfData:
        assert 1, 'okay'
开发者ID:Crazy4Tech,项目名称:msgpack-python,代码行数:14,代码来源:test_read_size.py

示例12: test_max_ext_len

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import unpack [as 别名]
def test_max_ext_len():
    d = ExtType(42, b"abc")
    packed = packb(d)

    unpacker = Unpacker(max_ext_len=3)
    unpacker.feed(packed)
    assert unpacker.unpack() == d

    unpacker = Unpacker(max_ext_len=2)
    with pytest.raises(ValueError):
        unpacker.feed(packed)
        unpacker.unpack()
开发者ID:RobertSzefler,项目名称:msgpack-python,代码行数:14,代码来源:test_limits.py

示例13: test_max_map_len

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import unpack [as 别名]
def test_max_map_len():
    d = {1: 2, 3: 4, 5: 6}
    packed = packb(d)

    unpacker = Unpacker(max_map_len=3)
    unpacker.feed(packed)
    assert unpacker.unpack() == d

    unpacker = Unpacker(max_map_len=2)
    with pytest.raises(ValueError):
        unpacker.feed(packed)
        unpacker.unpack()
开发者ID:RobertSzefler,项目名称:msgpack-python,代码行数:14,代码来源:test_limits.py

示例14: test_max_array_len

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import unpack [as 别名]
def test_max_array_len():
    d = [1,2,3]
    packed = packb(d)

    unpacker = Unpacker(max_array_len=3)
    unpacker.feed(packed)
    assert unpacker.unpack() == d

    unpacker = Unpacker(max_array_len=2)
    with pytest.raises(ValueError):
        unpacker.feed(packed)
        unpacker.unpack()
开发者ID:RobertSzefler,项目名称:msgpack-python,代码行数:14,代码来源:test_limits.py

示例15: test_max_bin_len

# 需要导入模块: from msgpack import Unpacker [as 别名]
# 或者: from msgpack.Unpacker import unpack [as 别名]
def test_max_bin_len():
    d = b'x' * 3
    packed = packb(d, use_bin_type=True)

    unpacker = Unpacker(max_bin_len=3)
    unpacker.feed(packed)
    assert unpacker.unpack() == d

    unpacker = Unpacker(max_bin_len=2)
    with pytest.raises(ValueError):
        unpacker.feed(packed)
        unpacker.unpack()
开发者ID:RobertSzefler,项目名称:msgpack-python,代码行数:14,代码来源:test_limits.py


注:本文中的msgpack.Unpacker.unpack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。