event_dispatcher.py 文件源码

python
阅读 48 收藏 0 点赞 0 评论 0

项目:clubsandwich 作者: irskep 项目源码 文件源码
def add_subscriber(self, obj, name, entity):
        """
        :param object obj: Object to be called when the event fires
        :param str|Enum name: Name of the event. May be a string-valued enum.
        :param entity: If ``None``, receive all events regardless of their entity.
                       Otherwise, only receive events whose entity ``is`` this
                       object.

        Store ``(obj, entity)`` as a subscriber for the event *name*. When
        :py:meth:`fire` is called with a pattern that matches ``(obj, entity)``,
        call ``obj.on_[name](Event(name, entity, data))``.

        An event is said to "match" a subscription if the subscription has the same
        event name, and either the subscriber's entity is ``None``, or the
        subscriber's entity ``is`` the event's entity.

        You may subscribe more than once to receive the event multiple times.
        """
        if isinstance(name, Enum):
            name = name.value
        self.handlers[name].append((obj, entity))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号