Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def disconnected_from_listeners(signal):
"""Temporarily disconnect all listeners for a Blinker signal."""
listeners = list(signal.receivers_for(ANY))
for listener in listeners:
signal.disconnect(listener)
yield
for listener in listeners:
signal.connect(listener)
def teardown():
# Disconnect any triggers
for receiver in trigger_event.receivers_for(ANY):
trigger_event.disconnect(receiver)
def teardown():
# Disconnect any triggers
for receiver in image_analysis.receivers_for(ANY):
image_analysis.disconnect(receiver)
for receiver in trigger_event.receivers_for(ANY):
trigger_event.disconnect(receiver)
sentinel = []
def meta_received(sender, **kw):
sentinel.append(dict(kw, sender=sender))
assert not blinker.receiver_connected.receivers
blinker.receiver_connected.connect(meta_received)
assert not sentinel
def receiver(sender, **kw):
pass
sig = blinker.Signal()
sig.connect(receiver)
assert sentinel == [dict(sender=sig,
receiver_arg=receiver,
sender_arg=blinker.ANY,
weak_arg=True)]
blinker.receiver_connected._clear_state()
def assertSignals(self, expected_events, sender=ANY):
events = []
def receiver_(signal, sender, **kwargs):
events.append((signal, sender, kwargs))
receivers = {
signal: partial(receiver_, signal) for signal in [
signals.before_create,
signals.after_create,
signals.before_update,
signals.after_update,
signals.before_delete,
signals.after_delete,
signals.before_add_to_relation,
signals.after_add_to_relation,
signals.before_remove_from_relation,
def teardown():
# Disconnect any triggers
for receiver in image.receivers_for(ANY):
image.disconnect(receiver)
for receiver in image_buffer.receivers_for(ANY):
image_buffer.disconnect(receiver)
@item_modified.connect_via(ANY)
def send_notifications(app, fqname, **kwargs):
""" Send mail notifications to subscribers on item change
:param app: local proxy app
:param fqname: fqname of the changed item
:param kwargs: key/value pairs that contain extra information about the item
required in order to create a notification
"""
action = kwargs.get('action')
revs = get_item_last_revisions(app, fqname) if action not in [
DESTROY_REV, DESTROY_ALL, ] else []
notification = Notification(app, fqname, revs, **kwargs)
try:
content_diff = notification.get_content_diff()
except Exception:
# current user has likely corrupted an item or fixed a corrupted item
@signals.before_create.connect_via(ANY)
def before_create_article_comment(sender, item):
if issubclass(sender, (ArticleResource, CommentResource)):
item.author_id = current_user.id
def get_worker(*args, **kwargs):
return blinker.ANY
@item_modified.connect_via(ANY)
def send_notifications(app, fqname, **kwargs):
""" Send mail notifications to subscribers on item change
:param app: local proxy app
:param fqname: fqname of the changed item
:param kwargs: key/value pairs that contain extra information about the item
required in order to create a notification
"""
action = kwargs.get('action')
revs = get_item_last_revisions(app, fqname) if action not in [
DESTROY_REV, DESTROY_ALL, ] else []
notification = Notification(app, fqname, revs, **kwargs)
try:
content_diff = notification.get_content_diff()
except Exception:
# current user has likely corrupted an item or fixed a corrupted item