当前位置: 首页>>代码示例>>Python>>正文


Python blinker.signal方法代码示例

本文整理汇总了Python中blinker.signal方法的典型用法代码示例。如果您正苦于以下问题:Python blinker.signal方法的具体用法?Python blinker.signal怎么用?Python blinker.signal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在blinker的用法示例。


在下文中一共展示了blinker.signal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: send_safe

# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def send_safe(signal, logger, sender, **kwargs):
	"""
	Send a signal and catch any exception which may be raised during it's
	emission. Details regarding the error that occurs (including a stack trace)
	are logged to the specified *logger*. This is suitable for allowing signals
	to be emitted in critical code paths without interrupting the emitter.

	:param str signal: The name of the signal to send safely.
	:param logger: The logger to use for logging exceptions.
	:type logger: :py:class:`logging.Logger`
	:param sender: The sender for this signal emission.
	:param kwargs: The key word arguments to be forward to the signal as it is sent.
	"""
	return tuple(send_safe_iter(signal, logger, sender, **kwargs))

# campaign signals 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:18,代码来源:signals.py

示例2: _send_safe_campaign_alerts

# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def _send_safe_campaign_alerts(campaign, signal_name, sender, **kwargs):
	alert_subscriptions = tuple(subscription for subscription in campaign.alert_subscriptions if not subscription.has_expired)
	logger = logging.getLogger('KingPhisher.Server.CampaignAlerts')
	logger.debug("dispatching campaign alerts for '{0}' (sender: {1!r}) to {2:,} active subscriptions".format(signal_name, sender, len(alert_subscriptions)))
	if not alert_subscriptions:
		return
	signal = blinker.signal(signal_name)
	if not signal.receivers:
		logger.warning("users are subscribed to '{0}', and no signal handlers are connected".format(signal_name))
		return
	if not signal.has_receivers_for(sender):
		logger.info("users are subscribed to '{0}', and no signal handlers are connected for sender: {1}".format(signal_name, sender))
		return
	for subscription in alert_subscriptions:
		results = signals.send_safe(signal_name, logger, sender, alert_subscription=subscription, **kwargs)
		if any((result for (_, result) in results)):
			continue
		logger.warning("user {0} is subscribed to '{1}', and no signal handlers succeeded to send an alert".format(subscription.user.name, signal_name)) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:20,代码来源:server.py

示例3: _do_rpc_method

# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def _do_rpc_method(self, *args, **kwargs):
		self.connection.settimeout(smoke_zephyr.utilities.parse_timespan('20s'))  # set a timeout as a fail safe
		self.rpc_session_id = self.headers.get(server_rpc.RPC_AUTH_HEADER, None)
		self.semaphore_acquire()

		http_method_handler = None
		try:
			signals.request_handle.send(self)
			http_method_handler = getattr(super(KingPhisherRequestHandler, self), 'do_RPC')
			http_method_handler(*args, **kwargs)
		except errors.KingPhisherAbortRequestError as error:
			if http_method_handler is None:
				self.logger.debug('rpc request aborted by a signal handler')
			else:
				self.logger.info('rpc request aborted')
			if not error.response_sent:
				self.respond_not_found()
		finally:
			self.semaphore_release()
		self.connection.settimeout(None) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:22,代码来源:server.py

示例4: unset

# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def unset(self, *fields):
        """Unset the given list of fields for this document."""

        # Send update signal
        signal('update').send(self.__class__, frames=[self])

        # Clear the fields from the document and build the unset object
        unset = {}
        for field in fields:
            self._document.pop(field, None)
            unset[field] = True

        # Update the document
        self.get_collection().update_one(
            {'_id': self._id},
            {'$unset': unset}
        )

        # Send updated signal
        signal('updated').send(self.__class__, frames=[self]) 
开发者ID:GetmeUK,项目名称:MongoFrames,代码行数:22,代码来源:frames.py

示例5: insert_many

# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def insert_many(cls, documents):
        """Insert a list of documents"""
        from mongoframes.queries import to_refs

        # Ensure all documents have been converted to frames
        frames = cls._ensure_frames(documents)

        # Send insert signal
        signal('insert').send(cls, frames=frames)

        # Prepare the documents to be inserted
        documents = [to_refs(f._document) for f in frames]

        # Bulk insert
        ids = cls.get_collection().insert_many(documents).inserted_ids

        # Apply the Ids to the frames
        for i, id in enumerate(ids):
            frames[i]._id = id

        # Send inserted signal
        signal('inserted').send(cls, frames=frames)

        return frames 
开发者ID:GetmeUK,项目名称:MongoFrames,代码行数:26,代码来源:frames.py

示例6: delete_many

# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def delete_many(cls, documents):
        """Delete multiple documents"""

        # Ensure all documents have been converted to frames
        frames = cls._ensure_frames(documents)

        all_count = len(documents)
        assert len([f for f in frames if '_id' in f._document]) == all_count, \
                "Can't delete documents without `_id`s"

        # Send delete signal
        signal('delete').send(cls, frames=frames)

        # Prepare the documents to be deleted
        ids = [f._id for f in frames]

        # Delete the documents
        cls.get_collection().delete_many({'_id': {'$in': ids}})

        # Send deleted signal
        signal('deleted').send(cls, frames=frames) 
开发者ID:GetmeUK,项目名称:MongoFrames,代码行数:23,代码来源:frames.py

示例7: blinker_publish

# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def blinker_publish(topic, message):
    _log.info("Sending blinker signal to: pagure - topic: %s", topic)
    ready = blinker.signal("pagure")
    ready.send("pagure", topic=topic, message=message) 
开发者ID:Pagure,项目名称:pagure,代码行数:6,代码来源:notify.py

示例8: send_safe_iter

# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def send_safe_iter(signal, logger, sender, **kwargs):
	utilities.assert_arg_type(signal, str, 1)
	utilities.assert_arg_type(logger, (logging.Logger, logging.LoggerAdapter), 2)

	signal = blinker.signal(signal)
	for receiver in signal.receivers_for(sender):
		try:
			result = receiver(sender, **kwargs)
		except Exception:
			calling_frame = inspect.stack()[1]
			logger.error("an error occurred while emitting signal '{0}' from {1}:{2}".format(signal, calling_frame[1], calling_frame[2]), exc_info=True)
		else:
			yield (receiver, result)
	return 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:16,代码来源:signals.py

示例9: _do_http_method

# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def _do_http_method(self, *args, **kwargs):
		# This method wraps all of the default do_* HTTP verb handlers to
		# provide error handling and (for non-RPC requests) path adjustments.
		# This also is also a high level location where the throttle semaphore
		# is managed which is acquired for all RPC requests. Non-RPC requests
		# can acquire it as necessary and *should* release it when they are
		# finished with it, however if they fail to do so or encounter an error
		# the semaphore will be released here as a fail safe.
		self.connection.settimeout(smoke_zephyr.utilities.parse_timespan('20s'))  # set a timeout as a fail safe
		self.rpc_session_id = self.headers.get(server_rpc.RPC_AUTH_HEADER, None)
		# delete cached properties so they are handled per request instead of connection.
		for cache_prop in ('_campaign_id', '_message_id', '_visit_id'):
			if hasattr(self, cache_prop):
				delattr(self, cache_prop)
		self.adjust_path()
		self._session = db_manager.Session()

		http_method_handler = None
		try:
			signals.request_handle.send(self)
			http_method_handler = getattr(super(KingPhisherRequestHandler, self), 'do_' + self.command)
			http_method_handler(*args, **kwargs)
		except errors.KingPhisherAbortRequestError as error:
			if http_method_handler is None:
				self.logger.debug('http request aborted by a signal handler')
			else:
				self.logger.info('http request aborted')
			if not error.response_sent:
				self.respond_not_found()
		finally:
			if self.semaphore_acquired:
				self.logger.warning('http request failed to cleanly release resources')
				self.semaphore_release()
			self._session.close()
		self.connection.settimeout(None) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:37,代码来源:server.py

示例10: __init__

# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def __init__(self, connection_pool):
        self.SR = redis.StrictRedis(connection_pool=connection_pool)
        self._g = None
        self._signal = signal('mm-status') 
