<s> '''<STR_LIT>''' <EOL> import ast , _ast <EOL> DEBUG = False <EOL> blacklist = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:type>" ] <EOL> class SafetyVisitor ( ast . NodeVisitor ) : <EOL> def __init__ ( self ) : <EOL> self . safe = True <EOL> self . classes = [ ] <EOL> def generic_visit ( self , node ) : <EOL> if DEBUG : <EOL> print "<STR_LIT>" , ast . dump ( node ) <EOL> ast . NodeVisitor . generic_visit ( self , node ) <EOL> def visit_Import ( self , node ) : <EOL> self . safe = False <EOL> print "<STR_LIT>" % ( node . lineno , node . names [ <NUM_LIT:0> ] . name ) <EOL> def visit_ImportFrom ( self , node ) : <EOL> self . safe = False <EOL> print "<STR_LIT>" % ( node . lineno , node . module ) <EOL> def visit_Exec ( self , node ) : <EOL> self . safe = False <EOL> print "<STR_LIT>" % node . lineno <EOL> def visit_Call ( self , node ) : <EOL> if DEBUG : <EOL> print '<STR_LIT>' <EOL> self . check_functioncall ( node ) <EOL> self . generic_visit ( node ) <EOL> def visit_ClassDef ( self , node ) : <EOL> if DEBUG : <EOL> print '<STR_LIT>' , node . name <EOL> self . classes . append ( node . name ) <EOL> self . generic_visit ( node ) <EOL> def visit_Name ( self , node ) : <EOL> if DEBUG : <EOL> print '<STR_LIT>' , node . id <EOL> def visit_Num ( self , node ) : <EOL> if DEBUG : <EOL> print '<STR_LIT>' , node . __dict__ [ '<STR_LIT:n>' ] <EOL> def visit_Str ( self , node ) : <EOL> if DEBUG : <EOL> print "<STR_LIT>" , node . s <EOL> def visit_Print ( self , node ) : <EOL> if DEBUG : <EOL> print "<STR_LIT>" <EOL> self . generic_visit ( node ) <EOL> def visit_Assign ( self , node ) : <EOL> if DEBUG : <EOL> print "<STR_LIT>" <EOL> self . check_assignment ( node ) <EOL> self . generic_visit ( node ) <EOL> def visit_Expr ( self , node ) : <EOL> if DEBUG : <EOL> print "<STR_LIT>" <EOL> self . generic_visit ( node ) <EOL> def check_assignment ( self , node ) : <EOL> if DEBUG : <EOL> print "<STR_LIT>" <EOL> global blacklist <EOL> if type ( node . value ) . __name__ == '<STR_LIT:Name>' : <EOL> if node . value . id in blacklist : <EOL> self . safe = False <EOL> print "<STR_LIT>" % ( node . lineno , node . value . id ) <EOL> def check_functioncall ( self , node ) : <EOL> if DEBUG : <EOL> print "<STR_LIT>" <EOL> global blacklist <EOL> isopen = False <EOL> for fname , fvalue in ast . iter_fields ( node ) : <EOL> if DEBUG : <EOL> print fname , "<STR_LIT:U+0020>" , fvalue <EOL> if fname == '<STR_LIT>' and type ( fvalue ) . __name__ == '<STR_LIT:Name>' : <EOL> if fvalue . id == '<STR_LIT>' : <EOL> isopen = True <EOL> elif fvalue . id in blacklist : <EOL> self . safe = False <EOL> print "<STR_LIT>" % ( node . lineno , fvalue . id ) <EOL> if fname == '<STR_LIT:args>' and isopen : <EOL> for arg in fvalue : <EOL> if type ( arg ) . __name__ == '<STR_LIT>' : <EOL> if arg . __dict__ [ '<STR_LIT:s>' ] == '<STR_LIT:w>' or arg . __dict__ [ '<STR_LIT:s>' ] == '<STR_LIT:a>' : <EOL> self . safe = False <EOL> print "<STR_LIT>" % node . lineno <EOL> elif type ( arg ) . __name__ == '<STR_LIT:Name>' : <EOL> self . safe = False <EOL> print "<STR_LIT>" % ( node . lineno , arg . id ) <EOL> def main ( ) : <EOL> path = "<STR_LIT>" <EOL> astnode = compile ( open ( path , '<STR_LIT>' ) . read ( ) , "<STR_LIT>" , "<STR_LIT>" , _ast . PyCF_ONLY_AST ) <EOL> v = SafetyVisitor ( ) <EOL> v . visit ( astnode ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
