eval.py 文件源码

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

项目:plash 作者: ihucos 项目源码 文件源码
def action(action_name=None, keep_comments=False, escape=True):
    def decorator(func):

        action = action_name or func.__name__.replace('_', '-')

        def function_wrapper(*args, **kw):

            if not keep_comments:
                args = [i for i in args if not i.startswith('#')]

            if escape:
                args = [shlex.quote(i) for i in args]

            res = func(*args, **kw)

            # allow actions to yield each line
            if not isinstance(res, str) and res is not None:
                res = '\n'.join(res)

            return res

        state['actions'][action] = function_wrapper
        return function_wrapper

    return decorator
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号