diff options
Diffstat (limited to 'bin/tools/safe_eval.py')
| -rw-r--r-- | bin/tools/safe_eval.py | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/bin/tools/safe_eval.py b/bin/tools/safe_eval.py index 7c4da78375c..bfbc0b34fe9 100644 --- a/bin/tools/safe_eval.py +++ b/bin/tools/safe_eval.py @@ -29,38 +29,38 @@ __export_bis = {} import sys def __init_ebis(): - global __export_bis - - _evars = [ 'abs', 'all', 'any', 'basestring' , 'bool', - 'chr', 'cmp','complex', 'dict', 'divmod', 'enumerate', - 'float', 'frozenset', 'getattr', 'hasattr', 'hash', - 'hex', 'id','int', 'iter', 'len', 'list', 'long', 'map', 'max', - 'min', 'oct', 'ord','pow', 'range', 'reduce', 'repr', - 'reversed', 'round', 'set', 'setattr', 'slice','sorted', 'str', - 'sum', 'tuple','type', 'unichr','unicode', 'xrange', - 'True','False', 'None', 'NotImplemented', 'Ellipsis', ] - - if sys.version_info[0:2] >= (2,6): - _evars.extend(['bin', 'format', 'next']) - for v in _evars: - __export_bis[v] = __builtins__[v] - + global __export_bis + + _evars = [ 'abs', 'all', 'any', 'basestring' , 'bool', + 'chr', 'cmp','complex', 'dict', 'divmod', 'enumerate', + 'float', 'frozenset', 'getattr', 'hasattr', 'hash', + 'hex', 'id','int', 'iter', 'len', 'list', 'long', 'map', 'max', + 'min', 'oct', 'ord','pow', 'range', 'reduce', 'repr', + 'reversed', 'round', 'set', 'setattr', 'slice','sorted', 'str', + 'sum', 'tuple','type', 'unichr','unicode', 'xrange', + 'True','False', 'None', 'NotImplemented', 'Ellipsis', ] + + if sys.version_info[0:2] >= (2,6): + _evars.extend(['bin', 'format', 'next']) + for v in _evars: + __export_bis[v] = __builtins__[v] + __init_ebis() def safe_eval(expr,sglobals,slocals = None): - """ A little safer version of eval(). - This one, will use fewer builtin functions, so that only - arithmetic and logic expressions can really work """ - - global __export_bis + """ A little safer version of eval(). + This one, will use fewer builtin functions, so that only + arithmetic and logic expressions can really work """ + + global __export_bis - if not sglobals.has_key('__builtins__'): - # we copy, because we wouldn't want successive calls to safe_eval - # to be able to alter the builtins. - sglobals['__builtins__'] = __export_bis.copy() - - return eval(expr,sglobals,slocals) - -#eof
\ No newline at end of file + if not sglobals.has_key('__builtins__'): + # we copy, because we wouldn't want successive calls to safe_eval + # to be able to alter the builtins. + sglobals['__builtins__'] = __export_bis.copy() + + return eval(expr,sglobals,slocals) + +#eof |
