本文整理汇总了Python中zmq.utils.jsonapi.jsonmod.dumps函数的典型用法代码示例。如果您正苦于以下问题:Python dumps函数的具体用法?Python dumps怎么用?Python dumps使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dumps函数的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: notify_event
def notify_event(self, topic, msg):
"""Publish a message on the event publisher channel"""
json_msg = json.dumps(msg)
if isinstance(json_msg, unicode):
json_msg = json_msg.encode('utf8')
if isinstance(self.res_name, unicode):
name = self.res_name.encode('utf8')
else:
name = self.res_name
multipart_msg = ["watcher.%s.%s" % (name, topic), json.dumps(msg)]
if self.evpub_socket is not None and not self.evpub_socket.closed:
self.evpub_socket.send_multipart(multipart_msg)
开发者ID:ajah,项目名称:circus,代码行数:16,代码来源:watcher.py
示例2: handle_autodiscover_message
def handle_autodiscover_message(self, fd_no, type):
data, address = self.udp_socket.recvfrom(1024)
data = json.loads(data)
self.udp_socket.sendto(
json.dumps({
'endpoint': self.endpoint
}), address)
开发者ID:rsdy,项目名称:circus,代码行数:7,代码来源:controller.py
示例3: send_msg
def send_msg(self, topic, msg):
"""send msg"""
json_msg = json.dumps(msg)
if isinstance(json_msg, unicode):
json_msg = json_msg.encode("utf8")
if isinstance(self.res_name, unicode):
name = self.res_name.encode("utf8")
else:
name = self.res_name
multipart_msg = ["watcher.%s.%s" % (name, topic), json.dumps(msg)]
if not self.evpub_socket.closed:
self.evpub_socket.send_multipart(multipart_msg)
开发者ID:kuzmich,项目名称:circus,代码行数:16,代码来源:watcher.py
示例4: cast
def cast(self, command, **props):
"""Fire-and-forget a command to **circusd**
Options:
- **command** -- the command to call
- **props** -- keyword arguments to add to the call
"""
msg = cast_message(command, **props)
self.client.send(json.dumps(msg))
开发者ID:amarandon,项目名称:circus,代码行数:10,代码来源:__init__.py
示例5: call
def call(self, cmd):
if not isinstance(cmd, string_types):
try:
cmd = json.dumps(cmd)
except ValueError as e:
raise CallError(str(e))
try:
self.socket.send(cmd)
except zmq.ZMQError, e:
raise CallError(str(e))
开发者ID:jlebleu,项目名称:circus,代码行数:11,代码来源:client.py
示例6: call
def call(self, command, **props):
"""Sends the command to **circusd**
Options:
- **command** -- the command to call
- **props** -- keyword arguments to add to the call
Returns the JSON mapping sent back by **circusd**
"""
msg = make_message(command, **props)
self.client.send(json.dumps(msg))
msg = self.client.recv()
return json.loads(msg)
开发者ID:amarandon,项目名称:circus,代码行数:14,代码来源:__init__.py
示例7: call
def call(self, cmd):
if isinstance(cmd, string_types):
raise DeprecationWarning('call() takes a mapping')
call_id = uuid.uuid4().hex
cmd['id'] = call_id
try:
cmd = json.dumps(cmd)
except ValueError as e:
raise CallError(str(e))
try:
self.socket.send(cmd)
except zmq.ZMQError, e:
raise CallError(str(e))
开发者ID:jsonkey,项目名称:circus,代码行数:15,代码来源:client.py
示例8: send_response
def send_response(self, cid, msg, resp):
if cid is None:
return
if not isinstance(resp, string_types):
resp = json.dumps(resp)
if isinstance(resp, unicode):
resp = resp.encode('utf8')
try:
self.stream.send(cid, zmq.SNDMORE)
self.stream.send(resp)
except zmq.ZMQError as e:
logger.debug("Received %r - Could not send back %r - %s", msg,
resp, str(e))
开发者ID:crashekar,项目名称:circus,代码行数:16,代码来源:controller.py
示例9: log
def log(self, entry):
"""Log an entry.
Will check if the handler contains filters and apply them if needed
(so that if multiple handlers have the same filters, they are only
applied once). Likewise, it will check if the log entry needs to be
serialized to JSON data, and make sure that the data is only
serialized once for each set of filters.
Parameters
----------
entry : dict
A log entry is a (JSON-compatible) dict.
"""
# Store entry for retrieval
self._entries.append(entry)
# For each set of filters, we store the JSON serialized entry
filtered_entries = {}
serialized_entries = {}
for handler in self.handlers:
filters = frozenset(handler.filters)
# If the content needs to be filtered, do so
if filters:
if filters not in filtered_entries:
filtered_entries[filters] = handler.filter(entry)
filtered_entry = filtered_entries[filters]
else:
filtered_entry = entry
# If the handler wants JSON data, give it
if handler.JSON:
if filters not in serialized_entries:
serialized_entries[filters] = json.dumps(
filtered_entry, **self.json_kwargs)
serialized_entry = serialized_entries[filters]
handler.log(serialized_entry)
else:
handler.log(filtered_entry)
开发者ID:anirudh9119,项目名称:mimir,代码行数:41,代码来源:__init__.py
示例10: send_response
def send_response(self, mid, cid, msg, resp, cast=False):
if cast:
return
if cid is None:
return
if isinstance(resp, string_types):
raise DeprecationWarning('Takes only a mapping')
resp['id'] = mid
resp = json.dumps(resp)
if isinstance(resp, unicode):
resp = resp.encode('utf8')
try:
self.stream.send(cid, zmq.SNDMORE)
self.stream.send(resp)
except zmq.ZMQError as e:
logger.debug("Received %r - Could not send back %r - %s", msg,
resp, str(e))
开发者ID:jsonkey,项目名称:circus,代码行数:22,代码来源:controller.py
示例11: call
def call(self, cmd, callback):
if not isinstance(cmd, string_types):
try:
cmd = json.dumps(cmd)
except ValueError as e:
raise CallError(str(e))
socket = self.context.socket(zmq.DEALER)
socket.setsockopt(zmq.IDENTITY, uuid.uuid4().hex)
socket.setsockopt(zmq.LINGER, 0)
get_connection(socket, self.endpoint, self.ssh_server,
self.ssh_keyfile)
if callback:
stream = ZMQStream(socket, self.loop)
def timeout_callback():
stream.stop_on_recv()
stream.close()
raise CallError('Call timeout for cmd', cmd)
timeout = self.loop.add_timeout(timedelta(seconds=5),
timeout_callback)
def recv_callback(msg):
self.loop.remove_timeout(timeout)
stream.stop_on_recv()
stream.close()
callback(json.loads(msg[0]))
stream.on_recv(recv_callback)
try:
socket.send(cmd)
except zmq.ZMQError as e:
raise CallError(str(e))
if not callback:
return json.loads(socket.recv())
开发者ID:TimPchelintsev,项目名称:circus-web,代码行数:39,代码来源:client.py
示例12: make_json
def make_json(command, **props):
return json.dumps(make_message(command, **props))
开发者ID:jlebleu,项目名称:circus,代码行数:2,代码来源:client.py
示例13: call
def call(self, cmd):
self.client.send(json.dumps(cmd))
msg = self.client.recv()
return json.loads(msg)
开发者ID:fetep,项目名称:circus,代码行数:4,代码来源:flapping.py
示例14: cast
def cast(self, cmd):
self.client.send(json.dumps(cmd))
开发者ID:crashekar,项目名称:circus,代码行数:2,代码来源:flapping.py
示例15: cast
def cast(self, command, **props):
msg = cast_message(command, **props)
self.client.send(json.dumps(msg))
开发者ID:MPOWER4RU,项目名称:circus,代码行数:3,代码来源:flapping.py
示例16: call
def call(self, command, **props):
msg = make_message(command, **props)
self.client.send(json.dumps(msg))
msg = self.client.recv()
return json.loads(msg)
开发者ID:MPOWER4RU,项目名称:circus,代码行数:5,代码来源:flapping.py
注:本文中的zmq.utils.jsonapi.jsonmod.dumps函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论