Better error reporting.

This commit is contained in:
Jeremy Fincher 2004-08-11 06:18:29 +00:00
parent 0768ce1c85
commit 8a53eab39d

View File

@ -471,10 +471,10 @@ def safeEval(s, namespace={'True': True, 'False': False, 'None': None}):
if node.__class__ is compiler.ast.Module: if node.__class__ is compiler.ast.Module:
return node.doc return node.doc
else: else:
raise ValueError, 'Unsafe string.' raise ValueError, 'Unsafe string: %r' % s
node = nodes[0] node = nodes[0]
if node.__class__ is not compiler.ast.Discard: if node.__class__ is not compiler.ast.Discard:
raise ValueError, 'Invalid expression: %s' raise ValueError, 'Invalid expression: %r' % s
node = node.getChildNodes()[0] node = node.getChildNodes()[0]
def checkNode(node): def checkNode(node):
if node.__class__ is compiler.ast.Const: if node.__class__ is compiler.ast.Const:
@ -493,7 +493,7 @@ def safeEval(s, namespace={'True': True, 'False': False, 'None': None}):
if checkNode(node): if checkNode(node):
return eval(s, namespace, namespace) return eval(s, namespace, namespace)
else: else:
raise ValueError, 'Unsafe string.' raise ValueError, 'Unsafe string: %r' % s
def exnToString(e): def exnToString(e):
"""Turns a simple exception instance into a string (better than str(e))""" """Turns a simple exception instance into a string (better than str(e))"""