Jinja2 Changelog
================
+Version 2.9.6
+-------------
+(bugfix release, release date to be decided)
+
+- Fixed custom context behavior in fast resolve mode (#675)
+
Version 2.9.5
-------------
(bugfix release, released on January 28th 2017)
import sys
from itertools import chain
+from types import MethodType
+
from jinja2.nodes import EvalContext, _context_function_types
from jinja2.utils import Markup, soft_unicode, escape, missing, concat, \
internalcode, object_type_repr, evalcontextfunction
# In case we detect the fast resolve mode we can set up an alias
# here that bypasses the legacy code logic.
if self._fast_resolve_mode:
- self.resolve_or_missing = resolve_or_missing
+ self.resolve_or_missing = MethodType(resolve_or_missing, self)
def super(self, name, current):
"""Render a parent block."""
assert repr(t) == "('foo', [1, 2])"
assert str(t) == "('foo', [1, 2])"
+ def test_custom_context(self, env):
+ from jinja2.runtime import Context
+
+ class MyContext(Context):
+ pass
+
+ class MyEnvironment(Environment):
+ context_class = MyContext
+
+ loader = DictLoader({'base': '{{ foobar }}',
+ 'test': '{% extends "base" %}'})
+ env = MyEnvironment(loader=loader)
+ assert env.get_template('test').render(foobar='test') == 'test'
+
def test_legacy_custom_context(self, env):
from jinja2.runtime import Context, Undefined, missing