本文整理汇总了Python中pydispatch.dispatcher.Any方法的典型用法代码示例。如果您正苦于以下问题:Python dispatcher.Any方法的具体用法?Python dispatcher.Any怎么用?Python dispatcher.Any使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pydispatch.dispatcher
的用法示例。
在下文中一共展示了dispatcher.Any方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect_error_dispatcher
# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import Any [as 别名]
def connect_error_dispatcher():
clazz = 'aggregator'
method = 'connect_error_dispatcher'
# Load dispatchers for communicating error messages to slack (or somewhere else)
# noinspection PyPep8Naming
SIGNAL = 'publish-error-signal'
if 'slack' in BuildConfig.json_config:
commons.print_msg(clazz, method, 'Detected slack in buildConfig. Connecting error dispatcher to slack.')
dispatcher.connect(Slack.publish_error, signal=SIGNAL, sender=dispatcher.Any)
elif BuildConfig.settings.has_section('slack'):
commons.print_msg(clazz, method, 'Detected slack in global settings.ini. Connecting error dispatcher to slack.')
dispatcher.connect(Slack.publish_error, signal=SIGNAL, sender=dispatcher.Any)
else:
commons.print_msg(clazz, method, 'No event dispatcher detected. The only place errors will show up is in this '
'log.', 'WARN')
示例2: send
# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import Any [as 别名]
def send(self, signal=dispatcher.Any, sender=dispatcher.Anonymous,
*args, **kwargs):
"""
Send signal/event to registered receivers.
:param args:
:param kwargs:
:return:
"""
if signal is None:
signal = dispatcher.Any
if sender is None:
sender = dispatcher.Anonymous
self._dispatcher.send(signal, sender, *args, **kwargs)
# dispatch this signal to the shell.
logger.info("sending signal: %s", signal)
if self._outbox:
self._outbox.put_nowait((signal, kwargs))
示例3: disconnect
# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import Any [as 别名]
def disconnect(self, receiver, signal=dispatcher.Any,
sender=dispatcher.Any):
"""
Disconnect the specified receiver.
:param receiver
:param signal:
:param sender:
"""
if signal is None:
signal = dispatcher.Any
if sender is None:
sender = dispatcher.Anonymous
self._dispatcher.disconnect(receiver, signal, sender)
示例4: dispatch_signal
# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import Any [as 别名]
def dispatch_signal(signal=dispatcher.Any, sender=dispatcher.Anonymous,
*arguments, **named):
'''
Dispatch signal with exception proof
'''
LOGGER.debug('Dispatch %s', signal)
try:
dispatcher.send(signal, sender, *arguments, **named)
except Exception:
LOGGER.error('Exception dispatching signal %s', signal)
LOGGER.error(traceback.format_exc())
示例5: connect
# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import Any [as 别名]
def connect(self, receiver, signal=dispatcher.Any, sender=dispatcher.Any):
"""
Connect the receiver to listen for signals/events.
:param receiver
:param signal:
:param sender:
"""
if signal is None:
signal = dispatcher.Any
if sender is None:
sender = dispatcher.Anonymous
self._dispatcher.connect(receiver, signal, sender)
示例6: send
# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import Any [as 别名]
def send(self, signal=dispatcher.Any, sender=dispatcher.Anonymous, *args, **kwargs):
if signal is None:
signal = dispatcher.Any
if sender is None:
sender = dispatcher.Anonymous
self._dispatcher.send(signal, sender, *args, **kwargs)
示例7: connect
# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import Any [as 别名]
def connect(self, receiver, signal=dispatcher.Any, sender=dispatcher.Any):
if signal is None:
signal = dispatcher.Any
if sender is None:
sender = dispatcher.Anonymous
self._dispatcher.connect(receiver, signal, sender)
示例8: __init__
# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import Any [as 别名]
def __init__(self, mainMenu, sessionID):
cmd.Cmd.__init__(self)
self.mainMenu = mainMenu
self.sessionID = sessionID
self.doc_header = 'Agent Commands'
# try to resolve the sessionID to a name
name = self.mainMenu.agents.get_agent_name(sessionID)
# set the text prompt
self.prompt = '(EmPyre: '+helpers.color(name, 'red')+') > '
# listen for messages from this specific agent
dispatcher.connect(self.handle_agent_event, sender=dispatcher.Any)
# display any results from the database that were stored
# while we weren't interacting with the agent
results = self.mainMenu.agents.get_agent_results(self.sessionID)
if results:
print "\n" + results.rstrip('\r\n')
# def preloop(self):
# traceback.print_stack()
示例9: _debug_send
# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import Any [as 别名]
def _debug_send(signal=dispatcher.Any, sender=dispatcher.Anonymous,
*arguments, **named):
print("send %s from %s: %s" % (
nice_repr(signal), nice_repr(sender),
fmt_args(*arguments, **named)))
return _real_dispatcher_send(signal, sender, *arguments, **named)
示例10: _debug_sendExact
# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import Any [as 别名]
def _debug_sendExact(signal=dispatcher.Any, sender=dispatcher.Anonymous,
*arguments, **named):
print("sendExact %s from %s: %s" % (
nice_repr(signal), nice_repr(sender), fmt_args(*arguments, **name)))
return _real_dispatcher_sendExact(signal, sender, *arguments, **named)
示例11: _debug_connect
# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import Any [as 别名]
def _debug_connect(receiver, signal=dispatcher.Any, sender=dispatcher.Any,
weak=True):
print("connect %s to %s signal %s" % (
nice_repr(receiver), nice_repr(signal), nice_repr(sender)))
return _real_dispatcher_connect(receiver, signal, sender, weak)
示例12: _debug_disconnect
# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import Any [as 别名]
def _debug_disconnect(receiver, signal=dispatcher.Any, sender=dispatcher.Any,
weak=True):
print("disconnecting %s from %s signal %s" % (
nice_repr(receiver), nice_repr(signal), nice_repr(sender)))
return _real_dispatcher_disconnect(receiver, signal, sender, weak)
示例13: sendRobust
# 需要导入模块: from pydispatch import dispatcher [as 别名]
# 或者: from pydispatch.dispatcher import Any [as 别名]
def sendRobust(
signal=Any,
sender=Anonymous,
*arguments, **named
):
"""Send signal from sender to all connected receivers catching errors
signal -- (hashable) signal value, see connect for details
sender -- the sender of the signal
if Any, only receivers registered for Any will receive
the message.
if Anonymous, only receivers registered to receive
messages from Anonymous or Any will receive the message
Otherwise can be any python object (normally one
registered with a connect if you actually want
something to occur).
arguments -- positional arguments which will be passed to
*all* receivers. Note that this may raise TypeErrors
if the receivers do not allow the particular arguments.
Note also that arguments are applied before named
arguments, so they should be used with care.
named -- named arguments which will be filtered according
to the parameters of the receivers to only provide those
acceptable to the receiver.
Return a list of tuple pairs [(receiver, response), ... ]
if any receiver raises an error (specifically any subclass of Exception),
the error instance is returned as the result for that receiver.
"""
# Call each receiver with whatever arguments it can accept.
# Return a list of tuple pairs [(receiver, response), ... ].
responses = []
for receiver in liveReceivers(getAllReceivers(sender, signal)):
try:
response = robustApply(
receiver,
signal=signal,
sender=sender,
*arguments,
**named
)
except Exception as err:
responses.append((receiver, err))
else:
responses.append((receiver, response))
return responses