#NEWLINE# def _render( self , compiled , * args , **kwargs ) : #NEWLINE# #INDENT# ' Returns the rendered string as an iterator.\n            Replaces template placeholders with keyword arguments (if any).\n            Replaces source code with the return value of eval() or exec().\n        ' #NEWLINE# k = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for d in args : #NEWLINE# #INDENT# k . update ( k ) #NEWLINE# #UNINDENT# k . update ( kwargs ) #NEWLINE# k [ 'template' ] = template #NEWLINE# indent = kwargs . pop ( 'indent' , False ) #NEWLINE# for ( cmd , v , w ) in compiled : #NEWLINE# #INDENT# if ( indent is False ) : #NEWLINE# #INDENT# w = '' #NEWLINE# #UNINDENT# if ( cmd is None ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == '<str>' ) : #NEWLINE# #INDENT# ( yield self . _encode ( v , w ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == '<arg>' ) : #NEWLINE# #INDENT# ( yield self . _encode ( k . get ( v , ( '$' + v ) ) , w ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == '<if>' ) : #NEWLINE# #INDENT# ( yield ( '' . join ( self . _render ( v [ 1 ] , k ) ) if eval ( v [ 0 ] ) else '' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == '<for>' ) : #NEWLINE# #INDENT# ( yield '' . join ( [ '' . join ( self . _render ( v [ 2 ] , k , self . _dict ( v [ 0 ] , i ) ) ) for i in eval ( v [ 1 ] , k ) ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == '<eval>' ) : #NEWLINE# #INDENT# ( yield self . _encode ( eval ( v , k ) , w ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cmd == '<exec>' ) : #NEWLINE# #INDENT# o = StringIO ( ) #NEWLINE# k [ 'write' ] = o . write #NEWLINE# exec ( v , k ) #NEWLINE# ( yield self . _encode ( o . getvalue ( ) , w ) ) #NEWLINE# del k [ 'write' ] #NEWLINE# o . close ( )