Home | History | Annotate | Download | only in jinja2

Lines Matching refs:node

11 from jinja2.nodes import Node
16 node found. The visitor functions may return values which will be
20 class name of the node. So a `TryFinally` node visit function would
22 the `get_visitor` function. If no visitor function exists for a node
26 def get_visitor(self, node):
27 """Return the visitor function for this node or `None` if no visitor
28 exists for this node. In that case the generic visit function is
31 method = 'visit_' + node.__class__.__name__
34 def visit(self, node, *args, **kwargs):
35 """Visit a node."""
36 f = self.get_visitor(node)
38 return f(node, *args, **kwargs)
39 return self.generic_visit(node, *args, **kwargs)
41 def generic_visit(self, node, *args, **kwargs):
42 """Called if no explicit visitor function exists for a node."""
43 for node in node.iter_child_nodes():
44 self.visit(node, *args, **kwargs)
51 visitor functions to replace or remove the old node. If the return
52 value of the visitor function is `None` the node will be removed
54 value. The return value may be the original node in which case no
58 def generic_visit(self, node, *args, **kwargs):
59 for field, old_value in node.iter_fields():
63 if isinstance(value, Node):
67 elif not isinstance(value, Node):
72 elif isinstance(old_value, Node):
75 delattr(node, field)
77 setattr(node, field, new_node)
78 return node
80 def visit_list(self, node, *args, **kwargs):
84 rv = self.visit(node, *args, **kwargs)