X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=scripts%2Fjinja2%2Fnodes.py;h=40ea2858af9027c3d8d32d1b229e1c92eb9dee48;hb=65f2648ba9eb6b3cdd7f0098f7a4e1882fab152a;hp=405622a9de0b940aa7f7f1d2883d783dc9a58ae3;hpb=279822e9e2a4f26deaf67b5fe8423b27837a75d7;p=libfirm diff --git a/scripts/jinja2/nodes.py b/scripts/jinja2/nodes.py index 405622a9d..40ea2858a 100644 --- a/scripts/jinja2/nodes.py +++ b/scripts/jinja2/nodes.py @@ -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')