Python zmq.utils.jsonapi.dumps() Examples

The following are 30 code examples of zmq.utils.jsonapi.dumps(). 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.utils.jsonapi , or try the search function .
Example #1
Source File: socket.py    From Carnets with BSD 3-Clause "New" or "Revised" 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`
        """
        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: handlers.py    From Computable with MIT License 6 votes vote down vote up
def post(self, profile, action):
        cm = self.cluster_manager
        if action == 'start':
            n = self.get_argument('n', default=None)
            if not n:
                data = cm.start_cluster(profile)
            else:
                data = cm.start_cluster(profile, int(n))
        if action == 'stop':
            data = cm.stop_cluster(profile)
        self.finish(jsonapi.dumps(data))


#-----------------------------------------------------------------------------
# URL to handler mappings
#----------------------------------------------------------------------------- 
Example #3
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 #4
Source File: zmqhandlers.py    From Computable with MIT License 6 votes vote down vote up
def _reserialize_reply(self, msg_list):
        """Reserialize a reply message using JSON.

        This takes the msg list from the ZMQ socket, unserializes it using
        self.session and then serializes the result using JSON. This method
        should be used by self._on_zmq_reply to build messages that can
        be sent back to the browser.
        """
        idents, msg_list = self.session.feed_identities(msg_list)
        msg = self.session.unserialize(msg_list)
        try:
            msg['header'].pop('date')
        except KeyError:
            pass
        try:
            msg['parent_header'].pop('date')
        except KeyError:
            pass
        msg.pop('buffers')
        return jsonapi.dumps(msg, default=date_default) 
Example #5
Source File: __init__.py    From emnlp19-moverscore with MIT License 6 votes vote down vote up
def eval(self, pairs):
        """ Encode a list of strings to a list of vectors

        `texts` should be a list of strings, each of which represents a sentence.
        If `is_tokenized` is set to True, then `texts` should be list[list[str]],
        outer list represents sentence and inner list represent tokens in the sentence.
        Note that if `blocking` is set to False, then you need to fetch the result manually afterwards.

        .. highlight:: python
        .. code-block:: python

            with EvalClient() as bc:
                # evaluate pair of summary and references untokenized sentences
                bc.eval([['summary'], [ref]])
            :rtype: dictionary {}

        """
        
        req_id = self._send(jsonapi.dumps(pairs), len(pairs))
        
        r = self._recv_scores(req_id)
        
        return r.scores 
Example #6
Source File: socket.py    From pySINDy 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`
        """
        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 #7
Source File: socket.py    From Computable with MIT License 6 votes vote down vote up
def send_pyobj(self, obj, flags=0, protocol=-1):
        """send a Python object as a message using pickle to serialize

        Parameters
        ----------
        obj : Python object
            The Python object to send.
        flags : int
            Any valid send flag.
        protocol : int
            The pickle protocol number to use. Default of -1 will select
            the highest supported number. Use 0 for multiple platform
            support.
        """
        msg = pickle.dumps(obj, protocol)
        return self.send(msg, flags) 
Example #8
Source File: zmqstream.py    From pySINDy with MIT License 5 votes vote down vote up
def send_pyobj(self, obj, flags=0, protocol=-1, callback=None, **kwargs):
        """Send a Python object as a message using pickle to serialize.

        See zmq.socket.send_json for details.
        """
        msg = pickle.dumps(obj, protocol)
        return self.send(msg, flags, callback=callback, **kwargs) 
Example #9
Source File: handlers.py    From Computable with MIT License 5 votes vote down vote up
def post(self):
        nbm = self.notebook_manager
        body = self.request.body.strip()
        format = self.get_argument('format', default='json')
        name = self.get_argument('name', default=None)
        if body:
            notebook_id = nbm.save_new_notebook(body, name=name, format=format)
        else:
            notebook_id = nbm.new_notebook()
        self.set_header('Location', '{0}notebooks/{1}'.format(self.base_project_url, notebook_id))
        self.finish(jsonapi.dumps(notebook_id)) 
Example #10
Source File: handlers.py    From Computable with MIT License 5 votes vote down vote up
def get(self, notebook_id):
        """get lists checkpoints for a notebook"""
        nbm = self.notebook_manager
        checkpoints = nbm.list_checkpoints(notebook_id)
        data = jsonapi.dumps(checkpoints, default=date_default)
        self.finish(data) 
Example #11
Source File: handlers.py    From Computable with MIT License 5 votes vote down vote up
def post(self, notebook_id):
        """post creates a new checkpoint"""
        nbm = self.notebook_manager
        checkpoint = nbm.create_checkpoint(notebook_id)
        data = jsonapi.dumps(checkpoint, default=date_default)
        self.set_header('Location', '{0}notebooks/{1}/checkpoints/{2}'.format(
            self.base_project_url, notebook_id, checkpoint['checkpoint_id']
        ))
        
        self.finish(data) 
Example #12
Source File: thread.py    From pySINDy with MIT License 5 votes vote down vote up
def configure_plain(self, domain='*', passwords=None):
        self.pipe.send_multipart([b'PLAIN', b(domain, self.encoding), jsonapi.dumps(passwords or {})]) 
Example #13
Source File: socket.py    From pySINDy with MIT License 5 votes vote down vote up
def send_pyobj(self, obj, flags=0, protocol=DEFAULT_PROTOCOL, **kwargs):
        """Send a Python object as a message using pickle to serialize.

        Parameters
        ----------
        obj : Python object
            The Python object to send.
        flags : int
            Any valid flags for :func:`Socket.send`.
        protocol : int
            The pickle protocol number to use. The default is pickle.DEFAULT_PROTOCOL
            where defined, and pickle.HIGHEST_PROTOCOL elsewhere.
        """
        msg = pickle.dumps(obj, protocol)
        return self.send(msg, flags=flags, **kwargs) 
Example #14
Source File: zmqstream.py    From pySINDy with MIT License 5 votes vote down vote up
def send_json(self, obj, flags=0, callback=None, **kwargs):
        """Send json-serialized version of an object.
        See zmq.socket.send_json for details.
        """
        if jsonapi is None:
            raise ImportError('jsonlib{1,2}, json or simplejson library is required.')
        else:
            msg = jsonapi.dumps(obj)
            return self.send(msg, flags=flags, callback=callback, **kwargs) 
Example #15
Source File: handlers.py    From Computable with MIT License 5 votes vote down vote up
def post(self):
        km = self.kernel_manager
        nbm = self.notebook_manager
        notebook_id = self.get_argument('notebook', default=None)
        kernel_id = km.start_kernel(notebook_id, cwd=nbm.notebook_dir)
        data = {'ws_url':self.ws_url,'kernel_id':kernel_id}
        self.set_header('Location', '{0}kernels/{1}'.format(self.base_kernel_url, kernel_id))
        self.finish(jsonapi.dumps(data)) 
Example #16
Source File: __init__.py    From emnlp19-moverscore with MIT License 5 votes vote down vote up
def result(self):
        x = jsonapi.dumps(self.final_scores)
        return x 
Example #17
Source File: helper.py    From emnlp19-moverscore with MIT License 5 votes vote down vote up
def send_scores(src, dest, X, req_id=b'', flags=0, copy=True, track=False):
    """send a numpy array with metadata"""
    print(X)
    return src.send_multipart([dest, jsonapi.dumps(X), jsonapi.dumps(""), req_id], flags, copy=copy, track=track) 
Example #18
Source File: thread.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def configure_plain(self, domain='*', passwords=None):
        self.pipe.send_multipart([b'PLAIN', b(domain, self.encoding), jsonapi.dumps(passwords or {})]) 
Example #19
Source File: socket.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def send_pyobj(self, obj, flags=0, protocol=DEFAULT_PROTOCOL, **kwargs):
        """Send a Python object as a message using pickle to serialize.

        Parameters
        ----------
        obj : Python object
            The Python object to send.
        flags : int
            Any valid flags for :func:`Socket.send`.
        protocol : int
            The pickle protocol number to use. The default is pickle.DEFAULT_PROTOCOL
            where defined, and pickle.HIGHEST_PROTOCOL elsewhere.
        """
        msg = pickle.dumps(obj, protocol)
        return self.send(msg, flags=flags, **kwargs) 
Example #20
Source File: zmqstream.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def send_json(self, obj, flags=0, callback=None, **kwargs):
        """Send json-serialized version of an object.
        See zmq.socket.send_json for details.
        """
        if jsonapi is None:
            raise ImportError('jsonlib{1,2}, json or simplejson library is required.')
        else:
            msg = jsonapi.dumps(obj)
            return self.send(msg, flags=flags, callback=callback, **kwargs) 
Example #21
Source File: zmqstream.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def send_pyobj(self, obj, flags=0, protocol=-1, callback=None, **kwargs):
        """Send a Python object as a message using pickle to serialize.

        See zmq.socket.send_json for details.
        """
        msg = pickle.dumps(obj, protocol)
        return self.send(msg, flags, callback=callback, **kwargs) 
Example #22
Source File: adtran_zmq.py    From voltha with Apache License 2.0 5 votes vote down vote up
def configure_plain(self, domain='*', passwords=None):
        try:
            self.pipe.send([b'PLAIN', b(domain, self.encoding), jsonapi.dumps(passwords or {})])

        except Exception as e:
            self.log.exception('configure-plain', e=e) 
Example #23
Source File: handlers.py    From Computable with MIT License 5 votes vote down vote up
def post(self, kernel_id, action):
        km = self.kernel_manager
        if action == 'interrupt':
            km.interrupt_kernel(kernel_id)
            self.set_status(204)
        if action == 'restart':
            km.restart_kernel(kernel_id)
            data = {'ws_url':self.ws_url, 'kernel_id':kernel_id}
            self.set_header('Location', '{0}kernels/{1}'.format(self.base_kernel_url, kernel_id))
            self.write(jsonapi.dumps(data))
        self.finish() 
Example #24
Source File: handlers.py    From Computable with MIT License 5 votes vote down vote up
def get(self):
        nbm = self.notebook_manager
        km = self.kernel_manager
        files = nbm.list_notebooks()
        for f in files :
            f['kernel_id'] = km.kernel_for_notebook(f['notebook_id'])
        self.finish(jsonapi.dumps(files)) 
Example #25
Source File: handlers.py    From Computable with MIT License 5 votes vote down vote up
def get(self):
        km = self.kernel_manager
        self.finish(jsonapi.dumps(km.list_kernel_ids())) 
Example #26
Source File: handlers.py    From Computable with MIT License 5 votes vote down vote up
def get(self, profile):
        self.finish(jsonapi.dumps(self.cluster_manager.profile_info(profile))) 
Example #27
Source File: zmqstream.py    From Computable with MIT License 5 votes vote down vote up
def send_pyobj(self, obj, flags=0, protocol=-1, callback=None):
        """Send a Python object as a message using pickle to serialize.

        See zmq.socket.send_json for details.
        """
        msg = pickle.dumps(obj, protocol)
        return self.send(msg, flags, callback=callback) 
Example #28
Source File: zmqstream.py    From Computable with MIT License 5 votes vote down vote up
def send_json(self, obj, flags=0, callback=None):
        """Send json-serialized version of an object.
        See zmq.socket.send_json for details.
        """
        if jsonapi is None:
            raise ImportError('jsonlib{1,2}, json or simplejson library is required.')
        else:
            msg = jsonapi.dumps(obj)
            return self.send(msg, flags=flags, callback=callback) 
Example #29
Source File: socket.py    From Computable with MIT License 5 votes vote down vote up
def send_json(self, obj, flags=0):
        """send a Python object as a message using json to serialize

        Parameters
        ----------
        obj : Python object
            The Python object to send.
        flags : int
            Any valid send flag.
        """
        if jsonapi.jsonmod is None:
            raise ImportError('jsonlib{1,2}, json or simplejson library is required.')
        else:
            msg = jsonapi.dumps(obj)
            return self.send(msg, flags) 
Example #30
Source File: helper.py    From bert-as-service with MIT License 5 votes vote down vote up
def send_ndarray(src, dest, X, req_id=b'', flags=0, copy=True, track=False):
    """send a numpy array with metadata"""
    md = dict(dtype=str(X.dtype), shape=X.shape)
    return src.send_multipart([dest, jsonapi.dumps(md), X, req_id], flags, copy=copy, track=track)