From: Armin Ronacher Date: Sun, 23 May 2010 20:58:28 +0000 (+0200) Subject: Fixed a failing testcase. (Error caused by constant folding of undefined X-Git-Tag: 2.5~18 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5a5ce730ee6e49aad63933efec9b1b54ed1e42a0;p=jinja2.git Fixed a failing testcase. (Error caused by constant folding of undefined values) --HG-- branch : trunk --- diff --git a/jinja2/nodes.py b/jinja2/nodes.py index c8bb047..11247d8 100644 --- a/jinja2/nodes.py +++ b/jinja2/nodes.py @@ -15,7 +15,11 @@ import operator from itertools import chain, izip from collections import deque -from jinja2.utils import Markup +from jinja2.utils import Markup, MethodType, FunctionType + + +#: the types we support for context functions +_context_function_types = (FunctionType, MethodType) _binop_to_func = { @@ -585,12 +589,13 @@ class Call(Expr): # don't evaluate context functions args = [x.as_const(eval_ctx) for x in self.args] - if getattr(obj, 'contextfunction', False): - raise Impossible() - elif getattr(obj, 'evalcontextfunction', False): - args.insert(0, eval_ctx) - elif getattr(obj, 'environmentfunction', False): - args.insert(0, self.environment) + if isinstance(obj, _context_function_types): + if getattr(obj, 'contextfunction', False): + raise Impossible() + elif getattr(obj, 'evalcontextfunction', False): + args.insert(0, eval_ctx) + elif getattr(obj, 'environmentfunction', False): + args.insert(0, self.environment) kwargs = dict(x.as_const(eval_ctx) for x in self.kwargs) if self.dyn_args is not None: diff --git a/jinja2/runtime.py b/jinja2/runtime.py index 1961e9f..a89812f 100644 --- a/jinja2/runtime.py +++ b/jinja2/runtime.py @@ -10,10 +10,9 @@ """ import sys from itertools import chain, imap -from jinja2.nodes import EvalContext +from jinja2.nodes import EvalContext, _context_function_types from jinja2.utils import Markup, partial, soft_unicode, escape, missing, \ - concat, MethodType, FunctionType, internalcode, next, \ - object_type_repr + concat, internalcode, next, object_type_repr from jinja2.exceptions import UndefinedError, TemplateRuntimeError, \ TemplateNotFound @@ -24,10 +23,6 @@ __all__ = ['LoopContext', 'TemplateReference', 'Macro', 'Markup', 'markup_join', 'unicode_join', 'to_string', 'TemplateNotFound'] - -#: the types we support for context functions -_context_function_types = (FunctionType, MethodType) - #: the name of the function that is used to convert something into #: a string. 2to3 will adopt that automatically and the generated #: code can take advantage of it.