<s> """<STR_LIT>""" <EOL> from __future__ import with_statement <EOL> import sys <EOL> import os <EOL> import _ast <EOL> from optparse import OptionParser <EOL> from . import checker , __version__ <EOL> from . import reporter as modReporter <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def check ( codeString , filename , reporter = None ) : <EOL> """<STR_LIT>""" <EOL> if reporter is None : <EOL> reporter = modReporter . _makeDefaultReporter ( ) <EOL> try : <EOL> tree = compile ( codeString , filename , "<STR_LIT>" , _ast . PyCF_ONLY_AST ) <EOL> except SyntaxError : <EOL> value = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> msg = value . args [ <NUM_LIT:0> ] <EOL> ( lineno , offset , text ) = value . lineno , value . offset , value . text <EOL> if text is None : <EOL> reporter . unexpectedError ( filename , '<STR_LIT>' ) <EOL> else : <EOL> reporter . syntaxError ( filename , msg , lineno , offset , text ) <EOL> return <NUM_LIT:1> <EOL> except Exception : <EOL> reporter . unexpectedError ( filename , '<STR_LIT>' ) <EOL> return <NUM_LIT:1> <EOL> w = checker . Checker ( tree , filename ) <EOL> w . messages . sort ( key = lambda m : m . lineno ) <EOL> for warning in w . messages : <EOL> reporter . flake ( warning ) <EOL> return len ( w . messages ) <EOL> def checkPath ( filename , reporter = None ) : <EOL> """<STR_LIT>""" <EOL> if reporter is None : <EOL> reporter = modReporter . _makeDefaultReporter ( ) <EOL> try : <EOL> with open ( filename , '<STR_LIT>' ) as f : <EOL> codestr = f . read ( ) + '<STR_LIT:\n>' <EOL> except UnicodeError : <EOL> reporter . unexpectedError ( filename , '<STR_LIT>' ) <EOL> return <NUM_LIT:1> <EOL> except IOError : <EOL> msg = sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> reporter . unexpectedError ( filename , msg . args [ <NUM_LIT:1> ] ) <EOL> return <NUM_LIT:1> <EOL> return check ( codestr , filename , reporter ) <EOL> def iterSourceCode ( paths ) : <EOL> """<STR_LIT>""" <EOL> for path in paths : <EOL> if os . path . isdir ( path ) : <EOL> for dirpath , dirnames , filenames in os . walk ( path ) : <EOL> for filename in filenames : <EOL> if filename . endswith ( '<STR_LIT>' ) : <EOL> yield os . path . join ( dirpath , filename ) <EOL> else : <EOL> yield path <EOL> def checkRecursive ( paths , reporter ) : <EOL> """<STR_LIT>""" <EOL> warnings = <NUM_LIT:0> <EOL> for sourcePath in iterSourceCode ( paths ) : <EOL> warnings += checkPath ( sourcePath , reporter ) <EOL> return warnings <EOL> def main ( prog = None ) : <EOL> parser = OptionParser ( prog = prog , version = __version__ ) <EOL> __ , args = parser . parse_args ( ) <EOL> reporter = modReporter . _makeDefaultReporter ( ) <EOL> if args : <EOL> warnings = checkRecursive ( args , reporter ) <EOL> else : <EOL> warnings = check ( sys . stdin . read ( ) , '<STR_LIT>' , reporter ) <EOL> raise SystemExit ( warnings > <NUM_LIT:0> ) </s>
