本文整理汇总了Python中zmq.utils方法的典型用法代码示例。如果您正苦于以下问题:Python zmq.utils方法的具体用法?Python zmq.utils怎么用?Python zmq.utils使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类zmq
的用法示例。
在下文中一共展示了zmq.utils方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_json
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import utils [as 别名]
def send_json(self, obj, flags=0, **kwargs):
"""Send a Python object as a message using json to serialize.
Keyword arguments are passed on to json.dumps
Parameters
----------
obj : Python object
The Python object to send
flags : int
Any valid flags for :func:`Socket.send`
"""
from zmq.utils import jsonapi
send_kwargs = {}
for key in ('routing_id', 'group'):
if key in kwargs:
send_kwargs[key] = kwargs.pop(key)
msg = jsonapi.dumps(obj, **kwargs)
return self.send(msg, flags=flags, **send_kwargs)
示例2: recv_json
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import utils [as 别名]
def recv_json(self, flags=0, **kwargs):
"""Receive a Python object as a message using json to serialize.
Keyword arguments are passed on to json.loads
Parameters
----------
flags : int
Any valid flags for :func:`Socket.recv`.
Returns
-------
obj : Python object
The Python object that arrives as a message.
Raises
------
ZMQError
for any of the reasons :func:`~Socket.recv` might fail
"""
from zmq.utils import jsonapi
msg = self.recv(flags)
return self._deserialize(msg, lambda buf: jsonapi.loads(buf, **kwargs))
示例3: shadow
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import utils [as 别名]
def shadow(cls, address):
"""Shadow an existing libzmq socket
address is the integer address of the libzmq socket
or an FFI pointer to it.
.. versionadded:: 14.1
"""
from zmq.utils.interop import cast_int_addr
address = cast_int_addr(address)
return cls(shadow=address)
#-------------------------------------------------------------------------
# Deprecated aliases
#-------------------------------------------------------------------------
示例4: test_utils
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import utils [as 别名]
def test_utils(self):
"""test util imports"""
import zmq.utils
from zmq.utils import strtypes
from zmq.utils import jsonapi
示例5: patch_pyzmq
# 需要导入模块: import zmq [as 别名]
# 或者: from zmq import utils [as 别名]
def patch_pyzmq():
"""backport a few patches from newer pyzmq
These can be removed as we bump our minimum pyzmq version
"""
import zmq
# fallback on stdlib json if jsonlib is selected, because jsonlib breaks things.
# jsonlib support is removed from pyzmq >= 2.2.0
from zmq.utils import jsonapi
if jsonapi.jsonmod.__name__ == 'jsonlib':
import json
jsonapi.jsonmod = json