mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 18:44:04 +01:00
Use ast.parse in 'eval' mode instead of 'exec'.
This fixes compatibility with Python 3.7; but we should have been doing this sinceb8fe420ef3
. The incompatibility with Python 3.7 was introduced incb41b2766d
See also: http://bugs.python.org/issue29646
This commit is contained in:
parent
8b1299cf09
commit
8bae847682
@ -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.
|
"""Evaluates s, safely. Useful for turning strings into tuples/lists/etc.
|
||||||
without unsafely using eval()."""
|
without unsafely using eval()."""
|
||||||
try:
|
try:
|
||||||
node = ast.parse(s)
|
node = ast.parse(s, mode='eval').body
|
||||||
except SyntaxError as e:
|
except SyntaxError as e:
|
||||||
raise ValueError('Invalid string: %s.' % 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):
|
def checkNode(node):
|
||||||
if node.__class__ is ast.Expr:
|
if node.__class__ is ast.Expr:
|
||||||
node = node.value
|
node = node.value
|
||||||
|
Loading…
Reference in New Issue
Block a user