executil.py 文件源码

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

项目:Snipping 作者: yittg 项目源码 文件源码
def execwrap(content, from_file=None):
    from_file = from_file or '<stdin>'
    if isinstance(content, six.string_types):
        content = compile_text(content, from_file=from_file)

    def _inner():
        global_env = exec_globals()
        local_env = global_env
        six.exec_(content, global_env, local_env)
        return global_env

    globals_ = {}
    output_handler = None
    try:
        with reopen_stdout_stderr() as output_handler:
            globals_ = _inner()
    except Exception:
        if output_handler is not None:
            output = "%s%s" % (output_handler.read(),
                               _exception(from_file))
        else:
            output = _exception(from_file)
    else:
        output = output_handler.read()

    output = strutil.ensure_text(output)

    return output, globals_
评论列表


问题


面经


文章

微信
公众号

扫码关注公众号