# Path: jinja2/nodes.py
# class Node(object):
#     """Baseclass for all Jinja2 nodes.  There are a number of nodes available
#     of different types.  There are three major types:
# 
#     -   :class:`Stmt`: statements
#     -   :class:`Expr`: expressions
#     -   :class:`Helper`: helper nodes
#     -   :class:`Template`: the outermost wrapper node
# 
#     All nodes have fields and attributes.  Fields may be other nodes, lists,
#     or arbitrary values.  Fields are passed to the constructor as regular
#     positional arguments, attributes as keyword arguments.  Each node has
#     two attributes: `lineno` (the line number of the node) and `environment`.
#     The `environment` attribute is set at the end of the parsing process for
#     all nodes automatically.
#     """
#     __metaclass__ = NodeType
#     fields = ()
#     attributes = ('lineno', 'environment')
#     abstract = True
# 
#     def __init__(self, *fields, **attributes):
#         if self.abstract:
#             raise TypeError('abstract nodes are not instanciable')
#         if fields:
#             if len(fields) != len(self.fields):
#                 if not self.fields:
#                     raise TypeError('%r takes 0 arguments' %
#                                     self.__class__.__name__)
#                 raise TypeError('%r takes 0 or %d argument%s' % (
#                     self.__class__.__name__,
#                     len(self.fields),
#                     len(self.fields) != 1 and 's' or ''
#                 ))
#             for name, arg in izip(self.fields, fields):
#                 setattr(self, name, arg)
#         for attr in self.attributes:
#             setattr(self, attr, attributes.pop(attr, None))
#         if attributes:
#             raise TypeError('unknown attribute %r' %
#                             iter(attributes).next())
# 
#     def iter_fields(self, exclude=None, only=None):
#         """This method iterates over all fields that are defined and yields
#         ``(key, value)`` tuples.  Per default all fields are returned, but
#         it's possible to limit that to some fields by providing the `only`
#         parameter or to exclude some using the `exclude` parameter.  Both
#         should be sets or tuples of field names.
#         """
#         for name in self.fields:
#             if (exclude is only is None) or \
#                (exclude is not None and name not in exclude) or \
#                (only is not None and name in only):
#                 try:
#                     yield name, getattr(self, name)
#                 except AttributeError:
#                     pass
# 
#     def iter_child_nodes(self, exclude=None, only=None):
#         """Iterates over all direct child nodes of the node.  This iterates
#         over all fields and yields the values of they are nodes.  If the value
#         of a field is a list all the nodes in that list are returned.
#         """
#         for field, item in self.iter_fields(exclude, only):
#             if isinstance(item, list):
#                 for n in item:
#                     if isinstance(n, Node):
#                         yield n
#             elif isinstance(item, Node):
#                 yield item
# 
#     def find(self, node_type):
#         """Find the first node of a given type.  If no such node exists the
#         return value is `None`.
#         """
#         for result in self.find_all(node_type):
#             return result
# 
#     def find_all(self, node_type):
#         """Find all the nodes of a given type."""
#         for child in self.iter_child_nodes():
#             if isinstance(child, node_type):
#                 yield child
#             for result in child.find_all(node_type):
#                 yield result
# 
#     def set_ctx(self, ctx):
#         """Reset the context of a node and all child nodes.  Per default the
#         parser will all generate nodes that have a 'load' context as it's the
#         most common one.  This method is used in the parser to set assignment
#         targets and other nodes to a store context.
#         """
#         todo = deque([self])
#         while todo:
#             node = todo.popleft()
#             if 'ctx' in node.fields:
#                 node.ctx = ctx
#             todo.extend(node.iter_child_nodes())
#         return self
# 
#     def set_lineno(self, lineno, override=False):
#         """Set the line numbers of the node and children."""
#         todo = deque([self])
#         while todo:
#             node = todo.popleft()
#             if 'lineno' in node.attributes:
#                 if node.lineno is None or override:
#                     node.lineno = lineno
#             todo.extend(node.iter_child_nodes())
#         return self
# 
#     def set_environment(self, environment):
#         """Set the environment for all nodes."""
#         todo = deque([self])
#         while todo:
#             node = todo.popleft()
#             node.environment = environment
#             todo.extend(node.iter_child_nodes())
#         return self
# 
#     def __eq__(self, other):
#         return type(self) is type(other) and \
#                tuple(self.iter_fields()) == tuple(other.iter_fields())
# 
#     def __ne__(self, other):
#         return not self.__eq__(other)
# 
#     def __repr__(self):
#         return '%s(%s)' % (
#             self.__class__.__name__,
#             ', '.join('%s=%r' % (arg, getattr(self, arg, None)) for
#                       arg in self.fields)
#         )


from jinja2.nodes import Node
        """Called if no explicit visitor function exists for a node."""
        for node in node.iter_child_nodes():
            self.visit(node, *args, **kwargs)


class NodeTransformer(NodeVisitor):
    """Walks the abstract syntax tree and allows modifications of nodes.

    The `NodeTransformer` will walk the AST and use the return value of the
    visitor functions to replace or remove the old node.  If the return
    value of the visitor function is `None` the node will be removed
    from the previous location otherwise it's replaced with the return
    value.  The return value may be the original node in which case no
    replacement takes place.
    """

    def generic_visit(self, node, *args, **kwargs):
        for field, old_value in node.iter_fields():
            if isinstance(old_value, list):
                new_values = []
                for value in old_value:
                    if isinstance(value, Node):
                        value = self.visit(value, *args, **kwargs)
                        if value is None:
                            continue
                        elif not isinstance(value, Node):
                            new_values.extend(value)
                            continue
                    new_values.append(value)
                old_value[:] = new_values

