<s> """<STR_LIT>""" <EOL> from lib2to3 . compiler import ast , walk <EOL> def is_future ( stmt ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( stmt , ast . From ) : <EOL> return <NUM_LIT:0> <EOL> if stmt . modname == "<STR_LIT>" : <EOL> return <NUM_LIT:1> <EOL> else : <EOL> return <NUM_LIT:0> <EOL> class FutureParser : <EOL> features = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> def __init__ ( self ) : <EOL> self . found = { } <EOL> def visitModule ( self , node ) : <EOL> stmt = node . node <EOL> for s in stmt . nodes : <EOL> if not self . check_stmt ( s ) : <EOL> break <EOL> def check_stmt ( self , stmt ) : <EOL> if is_future ( stmt ) : <EOL> for name , asname in stmt . names : <EOL> if name in self . features : <EOL> self . found [ name ] = <NUM_LIT:1> <EOL> else : <EOL> raise SyntaxError , "<STR_LIT>" % name <EOL> stmt . valid_future = <NUM_LIT:1> <EOL> return <NUM_LIT:1> <EOL> return <NUM_LIT:0> <EOL> def get_features ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . found . keys ( ) <EOL> class BadFutureParser : <EOL> """<STR_LIT>""" <EOL> def visitFrom ( self , node ) : <EOL> if hasattr ( node , '<STR_LIT>' ) : <EOL> return <EOL> if node . modname != "<STR_LIT>" : <EOL> return <EOL> raise SyntaxError , "<STR_LIT>" + repr ( node ) <EOL> def find_futures ( node ) : <EOL> p1 = FutureParser ( ) <EOL> p2 = BadFutureParser ( ) <EOL> walk ( node , p1 ) <EOL> walk ( node , p2 ) <EOL> return p1 . get_features ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import sys <EOL> from compiler import parseFile , walk <EOL> for file in sys . argv [ <NUM_LIT:1> : ] : <EOL> print file <EOL> tree = parseFile ( file ) <EOL> v = FutureParser ( ) <EOL> walk ( tree , v ) <EOL> print v . found <EOL> print </s>
