`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
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
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):
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:
except:
raise Impossible()
try:
- return filter(obj, *args, **kwargs)
+ return filter_(obj, *args, **kwargs)
except:
raise Impossible()
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',)
"""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')