本文整理匯總了Python中blinker.Signal.ANY屬性的典型用法代碼示例。如果您正苦於以下問題:Python Signal.ANY屬性的具體用法?Python Signal.ANY怎麽用?Python Signal.ANY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類blinker.Signal
的用法示例。
在下文中一共展示了Signal.ANY屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: connect_via
# 需要導入模塊: from blinker import Signal [as 別名]
# 或者: from blinker.Signal import ANY [as 別名]
def connect_via(self, sender, weak=False):
"""Connect the decorated function as a receiver for *sender*.
:param sender: Any object or :obj:`ANY`. The decorated function
will only receive :meth:`send` emissions sent by *sender*. If
``ANY``, the receiver will always be notified. A function may be
decorated multiple times with differing *sender* values.
:param weak: If true, the Signal will hold a weakref to the
decorated function and automatically disconnect when *receiver*
goes out of scope or is garbage collected. Unlike
:meth:`connect`, this defaults to False.
The decorated function will be invoked by :meth:`send` with
`sender=` as a single positional argument and any \*\*kwargs that
were provided to the call to :meth:`send`.
.. versionadded:: 1.1
"""
def decorator(fn):
self.connect(fn, sender, weak)
return fn
return decorator
示例2: temporarily_connected_to
# 需要導入模塊: from blinker import Signal [as 別名]
# 或者: from blinker.Signal import ANY [as 別名]
def temporarily_connected_to(self, receiver, sender=ANY):
"""An alias for :meth:`connected_to`.
:param receiver: a receiver callable
:param sender: optional, a sender to filter on
.. versionadded:: 0.9
.. versionchanged:: 1.1
Renamed to :meth:`connected_to`. ``temporarily_connected_to`` was
deprecated in 1.2 and will be removed in a subsequent version.
"""
warn("temporarily_connected_to is deprecated; "
"use connected_to instead.",
DeprecationWarning)
return self.connected_to(receiver, sender)
示例3: receivers_for
# 需要導入模塊: from blinker import Signal [as 別名]
# 或者: from blinker.Signal import ANY [as 別名]
def receivers_for(self, sender):
"""Iterate all live receivers listening for *sender*."""
# TODO: test receivers_for(ANY)
if self.receivers:
sender_id = hashable_identity(sender)
if sender_id in self._by_sender:
ids = (self._by_sender[ANY_ID] |
self._by_sender[sender_id])
else:
ids = self._by_sender[ANY_ID].copy()
for receiver_id in ids:
receiver = self.receivers.get(receiver_id)
if receiver is None:
continue
if isinstance(receiver, WeakTypes):
strong = receiver()
if strong is None:
self._disconnect(receiver_id, ANY_ID)
continue
receiver = strong
yield receiver
示例4: temporarily_connected_to
# 需要導入模塊: from blinker import Signal [as 別名]
# 或者: from blinker.Signal import ANY [as 別名]
def temporarily_connected_to(self, receiver, sender=ANY):
"""An alias for :meth:`connected_to`.
:param receiver: a receiver callable
:param sender: optional, a sender to filter on
.. versionadded:: 0.9
.. versionchanged:: 1.1
Renamed to :meth:`connected_to`. ``temporarily_connected_to``
was deprecated in 1.2 and removed in a subsequent version.
"""
warn("temporarily_connected_to is deprecated; "
"use connected_to instead.",
DeprecationWarning)
return self.connected_to(receiver, sender)
示例5: connected_to
# 需要導入模塊: from blinker import Signal [as 別名]
# 或者: from blinker.Signal import ANY [as 別名]
def connected_to(self, receiver, sender=ANY):
"""Execute a block with the signal temporarily connected to *receiver*.
:param receiver: a receiver callable
:param sender: optional, a sender to filter on
This is a context manager for use in the ``with`` statement. It can
be useful in unit tests. *receiver* is connected to the signal for
the duration of the ``with`` block, and will be disconnected
automatically when exiting the block:
.. testsetup::
from __future__ import with_statement
from blinker import Signal
on_ready = Signal()
receiver = lambda sender: None
.. testcode::
with on_ready.connected_to(receiver):
# do stuff
on_ready.send(123)
.. versionadded:: 1.1
"""
self.connect(receiver, sender=sender, weak=False)
try:
yield None
except:
self.disconnect(receiver)
raise
else:
self.disconnect(receiver)
示例6: has_receivers_for
# 需要導入模塊: from blinker import Signal [as 別名]
# 或者: from blinker.Signal import ANY [as 別名]
def has_receivers_for(self, sender):
"""True if there is probably a receiver for *sender*.
Performs an optimistic check only. Does not guarantee that all
weakly referenced receivers are still alive. See
:meth:`receivers_for` for a stronger search.
"""
if not self.receivers:
return False
if self._by_sender[ANY_ID]:
return True
if sender is ANY:
return False
return hashable_identity(sender) in self._by_sender
示例7: test_strong
# 需要導入模塊: from blinker import Signal [as 別名]
# 或者: from blinker.Signal import ANY [as 別名]
def test_strong():
@weak_signal.connect_via(Signal.ANY)
def receive_data(sender, **kw):
print ("Caught strong signal from : {}, data: {}".format(sender, kw))
return "test"
示例8: test_weak
# 需要導入模塊: from blinker import Signal [as 別名]
# 或者: from blinker.Signal import ANY [as 別名]
def test_weak():
@weak_signal.connect_via(Signal.ANY, weak=True)
def receive_data(sender, **kw):
print ("Caught weak signal from : {}, data: {}".format(sender, kw))
return "test"