:license: BSD, see LICENSE for more details.
"""
import operator
-from itertools import chain, izip
+from itertools import chain
from collections import deque
from jinja2.utils import Markup, MethodType, FunctionType
+import collections
#: the types we support for context functions
def __init__(self, environment, template_name=None):
self.environment = environment
- if callable(environment.autoescape):
+ if isinstance(environment.autoescape, collections.Callable):
self.autoescape = environment.autoescape(template_name)
else:
self.autoescape = environment.autoescape
return ctx
-class Node(object):
+class Node(object, metaclass=NodeType):
"""Baseclass for all Jinja2 nodes. There are a number of nodes available
of different types. There are three major types:
The `environment` attribute is set at the end of the parsing process for
all nodes automatically.
"""
- __metaclass__ = NodeType
fields = ()
attributes = ('lineno', 'environment')
abstract = True
len(self.fields),
len(self.fields) != 1 and 's' or ''
))
- for name, arg in izip(self.fields, fields):
+ for name, arg in zip(self.fields, fields):
setattr(self, name, arg)
for attr in self.attributes:
setattr(self, attr, attributes.pop(attr, None))
if attributes:
raise TypeError('unknown attribute %r' %
- iter(attributes).next())
+ next(iter(attributes)))
def iter_fields(self, exclude=None, only=None):
"""This method iterates over all fields that are defined and yields
constant value in the generated code, otherwise it will raise
an `Impossible` exception.
"""
- from compiler import has_safe_repr
+ from .compiler import has_safe_repr
if not has_safe_repr(value):
raise Impossible()
return cls(value, lineno=lineno, environment=environment)
def as_const(self, eval_ctx=None):
eval_ctx = get_eval_context(self, eval_ctx)
- return ''.join(unicode(x.as_const(eval_ctx)) for x in self.nodes)
+ return ''.join(str(x.as_const(eval_ctx)) for x in self.nodes)
class Compare(Expr):