<s> """<STR_LIT>""" <EOL> from cStringIO import StringIO <EOL> from itertools import chain <EOL> from copy import deepcopy <EOL> from jinja2 import nodes <EOL> from jinja2 . nodes import EvalContext <EOL> from jinja2 . visitor import NodeVisitor , NodeTransformer <EOL> from jinja2 . exceptions import TemplateAssertionError <EOL> from jinja2 . utils import Markup , concat , escape , is_python_keyword , next <EOL> operators = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:>>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:<>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> try : <EOL> exec ( '<STR_LIT>' ) <EOL> except SyntaxError : <EOL> have_condexpr = False <EOL> else : <EOL> have_condexpr = True <EOL> if hasattr ( dict , '<STR_LIT>' ) : <EOL> dict_item_iter = '<STR_LIT>' <EOL> else : <EOL> dict_item_iter = '<STR_LIT>' <EOL> def unoptimize_before_dead_code ( ) : <EOL> x = <NUM_LIT> <EOL> def f ( ) : <EOL> if <NUM_LIT:0> : dummy ( x ) <EOL> return f <EOL> unoptimize_before_dead_code = bool ( unoptimize_before_dead_code ( ) . func_closure ) <EOL> def generate ( node , environment , name , filename , stream = None , <EOL> defer_init = False ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( node , nodes . Template ) : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> generator = CodeGenerator ( environment , name , filename , stream , defer_init ) <EOL> generator . visit ( node ) <EOL> if stream is None : <EOL> return generator . stream . getvalue ( ) <EOL> def has_safe_repr ( value ) : <EOL> """<STR_LIT>""" <EOL> if value is None or value is NotImplemented or value is Ellipsis : <EOL> return True <EOL> if isinstance ( value , ( bool , int , long , float , complex , basestring , <EOL> xrange , Markup ) ) : <EOL> return True <EOL> if isinstance ( value , ( tuple , list , set , frozenset ) ) : <EOL> for item in value : <EOL> if not has_safe_repr ( item ) : <EOL> return False <EOL> return True <EOL> elif isinstance ( value , dict ) : <EOL> for key , value in value . iteritems ( ) : <EOL> if not has_safe_repr ( key ) : <EOL> return False <EOL> if not has_safe_repr ( value ) : <EOL> return False <EOL> return True <EOL> return False <EOL> def find_undeclared ( nodes , names ) : <EOL> """<STR_LIT>""" <EOL> visitor = UndeclaredNameVisitor ( names ) <EOL> try : <EOL> for node in nodes : <EOL> visitor . visit ( node ) <EOL> except VisitorExit : <EOL> pass <EOL> return visitor . undeclared <EOL> class Identifiers ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . declared = set ( ) <EOL> self . outer_undeclared = set ( ) <EOL> self . undeclared = set ( ) <EOL> self . declared_locally = set ( ) <EOL> self . declared_parameter = set ( ) <EOL> def add_special ( self , name ) : <EOL> """<STR_LIT>""" <EOL> self . undeclared . discard ( name ) <EOL> self . declared . add ( name ) <EOL> def is_declared ( self , name , local_only = False ) : <EOL> """<STR_LIT>""" <EOL> if name in self . declared_locally or name in self . declared_parameter : <EOL> return True <EOL> if local_only : <EOL> return False <EOL> return name in self . declared <EOL> def copy ( self ) : <EOL> return deepcopy ( self ) <EOL> class Frame ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , eval_ctx , parent = None ) : <EOL> self . eval_ctx = eval_ctx <EOL> self . identifiers = Identifiers ( ) <EOL> self . toplevel = False <EOL> self . rootlevel = False <EOL> self . require_output_check = parent and parent . require_output_check <EOL> self . buffer = None <EOL> self . block = parent and parent . block or None <EOL> self . assigned_names = set ( ) <EOL> self . parent = parent <EOL> if parent is not None : <EOL> self . identifiers . declared . update ( <EOL> parent . identifiers . declared | <EOL> parent . identifiers . declared_parameter | <EOL> parent . assigned_names <EOL> ) <EOL> self . identifiers . outer_undeclared . update ( <EOL> parent . identifiers . undeclared - <EOL> self . identifiers . declared <EOL> ) <EOL> self . buffer = parent . buffer <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> rv = object . __new__ ( self . __class__ ) <EOL> rv . __dict__ . update ( self . __dict__ ) <EOL> rv . identifiers = object . __new__ ( self . identifiers . __class__ ) <EOL> rv . identifiers . __dict__ . update ( self . identifiers . __dict__ ) <EOL> return rv <EOL> def inspect ( self , nodes , hard_scope = False ) : <EOL> """<STR_LIT>""" <EOL> visitor = FrameIdentifierVisitor ( self . identifiers , hard_scope ) <EOL> for node in nodes : <EOL> visitor . visit ( node ) <EOL> def find_shadowed ( self , extra = ( ) ) : <EOL> """<STR_LIT>""" <EOL> i = self . identifiers <EOL> return ( i . declared | i . outer_undeclared ) & ( i . declared_locally | i . declared_parameter ) | set ( x for x in extra if i . is_declared ( x ) ) <EOL> def inner ( self ) : <EOL> """<STR_LIT>""" <EOL> return Frame ( self . eval_ctx , self ) <EOL> def soft ( self ) : <EOL> """<STR_LIT>""" <EOL> rv = self . copy ( ) <EOL> rv . rootlevel = False <EOL> return rv <EOL> __copy__ = copy <EOL> class VisitorExit ( RuntimeError ) : <EOL> """<STR_LIT>""" <EOL> class DependencyFinderVisitor ( NodeVisitor ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . filters = set ( ) <EOL> self . tests = set ( ) <EOL> def visit_Filter ( self , node ) : <EOL> self . generic_visit ( node ) <EOL> self . filters . add ( node . name ) <EOL> def visit_Test ( self , node ) : <EOL> self . generic_visit ( node ) <EOL> self . tests . add ( node . name ) <EOL> def visit_Block ( self , node ) : <EOL> """<STR_LIT>""" <EOL> class UndeclaredNameVisitor ( NodeVisitor ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , names ) : <EOL> self . names = set ( names ) <EOL> self . undeclared = set ( ) <EOL> def visit_Name ( self , node ) : <EOL> if node . ctx == '<STR_LIT>' and node . name in self . names : <EOL> self . undeclared . add ( node . name ) <EOL> if self . undeclared == self . names : <EOL> raise VisitorExit ( ) <EOL> else : <EOL> self . names . discard ( node . name ) <EOL> def visit_Block ( self , node ) : <EOL> """<STR_LIT>""" <EOL> class FrameIdentifierVisitor ( NodeVisitor ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , identifiers , hard_scope ) : <EOL> self . identifiers = identifiers <EOL> self . hard_scope = hard_scope <EOL> def visit_Name ( self , node ) : <EOL> """<STR_LIT>""" <EOL> if node . ctx == '<STR_LIT:store>' : <EOL> self . identifiers . declared_locally . add ( node . name ) <EOL> elif node . ctx == '<STR_LIT>' : <EOL> self . identifiers . declared_parameter . add ( node . name ) <EOL> elif node . ctx == '<STR_LIT>' and not self . identifiers . is_declared ( node . name , self . hard_scope ) : <EOL> self . identifiers . undeclared . add ( node . name ) <EOL> def visit_If ( self , node ) : <EOL> self . visit ( node . test ) <EOL> real_identifiers = self . identifiers <EOL> old_names = real_identifiers . declared_locally | real_identifiers . declared_parameter <EOL> def inner_visit ( nodes ) : <EOL> if not nodes : <EOL> return set ( ) <EOL> self . identifiers = real_identifiers . copy ( ) <EOL> for subnode in nodes : <EOL> self . visit ( subnode ) <EOL> rv = self . identifiers . declared_locally - old_names <EOL> real_identifiers . undeclared . update ( self . identifiers . undeclared ) <EOL> self . identifiers = real_identifiers <EOL> return rv <EOL> body = inner_visit ( node . body ) <EOL> else_ = inner_visit ( node . else_ or ( ) ) <EOL> real_identifiers . undeclared . update ( body . symmetric_difference ( else_ ) - <EOL> real_identifiers . declared ) <EOL> real_identifiers . declared_locally . update ( body | else_ ) <EOL> def visit_Macro ( self , node ) : <EOL> self . identifiers . declared_locally . add ( node . name ) <EOL> def visit_Import ( self , node ) : <EOL> self . generic_visit ( node ) <EOL> self . identifiers . declared_locally . add ( node . target ) <EOL> def visit_FromImport ( self , node ) : <EOL> self . generic_visit ( node ) <EOL> for name in node . names : <EOL> if isinstance ( name , tuple ) : <EOL> self . identifiers . declared_locally . add ( name [ <NUM_LIT:1> ] ) <EOL> else : <EOL> self . identifiers . declared_locally . add ( name ) <EOL> def visit_Assign ( self , node ) : <EOL> """<STR_LIT>""" <EOL> self . visit ( node . node ) <EOL> self . visit ( node . target ) <EOL> def visit_For ( self , node ) : <EOL> """<STR_LIT>""" <EOL> self . visit ( node . iter ) <EOL> def visit_CallBlock ( self , node ) : <EOL> self . visit ( node . call ) <EOL> def visit_FilterBlock ( self , node ) : <EOL> self . visit ( node . filter ) <EOL> def visit_Scope ( self , node ) : <EOL> """<STR_LIT>""" <EOL> def visit_Block ( self , node ) : <EOL> """<STR_LIT>""" <EOL> class CompilerExit ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class CodeGenerator ( NodeVisitor ) : <EOL> def __init__ ( self , environment , name , filename , stream = None , <EOL> defer_init = False ) : <EOL> if stream is None : <EOL> stream = StringIO ( ) <EOL> self . environment = environment <EOL> self . name = name <EOL> self . filename = filename <EOL> self . stream = stream <EOL> self . created_block_context = False <EOL> self . defer_init = defer_init <EOL> self . import_aliases = { } <EOL> self . blocks = { } <EOL> self . extends_so_far = <NUM_LIT:0> <EOL> self . has_known_extends = False <EOL> self . code_lineno = <NUM_LIT:1> <EOL> self . tests = { } <EOL> self . filters = { } <EOL> self . debug_info = [ ] <EOL> self . _write_debug_info = None <EOL> self . _new_lines = <NUM_LIT:0> <EOL> self . _last_line = <NUM_LIT:0> <EOL> self . _first_write = True <EOL> self . _last_identifier = <NUM_LIT:0> <EOL> self . _indentation = <NUM_LIT:0> <EOL> def fail ( self , msg , lineno ) : <EOL> """<STR_LIT>""" <EOL> raise TemplateAssertionError ( msg , lineno , self . name , self . filename ) <EOL> def temporary_identifier ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _last_identifier += <NUM_LIT:1> <EOL> return '<STR_LIT>' % self . _last_identifier <EOL> def buffer ( self , frame ) : <EOL> """<STR_LIT>""" <EOL> frame . buffer = self . temporary_identifier ( ) <EOL> self . writeline ( '<STR_LIT>' % frame . buffer ) <EOL> def return_buffer_contents ( self , frame ) : <EOL> """<STR_LIT>""" <EOL> if frame . eval_ctx . volatile : <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . indent ( ) <EOL> self . writeline ( '<STR_LIT>' % frame . buffer ) <EOL> self . outdent ( ) <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . indent ( ) <EOL> self . writeline ( '<STR_LIT>' % frame . buffer ) <EOL> self . outdent ( ) <EOL> elif frame . eval_ctx . autoescape : <EOL> self . writeline ( '<STR_LIT>' % frame . buffer ) <EOL> else : <EOL> self . writeline ( '<STR_LIT>' % frame . buffer ) <EOL> def indent ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _indentation += <NUM_LIT:1> <EOL> def outdent ( self , step = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> self . _indentation -= step <EOL> def start_write ( self , frame , node = None ) : <EOL> """<STR_LIT>""" <EOL> if frame . buffer is None : <EOL> self . writeline ( '<STR_LIT>' , node ) <EOL> else : <EOL> self . writeline ( '<STR_LIT>' % frame . buffer , node ) <EOL> def end_write ( self , frame ) : <EOL> """<STR_LIT>""" <EOL> if frame . buffer is not None : <EOL> self . write ( '<STR_LIT:)>' ) <EOL> def simple_write ( self , s , frame , node = None ) : <EOL> """<STR_LIT>""" <EOL> self . start_write ( frame , node ) <EOL> self . write ( s ) <EOL> self . end_write ( frame ) <EOL> def blockvisit ( self , nodes , frame ) : <EOL> """<STR_LIT>""" <EOL> if frame . buffer is None : <EOL> self . writeline ( '<STR_LIT>' ) <EOL> else : <EOL> self . writeline ( '<STR_LIT>' ) <EOL> try : <EOL> for node in nodes : <EOL> self . visit ( node , frame ) <EOL> except CompilerExit : <EOL> pass <EOL> def write ( self , x ) : <EOL> """<STR_LIT>""" <EOL> if self . _new_lines : <EOL> if not self . _first_write : <EOL> self . stream . write ( '<STR_LIT:\n>' * self . _new_lines ) <EOL> self . code_lineno += self . _new_lines <EOL> if self . _write_debug_info is not None : <EOL> self . debug_info . append ( ( self . _write_debug_info , <EOL> self . code_lineno ) ) <EOL> self . _write_debug_info = None <EOL> self . _first_write = False <EOL> self . stream . write ( '<STR_LIT:U+0020>' * self . _indentation ) <EOL> self . _new_lines = <NUM_LIT:0> <EOL> self . stream . write ( x ) <EOL> def writeline ( self , x , node = None , extra = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . newline ( node , extra ) <EOL> self . write ( x ) <EOL> def newline ( self , node = None , extra = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> self . _new_lines = max ( self . _new_lines , <NUM_LIT:1> + extra ) <EOL> if node is not None and node . lineno != self . _last_line : <EOL> self . _write_debug_info = node . lineno <EOL> self . _last_line = node . lineno <EOL> def signature ( self , node , frame , extra_kwargs = None ) : <EOL> """<STR_LIT>""" <EOL> kwarg_workaround = False <EOL> for kwarg in chain ( ( x . key for x in node . kwargs ) , extra_kwargs or ( ) ) : <EOL> if is_python_keyword ( kwarg ) : <EOL> kwarg_workaround = True <EOL> break <EOL> for arg in node . args : <EOL> self . write ( '<STR_LIT:U+002CU+0020>' ) <EOL> self . visit ( arg , frame ) <EOL> if not kwarg_workaround : <EOL> for kwarg in node . kwargs : <EOL> self . write ( '<STR_LIT:U+002CU+0020>' ) <EOL> self . visit ( kwarg , frame ) <EOL> if extra_kwargs is not None : <EOL> for key , value in extra_kwargs . iteritems ( ) : <EOL> self . write ( '<STR_LIT>' % ( key , value ) ) <EOL> if node . dyn_args : <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( node . dyn_args , frame ) <EOL> if kwarg_workaround : <EOL> if node . dyn_kwargs is not None : <EOL> self . write ( '<STR_LIT>' ) <EOL> else : <EOL> self . write ( '<STR_LIT>' ) <EOL> for kwarg in node . kwargs : <EOL> self . write ( '<STR_LIT>' % kwarg . key ) <EOL> self . visit ( kwarg . value , frame ) <EOL> self . write ( '<STR_LIT:U+002CU+0020>' ) <EOL> if extra_kwargs is not None : <EOL> for key , value in extra_kwargs . iteritems ( ) : <EOL> self . write ( '<STR_LIT>' % ( key , value ) ) <EOL> if node . dyn_kwargs is not None : <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( node . dyn_kwargs , frame ) <EOL> self . write ( '<STR_LIT:)>' ) <EOL> else : <EOL> self . write ( '<STR_LIT:}>' ) <EOL> elif node . dyn_kwargs is not None : <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( node . dyn_kwargs , frame ) <EOL> def pull_locals ( self , frame ) : <EOL> """<STR_LIT>""" <EOL> for name in frame . identifiers . undeclared : <EOL> self . writeline ( '<STR_LIT>' % ( name , name ) ) <EOL> def pull_dependencies ( self , nodes ) : <EOL> """<STR_LIT>""" <EOL> visitor = DependencyFinderVisitor ( ) <EOL> for node in nodes : <EOL> visitor . visit ( node ) <EOL> for dependency in '<STR_LIT>' , '<STR_LIT>' : <EOL> mapping = getattr ( self , dependency ) <EOL> for name in getattr ( visitor , dependency ) : <EOL> if name not in mapping : <EOL> mapping [ name ] = self . temporary_identifier ( ) <EOL> self . writeline ( '<STR_LIT>' % <EOL> ( mapping [ name ] , dependency , name ) ) <EOL> def unoptimize_scope ( self , frame ) : <EOL> """<STR_LIT>""" <EOL> if frame . identifiers . declared : <EOL> self . writeline ( '<STR_LIT>' % ( <EOL> unoptimize_before_dead_code and '<STR_LIT>' or '<STR_LIT>' , <EOL> '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' + name for name in frame . identifiers . declared ) <EOL> ) ) <EOL> def push_scope ( self , frame , extra_vars = ( ) ) : <EOL> """<STR_LIT>""" <EOL> aliases = { } <EOL> for name in frame . find_shadowed ( extra_vars ) : <EOL> aliases [ name ] = ident = self . temporary_identifier ( ) <EOL> self . writeline ( '<STR_LIT>' % ( ident , name ) ) <EOL> to_declare = set ( ) <EOL> for name in frame . identifiers . declared_locally : <EOL> if name not in aliases : <EOL> to_declare . add ( '<STR_LIT>' + name ) <EOL> if to_declare : <EOL> self . writeline ( '<STR_LIT>' . join ( to_declare ) + '<STR_LIT>' ) <EOL> return aliases <EOL> def pop_scope ( self , aliases , frame ) : <EOL> """<STR_LIT>""" <EOL> for name , alias in aliases . iteritems ( ) : <EOL> self . writeline ( '<STR_LIT>' % ( name , alias ) ) <EOL> to_delete = set ( ) <EOL> for name in frame . identifiers . declared_locally : <EOL> if name not in aliases : <EOL> to_delete . add ( '<STR_LIT>' + name ) <EOL> if to_delete : <EOL> self . writeline ( '<STR_LIT>' . join ( to_delete ) + '<STR_LIT>' ) <EOL> def function_scoping ( self , node , frame , children = None , <EOL> find_special = True ) : <EOL> """<STR_LIT>""" <EOL> if children is None : <EOL> children = node . iter_child_nodes ( ) <EOL> children = list ( children ) <EOL> func_frame = frame . inner ( ) <EOL> func_frame . inspect ( children , hard_scope = True ) <EOL> overriden_closure_vars = ( <EOL> func_frame . identifiers . undeclared & <EOL> func_frame . identifiers . declared & <EOL> ( func_frame . identifiers . declared_locally | <EOL> func_frame . identifiers . declared_parameter ) <EOL> ) <EOL> if overriden_closure_vars : <EOL> self . fail ( '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> '<STR_LIT:U+002CU+0020>' . join ( sorted ( overriden_closure_vars ) ) , node . lineno ) <EOL> func_frame . identifiers . undeclared -= ( <EOL> func_frame . identifiers . undeclared & <EOL> func_frame . identifiers . declared <EOL> ) <EOL> if not find_special : <EOL> return func_frame <EOL> func_frame . accesses_kwargs = False <EOL> func_frame . accesses_varargs = False <EOL> func_frame . accesses_caller = False <EOL> func_frame . arguments = args = [ '<STR_LIT>' + x . name for x in node . args ] <EOL> undeclared = find_undeclared ( children , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if '<STR_LIT>' in undeclared : <EOL> func_frame . accesses_caller = True <EOL> func_frame . identifiers . add_special ( '<STR_LIT>' ) <EOL> args . append ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in undeclared : <EOL> func_frame . accesses_kwargs = True <EOL> func_frame . identifiers . add_special ( '<STR_LIT>' ) <EOL> args . append ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in undeclared : <EOL> func_frame . accesses_varargs = True <EOL> func_frame . identifiers . add_special ( '<STR_LIT>' ) <EOL> args . append ( '<STR_LIT>' ) <EOL> return func_frame <EOL> def macro_body ( self , node , frame , children = None ) : <EOL> """<STR_LIT>""" <EOL> frame = self . function_scoping ( node , frame , children ) <EOL> frame . require_output_check = False <EOL> args = frame . arguments <EOL> if '<STR_LIT>' in frame . identifiers . declared : <EOL> args = args + [ '<STR_LIT>' ] <EOL> self . writeline ( '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( args ) , node ) <EOL> self . indent ( ) <EOL> self . buffer ( frame ) <EOL> self . pull_locals ( frame ) <EOL> self . blockvisit ( node . body , frame ) <EOL> self . return_buffer_contents ( frame ) <EOL> self . outdent ( ) <EOL> return frame <EOL> def macro_def ( self , node , frame ) : <EOL> """<STR_LIT>""" <EOL> arg_tuple = '<STR_LIT:U+002CU+0020>' . join ( repr ( x . name ) for x in node . args ) <EOL> name = getattr ( node , '<STR_LIT:name>' , None ) <EOL> if len ( node . args ) == <NUM_LIT:1> : <EOL> arg_tuple += '<STR_LIT:U+002C>' <EOL> self . write ( '<STR_LIT>' % <EOL> ( name , arg_tuple ) ) <EOL> for arg in node . defaults : <EOL> self . visit ( arg , frame ) <EOL> self . write ( '<STR_LIT:U+002CU+0020>' ) <EOL> self . write ( '<STR_LIT>' % ( <EOL> bool ( frame . accesses_kwargs ) , <EOL> bool ( frame . accesses_varargs ) , <EOL> bool ( frame . accesses_caller ) <EOL> ) ) <EOL> def position ( self , node ) : <EOL> """<STR_LIT>""" <EOL> rv = '<STR_LIT>' % node . lineno <EOL> if self . name is not None : <EOL> rv += '<STR_LIT>' + repr ( self . name ) <EOL> return rv <EOL> def visit_Template ( self , node , frame = None ) : <EOL> assert frame is None , '<STR_LIT>' <EOL> eval_ctx = EvalContext ( self . environment , self . name ) <EOL> from jinja2 . runtime import __all__ as exported <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . writeline ( '<STR_LIT>' + '<STR_LIT:U+002CU+0020>' . join ( exported ) ) <EOL> if not unoptimize_before_dead_code : <EOL> self . writeline ( '<STR_LIT>' ) <EOL> envenv = not self . defer_init and '<STR_LIT>' or '<STR_LIT>' <EOL> have_extends = node . find ( nodes . Extends ) is not None <EOL> for block in node . find_all ( nodes . Block ) : <EOL> if block . name in self . blocks : <EOL> self . fail ( '<STR_LIT>' % block . name , block . lineno ) <EOL> self . blocks [ block . name ] = block <EOL> for import_ in node . find_all ( nodes . ImportedName ) : <EOL> if import_ . importname not in self . import_aliases : <EOL> imp = import_ . importname <EOL> self . import_aliases [ imp ] = alias = self . temporary_identifier ( ) <EOL> if '<STR_LIT:.>' in imp : <EOL> module , obj = imp . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> self . writeline ( '<STR_LIT>' % <EOL> ( module , obj , alias ) ) <EOL> else : <EOL> self . writeline ( '<STR_LIT>' % ( imp , alias ) ) <EOL> self . writeline ( '<STR_LIT>' % self . name ) <EOL> self . writeline ( '<STR_LIT>' % envenv , extra = <NUM_LIT:1> ) <EOL> frame = Frame ( eval_ctx ) <EOL> frame . inspect ( node . body ) <EOL> frame . toplevel = frame . rootlevel = True <EOL> frame . require_output_check = have_extends and not self . has_known_extends <EOL> self . indent ( ) <EOL> if have_extends : <EOL> self . writeline ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in find_undeclared ( node . body , ( '<STR_LIT>' , ) ) : <EOL> frame . identifiers . add_special ( '<STR_LIT>' ) <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . pull_locals ( frame ) <EOL> self . pull_dependencies ( node . body ) <EOL> self . blockvisit ( node . body , frame ) <EOL> self . outdent ( ) <EOL> if have_extends : <EOL> if not self . has_known_extends : <EOL> self . indent ( ) <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . indent ( ) <EOL> self . writeline ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . indent ( ) <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . outdent ( <NUM_LIT:2> + ( not self . has_known_extends ) ) <EOL> for name , block in self . blocks . iteritems ( ) : <EOL> block_frame = Frame ( eval_ctx ) <EOL> block_frame . inspect ( block . body ) <EOL> block_frame . block = name <EOL> self . writeline ( '<STR_LIT>' % ( name , envenv ) , <EOL> block , <NUM_LIT:1> ) <EOL> self . indent ( ) <EOL> undeclared = find_undeclared ( block . body , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if '<STR_LIT>' in undeclared : <EOL> block_frame . identifiers . add_special ( '<STR_LIT>' ) <EOL> self . writeline ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in undeclared : <EOL> block_frame . identifiers . add_special ( '<STR_LIT>' ) <EOL> self . writeline ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( name , name ) ) <EOL> self . pull_locals ( block_frame ) <EOL> self . pull_dependencies ( block . body ) <EOL> self . blockvisit ( block . body , block_frame ) <EOL> self . outdent ( ) <EOL> self . writeline ( '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' % ( x , x ) <EOL> for x in self . blocks ) , <EOL> extra = <NUM_LIT:1> ) <EOL> self . writeline ( '<STR_LIT>' % '<STR_LIT:&>' . join ( '<STR_LIT>' % x for x <EOL> in self . debug_info ) ) <EOL> def visit_Block ( self , node , frame ) : <EOL> """<STR_LIT>""" <EOL> level = <NUM_LIT:1> <EOL> if frame . toplevel : <EOL> if self . has_known_extends : <EOL> return <EOL> if self . extends_so_far > <NUM_LIT:0> : <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . indent ( ) <EOL> level += <NUM_LIT:1> <EOL> context = node . scoped and '<STR_LIT>' or '<STR_LIT>' <EOL> self . writeline ( '<STR_LIT>' % ( <EOL> node . name , context ) , node ) <EOL> self . indent ( ) <EOL> self . simple_write ( '<STR_LIT>' , frame ) <EOL> self . outdent ( level ) <EOL> def visit_Extends ( self , node , frame ) : <EOL> """<STR_LIT>""" <EOL> if not frame . toplevel : <EOL> self . fail ( '<STR_LIT>' , <EOL> node . lineno ) <EOL> if self . extends_so_far > <NUM_LIT:0> : <EOL> if not self . has_known_extends : <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . indent ( ) <EOL> self . writeline ( '<STR_LIT>' % <EOL> '<STR_LIT>' ) <EOL> self . outdent ( ) <EOL> if self . has_known_extends : <EOL> raise CompilerExit ( ) <EOL> self . writeline ( '<STR_LIT>' , node ) <EOL> self . visit ( node . template , frame ) <EOL> self . write ( '<STR_LIT>' % self . name ) <EOL> self . writeline ( '<STR_LIT>' <EOL> '<STR_LIT>' % dict_item_iter ) <EOL> self . indent ( ) <EOL> self . writeline ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . outdent ( ) <EOL> if frame . rootlevel : <EOL> self . has_known_extends = True <EOL> self . extends_so_far += <NUM_LIT:1> <EOL> def visit_Include ( self , node , frame ) : <EOL> """<STR_LIT>""" <EOL> if node . with_context : <EOL> self . unoptimize_scope ( frame ) <EOL> if node . ignore_missing : <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . indent ( ) <EOL> func_name = '<STR_LIT>' <EOL> if isinstance ( node . template , nodes . Const ) : <EOL> if isinstance ( node . template . value , basestring ) : <EOL> func_name = '<STR_LIT>' <EOL> elif isinstance ( node . template . value , ( tuple , list ) ) : <EOL> func_name = '<STR_LIT>' <EOL> elif isinstance ( node . template , ( nodes . Tuple , nodes . List ) ) : <EOL> func_name = '<STR_LIT>' <EOL> self . writeline ( '<STR_LIT>' % func_name , node ) <EOL> self . visit ( node . template , frame ) <EOL> self . write ( '<STR_LIT>' % self . name ) <EOL> if node . ignore_missing : <EOL> self . outdent ( ) <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . indent ( ) <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . outdent ( ) <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . indent ( ) <EOL> if node . with_context : <EOL> self . writeline ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> else : <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . indent ( ) <EOL> self . simple_write ( '<STR_LIT>' , frame ) <EOL> self . outdent ( ) <EOL> if node . ignore_missing : <EOL> self . outdent ( ) <EOL> def visit_Import ( self , node , frame ) : <EOL> """<STR_LIT>""" <EOL> if node . with_context : <EOL> self . unoptimize_scope ( frame ) <EOL> self . writeline ( '<STR_LIT>' % node . target , node ) <EOL> if frame . toplevel : <EOL> self . write ( '<STR_LIT>' % node . target ) <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( node . template , frame ) <EOL> self . write ( '<STR_LIT>' % self . name ) <EOL> if node . with_context : <EOL> self . write ( '<STR_LIT>' ) <EOL> else : <EOL> self . write ( '<STR_LIT>' ) <EOL> if frame . toplevel and not node . target . startswith ( '<STR_LIT:_>' ) : <EOL> self . writeline ( '<STR_LIT>' % node . target ) <EOL> frame . assigned_names . add ( node . target ) <EOL> def visit_FromImport ( self , node , frame ) : <EOL> """<STR_LIT>""" <EOL> self . newline ( node ) <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( node . template , frame ) <EOL> self . write ( '<STR_LIT>' % self . name ) <EOL> if node . with_context : <EOL> self . write ( '<STR_LIT>' ) <EOL> else : <EOL> self . write ( '<STR_LIT>' ) <EOL> var_names = [ ] <EOL> discarded_names = [ ] <EOL> for name in node . names : <EOL> if isinstance ( name , tuple ) : <EOL> name , alias = name <EOL> else : <EOL> alias = name <EOL> self . writeline ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( alias , name ) ) <EOL> self . writeline ( '<STR_LIT>' % alias ) <EOL> self . indent ( ) <EOL> self . writeline ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> ( alias , '<STR_LIT>' <EOL> '<STR_LIT>' % ( <EOL> self . position ( node ) , <EOL> repr ( name ) <EOL> ) , name ) ) <EOL> self . outdent ( ) <EOL> if frame . toplevel : <EOL> var_names . append ( alias ) <EOL> if not alias . startswith ( '<STR_LIT:_>' ) : <EOL> discarded_names . append ( alias ) <EOL> frame . assigned_names . add ( alias ) <EOL> if var_names : <EOL> if len ( var_names ) == <NUM_LIT:1> : <EOL> name = var_names [ <NUM_LIT:0> ] <EOL> self . writeline ( '<STR_LIT>' % ( name , name ) ) <EOL> else : <EOL> self . writeline ( '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( <EOL> '<STR_LIT>' % ( name , name ) for name in var_names <EOL> ) ) <EOL> if discarded_names : <EOL> if len ( discarded_names ) == <NUM_LIT:1> : <EOL> self . writeline ( '<STR_LIT>' % <EOL> discarded_names [ <NUM_LIT:0> ] ) <EOL> else : <EOL> self . writeline ( '<STR_LIT>' <EOL> '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( map ( repr , discarded_names ) ) ) <EOL> def visit_For ( self , node , frame ) : <EOL> children = node . iter_child_nodes ( exclude = ( '<STR_LIT>' , ) ) <EOL> if node . recursive : <EOL> loop_frame = self . function_scoping ( node , frame , children , <EOL> find_special = False ) <EOL> else : <EOL> loop_frame = frame . inner ( ) <EOL> loop_frame . inspect ( children ) <EOL> extended_loop = node . recursive or '<STR_LIT>' in find_undeclared ( node . iter_child_nodes ( <EOL> only = ( '<STR_LIT:body>' , ) ) , ( '<STR_LIT>' , ) ) <EOL> if not node . recursive : <EOL> aliases = self . push_scope ( loop_frame , ( '<STR_LIT>' , ) ) <EOL> else : <EOL> self . writeline ( '<STR_LIT>' , node ) <EOL> self . indent ( ) <EOL> self . buffer ( loop_frame ) <EOL> aliases = { } <EOL> if extended_loop : <EOL> loop_frame . identifiers . add_special ( '<STR_LIT>' ) <EOL> for name in node . find_all ( nodes . Name ) : <EOL> if name . ctx == '<STR_LIT:store>' and name . name == '<STR_LIT>' : <EOL> self . fail ( '<STR_LIT>' <EOL> '<STR_LIT>' , name . lineno ) <EOL> self . pull_locals ( loop_frame ) <EOL> if node . else_ : <EOL> iteration_indicator = self . temporary_identifier ( ) <EOL> self . writeline ( '<STR_LIT>' % iteration_indicator ) <EOL> if '<STR_LIT>' not in aliases and '<STR_LIT>' in find_undeclared ( <EOL> node . iter_child_nodes ( only = ( '<STR_LIT>' , '<STR_LIT:test>' ) ) , ( '<STR_LIT>' , ) ) : <EOL> self . writeline ( "<STR_LIT>" % <EOL> ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> self . position ( node ) ) ) <EOL> self . writeline ( '<STR_LIT>' , node ) <EOL> self . visit ( node . target , loop_frame ) <EOL> self . write ( extended_loop and '<STR_LIT>' or '<STR_LIT>' ) <EOL> if extended_loop and node . test is not None : <EOL> self . write ( '<STR_LIT:(>' ) <EOL> self . visit ( node . target , loop_frame ) <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( node . target , loop_frame ) <EOL> self . write ( '<STR_LIT>' ) <EOL> if node . recursive : <EOL> self . write ( '<STR_LIT>' ) <EOL> else : <EOL> self . visit ( node . iter , loop_frame ) <EOL> self . write ( '<STR_LIT>' ) <EOL> test_frame = loop_frame . copy ( ) <EOL> self . visit ( node . test , test_frame ) <EOL> self . write ( '<STR_LIT>' ) <EOL> elif node . recursive : <EOL> self . write ( '<STR_LIT>' ) <EOL> else : <EOL> self . visit ( node . iter , loop_frame ) <EOL> if node . recursive : <EOL> self . write ( '<STR_LIT>' ) <EOL> else : <EOL> self . write ( extended_loop and '<STR_LIT>' or '<STR_LIT::>' ) <EOL> if not extended_loop and node . test is not None : <EOL> self . indent ( ) <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . visit ( node . test , loop_frame ) <EOL> self . write ( '<STR_LIT::>' ) <EOL> self . indent ( ) <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . outdent ( <NUM_LIT:2> ) <EOL> self . indent ( ) <EOL> self . blockvisit ( node . body , loop_frame ) <EOL> if node . else_ : <EOL> self . writeline ( '<STR_LIT>' % iteration_indicator ) <EOL> self . outdent ( ) <EOL> if node . else_ : <EOL> self . writeline ( '<STR_LIT>' % iteration_indicator ) <EOL> self . indent ( ) <EOL> self . blockvisit ( node . else_ , loop_frame ) <EOL> self . outdent ( ) <EOL> if not node . recursive : <EOL> self . pop_scope ( aliases , loop_frame ) <EOL> if node . recursive : <EOL> self . return_buffer_contents ( loop_frame ) <EOL> self . outdent ( ) <EOL> self . start_write ( frame , node ) <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( node . iter , frame ) <EOL> self . write ( '<STR_LIT>' ) <EOL> self . end_write ( frame ) <EOL> def visit_If ( self , node , frame ) : <EOL> if_frame = frame . soft ( ) <EOL> self . writeline ( '<STR_LIT>' , node ) <EOL> self . visit ( node . test , if_frame ) <EOL> self . write ( '<STR_LIT::>' ) <EOL> self . indent ( ) <EOL> self . blockvisit ( node . body , if_frame ) <EOL> self . outdent ( ) <EOL> if node . else_ : <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . indent ( ) <EOL> self . blockvisit ( node . else_ , if_frame ) <EOL> self . outdent ( ) <EOL> def visit_Macro ( self , node , frame ) : <EOL> macro_frame = self . macro_body ( node , frame ) <EOL> self . newline ( ) <EOL> if frame . toplevel : <EOL> if not node . name . startswith ( '<STR_LIT:_>' ) : <EOL> self . write ( '<STR_LIT>' % node . name ) <EOL> self . writeline ( '<STR_LIT>' % node . name ) <EOL> self . write ( '<STR_LIT>' % node . name ) <EOL> self . macro_def ( node , macro_frame ) <EOL> frame . assigned_names . add ( node . name ) <EOL> def visit_CallBlock ( self , node , frame ) : <EOL> children = node . iter_child_nodes ( exclude = ( '<STR_LIT>' , ) ) <EOL> call_frame = self . macro_body ( node , frame , children ) <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . macro_def ( node , call_frame ) <EOL> self . start_write ( frame , node ) <EOL> self . visit_Call ( node . call , call_frame , forward_caller = True ) <EOL> self . end_write ( frame ) <EOL> def visit_FilterBlock ( self , node , frame ) : <EOL> filter_frame = frame . inner ( ) <EOL> filter_frame . inspect ( node . iter_child_nodes ( ) ) <EOL> aliases = self . push_scope ( filter_frame ) <EOL> self . pull_locals ( filter_frame ) <EOL> self . buffer ( filter_frame ) <EOL> self . blockvisit ( node . body , filter_frame ) <EOL> self . start_write ( frame , node ) <EOL> self . visit_Filter ( node . filter , filter_frame ) <EOL> self . end_write ( frame ) <EOL> self . pop_scope ( aliases , filter_frame ) <EOL> def visit_ExprStmt ( self , node , frame ) : <EOL> self . newline ( node ) <EOL> self . visit ( node . node , frame ) <EOL> def visit_Output ( self , node , frame ) : <EOL> if self . has_known_extends and frame . require_output_check : <EOL> return <EOL> if self . environment . finalize : <EOL> finalize = lambda x : unicode ( self . environment . finalize ( x ) ) <EOL> else : <EOL> finalize = unicode <EOL> self . newline ( node ) <EOL> outdent_later = False <EOL> if frame . require_output_check : <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . indent ( ) <EOL> outdent_later = True <EOL> body = [ ] <EOL> for child in node . nodes : <EOL> try : <EOL> const = child . as_const ( frame . eval_ctx ) <EOL> except nodes . Impossible : <EOL> body . append ( child ) <EOL> continue <EOL> try : <EOL> if frame . eval_ctx . autoescape : <EOL> if hasattr ( const , '<STR_LIT>' ) : <EOL> const = const . __html__ ( ) <EOL> else : <EOL> const = escape ( const ) <EOL> const = finalize ( const ) <EOL> except : <EOL> body . append ( child ) <EOL> continue <EOL> if body and isinstance ( body [ - <NUM_LIT:1> ] , list ) : <EOL> body [ - <NUM_LIT:1> ] . append ( const ) <EOL> else : <EOL> body . append ( [ const ] ) <EOL> if len ( body ) < <NUM_LIT:3> or frame . buffer is not None : <EOL> if frame . buffer is not None : <EOL> if len ( body ) == <NUM_LIT:1> : <EOL> self . writeline ( '<STR_LIT>' % frame . buffer ) <EOL> else : <EOL> self . writeline ( '<STR_LIT>' % frame . buffer ) <EOL> self . indent ( ) <EOL> for item in body : <EOL> if isinstance ( item , list ) : <EOL> val = repr ( concat ( item ) ) <EOL> if frame . buffer is None : <EOL> self . writeline ( '<STR_LIT>' + val ) <EOL> else : <EOL> self . writeline ( val + '<STR_LIT:U+002CU+0020>' ) <EOL> else : <EOL> if frame . buffer is None : <EOL> self . writeline ( '<STR_LIT>' , item ) <EOL> else : <EOL> self . newline ( item ) <EOL> close = <NUM_LIT:1> <EOL> if frame . eval_ctx . volatile : <EOL> self . write ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif frame . eval_ctx . autoescape : <EOL> self . write ( '<STR_LIT>' ) <EOL> else : <EOL> self . write ( '<STR_LIT>' ) <EOL> if self . environment . finalize is not None : <EOL> self . write ( '<STR_LIT>' ) <EOL> close += <NUM_LIT:1> <EOL> self . visit ( item , frame ) <EOL> self . write ( '<STR_LIT:)>' * close ) <EOL> if frame . buffer is not None : <EOL> self . write ( '<STR_LIT:U+002CU+0020>' ) <EOL> if frame . buffer is not None : <EOL> self . outdent ( ) <EOL> self . writeline ( len ( body ) == <NUM_LIT:1> and '<STR_LIT:)>' or '<STR_LIT>' ) <EOL> else : <EOL> format = [ ] <EOL> arguments = [ ] <EOL> for item in body : <EOL> if isinstance ( item , list ) : <EOL> format . append ( concat ( item ) . replace ( '<STR_LIT:%>' , '<STR_LIT>' ) ) <EOL> else : <EOL> format . append ( '<STR_LIT:%s>' ) <EOL> arguments . append ( item ) <EOL> self . writeline ( '<STR_LIT>' ) <EOL> self . write ( repr ( concat ( format ) ) + '<STR_LIT>' ) <EOL> idx = - <NUM_LIT:1> <EOL> self . indent ( ) <EOL> for argument in arguments : <EOL> self . newline ( argument ) <EOL> close = <NUM_LIT:0> <EOL> if frame . eval_ctx . volatile : <EOL> self . write ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> close += <NUM_LIT:1> <EOL> elif frame . eval_ctx . autoescape : <EOL> self . write ( '<STR_LIT>' ) <EOL> close += <NUM_LIT:1> <EOL> if self . environment . finalize is not None : <EOL> self . write ( '<STR_LIT>' ) <EOL> close += <NUM_LIT:1> <EOL> self . visit ( argument , frame ) <EOL> self . write ( '<STR_LIT:)>' * close + '<STR_LIT:U+002CU+0020>' ) <EOL> self . outdent ( ) <EOL> self . writeline ( '<STR_LIT:)>' ) <EOL> if outdent_later : <EOL> self . outdent ( ) <EOL> def visit_Assign ( self , node , frame ) : <EOL> self . newline ( node ) <EOL> if frame . toplevel : <EOL> assignment_frame = frame . copy ( ) <EOL> assignment_frame . toplevel_assignments = set ( ) <EOL> else : <EOL> assignment_frame = frame <EOL> self . visit ( node . target , assignment_frame ) <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( node . node , frame ) <EOL> if frame . toplevel : <EOL> public_names = [ x for x in assignment_frame . toplevel_assignments <EOL> if not x . startswith ( '<STR_LIT:_>' ) ] <EOL> if len ( assignment_frame . toplevel_assignments ) == <NUM_LIT:1> : <EOL> name = next ( iter ( assignment_frame . toplevel_assignments ) ) <EOL> self . writeline ( '<STR_LIT>' % ( name , name ) ) <EOL> else : <EOL> self . writeline ( '<STR_LIT>' ) <EOL> for idx , name in enumerate ( assignment_frame . toplevel_assignments ) : <EOL> if idx : <EOL> self . write ( '<STR_LIT:U+002CU+0020>' ) <EOL> self . write ( '<STR_LIT>' % ( name , name ) ) <EOL> self . write ( '<STR_LIT>' ) <EOL> if public_names : <EOL> if len ( public_names ) == <NUM_LIT:1> : <EOL> self . writeline ( '<STR_LIT>' % <EOL> public_names [ <NUM_LIT:0> ] ) <EOL> else : <EOL> self . writeline ( '<STR_LIT>' % <EOL> '<STR_LIT:U+002CU+0020>' . join ( map ( repr , public_names ) ) ) <EOL> def visit_Name ( self , node , frame ) : <EOL> if node . ctx == '<STR_LIT:store>' and frame . toplevel : <EOL> frame . toplevel_assignments . add ( node . name ) <EOL> self . write ( '<STR_LIT>' + node . name ) <EOL> frame . assigned_names . add ( node . name ) <EOL> def visit_Const ( self , node , frame ) : <EOL> val = node . value <EOL> if isinstance ( val , float ) : <EOL> self . write ( str ( val ) ) <EOL> else : <EOL> self . write ( repr ( val ) ) <EOL> def visit_TemplateData ( self , node , frame ) : <EOL> self . write ( repr ( node . as_const ( frame . eval_ctx ) ) ) <EOL> def visit_Tuple ( self , node , frame ) : <EOL> self . write ( '<STR_LIT:(>' ) <EOL> idx = - <NUM_LIT:1> <EOL> for idx , item in enumerate ( node . items ) : <EOL> if idx : <EOL> self . write ( '<STR_LIT:U+002CU+0020>' ) <EOL> self . visit ( item , frame ) <EOL> self . write ( idx == <NUM_LIT:0> and '<STR_LIT>' or '<STR_LIT:)>' ) <EOL> def visit_List ( self , node , frame ) : <EOL> self . write ( '<STR_LIT:[>' ) <EOL> for idx , item in enumerate ( node . items ) : <EOL> if idx : <EOL> self . write ( '<STR_LIT:U+002CU+0020>' ) <EOL> self . visit ( item , frame ) <EOL> self . write ( '<STR_LIT:]>' ) <EOL> def visit_Dict ( self , node , frame ) : <EOL> self . write ( '<STR_LIT:{>' ) <EOL> for idx , item in enumerate ( node . items ) : <EOL> if idx : <EOL> self . write ( '<STR_LIT:U+002CU+0020>' ) <EOL> self . visit ( item . key , frame ) <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( item . value , frame ) <EOL> self . write ( '<STR_LIT:}>' ) <EOL> def binop ( operator ) : <EOL> def visitor ( self , node , frame ) : <EOL> self . write ( '<STR_LIT:(>' ) <EOL> self . visit ( node . left , frame ) <EOL> self . write ( '<STR_LIT>' % operator ) <EOL> self . visit ( node . right , frame ) <EOL> self . write ( '<STR_LIT:)>' ) <EOL> return visitor <EOL> def uaop ( operator ) : <EOL> def visitor ( self , node , frame ) : <EOL> self . write ( '<STR_LIT:(>' + operator ) <EOL> self . visit ( node . node , frame ) <EOL> self . write ( '<STR_LIT:)>' ) <EOL> return visitor <EOL> visit_Add = binop ( '<STR_LIT:+>' ) <EOL> visit_Sub = binop ( '<STR_LIT:->' ) <EOL> visit_Mul = binop ( '<STR_LIT:*>' ) <EOL> visit_Div = binop ( '<STR_LIT:/>' ) <EOL> visit_FloorDiv = binop ( '<STR_LIT>' ) <EOL> visit_Pow = binop ( '<STR_LIT>' ) <EOL> visit_Mod = binop ( '<STR_LIT:%>' ) <EOL> visit_And = binop ( '<STR_LIT>' ) <EOL> visit_Or = binop ( '<STR_LIT>' ) <EOL> visit_Pos = uaop ( '<STR_LIT:+>' ) <EOL> visit_Neg = uaop ( '<STR_LIT:->' ) <EOL> visit_Not = uaop ( '<STR_LIT>' ) <EOL> del binop , uaop <EOL> def visit_Concat ( self , node , frame ) : <EOL> if frame . eval_ctx . volatile : <EOL> func_name = '<STR_LIT>' '<STR_LIT>' <EOL> elif frame . eval_ctx . autoescape : <EOL> func_name = '<STR_LIT>' <EOL> else : <EOL> func_name = '<STR_LIT>' <EOL> self . write ( '<STR_LIT>' % func_name ) <EOL> for arg in node . nodes : <EOL> self . visit ( arg , frame ) <EOL> self . write ( '<STR_LIT:U+002CU+0020>' ) <EOL> self . write ( '<STR_LIT>' ) <EOL> def visit_Compare ( self , node , frame ) : <EOL> self . visit ( node . expr , frame ) <EOL> for op in node . ops : <EOL> self . visit ( op , frame ) <EOL> def visit_Operand ( self , node , frame ) : <EOL> self . write ( '<STR_LIT>' % operators [ node . op ] ) <EOL> self . visit ( node . expr , frame ) <EOL> def visit_Getattr ( self , node , frame ) : <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( node . node , frame ) <EOL> self . write ( '<STR_LIT>' % node . attr ) <EOL> def visit_Getitem ( self , node , frame ) : <EOL> if isinstance ( node . arg , nodes . Slice ) : <EOL> self . visit ( node . node , frame ) <EOL> self . write ( '<STR_LIT:[>' ) <EOL> self . visit ( node . arg , frame ) <EOL> self . write ( '<STR_LIT:]>' ) <EOL> else : <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( node . node , frame ) <EOL> self . write ( '<STR_LIT:U+002CU+0020>' ) <EOL> self . visit ( node . arg , frame ) <EOL> self . write ( '<STR_LIT:)>' ) <EOL> def visit_Slice ( self , node , frame ) : <EOL> if node . start is not None : <EOL> self . visit ( node . start , frame ) <EOL> self . write ( '<STR_LIT::>' ) <EOL> if node . stop is not None : <EOL> self . visit ( node . stop , frame ) <EOL> if node . step is not None : <EOL> self . write ( '<STR_LIT::>' ) <EOL> self . visit ( node . step , frame ) <EOL> def visit_Filter ( self , node , frame ) : <EOL> self . write ( self . filters [ node . name ] + '<STR_LIT:(>' ) <EOL> func = self . environment . filters . get ( node . name ) <EOL> if func is None : <EOL> self . fail ( '<STR_LIT>' % node . name , node . lineno ) <EOL> if getattr ( func , '<STR_LIT>' , False ) : <EOL> self . write ( '<STR_LIT>' ) <EOL> elif getattr ( func , '<STR_LIT>' , False ) : <EOL> self . write ( '<STR_LIT>' ) <EOL> elif getattr ( func , '<STR_LIT>' , False ) : <EOL> self . write ( '<STR_LIT>' ) <EOL> if node . node is not None : <EOL> self . visit ( node . node , frame ) <EOL> elif frame . eval_ctx . volatile : <EOL> self . write ( '<STR_LIT>' <EOL> '<STR_LIT>' % <EOL> ( frame . buffer , frame . buffer ) ) <EOL> elif frame . eval_ctx . autoescape : <EOL> self . write ( '<STR_LIT>' % frame . buffer ) <EOL> else : <EOL> self . write ( '<STR_LIT>' % frame . buffer ) <EOL> self . signature ( node , frame ) <EOL> self . write ( '<STR_LIT:)>' ) <EOL> def visit_Test ( self , node , frame ) : <EOL> self . write ( self . tests [ node . name ] + '<STR_LIT:(>' ) <EOL> if node . name not in self . environment . tests : <EOL> self . fail ( '<STR_LIT>' % node . name , node . lineno ) <EOL> self . visit ( node . node , frame ) <EOL> self . signature ( node , frame ) <EOL> self . write ( '<STR_LIT:)>' ) <EOL> def visit_CondExpr ( self , node , frame ) : <EOL> def write_expr2 ( ) : <EOL> if node . expr2 is not None : <EOL> return self . visit ( node . expr2 , frame ) <EOL> self . write ( '<STR_LIT>' % ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % self . position ( node ) ) ) <EOL> if not have_condexpr : <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( node . test , frame ) <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( node . expr1 , frame ) <EOL> self . write ( '<STR_LIT>' ) <EOL> write_expr2 ( ) <EOL> self . write ( '<STR_LIT>' ) <EOL> else : <EOL> self . write ( '<STR_LIT:(>' ) <EOL> self . visit ( node . expr1 , frame ) <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( node . test , frame ) <EOL> self . write ( '<STR_LIT>' ) <EOL> write_expr2 ( ) <EOL> self . write ( '<STR_LIT:)>' ) <EOL> def visit_Call ( self , node , frame , forward_caller = False ) : <EOL> if self . environment . sandboxed : <EOL> self . write ( '<STR_LIT>' ) <EOL> else : <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( node . node , frame ) <EOL> extra_kwargs = forward_caller and { '<STR_LIT>' : '<STR_LIT>' } or None <EOL> self . signature ( node , frame , extra_kwargs ) <EOL> self . write ( '<STR_LIT:)>' ) <EOL> def visit_Keyword ( self , node , frame ) : <EOL> self . write ( node . key + '<STR_LIT:=>' ) <EOL> self . visit ( node . value , frame ) <EOL> def visit_MarkSafe ( self , node , frame ) : <EOL> self . write ( '<STR_LIT>' ) <EOL> self . visit ( node . expr , frame ) <EOL> self . write ( '<STR_LIT:)>' ) <EOL> def visit_EnvironmentAttribute ( self , node , frame ) : <EOL> self . write ( '<STR_LIT>' + node . name ) <EOL> def visit_ExtensionAttribute ( self , node , frame ) : <EOL> self . write ( '<STR_LIT>' % ( node . identifier , node . name ) ) <EOL> def visit_ImportedName ( self , node , frame ) : <EOL> self . write ( self . import_aliases [ node . importname ] ) <EOL> def visit_InternalName ( self , node , frame ) : <EOL> self . write ( node . name ) <EOL> def visit_ContextReference ( self , node , frame ) : <EOL> self . write ( '<STR_LIT>' ) <EOL> def visit_Continue ( self , node , frame ) : <EOL> self . writeline ( '<STR_LIT>' , node ) <EOL> def visit_Break ( self , node , frame ) : <EOL> self . writeline ( '<STR_LIT>' , node ) <EOL> def visit_Scope ( self , node , frame ) : <EOL> scope_frame = frame . inner ( ) <EOL> scope_frame . inspect ( node . iter_child_nodes ( ) ) <EOL> aliases = self . push_scope ( scope_frame ) <EOL> self . pull_locals ( scope_frame ) <EOL> self . blockvisit ( node . body , scope_frame ) <EOL> self . pop_scope ( aliases , scope_frame ) <EOL> def visit_EvalContextModifier ( self , node , frame ) : <EOL> for keyword in node . options : <EOL> self . writeline ( '<STR_LIT>' % keyword . key ) <EOL> self . visit ( keyword . value , frame ) <EOL> try : <EOL> val = keyword . value . as_const ( frame . eval_ctx ) <EOL> except nodes . Impossible : <EOL> frame . eval_ctx . volatile = True <EOL> else : <EOL> setattr ( frame . eval_ctx , keyword . key , val ) <EOL> def visit_ScopedEvalContextModifier ( self , node , frame ) : <EOL> old_ctx_name = self . temporary_identifier ( ) <EOL> safed_ctx = frame . eval_ctx . save ( ) <EOL> self . writeline ( '<STR_LIT>' % old_ctx_name ) <EOL> self . visit_EvalContextModifier ( node , frame ) <EOL> for child in node . body : <EOL> self . visit ( child , frame ) <EOL> frame . eval_ctx . revert ( safed_ctx ) <EOL> self . writeline ( '<STR_LIT>' % old_ctx_name ) </s>
