print_routes.py 文件源码

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

项目:deb-python-falcon 作者: openstack 项目源码 文件源码
def traverse(roots, parent='', verbose=False):
    """
    Recursive call which also handles printing output.

    :param api: The falcon.API or callable that returns an instance to look at.
    :type api: falcon.API or callable
    :param parent: The parent uri path to the current iteration.
    :type parent: str
    :param verbose: If the output should be verbose.
    :type verbose: bool
    """
    for root in roots:
        if root.method_map:
            print('->', parent + '/' + root.raw_segment)
            if verbose:
                for method, func in root.method_map.items():
                    if func.__name__ != 'method_not_allowed':
                        if isinstance(func, partial):
                            real_func = func.func
                        else:
                            real_func = func

                        source_file = inspect.getsourcefile(real_func)

                        print('-->{0} {1}:{2}'.format(
                            method,
                            source_file,
                            source_file[1]
                        ))

        if root.children:
            traverse(root.children, parent + '/' + root.raw_segment, verbose)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号