lower_mode_b: handle BadB
[libfirm] / scripts / jinja2 / nodes.py
index 405622a..40ea285 100644 (file)
@@ -9,7 +9,7 @@
     `get_nodes` used by the parser and translator in order to normalize
     python and jinja nodes.
 
-    :copyright: 2008 by Armin Ronacher.
+    :copyright: (c) 2010 by the Jinja Team.
     :license: BSD, see LICENSE for more details.
 """
 import operator
@@ -146,7 +146,9 @@ class Node(object):
             return result
 
     def find_all(self, node_type):
-        """Find all the nodes of a given type."""
+        """Find all the nodes of a given type.  If the type is a tuple,
+        the check is performed for any of the tuple items.
+        """
         for child in self.iter_child_nodes():
             if isinstance(child, node_type):
                 yield child
@@ -269,12 +271,12 @@ class FilterBlock(Stmt):
 
 class Block(Stmt):
     """A node that represents a block."""
-    fields = ('name', 'body')
+    fields = ('name', 'body', 'scoped')
 
 
 class Include(Stmt):
     """A node that represents the include tag."""
-    fields = ('template', 'with_context')
+    fields = ('template', 'with_context', 'ignore_missing')
 
 
 class Import(Stmt):
@@ -492,13 +494,18 @@ class Filter(Expr):
     def as_const(self, obj=None):
         if self.node is obj is None:
             raise Impossible()
-        filter = self.environment.filters.get(self.name)
-        if filter is None or getattr(filter, 'contextfilter', False):
+        # we have to be careful here because we call filter_ below.
+        # if this variable would be called filter, 2to3 would wrap the
+        # call in a list beause it is assuming we are talking about the
+        # builtin filter function here which no longer returns a list in
+        # python 3.  because of that, do not rename filter_ to filter!
+        filter_ = self.environment.filters.get(self.name)
+        if filter_ is None or getattr(filter_, 'contextfilter', False):
             raise Impossible()
         if obj is None:
             obj = self.node.as_const()
         args = [x.as_const() for x in self.args]
-        if getattr(filter, 'environmentfilter', False):
+        if getattr(filter_, 'environmentfilter', False):
             args.insert(0, self.environment)
         kwargs = dict(x.as_const() for x in self.kwargs)
         if self.dyn_args is not None:
@@ -512,7 +519,7 @@ class Filter(Expr):
             except:
                 raise Impossible()
         try:
-            return filter(obj, *args, **kwargs)
+            return filter_(obj, *args, **kwargs)
         except:
             raise Impossible()
 
@@ -749,7 +756,7 @@ class InternalName(Expr):
     yourself but the parser provides a
     :meth:`~jinja2.parser.Parser.free_identifier` method that creates
     a new identifier for you.  This identifier is not available from the
-    template and is not threated specially by the compiler.
+    template and is not treated specially by the compiler.
     """
     fields = ('name',)
 
@@ -778,6 +785,11 @@ class Break(Stmt):
     """Break a loop."""
 
 
+class Scope(Stmt):
+    """An artificial scope."""
+    fields = ('body',)
+
+
 # make sure nobody creates custom nodes
 def _failing_new(*args, **kwargs):
     raise TypeError('can\'t create custom node types')