當前位置: 首頁>>代碼示例>>Python>>正文


Python Unpacker.unpack方法代碼示例

本文整理匯總了Python中pandas.msgpack.Unpacker.unpack方法的典型用法代碼示例。如果您正苦於以下問題:Python Unpacker.unpack方法的具體用法?Python Unpacker.unpack怎麽用?Python Unpacker.unpack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas.msgpack.Unpacker的用法示例。


在下文中一共展示了Unpacker.unpack方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_unpack_array_header_from_file

# 需要導入模塊: from pandas.msgpack import Unpacker [as 別名]
# 或者: from pandas.msgpack.Unpacker import unpack [as 別名]
 def test_unpack_array_header_from_file(self):
     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
     self.assertRaises(OutOfData, unpacker.unpack)
開發者ID:BrenBarn,項目名稱:pandas,代碼行數:11,代碼來源:test_unpack.py

示例2: test_foobar_skip

# 需要導入模塊: from pandas.msgpack import Unpacker [as 別名]
# 或者: from pandas.msgpack.Unpacker import unpack [as 別名]
 def test_foobar_skip(self):
     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()
     self.assertRaises(OutOfData, unpacker.unpack)
開發者ID:8ballbb,項目名稱:ProjectRothar,代碼行數:12,代碼來源:test_sequnpack.py

示例3: test_read_map_header

# 需要導入模塊: from pandas.msgpack import Unpacker [as 別名]
# 或者: from pandas.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:5i7788,項目名稱:pandas,代碼行數:13,代碼來源:test_read_size.py

示例4: test_read_array_header

# 需要導入模塊: from pandas.msgpack import Unpacker [as 別名]
# 或者: from pandas.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:5i7788,項目名稱:pandas,代碼行數:14,代碼來源:test_read_size.py

示例5: test_readbytes

# 需要導入模塊: from pandas.msgpack import Unpacker [as 別名]
# 或者: from pandas.msgpack.Unpacker import unpack [as 別名]
    def test_readbytes(self):
        unpacker = Unpacker(read_size=3)
        unpacker.feed(b"foobar")
        assert unpacker.unpack() == ord(b"f")
        assert unpacker.read_bytes(3) == b"oob"
        assert unpacker.unpack() == ord(b"a")
        assert unpacker.unpack() == ord(b"r")

        # Test buffer refill
        unpacker = Unpacker(compat.BytesIO(b"foobar"), read_size=3)
        assert unpacker.unpack() == ord(b"f")
        assert unpacker.read_bytes(3) == b"oob"
        assert unpacker.unpack() == ord(b"a")
        assert unpacker.unpack() == ord(b"r")
開發者ID:B-Rich,項目名稱:pandas,代碼行數:16,代碼來源:test_sequnpack.py

示例6: test_write_bytes_multi_buffer

# 需要導入模塊: from pandas.msgpack import Unpacker [as 別名]
# 或者: from pandas.msgpack.Unpacker import unpack [as 別名]
def test_write_bytes_multi_buffer():
    long_val = (5) * 100
    expected = packb(long_val)
    unpacker = Unpacker(io.BytesIO(expected), read_size=3, max_buffer_size=3)

    f = io.BytesIO()
    unpacked = unpacker.unpack(f.write)
    assert unpacked == long_val
    assert f.getvalue() == expected
開發者ID:8ballbb,項目名稱:ProjectRothar,代碼行數:11,代碼來源:test_unpack_raw.py

示例7: test_foobar

# 需要導入模塊: from pandas.msgpack import Unpacker [as 別名]
# 或者: from pandas.msgpack.Unpacker import unpack [as 別名]
    def test_foobar(self):
        unpacker = Unpacker(read_size=3, use_list=1)
        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')
        self.assertRaises(OutOfData, unpacker.unpack)

        unpacker.feed(b'foo')
        unpacker.feed(b'bar')

        k = 0
        for o, e in zip(unpacker, 'foobarbaz'):
            assert o == ord(e)
            k += 1
        assert k == len(b'foobar')
開發者ID:8ballbb,項目名稱:ProjectRothar,代碼行數:21,代碼來源:test_sequnpack.py

示例8: test_max_ext_len

# 需要導入模塊: from pandas.msgpack import Unpacker [as 別名]
# 或者: from pandas.msgpack.Unpacker import unpack [as 別名]
    def test_max_ext_len(self):
        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)
        unpacker.feed(packed)
        self.assertRaises(ValueError, unpacker.unpack)
開發者ID:cgrin,項目名稱:pandas,代碼行數:13,代碼來源:test_limits.py

示例9: test_max_array_len

# 需要導入模塊: from pandas.msgpack import Unpacker [as 別名]
# 或者: from pandas.msgpack.Unpacker import unpack [as 別名]
    def test_max_array_len(self):
        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)
        unpacker.feed(packed)
        self.assertRaises(ValueError, unpacker.unpack)
開發者ID:cgrin,項目名稱:pandas,代碼行數:13,代碼來源:test_limits.py

示例10: test_max_map_len

# 需要導入模塊: from pandas.msgpack import Unpacker [as 別名]
# 或者: from pandas.msgpack.Unpacker import unpack [as 別名]
    def test_max_map_len(self):
        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)
        unpacker.feed(packed)
        self.assertRaises(ValueError, unpacker.unpack)
開發者ID:cgrin,項目名稱:pandas,代碼行數:13,代碼來源:test_limits.py

示例11: test_max_str_len

# 需要導入模塊: from pandas.msgpack import Unpacker [as 別名]
# 或者: from pandas.msgpack.Unpacker import unpack [as 別名]
    def test_max_str_len(self):
        d = 'x' * 3
        packed = packb(d)

        unpacker = Unpacker(max_str_len=3, encoding='utf-8')
        unpacker.feed(packed)
        assert unpacker.unpack() == d

        unpacker = Unpacker(max_str_len=2, encoding='utf-8')
        unpacker.feed(packed)
        self.assertRaises(ValueError, unpacker.unpack)
開發者ID:cgrin,項目名稱:pandas,代碼行數:13,代碼來源:test_limits.py

示例12: test_max_bin_len

# 需要導入模塊: from pandas.msgpack import Unpacker [as 別名]
# 或者: from pandas.msgpack.Unpacker import unpack [as 別名]
    def test_max_bin_len(self):
        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)
        unpacker.feed(packed)
        self.assertRaises(ValueError, unpacker.unpack)
開發者ID:cgrin,項目名稱:pandas,代碼行數:13,代碼來源:test_limits.py

示例13: test_write_bytes

# 需要導入模塊: from pandas.msgpack import Unpacker [as 別名]
# 或者: from pandas.msgpack.Unpacker import unpack [as 別名]
def test_write_bytes():
    unpacker = Unpacker()
    unpacker.feed(b'abc')
    f = io.BytesIO()
    assert unpacker.unpack(f.write) == ord('a')
    assert f.getvalue() == b'a'
    f = io.BytesIO()
    assert unpacker.skip(f.write) is None
    assert f.getvalue() == b'b'
    f = io.BytesIO()
    assert unpacker.skip() is None
    assert f.getvalue() == b''
開發者ID:8ballbb,項目名稱:ProjectRothar,代碼行數:14,代碼來源:test_unpack_raw.py

示例14: testArraySize

# 需要導入模塊: from pandas.msgpack import Unpacker [as 別名]
# 或者: from pandas.msgpack.Unpacker import unpack [as 別名]
    def testArraySize(self, sizes=[0, 5, 50, 1000]):
        bio = compat.BytesIO()
        packer = Packer()
        for size in sizes:
            bio.write(packer.pack_array_header(size))
            for i in range(size):
                bio.write(packer.pack(i))

        bio.seek(0)
        unpacker = Unpacker(bio, use_list=1)
        for size in sizes:
            assert unpacker.unpack() == list(range(size))
開發者ID:8ballbb,項目名稱:ProjectRothar,代碼行數:14,代碼來源:test_pack.py

示例15: testMapSize

# 需要導入模塊: from pandas.msgpack import Unpacker [as 別名]
# 或者: from pandas.msgpack.Unpacker import unpack [as 別名]
    def testMapSize(self, sizes=[0, 5, 50, 1000]):
        bio = compat.BytesIO()
        packer = Packer()
        for size in sizes:
            bio.write(packer.pack_map_header(size))
            for i in range(size):
                bio.write(packer.pack(i))  # key
                bio.write(packer.pack(i * 2))  # value

        bio.seek(0)
        unpacker = Unpacker(bio)
        for size in sizes:
            assert unpacker.unpack() == dict((i, i * 2) for i in range(size))
開發者ID:8ballbb,項目名稱:ProjectRothar,代碼行數:15,代碼來源:test_pack.py


注:本文中的pandas.msgpack.Unpacker.unpack方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。