temporary identifiers are prefixed with "t_" now and the _node_setup_finished hack...
authorArmin Ronacher <armin.ronacher@active-4.com>
Mon, 19 May 2008 06:37:19 +0000 (08:37 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Mon, 19 May 2008 06:37:19 +0000 (08:37 +0200)
--HG--
branch : trunk

jinja2/compiler.py
jinja2/lexer.py
jinja2/nodes.py

index 8dd31df55941ad0eac55d3b2ac5bed6bb387cc89..e0f02f314769f64739f318363a033e32924f5e1d 100644 (file)
@@ -355,7 +355,7 @@ class CodeGenerator(NodeVisitor):
     def temporary_identifier(self):
         """Get a new unique identifier."""
         self._last_identifier += 1
-        return 't%d' % self._last_identifier
+        return 't_%d' % self._last_identifier
 
     def buffer(self, frame):
         """Enable buffering for the frame from that point onwards."""
index 2719dccb01062dcb91fdfaefe4955307172af3ca..61e1bca1022286614fd1007e8040e577d65bbeb6 100644 (file)
@@ -92,10 +92,7 @@ class Token(tuple):
         return tuple.__new__(cls, (lineno, intern(str(type)), value))
 
     def __str__(self):
-        from jinja.lexer import keywords, reverse_operators
-        if self.type in keywords:
-            return self.type
-        elif self.type in reverse_operators:
+        if self.type in reverse_operators:
             return reverse_operators[self.type]
         elif self.type is 'name':
             return self.value
index 960a5408005b814f4ef5f94fddc1d56082f9d59b..969d785910db723e9b127d16903a3ff0c88c7173 100644 (file)
@@ -48,10 +48,6 @@ _cmpop_to_func = {
 }
 
 
-# if this is `True` no new Node classes can be created.
-_node_setup_finished = False
-
-
 class Impossible(Exception):
     """Raised if the node could not perform a requested action."""
 
@@ -62,8 +58,6 @@ class NodeType(type):
     automatically forwarded to the child."""
 
     def __new__(cls, name, bases, d):
-        if __debug__ and _node_setup_finished:
-            raise TypeError('Can\'t create custom node types.')
         for attr in 'fields', 'attributes':
             storage = []
             storage.extend(getattr(bases[0], attr, ()))
@@ -808,5 +802,7 @@ class Break(Stmt):
     """Break a loop."""
 
 
-# and close down
-_node_setup_finished = True
+# make sure nobody creates custom nodes
+def _failing_new(*args, **kwargs):
+    raise TypeError('can\'t create custom node types')
+NodeType.__new__ = staticmethod(_failing_new); del _failing_new