mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-17 06:00:42 +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 since b8fe420ef35c63a85a92179b62adf4556f2d1a92.
The incompatibility with Python 3.7 was introduced in
cb41b2766d
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.
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user