# Path: jinja2/nodes.py
# class Node(object):
#     """Baseclass for all Jinja2 nodes.  There are a number of nodes available
#     of different types.  There are three major types:
# 
#     -   :class:`Stmt`: statements
#     -   :class:`Expr`: expressions
#     -   :class:`Helper`: helper nodes
#     -   :class:`Template`: the outermost wrapper node
# 
#     All nodes have fields and attributes.  Fields may be other nodes, lists,
#     or arbitrary values.  Fields are passed to the constructor as regular
#     positional arguments, attributes as keyword arguments.  Each node has
#     two attributes: `lineno` (the line number of the node) and `environment`.
#     The `environment` attribute is set at the end of the parsing process for
#     all nodes automatically.
#     """
#     __metaclass__ = NodeType
#     fields = ()
#     attributes = ('lineno', 'environment')
#     abstract = True
# 
#     def __init__(self, *fields, **attributes):
#         if self.abstract:
#             raise TypeError('abstract nodes are not instanciable')
#         if fields:
#             if len(fields) != len(self.fields):
#                 if not self.fields:
#                     raise TypeError('%r takes 0 arguments' %
#                                     self.__class__.__name__)
#                 raise TypeError('%r takes 0 or %d argument%s' % (
#                     self.__class__.__name__,
#                     len(self.fields),
#                     len(self.fields) != 1 and 's' or ''
#                 ))
#             for name, arg in izip(self.fields, fields):
#                 setattr(self, name, arg)
#         for attr in self.attributes:
#             setattr(self, attr, attributes.pop(attr, None))
#         if attributes:
#             raise TypeError('unknown attribute %r' %
#                             iter(attributes).next())
# 
#     def iter_fields(self, exclude=None, only=None):
#         """This method iterates over all fields that are defined and yields
#         ``(key, value)`` tuples.  Per default all fields are returned, but
#         it's possible to limit that to some fields by providing the `only`
#         parameter or to exclude some using the `exclude` parameter.  Both
#         should be sets or tuples of field names.
#         """
#         for name in self.fields:
#             if (exclude is only is None) or \
#                (exclude is not None and name not in exclude) or \
#                (only is not None and name in only):
#                 try:
#                     yield name, getattr(self, name)
#                 except AttributeError:
#                     pass
# 
#     def iter_child_nodes(self, exclude=None, only=None):
#         """Iterates over all direct child nodes of the node.  This iterates
#         over all fields and yields the values of they are nodes.  If the value
#         of a field is a list all the nodes in that list are returned.
#         """
#         for field, item in self.iter_fields(exclude, only):
#             if isinstance(item, list):
#                 for n in item:
#                     if isinstance(n, Node):
#                         yield n
#             elif isinstance(item, Node):
#                 yield item
# 
#     def find(self, node_type):
#         """Find the first node of a given type.  If no such node exists the
#         return value is `None`.
#         """
#         for result in self.find_all(node_type):
#             return result
# 
#     def find_all(self, node_type):
#         """Find all the nodes of a given type."""
#         for child in self.iter_child_nodes():
#             if isinstance(child, node_type):
#                 yield child
#             for result in child.find_all(node_type):
#                 yield result
# 
#     def set_ctx(self, ctx):
#         """Reset the context of a node and all child nodes.  Per default the
#         parser will all generate nodes that have a 'load' context as it's the
#         most common one.  This method is used in the parser to set assignment
#         targets and other nodes to a store context.
#         """
#         todo = deque([self])
#         while todo:
#             node = todo.popleft()
#             if 'ctx' in node.fields:
#                 node.ctx = ctx
#             todo.extend(node.iter_child_nodes())
#         return self
# 
#     def set_lineno(self, lineno, override=False):
#         """Set the line numbers of the node and children."""
#         todo = deque([self])
#         while todo:
#             node = todo.popleft()
#             if 'lineno' in node.attributes:
#                 if node.lineno is None or override:
#                     node.lineno = lineno
#             todo.extend(node.iter_child_nodes())
#         return self
# 
#     def set_environment(self, environment):
#         """Set the environment for all nodes."""
#         todo = deque([self])
#         while todo:
#             node = todo.popleft()
#             node.environment = environment
#             todo.extend(node.iter_child_nodes())
#         return self
# 
#     def __eq__(self, other):
#         return type(self) is type(other) and \
#                tuple(self.iter_fields()) == tuple(other.iter_fields())
# 
#     def __ne__(self, other):
#         return not self.__eq__(other)
# 
#     def __repr__(self):
#         return '%s(%s)' % (
#             self.__class__.__name__,
#             ', '.join('%s=%r' % (arg, getattr(self, arg, None)) for
#                       arg in self.fields)
#         )


# Path: jinja2/visitor.py
from jinja2.nodes import Node

        """Called if no explicit visitor function exists for a node."""
        for node in node.iter_child_nodes():
            self.visit(node, *args, **kwargs)


class NodeTransformer(NodeVisitor):
    """Walks the abstract syntax tree and allows modifications of nodes.

    The `NodeTransformer` will walk the AST and use the return value of the
    visitor functions to replace or remove the old node.  If the return
    value of the visitor function is `None` the node will be removed
    from the previous location otherwise it's replaced with the return
    value.  The return value may be the original node in which case no
    replacement takes place.
    """

    def generic_visit(self, node, *args, **kwargs):
        for field, old_value in node.iter_fields():
            if isinstance(old_value, list):
                new_values = []
                for value in old_value:
                    if isinstance(value, Node):
                        value = self.visit(value, *args, **kwargs)
                        if value is None:
                            continue
                        elif not isinstance(value, Node):
                            new_values.extend(value)
                            continue
                    new_values.append(value)
                old_value[:] = new_values

            elif isinstance(old_value, Node):