#NEWLINE# def visit_Template( self , node , frame = None ) : #NEWLINE# #INDENT# assert ( frame is None ) , 'no root frame allowed' #NEWLINE# eval_ctx = EvalContext ( self . environment , self . name ) #NEWLINE# from jinja2.runtime import __all__ as exported #NEWLINE# self . writeline ( 'from __future__ import division' ) #NEWLINE# self . writeline ( ( 'from jinja2.runtime import ' + ', ' . join ( exported ) ) ) #NEWLINE# if ( not unoptimize_before_dead_code ) : #NEWLINE# #INDENT# self . writeline ( 'dummy = lambda *x: None' ) #NEWLINE# #UNINDENT# envenv = ( ( ( not self . defer_init ) and ', environment=environment' ) or '' ) #NEWLINE# have_extends = ( node . find ( nodes . Extends ) is not None ) #NEWLINE# for block in node . find_all ( nodes . Block ) : #NEWLINE# #INDENT# if ( block . name in self . blocks ) : #NEWLINE# #INDENT# self . fail ( ( 'block %r defined twice' % block . name ) , block . lineno ) #NEWLINE# #UNINDENT# self . blocks [ block . name ] = block #NEWLINE# #UNINDENT# for import_ in node . find_all ( nodes . ImportedName ) : #NEWLINE# #INDENT# if ( import_ . importname not in self . import_aliases ) : #NEWLINE# #INDENT# imp = import_ . importname #NEWLINE# self . import_aliases [ imp ] = alias = self . temporary_identifier ( ) #NEWLINE# if ( '.' in imp ) : #NEWLINE# #INDENT# ( module , obj ) = imp . rsplit ( '.' , 1 ) #NEWLINE# self . writeline ( ( 'from %s import %s as %s' % ( module , obj , alias ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . writeline ( ( 'import %s as %s' % ( imp , alias ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . writeline ( ( 'name = %r' % self . name ) ) #NEWLINE# self . writeline ( ( 'def root(context%s):' % envenv ) , extra = 1 ) #NEWLINE# frame = Frame ( eval_ctx ) #NEWLINE# frame . inspect ( node . body ) #NEWLINE# frame . toplevel = frame . rootlevel = True #NEWLINE# frame . require_output_check = ( have_extends and ( not self . has_known_extends ) ) #NEWLINE# self . indent ( ) #NEWLINE# if have_extends : #NEWLINE# #INDENT# self . writeline ( 'parent_template = None' ) #NEWLINE# #UNINDENT# if ( 'self' in find_undeclared ( node . body , ( 'self' , ) ) ) : #NEWLINE# #INDENT# frame . identifiers . add_special ( 'self' ) #NEWLINE# self . writeline ( 'l_self = TemplateReference(context)' ) #NEWLINE# #UNINDENT# self . pull_locals ( frame ) #NEWLINE# self . pull_dependencies ( node . body ) #NEWLINE# self . blockvisit ( node . body , frame ) #NEWLINE# self . outdent ( ) #NEWLINE# if have_extends : #NEWLINE# #INDENT# if ( not self . has_known_extends ) : #NEWLINE# #INDENT# self . indent ( ) #NEWLINE# self . writeline ( 'if parent_template is not None:' ) #NEWLINE# #UNINDENT# self . indent ( ) #NEWLINE# self . writeline ( 'for event in parent_template.root_render_func(context):' ) #NEWLINE# self . indent ( ) #NEWLINE# self . writeline ( 'yield event' ) #NEWLINE# self . outdent ( ( 2 + ( not self . has_known_extends ) ) ) #NEWLINE# #UNINDENT# for ( name , block ) in iteritems ( self . blocks ) : #NEWLINE# #INDENT# block_frame = Frame ( eval_ctx ) #NEWLINE# block_frame . inspect ( block . body ) #NEWLINE# block_frame . block = name #NEWLINE# self . writeline ( ( 'def block_%s(context%s):' % ( name , envenv ) ) , block , 1 ) #NEWLINE# self . indent ( ) #NEWLINE# undeclared = find_undeclared ( block . body , ( 'self' , 'super' ) ) #NEWLINE# if ( 'self' in undeclared ) : #NEWLINE# #INDENT# block_frame . identifiers . add_special ( 'self' ) #NEWLINE# self . writeline ( 'l_self = TemplateReference(context)' ) #NEWLINE# #UNINDENT# if ( 'super' in undeclared ) : #NEWLINE# #INDENT# block_frame . identifiers . add_special ( 'super' ) #NEWLINE# self . writeline ( ( 'l_super = context.super(%r, block_%s)' % ( name , name ) ) ) #NEWLINE# #UNINDENT# self . pull_locals ( block_frame ) #NEWLINE# self . pull_dependencies ( block . body ) #NEWLINE# self . blockvisit ( block . body , block_frame ) #NEWLINE# self . outdent ( ) #NEWLINE# #UNINDENT# self . writeline ( ( 'blocks = {%s}' % ', ' . join ( ( ( '%r: block_%s' % ( x , x ) ) for x in self . blocks ) ) ) , extra = 1 ) #NEWLINE# self . writeline ( ( 'debug_info = %r' % '&' . join ( ( ( '%s=%s' % x ) for x in self . debug_info ) ) ) )