diff -r 1186d68715cc Lib/ast.py --- a/Lib/ast.py Wed Jul 04 19:33:45 2012 -0700 +++ b/Lib/ast.py Thu Jul 05 17:52:47 2012 -0300 @@ -35,14 +35,16 @@ return compile(source, filename, mode, PyCF_ONLY_AST) -def literal_eval(node_or_string): +def literal_eval(node_or_string, safe_names=None): """ Safely evaluate an expression node or a string containing a Python expression. The string or node provided may only consist of the following Python literal structures: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, and None. """ - _safe_names = {'None': None, 'True': True, 'False': False} + _safe_names = {'None': None, 'True': True, 'False': False, 'Ellipsis': ...} + if safe_names: + _safe_names.update(safe_names) if isinstance(node_or_string, str): node_or_string = parse(node_or_string, mode='eval') if isinstance(node_or_string, Expression): @@ -52,6 +54,8 @@ return node.s elif isinstance(node, Num): return node.n + elif isinstance(node, Ellipsis): + return ... elif isinstance(node, Tuple): return tuple(map(_convert, node.elts)) elif isinstance(node, List):