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


Python Signal.ANY属性代码示例

本文整理汇总了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 
开发者ID:sugarguo,项目名称:Flask_Blog,代码行数:27,代码来源:base.py

示例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) 
开发者ID:sugarguo,项目名称:Flask_Blog,代码行数:19,代码来源:base.py

示例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 
开发者ID:sugarguo,项目名称:Flask_Blog,代码行数:23,代码来源:base.py

示例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) 
开发者ID:RoseOu,项目名称:flasky,代码行数:19,代码来源:base.py

示例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) 
开发者ID:sugarguo,项目名称:Flask_Blog,代码行数:37,代码来源:base.py

示例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 
开发者ID:sugarguo,项目名称:Flask_Blog,代码行数:17,代码来源:base.py

示例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" 
开发者ID:yetship,项目名称:blinker-examples,代码行数:7,代码来源:example05.py

示例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" 
开发者ID:yetship,项目名称:blinker-examples,代码行数:7,代码来源:example05.py


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