python类Converter()的实例源码

converter.py 文件源码 项目:Chiaki-Nanami 作者: Ikusaba-san 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def ranged(low, high=None, *, type=int):
    'Converter to check if an argument is in a certain range INCLUSIVELY'
    if high is None:
        low, high = 0, low

    def ranged_argument(arg):
        result = type(arg)
        if low <= result <= high:
            return result
        raise commands.BadArgument(f'Value must be between {low} and {high}, '
                                   f'or equal to {low} or {high}.')
    return ranged_argument
data.py 文件源码 项目:RPGBot 作者: henry232323 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def union(*classes):
    class Union(commands.Converter):
        async def convert(self, ctx, argument):
            for cls in classes:
                try:
                    if cls in converters:
                        cls = converters[cls]
                    return await cls.convert(self, ctx, argument)
                except Exception as e:
                    pass
            else:
                raise e

    return Union
time.py 文件源码 项目:PyMiki 作者: TheGrammarJew 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, converter=None, *, default=None):
        if isinstance(converter, type) and issubclass(converter, commands.Converter):
            converter = converter()

        if converter is not None and not isinstance(converter, commands.Converter):
            raise TypeError('commands.Converter subclass necessary.')

        self.converter = converter
        self.default = default


问题


面经


文章

微信
公众号

扫码关注公众号