Python zmq.utils() Examples

The following are 8 code examples of zmq.utils(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module zmq , or try the search function .
Example #1
Source File: socket.py    From vnpy_crypto with MIT License 6 votes vote down vote up
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) 
Example #2
Source File: socket.py    From vnpy_crypto with MIT License 6 votes vote down vote up
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)) 
Example #3
Source File: socket.py    From vnpy_crypto with MIT License 5 votes vote down vote up
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
    #------------------------------------------------------------------------- 
Example #4
Source File: test_imports.py    From vnpy_crypto with MIT License 5 votes vote down vote up
def test_utils(self):
        """test util imports"""
        import zmq.utils
        from zmq.utils import strtypes
        from zmq.utils import jsonapi 
Example #5
Source File: zmqrelated.py    From Computable with MIT License 5 votes vote down vote up
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 
Example #6
Source File: socket.py    From pySINDy with MIT License 5 votes vote down vote up
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
    #------------------------------------------------------------------------- 
Example #7
Source File: test_imports.py    From pySINDy with MIT License 5 votes vote down vote up
def test_utils(self):
        """test util imports"""
        import zmq.utils
        from zmq.utils import strtypes
        from zmq.utils import jsonapi 
Example #8
Source File: socket.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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
    #-------------------------------------------------------------------------