:class:`nodes.ScopedEvalContextModifier` from an extension, not on the
eval context object itself.
+.. autoclass:: nodes.EvalContext
+
+ .. attribute:: autoescape
+
+ `True` or `False` depending on if autoescaping is active or not.
+
+ .. attribute:: volatile
+
+ `True` if the compiler cannot evaluate some expressions at compile
+ time. At runtime this should always be `False`.
+
+
.. _writing-tests:
Custom Tests
class EvalContext(object):
- """Holds evaluation time information"""
+ """Holds evaluation time information. Custom attributes can be attached
+ to it in extensions.
+ """
def __init__(self, environment):
self.autoescape = environment.autoescape
class EvalContextModifier(Stmt):
- """Modifies the eval context"""
+ """Modifies the eval context. For each option that should be modified,
+ a :class:`Keyword` has to be added to the :attr:`options` list.
+
+ Example to change the `autoescape` setting::
+
+ EvalContextModifier(options=[Keyword('autoescape', Const(True))])
+ """
fields = ('options',)
class ScopedEvalContextModifier(EvalContextModifier):
- """Modifies the eval context and reverts it later."""
+ """Modifies the eval context and reverts it later. Works exactly like
+ :class:`EvalContextModifier` but will only modify the
+ :class:`EvalContext` for nodes in the :attr:`body`.
+ """
fields = ('body',)