From: Armin Ronacher Date: Mon, 21 Apr 2008 05:55:52 +0000 (+0200) Subject: removed custom nodes again X-Git-Tag: 2.0rc1~142 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7324eb85c3c4c58a9f864a51c4b3f30586bdb751;p=jinja2.git removed custom nodes again --HG-- branch : trunk --- diff --git a/jinja2/compiler.py b/jinja2/compiler.py index f5e0b48..871728f 100644 --- a/jinja2/compiler.py +++ b/jinja2/compiler.py @@ -280,12 +280,6 @@ class CodeGenerator(NodeVisitor): # 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 diff --git a/jinja2/i18n.py b/jinja2/i18n.py index ef932d9..3e1392c 100644 --- a/jinja2/i18n.py +++ b/jinja2/i18n.py @@ -75,7 +75,9 @@ def babel_extract(fileobj, keywords, comment_tags, options): 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): diff --git a/jinja2/nodes.py b/jinja2/nodes.py index 8c58959..992752a 100644 --- a/jinja2/nodes.py +++ b/jinja2/nodes.py @@ -58,24 +58,12 @@ class NodeType(type): 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): @@ -205,15 +193,6 @@ class Helper(Node): """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',)