开发者ID:PaloAltoNetworks,项目名称:minemeld-core,代码行数:6,代码来源:events.py

示例11: __init__

# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def __init__(self, name="baked",**kvargs):

        super(self.__class__, self).__init__(name)
        self.inExec = self.createInputPin(DEFAULT_IN_EXEC_NAME, 'ExecPin', None, self.compute)
        self.createInputPin("Stop", 'ExecPin', None, self.stop)
        self.outExec = self.createOutputPin(DEFAULT_OUT_EXEC_NAME, 'ExecPin')
        self.signal=self.createInputPin('signalName', 'StringPin', 'blink')
        self.data=self.createInputPin('signalMessage', 'StringPin')
        self.d3=self.createInputPin('signalObject', 'FCobjPin')
        a=self.createInputPin('sleep', 'FloatPin',10)
        a.annotationDescriptionDict={ "ValueRange":(0.,300.)}

        a=self.createInputPin('loops', 'IntPin',1)
        a.annotationDescriptionDict={ "ValueRange":(0.,100.)} 
开发者ID:microelly2,项目名称:NodeEditor,代码行数:16,代码来源:FreeCAD_Signal.py

示例12: subscribe

# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def subscribe(self, *args, **kwargs):
        sayl()
        from blinker import signal
        sn=self.getData('signalName')

        send_data = signal(sn)
        @send_data.connect
        def receive_data(sender, **kw):
            print("%r: caught signal from %r, data %r" % (self.name,sender, kw))
            print ("SENDER",sender)
            
            try:
                self.sender = sender
                self.kw = kw
            except:
                print("PROBLEME mit sendern")
                return
            
            self.setData("senderName",sender)
            self.setData("senderMessage",self.kw['message'])
            self.setData("senderObject",self.kw['obj'])
            self.setColor(b=0,a=0.4)
            self.outExec.call()
            
            return ("got return from  "+ self.name)
            
        self.r=receive_data 
开发者ID:microelly2,项目名称:NodeEditor,代码行数:29,代码来源:FreeCAD_Signal.py

示例13: unsubscribe

# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def unsubscribe(self, *args, **kwargs):
        from blinker import signal
        sn=self.getData('signalName')
        send_data = signal(sn)
        send_data.disconnect(self.r)
        sayl()

        self.r=None
        self.sender = None
        self.kw = None 
开发者ID:microelly2,项目名称:NodeEditor,代码行数:12,代码来源:FreeCAD_Signal.py

示例14: owned_pre_save

# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def owned_pre_save(sender, document, **kwargs):
    '''
    Owned mongoengine.pre_save signal handler
    Need to fetch original owner before the new one erase it.
    '''
    if not isinstance(document, Owned):
        return
    changed_fields = getattr(document, '_changed_fields', [])
    if 'organization' in changed_fields:
        if document.owner:
            # Change from owner to organization
            document._previous_owner = document.owner
            document.owner = None
        else:
            # Change from org to another
            # Need to fetch previous value in base
            original = sender.objects.only('organization').get(pk=document.pk)
            document._previous_owner = original.organization
    elif 'owner' in changed_fields:
        if document.organization:
            # Change from organization to owner
            document._previous_owner = document.organization
            document.organization = None
        else:
            # Change from owner to another
            # Need to fetch previous value in base
            original = sender.objects.only('owner').get(pk=document.pk)
            document._previous_owner = original.owner 
开发者ID:opendatateam,项目名称:udata,代码行数:30,代码来源:owned.py

示例15: owned_post_save

# 需要导入模块: import blinker [as 别名]
# 或者: from blinker import signal [as 别名]
def owned_post_save(sender, document, **kwargs):
    '''
    Owned mongoengine.post_save signal handler
    Dispatch the `Owned.on_owner_change` signal
    once the document has been saved including the previous owner.

    The signal handler should have the following signature:
    ``def handler(document, previous)``
    '''
    if isinstance(document, Owned) and hasattr(document, '_previous_owner'):
        Owned.on_owner_change.send(document, previous=document._previous_owner) 
开发者ID:opendatateam,项目名称:udata,代码行数:13,代码来源:owned.py


注:本文中的blinker.signal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。