<s> """<STR_LIT>""" <EOL> __author__ = "<STR_LIT>" <EOL> import sys , os , re , getopt <EOL> try : <EOL> import pysource <EOL> except ImportError : <EOL> class pysource : <EOL> has_python_ext = looks_like_python = can_be_compiled = None <EOL> def walk_python_files ( self , paths , * args , ** kwargs ) : <EOL> for path in paths : <EOL> if os . path . isfile ( path ) : <EOL> yield path . endswith ( "<STR_LIT>" ) <EOL> elif os . path . isdir ( path ) : <EOL> for root , dirs , files in os . walk ( path ) : <EOL> for filename in files : <EOL> if filename . endswith ( "<STR_LIT>" ) : <EOL> yield os . path . join ( root , filename ) <EOL> pysource = pysource ( ) <EOL> print >> sys . stderr , ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> decl_re = re . compile ( r'<STR_LIT>' ) <EOL> blank_re = re . compile ( r'<STR_LIT>' ) <EOL> def get_declaration ( line ) : <EOL> match = decl_re . match ( line ) <EOL> if match : <EOL> return match . group ( <NUM_LIT:1> ) <EOL> return b'<STR_LIT>' <EOL> def has_correct_encoding ( text , codec ) : <EOL> try : <EOL> unicode ( text , codec ) <EOL> except UnicodeDecodeError : <EOL> return False <EOL> else : <EOL> return True <EOL> def needs_declaration ( fullpath ) : <EOL> try : <EOL> infile = open ( fullpath , '<STR_LIT>' ) <EOL> except IOError : <EOL> return None <EOL> line1 = infile . readline ( ) <EOL> line2 = infile . readline ( ) <EOL> if ( get_declaration ( line1 ) or <EOL> blank_re . match ( line1 ) and get_declaration ( line2 ) ) : <EOL> infile . close ( ) <EOL> return False <EOL> rest = infile . read ( ) <EOL> infile . close ( ) <EOL> if has_correct_encoding ( line1 + line2 + rest , "<STR_LIT:ascii>" ) : <EOL> return False <EOL> return True <EOL> usage = """<STR_LIT>""" % sys . argv [ <NUM_LIT:0> ] <EOL> try : <EOL> opts , args = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , '<STR_LIT>' ) <EOL> except getopt . error , msg : <EOL> print >> sys . stderr , msg <EOL> print >> sys . stderr , usage <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> is_python = pysource . looks_like_python <EOL> debug = False <EOL> for o , a in opts : <EOL> if o == '<STR_LIT:-c>' : <EOL> is_python = pysource . can_be_compiled <EOL> elif o == '<STR_LIT>' : <EOL> debug = True <EOL> if not args : <EOL> print >> sys . stderr , usage <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> for fullpath in pysource . walk_python_files ( args , is_python ) : <EOL> if debug : <EOL> print "<STR_LIT>" % fullpath <EOL> result = needs_declaration ( fullpath ) <EOL> if result : <EOL> print fullpath </s>
