def visit_Name(self, node):
    if not node.id in self.ALLOWED_NAMES:
        raise RuntimeError('Name access to %s is not allowed' % node.id)
return self.generic_visit(node)

def generic_visit(self, node):
    nodetype = type(node).__name__
if nodetype not in self.ALLOWED_NODE_TYPES:
    raise RuntimeError('Invalid expression: %s not allowed' % nodetype)
return ast.NodeTransformer.generic_visit(self, node)
transformer = Transformer()
transformer.visit(tree)
clause = compile(tree, '<AST>', 'eval')
result = eval(clause, dict(Decimal=decimal.Decimal))
print(result)
Malformed String ValueError ast.literal_eval() with String representation of Tuple