request.py 文件源码

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

项目:birdnet 作者: cyysu 项目源码 文件源码
def webpyfunc(inp, fvars, autoreload=False):
    """If `inp` is a url mapping, returns a function that calls handle."""
    if not hasattr(inp, '__call__'):
        if autoreload:
            def modname():
                """find name of the module name from fvars."""
                file, name = fvars['__file__'], fvars['__name__']
                if name == '__main__':
                    # Since the __main__ module can't be reloaded, the module has 
                    # to be imported using its file name.
                    name = os.path.splitext(os.path.basename(file))[0]
                return name

            mod = __import__(modname(), None, None, [""])
            #@@probably should replace this with some inspect magic
            name = utils.dictfind(fvars, inp)
            func = lambda: handle(getattr(mod, name), mod)
        else:
            func = lambda: handle(inp, fvars)
    else:
        func = inp
    return func
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号