安全的嵌入式python表达式解析器
embexpr的Python项目详细描述
盗用图片::https://travis-ci.org/orisano/embexpr.svg?branch=master
:目标:https://travis ci.org/orisano/embexpr
安全的嵌入式python表达式解析器(主要用于简单的dsl或配置文件)。
代码::bash
pip install embexpr
从embexpr import-expr中,parseerror
assert expr('3*5’)==15
assert expr('“foo”+“bar”“)=”foobar“
assert expr('len(“示例”))==7
assert expr('s.startswith('prefix“)”)(s=“prefix_后缀”)==true
try:
>expr('eval('1“)))))
除了parseerror为15
assert expr('foo“+”foo”+”bar“+”bar““E:
打印(E)
reference
----
https://github.com/ansible/ansible/blob/devel/lib/ansible/template/safe-eval.py
http://stackoverflow.com/questions/12523516/使用AST和白名单使pythons eval安全
:目标:https://travis ci.org/orisano/embexpr
安全的嵌入式python表达式解析器(主要用于简单的dsl或配置文件)。
代码::bash
pip install embexpr
从embexpr import-expr中,parseerror
assert expr('3*5’)==15
assert expr('“foo”+“bar”“)=”foobar“
assert expr('len(“示例”))==7
assert expr('s.startswith('prefix“)”)(s=“prefix_后缀”)==true
try:
>expr('eval('1“)))))
除了parseerror为15
assert expr('foo“+”foo”+”bar“+”bar““E:
打印(E)
reference
----
https://github.com/ansible/ansible/blob/devel/lib/ansible/template/safe-eval.py
http://stackoverflow.com/questions/12523516/使用AST和白名单使pythons eval安全