]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Python/Python-2.7.2/Lib/ast.py
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.2 / Lib / ast.py
diff --git a/AppPkg/Applications/Python/Python-2.7.2/Lib/ast.py b/AppPkg/Applications/Python/Python-2.7.2/Lib/ast.py
deleted file mode 100644 (file)
index 4070c39..0000000
+++ /dev/null
@@ -1,311 +0,0 @@
-# -*- coding: utf-8 -*-\r
-"""\r
-    ast\r
-    ~~~\r
-\r
-    The `ast` module helps Python applications to process trees of the Python\r
-    abstract syntax grammar.  The abstract syntax itself might change with\r
-    each Python release; this module helps to find out programmatically what\r
-    the current grammar looks like and allows modifications of it.\r
-\r
-    An abstract syntax tree can be generated by passing `ast.PyCF_ONLY_AST` as\r
-    a flag to the `compile()` builtin function or by using the `parse()`\r
-    function from this module.  The result will be a tree of objects whose\r
-    classes all inherit from `ast.AST`.\r
-\r
-    A modified abstract syntax tree can be compiled into a Python code object\r
-    using the built-in `compile()` function.\r
-\r
-    Additionally various helper functions are provided that make working with\r
-    the trees simpler.  The main intention of the helper functions and this\r
-    module in general is to provide an easy to use interface for libraries\r
-    that work tightly with the python syntax (template engines for example).\r
-\r
-\r
-    :copyright: Copyright 2008 by Armin Ronacher.\r
-    :license: Python License.\r
-"""\r
-from _ast import *\r
-from _ast import __version__\r
-\r
-\r
-def parse(source, filename='<unknown>', mode='exec'):\r
-    """\r
-    Parse the source into an AST node.\r
-    Equivalent to compile(source, filename, mode, PyCF_ONLY_AST).\r
-    """\r
-    return compile(source, filename, mode, PyCF_ONLY_AST)\r
-\r
-\r
-def literal_eval(node_or_string):\r
-    """\r
-    Safely evaluate an expression node or a string containing a Python\r
-    expression.  The string or node provided may only consist of the following\r
-    Python literal structures: strings, numbers, tuples, lists, dicts, booleans,\r
-    and None.\r
-    """\r
-    _safe_names = {'None': None, 'True': True, 'False': False}\r
-    if isinstance(node_or_string, basestring):\r
-        node_or_string = parse(node_or_string, mode='eval')\r
-    if isinstance(node_or_string, Expression):\r
-        node_or_string = node_or_string.body\r
-    def _convert(node):\r
-        if isinstance(node, Str):\r
-            return node.s\r
-        elif isinstance(node, Num):\r
-            return node.n\r
-        elif isinstance(node, Tuple):\r
-            return tuple(map(_convert, node.elts))\r
-        elif isinstance(node, List):\r
-            return list(map(_convert, node.elts))\r
-        elif isinstance(node, Dict):\r
-            return dict((_convert(k), _convert(v)) for k, v\r
-                        in zip(node.keys, node.values))\r
-        elif isinstance(node, Name):\r
-            if node.id in _safe_names:\r
-                return _safe_names[node.id]\r
-        elif isinstance(node, BinOp) and \\r
-             isinstance(node.op, (Add, Sub)) and \\r
-             isinstance(node.right, Num) and \\r
-             isinstance(node.right.n, complex) and \\r
-             isinstance(node.left, Num) and \\r
-             isinstance(node.left.n, (int, long, float)):\r
-            left = node.left.n\r
-            right = node.right.n\r
-            if isinstance(node.op, Add):\r
-                return left + right\r
-            else:\r
-                return left - right\r
-        raise ValueError('malformed string')\r
-    return _convert(node_or_string)\r
-\r
-\r
-def dump(node, annotate_fields=True, include_attributes=False):\r
-    """\r
-    Return a formatted dump of the tree in *node*.  This is mainly useful for\r
-    debugging purposes.  The returned string will show the names and the values\r
-    for fields.  This makes the code impossible to evaluate, so if evaluation is\r
-    wanted *annotate_fields* must be set to False.  Attributes such as line\r
-    numbers and column offsets are not dumped by default.  If this is wanted,\r
-    *include_attributes* can be set to True.\r
-    """\r
-    def _format(node):\r
-        if isinstance(node, AST):\r
-            fields = [(a, _format(b)) for a, b in iter_fields(node)]\r
-            rv = '%s(%s' % (node.__class__.__name__, ', '.join(\r
-                ('%s=%s' % field for field in fields)\r
-                if annotate_fields else\r
-                (b for a, b in fields)\r
-            ))\r
-            if include_attributes and node._attributes:\r
-                rv += fields and ', ' or ' '\r
-                rv += ', '.join('%s=%s' % (a, _format(getattr(node, a)))\r
-                                for a in node._attributes)\r
-            return rv + ')'\r
-        elif isinstance(node, list):\r
-            return '[%s]' % ', '.join(_format(x) for x in node)\r
-        return repr(node)\r
-    if not isinstance(node, AST):\r
-        raise TypeError('expected AST, got %r' % node.__class__.__name__)\r
-    return _format(node)\r
-\r
-\r
-def copy_location(new_node, old_node):\r
-    """\r
-    Copy source location (`lineno` and `col_offset` attributes) from\r
-    *old_node* to *new_node* if possible, and return *new_node*.\r
-    """\r
-    for attr in 'lineno', 'col_offset':\r
-        if attr in old_node._attributes and attr in new_node._attributes \\r
-           and hasattr(old_node, attr):\r
-            setattr(new_node, attr, getattr(old_node, attr))\r
-    return new_node\r
-\r
-\r
-def fix_missing_locations(node):\r
-    """\r
-    When you compile a node tree with compile(), the compiler expects lineno and\r
-    col_offset attributes for every node that supports them.  This is rather\r
-    tedious to fill in for generated nodes, so this helper adds these attributes\r
-    recursively where not already set, by setting them to the values of the\r
-    parent node.  It works recursively starting at *node*.\r
-    """\r
-    def _fix(node, lineno, col_offset):\r
-        if 'lineno' in node._attributes:\r
-            if not hasattr(node, 'lineno'):\r
-                node.lineno = lineno\r
-            else:\r
-                lineno = node.lineno\r
-        if 'col_offset' in node._attributes:\r
-            if not hasattr(node, 'col_offset'):\r
-                node.col_offset = col_offset\r
-            else:\r
-                col_offset = node.col_offset\r
-        for child in iter_child_nodes(node):\r
-            _fix(child, lineno, col_offset)\r
-    _fix(node, 1, 0)\r
-    return node\r
-\r
-\r
-def increment_lineno(node, n=1):\r
-    """\r
-    Increment the line number of each node in the tree starting at *node* by *n*.\r
-    This is useful to "move code" to a different location in a file.\r
-    """\r
-    for child in walk(node):\r
-        if 'lineno' in child._attributes:\r
-            child.lineno = getattr(child, 'lineno', 0) + n\r
-    return node\r
-\r
-\r
-def iter_fields(node):\r
-    """\r
-    Yield a tuple of ``(fieldname, value)`` for each field in ``node._fields``\r
-    that is present on *node*.\r
-    """\r
-    for field in node._fields:\r
-        try:\r
-            yield field, getattr(node, field)\r
-        except AttributeError:\r
-            pass\r
-\r
-\r
-def iter_child_nodes(node):\r
-    """\r
-    Yield all direct child nodes of *node*, that is, all fields that are nodes\r
-    and all items of fields that are lists of nodes.\r
-    """\r
-    for name, field in iter_fields(node):\r
-        if isinstance(field, AST):\r
-            yield field\r
-        elif isinstance(field, list):\r
-            for item in field:\r
-                if isinstance(item, AST):\r
-                    yield item\r
-\r
-\r
-def get_docstring(node, clean=True):\r
-    """\r
-    Return the docstring for the given node or None if no docstring can\r
-    be found.  If the node provided does not have docstrings a TypeError\r
-    will be raised.\r
-    """\r
-    if not isinstance(node, (FunctionDef, ClassDef, Module)):\r
-        raise TypeError("%r can't have docstrings" % node.__class__.__name__)\r
-    if node.body and isinstance(node.body[0], Expr) and \\r
-       isinstance(node.body[0].value, Str):\r
-        if clean:\r
-            import inspect\r
-            return inspect.cleandoc(node.body[0].value.s)\r
-        return node.body[0].value.s\r
-\r
-\r
-def walk(node):\r
-    """\r
-    Recursively yield all descendant nodes in the tree starting at *node*\r
-    (including *node* itself), in no specified order.  This is useful if you\r
-    only want to modify nodes in place and don't care about the context.\r
-    """\r
-    from collections import deque\r
-    todo = deque([node])\r
-    while todo:\r
-        node = todo.popleft()\r
-        todo.extend(iter_child_nodes(node))\r
-        yield node\r
-\r
-\r
-class NodeVisitor(object):\r
-    """\r
-    A node visitor base class that walks the abstract syntax tree and calls a\r
-    visitor function for every node found.  This function may return a value\r
-    which is forwarded by the `visit` method.\r
-\r
-    This class is meant to be subclassed, with the subclass adding visitor\r
-    methods.\r
-\r
-    Per default the visitor functions for the nodes are ``'visit_'`` +\r
-    class name of the node.  So a `TryFinally` node visit function would\r
-    be `visit_TryFinally`.  This behavior can be changed by overriding\r
-    the `visit` method.  If no visitor function exists for a node\r
-    (return value `None`) the `generic_visit` visitor is used instead.\r
-\r
-    Don't use the `NodeVisitor` if you want to apply changes to nodes during\r
-    traversing.  For this a special visitor exists (`NodeTransformer`) that\r
-    allows modifications.\r
-    """\r
-\r
-    def visit(self, node):\r
-        """Visit a node."""\r
-        method = 'visit_' + node.__class__.__name__\r
-        visitor = getattr(self, method, self.generic_visit)\r
-        return visitor(node)\r
-\r
-    def generic_visit(self, node):\r
-        """Called if no explicit visitor function exists for a node."""\r
-        for field, value in iter_fields(node):\r
-            if isinstance(value, list):\r
-                for item in value:\r
-                    if isinstance(item, AST):\r
-                        self.visit(item)\r
-            elif isinstance(value, AST):\r
-                self.visit(value)\r
-\r
-\r
-class NodeTransformer(NodeVisitor):\r
-    """\r
-    A :class:`NodeVisitor` subclass that walks the abstract syntax tree and\r
-    allows modification of nodes.\r
-\r
-    The `NodeTransformer` will walk the AST and use the return value of the\r
-    visitor methods to replace or remove the old node.  If the return value of\r
-    the visitor method is ``None``, the node will be removed from its location,\r
-    otherwise it is replaced with the return value.  The return value may be the\r
-    original node in which case no replacement takes place.\r
-\r
-    Here is an example transformer that rewrites all occurrences of name lookups\r
-    (``foo``) to ``data['foo']``::\r
-\r
-       class RewriteName(NodeTransformer):\r
-\r
-           def visit_Name(self, node):\r
-               return copy_location(Subscript(\r
-                   value=Name(id='data', ctx=Load()),\r
-                   slice=Index(value=Str(s=node.id)),\r
-                   ctx=node.ctx\r
-               ), node)\r
-\r
-    Keep in mind that if the node you're operating on has child nodes you must\r
-    either transform the child nodes yourself or call the :meth:`generic_visit`\r
-    method for the node first.\r
-\r
-    For nodes that were part of a collection of statements (that applies to all\r
-    statement nodes), the visitor may also return a list of nodes rather than\r
-    just a single node.\r
-\r
-    Usually you use the transformer like this::\r
-\r
-       node = YourTransformer().visit(node)\r
-    """\r
-\r
-    def generic_visit(self, node):\r
-        for field, old_value in iter_fields(node):\r
-            old_value = getattr(node, field, None)\r
-            if isinstance(old_value, list):\r
-                new_values = []\r
-                for value in old_value:\r
-                    if isinstance(value, AST):\r
-                        value = self.visit(value)\r
-                        if value is None:\r
-                            continue\r
-                        elif not isinstance(value, AST):\r
-                            new_values.extend(value)\r
-                            continue\r
-                    new_values.append(value)\r
-                old_value[:] = new_values\r
-            elif isinstance(old_value, AST):\r
-                new_node = self.visit(old_value)\r
-                if new_node is None:\r
-                    delattr(node, field)\r
-                else:\r
-                    setattr(node, field, new_node)\r
-        return node\r