Fixed a failing testcase. (Error caused by constant folding of undefined

values)

--HG--
branch : trunk
This commit is contained in:
Armin Ronacher 2010-05-23 22:58:28 +02:00
parent 93d2df782d
commit 5a5ce730ee
2 changed files with 14 additions and 14 deletions

View File

@ -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:

View File

@ -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.