SafeEval.py 文件源码

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

项目:download-manager 作者: thispc 项目源码 文件源码
def test_expr(expr, allowed_codes):
    try:
        c = compile(expr, "", "eval")
    except:
        raise ValueError, "%s is not a valid expression" % expr
    codes, names = _get_opcodes(c)
    for code in codes:
        if code not in allowed_codes:
            for n in names:
                if n not in _load_names:
                    raise ValueError, "opcode %s not allowed" % dis.opname[code]
    return c
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号