# the current indentation
self._indentation = 0
- def get_visitor(self, node):
- """Custom nodes have their own compilation method."""
- if isinstance(node, nodes.CustomStmt):
- return node.compile
- return NodeVisitor.get_visitor(self, node)
-
def temporary_identifier(self):
"""Get a new unique identifier."""
self._last_identifier += 1
options.get('comment_start_string', '{#'),
options.get('comment_end_string', '#}'),
options.get('line_statement_prefix') or None,
- options.get('trim_blocks', '').lower() in ('1', 'on', 'yes', 'true')
+ options.get('trim_blocks', '').lower() in ('1', 'on', 'yes', 'true'),
+ extensions=[x.strip() for x in options.get('extensions', '')
+ .split(',')] + [TransExtension]
)
node = environment.parse(fileobj.read().decode(encoding))
for lineno, func, message in extract_from_ast(node, keywords):
def __new__(cls, name, bases, d):
for attr in 'fields', 'attributes':
storage = []
- for base in bases:
- storage.extend(getattr(base, attr, ()))
+ storage.extend(getattr(bases[0], attr, ()))
storage.extend(d.get(attr, ()))
- assert len(storage) == len(set(storage))
+ assert len(bases) == 1, 'multiple inheritance not allowed'
+ assert len(storage) == len(set(storage)), 'layout conflict'
d[attr] = tuple(storage)
- rv = type.__new__(cls, name, bases, d)
-
- # unless the node is a subclass of `CustomNode` it may not
- # be defined in any other module than the jinja2.nodes module.
- # the reason for this is that the we don't want users to take
- # advantage of the fact that the parser is using the node name
- # only as callback name for non custom nodes. This could lead
- # to broken code in the future and is disallowed because of this.
- if rv.__module__ != 'jinja2.nodes' and not \
- isinstance(rv, CustomStmt):
- raise TypeError('non builtin node %r is not a subclass of '
- 'CustomStmt.' % node.__class__.__name__)
- return rv
+ return type.__new__(cls, name, bases, d)
class Node(object):
"""Nodes that exist in a specific context only."""
-class CustomStmt(Stmt):
- """Custom statements must extend this node."""
-
- def compile(self, compiler):
- """The compiler calls this method to get the python sourcecode
- for the statement.
- """
-
-
class Template(Node):
"""Node that represents a template."""
fields = ('body',)