• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python msgpack.packs函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中msgpack.packs函数的典型用法代码示例。如果您正苦于以下问题:Python packs函数的具体用法?Python packs怎么用?Python packs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: testPackUTF32

def testPackUTF32():
    test_data = [
        "", "abcd", ("defgh",), "Русский текст",
        ]
    for td in test_data:
        print(packs(td, encoding='utf-32'))
        re = unpacks(packs(td, encoding='utf-32'), encoding='utf-32')
        assert_equal(re, td)
开发者ID:Matzo,项目名称:msgpack,代码行数:8,代码来源:test_pack.py


示例2: testPackUnicode

def testPackUnicode():
    test_data = [
        u"", u"abcd", (u"defgh",), u"Русский текст",
        ]
    for td in test_data:
        re = unpacks(packs(td, encoding='utf-8'), encoding='utf-8')
        assert_equal(re, td)
开发者ID:Matzo,项目名称:msgpack,代码行数:7,代码来源:test_pack.py


示例3: _check

def _check(obj):
    # NOTE:
    # msgpack.packs(obj) nad msgpack_pure.packs(obj) are not necessarily
    # match because there are some possible variations which type to use
    # for integer values (i.e. uint8/int16 for 0xFF).
    obj = _list_to_tuple(obj)
    
    assert msgpack_pure.unpacks(msgpack.packs(obj)) == obj
    assert msgpack.unpacks(msgpack_pure.packs(obj)) == obj
    assert msgpack_pure.unpacks(msgpack_pure.packs(obj)) == obj
开发者ID:keisukefukuda,项目名称:msgpack-python-pure,代码行数:10,代码来源:test_main.py


示例4: testPackUnicode

def testPackUnicode():
    test_data = [
        "", "abcd", ("defgh",), "Русский текст",
        ]
    for td in test_data:
        re = unpacks(packs(td, encoding='utf-8'), encoding='utf-8')
        assert_equal(re, td)
        packer = Packer(encoding='utf-8')
        data = packer.pack(td)
        re = Unpacker(BytesIO(data), encoding='utf-8').unpack()
        assert_equal(re, td)
开发者ID:geoffsalmon,项目名称:msgpack-python,代码行数:11,代码来源:test_pack.py


示例5: handle

    def handle(self):
        unpacker = Unpacker()

        while 1:
            data = self.request.recv(4096)
            if len(data) == 0:
                break
            unpacker.feed(data)
            for msg in unpacker:
                print msg
                assert len(msg) == 4
                assert msg[0] == 0
                assert msg[2] == "echo"
                sdata = packs((1, msg[1], None, msg[-1]))
                self.request.sendall(sdata)
开发者ID:methane,项目名称:msgpack-rpc,代码行数:15,代码来源:echoserver.py


示例6: run

    def run(self):
        while True:
            # grab the next message
            message = self.queue.get(block=True)

            # we have a message to send, the heart beat
            # can take a break
            self.lastSentData = time.time()

            # msgpack it
            message = packs(message)

            # send the message
            success = self.transport.send(message)

            # tell the queue we are done
            self.queue.task_done()

            if (success):
                self.log("Message sent")
                self.dump(unpacks(message, use_list=True))
            else:
                self.error("Sending metrics to Graphdat failed")
开发者ID:alphashack,项目名称:graphdat-sdk-python,代码行数:23,代码来源:agent.py


示例7: testStrictUnicodeUnpack

def testStrictUnicodeUnpack():
    unpacks(packs('abc\xeddef'), encoding='utf-8')
开发者ID:Matzo,项目名称:msgpack,代码行数:2,代码来源:test_pack.py


示例8: check

def check(length, obj):
    v = packs(obj)
    assert_equal(len(v), length, "%r length should be %r but get %r" % (obj, length, len(v)))
    assert_equal(unpacks(v), obj)
开发者ID:Keith-Redding,项目名称:msgpack,代码行数:4,代码来源:test_case.py


