Home | History | Annotate | Download | only in mako

Lines Matching refs:node

24 def compile(node,
38 """Generate module source code given a parsetree node,
65 node)
100 def __init__(self, printer, compiler, node):
103 self.node = node
105 self.in_def = isinstance(node, (parsetree.DefTag, parsetree.BlockTag))
108 name = "render_%s" % node.funcname
109 args = node.get_argument_expressions()
110 filtered = len(node.filter_args.args) > 0
111 buffered = eval(node.attributes.get('buffered', 'False'))
112 cached = eval(node.attributes.get('cached', 'False'))
115 if node.is_block and not node.is_anonymous:
140 pagetag or node,
145 for node in defs:
146 _GenerateRenderMethod(printer, compiler, node)
184 def visitInheritTag(s, node):
185 inherit.append(node)
186 def visitNamespaceTag(s, node):
187 namespaces[node.name] = node
188 def visitPageTag(s, node):
189 self.compiler.pagetag = node
190 def visitCode(s, node):
191 if node.ismodule:
192 module_code.append(node)
195 for n in self.node.nodes:
241 main_identifiers = module_identifiers.branch(self.node)
267 def write_render_callable(self, node, name, args, buffered, filtered,
274 decorator = node.decorator
279 self.printer.start_source(node.lineno)
290 self.compiler.identifiers.branch(self.node))
291 if (not self.in_def or self.node.is_block) and '**pageargs' in args:
306 for n in self.node.nodes:
309 self.write_def_finish(self.node, buffered, filtered, cached)
314 node, name,
325 def write_inherit(self, node):
332 (node.parsed_attributes['file']),
350 for node in namespaces.values():
351 if 'import' in node.attributes:
353 self.printer.start_source(node.lineno)
354 if len(node.nodes):
357 identifiers = self.compiler.identifiers.branch(node)
360 def visitDefTag(s, node):
361 s.visitDefOrBase(node)
363 def visitBlockTag(s, node):
364 s.visitDefOrBase(node)
366 def visitDefOrBase(s, node):
367 if node.is_anonymous:
371 **node.exception_kwargs
373 self.write_inline_def(node, identifiers, nested=False)
374 export.append(node.funcname)
376 for n in node.nodes:
385 if 'file' in node.parsed_attributes:
392 node.name,
393 node.parsed_attributes.get('file', 'None'),
397 elif 'module' in node.parsed_attributes:
404 node.name,
406 node.parsed_attributes.get(
416 node.name,
420 if eval(node.attributes.get('inheritable', "False")):
421 self.printer.writeline("context['self'].%s = ns" % (node.name))
424 "context.namespaces[(__name__, %s)] = ns" % repr(node.name))
556 def write_def_decl(self, node, identifiers):
558 funcname = node.funcname
559 namedecls = node.get_argument_expressions()
560 nameargs = node.get_argument_expressions(as_call=True)
573 def write_inline_def(self, node, identifiers, nested):
576 namedecls = node.get_argument_expressions()
578 decorator = node.decorator
583 "def %s(%s):" % (node.funcname, ",".join(namedecls)))
584 filtered = len(node.filter_args.args) > 0
585 buffered = eval(node.attributes.get('buffered', 'False'))
586 cached = eval(node.attributes.get('cached', 'False'))
597 identifiers = identifiers.branch(node, nested=nested)
602 for n in node.nodes:
606 self.write_def_finish(node, buffered, filtered, cached)
609 self.write_cache_decorator(node, node.funcname,
613 def write_def_finish(self, node, buffered, filtered, cached,
653 s = self.create_filter_callable(node.filter_args.args, s,
772 def visitExpression(self, node):
773 self.printer.start_source(node.lineno)
774 if len(node.escapes) or \
781 s = self.create_filter_callable(node.escapes_code.args,
782 "%s" % node.text, True)
785 self.printer.writeline("__M_writer(%s)" % node.text)
787 def visitControlLine(self, node):
788 if node.isend:
790 if node.has_loop_context:
795 self.printer.start_source(node.lineno)
796 if self.compiler.enable_loop and node.keyword == 'for':
797 text = mangle_mako_loop(node, self.printer)
799 text = node.text
801 children = node.get_children()
811 compat.all((node.is_ternary(c.keyword) or c.isend)
816 def visitText(self, node):
817 self.printer.start_source(node.lineno)
818 self.printer.writeline("__M_writer(%s)" % repr(node.content))
820 def visitTextTag(self, node):
821 filtered = len(node.filter_args.args) > 0
827 for n in node.nodes:
835 node.filter_args.args,
841 def visitCode(self, node):
842 if not node.ismodule:
843 self.printer.start_source(node.lineno)
844 self.printer.write_indented_block(node.text)
857 ','.join([repr(x) for x in node.declared_identifiers()]))
859 def visitIncludeTag(self, node):
860 self.printer.start_source(node.lineno)
861 args = node.attributes.get('args')
865 (node.parsed_attributes['file'], args))
869 (node.parsed_attributes['file']))
871 def visitNamespaceTag(self, node):
874 def visitDefTag(self, node):
877 def visitBlockTag(self, node):
878 if node.is_anonymous:
879 self.printer.writeline("%s()" % node.funcname)
881 nameargs = node.get_argument_expressions(as_call=True)
885 % node.funcname)
887 "context['self'].%s(%s)" % (node.funcname, ",".join(nameargs)))
890 def visitCallNamespaceTag(self, node):
894 self.visitCallTag(node)
896 def visitCallTag(self, node):
899 callable_identifiers = self.identifiers.branch(node, nested=True)
900 body_identifiers = callable_identifiers.branch(node, nested=False)
909 def visitDefTag(s, node):
910 s.visitDefOrBase(node)
912 def visitBlockTag(s, node):
913 s.visitDefOrBase(node)
915 def visitDefOrBase(s, node):
916 self.write_inline_def(node, callable_identifiers, nested=False)
917 if not node.is_anonymous:
918 export.append(node.funcname)
921 if node.funcname in body_identifiers.closuredefs:
922 del body_identifiers.closuredefs[node.funcname]
925 for n in node.nodes:
929 bodyargs = node.body_decl.get_argument_expressions()
943 for n in node.nodes:
947 self.write_def_finish(node, buffered, False, False, callstack=False)
960 self.printer.start_source(node.lineno)
963 [], node.expression, True),
972 def __init__(self, compiler, node=None, parent=None, nested=False):
976 if isinstance(node, parsetree.NamespaceTag):
1023 self.node = node
1025 if node is not None:
1026 node.accept_visitor(self)
1036 def branch(self, node, **kwargs):
1037 """create a new Identifiers for a new Node, with
1040 return _Identifiers(self.compiler, node, self, **kwargs)
1058 def check_declared(self, node):
1060 and declared identifiers of the given node."""
1062 for ident in node.undeclared_identifiers():
1066 for ident in node.declared_identifiers():
1074 def visitExpression(self, node):
1075 self.check_declared(node)
1077 def visitControlLine(self, node):
1078 self.check_declared(node)
1080 def visitCode(self, node):
1081 if not node.ismodule:
1082 self.check_declared(node)
1084 node.declared_identifiers())
1086 def visitNamespaceTag(self, node):
1090 if self.node is node:
1091 for n in node.nodes:
1094 def _check_name_exists(self, collection, node):
1095 existing = collection.get(node.funcname)
1096 collection[node.funcname] = node
1098 existing is not node and \
1099 (node.is_block or existing.is_block):
1103 node.funcname, **node.exception_kwargs)
1105 def visitDefTag(self, node):
1106 if node.is_root() and not node.is_anonymous:
1107 self._check_name_exists(self.topleveldefs, node)
1108 elif node is not self.node:
1109 self._check_name_exists(self.closuredefs, node)
1111 for ident in node.undeclared_identifiers():
1117 if node is self.node:
1118 for ident in node.declared_identifiers():
1121 for n in node.nodes:
1124 def visitBlockTag(self, node):
1125 if node is not self.node and not node.is_anonymous:
1127 if isinstance(self.node, parsetree.DefTag):
1130 % (node.name, self.node.name), **node.exception_kwargs)
1131 elif isinstance(self.node,
1135 % (node.name, ), **node.exception_kwargs)
1137 for ident in node.undeclared_identifiers():
1142 if not node.is_anonymous:
1143 self._check_name_exists(self.topleveldefs, node)
1144 self.undeclared.add(node.funcname)
1145 elif node is not self.node:
1146 self._check_name_exists(self.closuredefs, node)
1147 for ident in node.declared_identifiers():
1149 for n in node.nodes:
1152 def visitTextTag(self, node):
1153 for ident in node.undeclared_identifiers():
1158 def visitIncludeTag(self, node):
1159 self.check_declared(node)
1161 def visitPageTag(self, node):
1162 for ident in node.declared_identifiers():
1164 self.check_declared(node)
1166 def visitCallNamespaceTag(self, node):
1167 self.visitCallTag(node)
1169 def visitCallTag(self, node):
1170 if node is self.node:
1171 for ident in node.undeclared_identifiers():
1176 for ident in node.declared_identifiers():
1178 for n in node.nodes:
1181 for ident in node.undeclared_identifiers():
1193 def mangle_mako_loop(node, printer):
1198 node.accept_visitor(loop_variable)
1200 node.nodes[-1].has_loop_context = True
1201 match = _FOR_LOOP.match(node.text)
1210 raise SyntaxError("Couldn't apply loop context: %s" % node.text)
1212 text = node.text
1217 """A node
1223 def _loop_reference_detected(self, node):
1224 if 'loop' in node.undeclared_identifiers():
1227 for n in node.get_children():
1230 def visitControlLine(self, node):
1231 self._loop_reference_detected(node)
1233 def visitCode(self, node):
1234 self._loop_reference_detected(node)
1236 def visitExpression(self, node):
1237 self._loop_reference_detected(node)