backported safe_eval to python 2.5

This commit is contained in:
mdipierro
2013-09-02 20:30:30 -05:00
parent 0b501612ad
commit 31904d58bd
2 changed files with 8 additions and 2 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.6.0-development+timestamp.2013.09.01.14.13.25
Version 2.6.0-development+timestamp.2013.09.02.20.29.38
+7 -1
View File
@@ -7,6 +7,12 @@ import re
import ast
from cgi import escape
from string import maketrans
try:
from ast import parse as ast_parse
import ast
except ImportError: # python 2.5
from compiler import parse
import compiler.ast as ast
"""
TODO: next version should use MathJax
@@ -569,7 +575,7 @@ def safe_eval(node_or_string, env):
_safe_names = {'None': None, 'True': True, 'False': False}
_safe_names.update(env)
if isinstance(node_or_string, basestring):
node_or_string = ast.parse(node_or_string, mode='eval')
node_or_string = ast_parse(node_or_string, mode='eval')
if isinstance(node_or_string, ast.Expression):
node_or_string = node_or_string.body
def _convert(node):