示例9: test_bad_hook

def test_bad_hook():
    packed = packs([3, 1 + 2j], default=lambda o: o)
    unpacked = unpacks(packed)
开发者ID:TSnake41,项目名称:msgpack,代码行数:3,代码来源:test_obj.py


示例10: test_encode_hook

def test_encode_hook():
    packed = packs([3, 1 + 2j], default=_encode_complex)
    unpacked = unpacks(packed)
    eq_(unpacked[1], {"__complex__": True, "real": 1, "imag": 2})
开发者ID:TSnake41,项目名称:msgpack,代码行数:4,代码来源:test_obj.py


示例11: test_decode_hook

def test_decode_hook():
    packed = packs([3, {b'__complex__': True, b'real': 1, b'imag': 2}])
    unpacked = unpacks(packed, object_hook=_decode_complex)
    eq_(unpacked[1], 1+2j)
开发者ID:Matzo,项目名称:msgpack,代码行数:4,代码来源:test_obj.py


示例12: testNoEncoding

def testNoEncoding():
    packs(u"abc", encoding=None)
开发者ID:Matzo,项目名称:msgpack,代码行数:2,代码来源:test_pack.py


示例13: _send_response

 def _send_response(self, msgid, error, result):
     print "Sending response: %r", ((msgid, error, result))
     msg = packs((1, msgid, error, result))
     self.request.sendall(msg)
开发者ID:methane,项目名称:msgpack-rpc,代码行数:4,代码来源:__init__.py


示例14: test_array_hook

def test_array_hook():
	packed = packs([1,2,3])
	cup = ArrayStrUnpacker()
	cup.feed(packed)
	unpacked = cup.unpack()
	eq_(unpacked, b'123')
开发者ID:rep,项目名称:msgpack,代码行数:6,代码来源:test_obj.py


示例15: test_decode_hook

def test_decode_hook():
	cup = ComplexUnpacker()
	packed = packs([3, {b'__complex__': True, b'real': 1, b'imag': 2}])
	cup.feed(packed)
	unpacked = cup.unpack()
	eq_(unpacked[1], 1+2j)
开发者ID:rep,项目名称:msgpack,代码行数:6,代码来源:test_obj.py


示例16: _send

 def _send(self, msg, name, level=10):
     msg = {'msg': msg, 'name': name, 'id': 1, 'path': self.path,
         'time': time.time(), 'level': level}
     txtmsg = msgpack.packs(msg)
     self.logd.sendto(txtmsg, (self.host, self.port))
开发者ID:hiidef,项目名称:logd,代码行数:5,代码来源:log.py


示例17: testStrictUnicodePack

def testStrictUnicodePack():
    packs(u"abc\xeddef", encoding='ascii', unicode_errors='strict')
开发者ID:Matzo,项目名称:msgpack,代码行数:2,代码来源:test_pack.py


示例18: testIgnoreErrorsPack

def testIgnoreErrorsPack():
    re = unpacks(
            packs(u"abcФФФdef", encoding='ascii', unicode_errors='ignore'),
            encoding='utf-8')
    assert_equal(re, u"abcdef")
开发者ID:Matzo,项目名称:msgpack,代码行数:5,代码来源:test_pack.py


示例19: sendmsg

def sendmsg(sock, to):
    id = uuid4().hex
    msg = {"id": id, "msg": "sending %s" % id}
    msgb = msgpack.packs(msg)
    return sock.sendto(msgb, to)
开发者ID:hiidef,项目名称:logd,代码行数:5,代码来源:hammer.py


示例20: testDecodeBinary

def testDecodeBinary():
    re = unpacks(packs(u"abc"), encoding=None)
    assert_equal(re, "abc")
开发者ID:Matzo,项目名称:msgpack,代码行数:3,代码来源:test_pack.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python msgpack.unpack函数代码示例发布时间:2022-05-27
下一篇:
Python msgpack.packb函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap