base.py 文件源码

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

项目:py2p 作者: p2p-today 项目源码 文件源码
def register_handler(
                self,  # type: BaseSocket
                method  # type: Callable[..., Union[bool, None]]
        ):  # type: (...) -> None
            """Register a handler for incoming method.

            Args:
                method: A function with two given arguments. Its signature
                            should be of the form ``handler(msg, handler)``,
                            where msg is a :py:class:`py2p.base.Message`
                            object, and handler is a
                            :py:class:`py2p.base.BaseConnection` object. It
                            should return ``True`` if it performed an action,
                            to reduce the number of handlers checked.

            Raises:
                ValueError: If the method signature doesn't parse correctly
            """
            args = inspect.getargspec(method)
            if (args[1:] != (None, None, None) or
                    len(args[0]) != (3 if args[0][0] == 'self' else 2)):
                raise ValueError(
                    "This method must contain exactly two arguments "
                    "(or three if first is self)")
            self.__handlers.append(method)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号