diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-10-03 21:28:28 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-10-03 21:28:28 +0200 |
commit | 7fc24c10cd3dad19a69392398671a78abecd71d1 (patch) | |
tree | b7a2f70ac2410ffebe22f70d5dc07398a2f162e0 /pyload/lib/SafeEval.py | |
parent | Remove trailing whitespaces (diff) | |
download | pyload-7fc24c10cd3dad19a69392398671a78abecd71d1.tar.xz |
Remove lib
Diffstat (limited to 'pyload/lib/SafeEval.py')
-rw-r--r-- | pyload/lib/SafeEval.py | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/pyload/lib/SafeEval.py b/pyload/lib/SafeEval.py deleted file mode 100644 index 8fc57f261..000000000 --- a/pyload/lib/SafeEval.py +++ /dev/null @@ -1,47 +0,0 @@ -## {{{ http://code.activestate.com/recipes/286134/ (r3) (modified) -import dis - -_const_codes = map(dis.opmap.__getitem__, [ - 'POP_TOP','ROT_TWO','ROT_THREE','ROT_FOUR','DUP_TOP', - 'BUILD_LIST','BUILD_MAP','BUILD_TUPLE', - 'LOAD_CONST','RETURN_VALUE','STORE_SUBSCR' - ]) - - -_load_names = ['False', 'True', 'null', 'true', 'false'] - -_locals = {'null': None, 'true': True, 'false': False} - -def _get_opcodes(codeobj): - i = 0 - opcodes = [] - s = codeobj.co_code - names = codeobj.co_names - while i < len(s): - code = ord(s[i]) - opcodes.append(code) - if code >= dis.HAVE_ARGUMENT: - i += 3 - else: - i += 1 - return opcodes, names - -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 - - -def const_eval(expr): - c = test_expr(expr, _const_codes) - return eval(c, None, _locals) - -## end of http://code.activestate.com/recipes/286134/ }}} |