<s> """<STR_LIT>""" <EOL> from jinja2 import nodes <EOL> from jinja2 . compiler import CodeGenerator <EOL> from jinja2 . _compat import string_types <EOL> class TrackingCodeGenerator ( CodeGenerator ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , environment ) : <EOL> CodeGenerator . __init__ ( self , environment , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> self . undeclared_identifiers = set ( ) <EOL> def write ( self , x ) : <EOL> """<STR_LIT>""" <EOL> def pull_locals ( self , frame ) : <EOL> """<STR_LIT>""" <EOL> self . undeclared_identifiers . update ( frame . identifiers . undeclared ) <EOL> def find_undeclared_variables ( ast ) : <EOL> """<STR_LIT>""" <EOL> codegen = TrackingCodeGenerator ( ast . environment ) <EOL> codegen . visit ( ast ) <EOL> return codegen . undeclared_identifiers <EOL> def find_referenced_templates ( ast ) : <EOL> """<STR_LIT>""" <EOL> for node in ast . find_all ( ( nodes . Extends , nodes . FromImport , nodes . Import , <EOL> nodes . Include ) ) : <EOL> if not isinstance ( node . template , nodes . Const ) : <EOL> if isinstance ( node . template , ( nodes . Tuple , nodes . List ) ) : <EOL> for template_name in node . template . items : <EOL> if isinstance ( template_name , nodes . Const ) : <EOL> if isinstance ( template_name . value , string_types ) : <EOL> yield template_name . value <EOL> else : <EOL> yield None <EOL> else : <EOL> yield None <EOL> continue <EOL> if isinstance ( node . template . value , string_types ) : <EOL> yield node . template . value <EOL> elif isinstance ( node , nodes . Include ) and isinstance ( node . template . value , ( tuple , list ) ) : <EOL> for template_name in node . template . value : <EOL> if isinstance ( template_name , string_types ) : <EOL> yield template_name <EOL> else : <EOL> yield None </s>
