Use ast.parse in 'eval' mode instead of 'exec'.

This fixes compatibility with Python 3.7; but we should have
been doing this since b8fe420ef3.

The incompatibility with Python 3.7 was introduced in
cb41b2766d

See also: http://bugs.python.org/issue29646
This commit is contained in:
Valentin Lorentz 2017-02-25 11:31:52 +01:00
parent 8b1299cf09
commit 8bae847682
1 changed files with 1 additions and 8 deletions

View File

@ -169,16 +169,9 @@ def safeEval(s, namespace={'True': True, 'False': False, 'None': None}):
"""Evaluates s, safely. Useful for turning strings into tuples/lists/etc.
without unsafely using eval()."""
try:
node = ast.parse(s)
node = ast.parse(s, mode='eval').body
except SyntaxError as e:
raise ValueError('Invalid string: %s.' % e)
nodes = ast.parse(s).body
if not nodes:
if node.__class__ is ast.Module:
return node.doc
else:
raise ValueError(format('Unsafe string: %q', s))
node = nodes[0]
def checkNode(node):
if node.__class__ is ast.Expr:
node = node.value