From e9411b41890c0882236918297fb2e77a3bf60cd1 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Thu, 15 May 2008 16:22:07 +0200 Subject: [PATCH] fixed bug with parameter parsing --HG-- branch : trunk --- jinja2/compiler.py | 7 ++++--- jinja2/parser.py | 1 + jinja2/runtime.py | 3 +-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/jinja2/compiler.py b/jinja2/compiler.py index 7a2ea4c..30054e7 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -254,8 +254,10 @@ class FrameIdentifierVisitor(NodeVisitor): def visit_Name(self, node): """All assignments to names go through this function.""" - if node.ctx in ('store', 'param'): + if node.ctx == 'store': self.identifiers.declared_locally.add(node.name) + elif node.ctx == 'param': + self.identifiers.declared_parameter.add(node.name) elif node.ctx == 'load' and not \ self.identifiers.is_declared(node.name, self.hard_scope): self.identifiers.undeclared.add(node.name) @@ -271,8 +273,7 @@ class FrameIdentifierVisitor(NodeVisitor): if isinstance(node.arg, nodes.Const) and \ isinstance(node.arg.value, basestring) and \ ((isinstance(node.node, nodes.Name) and - node.node.name not in (self.identifiers.declared_locally | - self.identifiers.declared_parameter)) or \ + node.node.name not in (self.identifiers.declared_locally)) or node.node in self.identifiers.static_subscribes): if node in self.identifiers.static_subscribes: self.identifiers.static_subscribes[node] += 1 diff --git a/jinja2/parser.py b/jinja2/parser.py index f2a129c..19ee166 100644 --- a/jinja2/parser.py +++ b/jinja2/parser.py @@ -220,6 +220,7 @@ class Parser(object): if args: self.stream.expect('comma') arg = self.parse_assign_target(name_only=True) + arg.set_ctx('param') if self.stream.skip_if('assign'): defaults.append(self.parse_expression()) args.append(arg) diff --git a/jinja2/runtime.py b/jinja2/runtime.py index cbe7115..b5f0783 100644 --- a/jinja2/runtime.py +++ b/jinja2/runtime.py @@ -121,8 +121,7 @@ class Context(object): return dict(self.parent, **self.vars) def _all(meth): - def proxy(self): - return getattr(self.get_all(), meth)() + proxy = lambda self: getattr(self.get_all(), meth)() proxy.__doc__ = getattr(dict, meth).__doc__ proxy.__name__ = meth return proxy -- 2.26.2