本文整理匯總了Python中zmq.utils.jsonapi.dumps方法的典型用法代碼示例。如果您正苦於以下問題:Python jsonapi.dumps方法的具體用法?Python jsonapi.dumps怎麽用?Python jsonapi.dumps使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類zmq.utils.jsonapi
的用法示例。
在下文中一共展示了jsonapi.dumps方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: send_json
# 需要導入模塊: from zmq.utils import jsonapi [as 別名]
# 或者: from zmq.utils.jsonapi import dumps [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: send_pyobj
# 需要導入模塊: from zmq.utils import jsonapi [as 別名]
# 或者: from zmq.utils.jsonapi import dumps [as 別名]
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)
示例3: _reserialize_reply
# 需要導入模塊: from zmq.utils import jsonapi [as 別名]
# 或者: from zmq.utils.jsonapi import dumps [as 別名]
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)
示例4: post
# 需要導入模塊: from zmq.utils import jsonapi [as 別名]
# 或者: from zmq.utils.jsonapi import dumps [as 別名]
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
#-----------------------------------------------------------------------------
示例5: send_json
# 需要導入模塊: from zmq.utils import jsonapi [as 別名]
# 或者: from zmq.utils.jsonapi import dumps [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`
"""
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)
示例6: eval
# 需要導入模塊: from zmq.utils import jsonapi [as 別名]
# 或者: from zmq.utils.jsonapi import dumps [as 別名]
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
示例7: send_ndarray
# 需要導入模塊: from zmq.utils import jsonapi [as 別名]
# 或者: from zmq.utils.jsonapi import dumps [as 別名]
def send_ndarray(src, dest, X, 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], flags, copy=copy, track=track)
示例8: encode
# 需要導入模塊: from zmq.utils import jsonapi [as 別名]
# 或者: from zmq.utils.jsonapi import dumps [as 別名]
def encode(self, texts, blocking=True):
if self.is_valid_input(texts):
texts = _unicode(texts)
self.send(jsonapi.dumps(texts))
return self.recv_ndarray() if blocking else None
else:
raise AttributeError('"texts" must be "List[str]" and non-empty!')
示例9: configure_plain
# 需要導入模塊: from zmq.utils import jsonapi [as 別名]
# 或者: from zmq.utils.jsonapi import dumps [as 別名]
def configure_plain(self, domain='*', passwords=None):
self.pipe.send_multipart([b'PLAIN', b(domain, self.encoding), jsonapi.dumps(passwords or {})])
示例10: send_pyobj
# 需要導入模塊: from zmq.utils import jsonapi [as 別名]
# 或者: from zmq.utils.jsonapi import dumps [as 別名]
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)
示例11: send_json
# 需要導入模塊: from zmq.utils import jsonapi [as 別名]
# 或者: from zmq.utils.jsonapi import dumps [as 別名]
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)
示例12: send_pyobj
# 需要導入模塊: from zmq.utils import jsonapi [as 別名]
# 或者: from zmq.utils.jsonapi import dumps [as 別名]
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)
示例13: result
# 需要導入模塊: from zmq.utils import jsonapi [as 別名]
# 或者: from zmq.utils.jsonapi import dumps [as 別名]
def result(self):
if self.max_seq_len_unset and not self.fixed_embed_length:
x = np.ascontiguousarray(self.final_ndarray[:, 0:self.max_effective_len])
else:
x = self.final_ndarray
x_info = {'dtype': str(x.dtype),
'shape': x.shape,
'tokens': list(chain.from_iterable(self.tokens)) if self.with_tokens else ''}
x_info = jsonapi.dumps(x_info)
return x, x_info
示例14: send_ndarray
# 需要導入模塊: from zmq.utils import jsonapi [as 別名]
# 或者: from zmq.utils.jsonapi import dumps [as 別名]
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)
示例15: send_json
# 需要導入模塊: from zmq.utils import jsonapi [as 別名]
# 或者: from zmq.utils.jsonapi import dumps [as 別名]
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)