Run `./2to3.py -w jinja2`
[jinja2.git] / jinja2 / nodes.py
index f9da1da5a295f364635ece012a746d3e3afc8814..cc2e3dfa7fa0165d1f7b1d4697b12c212f2f6603 100644 (file)
     :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
@@ -78,7 +79,7 @@ class EvalContext(object):
 
     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
@@ -102,7 +103,7 @@ def get_eval_context(node, ctx):
     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:
 
@@ -118,7 +119,6 @@ class Node(object):
     The `environment` attribute is set at the end of the parsing process for
     all nodes automatically.
     """
-    __metaclass__ = NodeType
     fields = ()
     attributes = ('lineno', 'environment')
     abstract = True
@@ -136,13 +136,13 @@ class Node(object):
                     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
@@ -440,7 +440,7 @@ class Const(Literal):
         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)
@@ -687,7 +687,7 @@ class Concat(Expr):
 
     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):