<s> import ast <EOL> from . base import ( <EOL> BaseAnalyzer , Result , AttributeVisitor , ModuleVisitor , set_lineno ) <EOL> class CallVisitor ( ast . NodeVisitor ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . names = set ( ) <EOL> def visit_Attribute ( self , node ) : <EOL> visitor = AttributeVisitor ( ) <EOL> visitor . visit ( node ) <EOL> if visitor . is_usable : <EOL> self . names . add ( visitor . get_name ( ) ) <EOL> def visit_Name ( self , node ) : <EOL> self . names . add ( node . id ) <EOL> class RenderToResponseVisitor ( ModuleVisitor ) : <EOL> interesting = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> @ set_lineno <EOL> def visit_Call ( self , node ) : <EOL> visitor = AttributeVisitor ( ) <EOL> visitor . visit ( node . func ) <EOL> if not visitor . is_usable : <EOL> return <EOL> name = visitor . get_name ( ) <EOL> if name not in self . names : <EOL> return <EOL> if self . names [ name ] != '<STR_LIT>' : <EOL> return <EOL> visitor = CallVisitor ( ) <EOL> visitor . visit ( node ) <EOL> for subname in visitor . names : <EOL> if subname not in self . names : <EOL> continue <EOL> if self . names [ subname ] == '<STR_LIT>' : <EOL> self . add_found ( name , node ) <EOL> class RenderToResponseAnalyzer ( BaseAnalyzer ) : <EOL> def analyze_file ( self , filepath , code ) : <EOL> if not isinstance ( code , ast . AST ) : <EOL> return <EOL> visitor = RenderToResponseVisitor ( ) <EOL> visitor . visit ( code ) <EOL> for name , node , start , stop in visitor . get_found ( ) : <EOL> result = Result ( <EOL> description = ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % name ) , <EOL> path = filepath , <EOL> line = start ) <EOL> lines = self . get_file_lines ( filepath , start , stop ) <EOL> for lineno , important , text in lines : <EOL> result . source . add_line ( lineno , text , important ) <EOL> yield result </s>
