<s> """<STR_LIT>""" <EOL> import fnmatch <EOL> import os <EOL> import re <EOL> import sys <EOL> excluded_docs = [ '<STR_LIT>' ] <EOL> api_doc = '<STR_LIT>' <EOL> def usage ( cmd ) : <EOL> print ( "<STR_LIT>" % cmd ) <EOL> print ( ) <EOL> print ( "<STR_LIT>" % api_doc ) <EOL> print ( "<STR_LIT>" ) <EOL> exit ( <NUM_LIT:0> ) <EOL> def main ( argv ) : <EOL> api_files = rst_files = [ rst for rst in os . listdir ( '<STR_LIT>' ) <EOL> if fnmatch . fnmatch ( rst , '<STR_LIT>' ) <EOL> and rst not in excluded_docs ] <EOL> cmd = argv . pop ( <NUM_LIT:0> ) <EOL> def has ( * options ) : <EOL> for opt in options : <EOL> if opt in argv : <EOL> return argv . pop ( argv . index ( opt ) ) <EOL> if has ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> usage ( cmd ) <EOL> verbose = has ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> only_documented = not has ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if argv : <EOL> given_files = [ ] <EOL> for arg in argv : <EOL> arg = arg . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) . replace ( api_doc + '<STR_LIT:/>' , '<STR_LIT>' ) <EOL> arg = arg . replace ( '<STR_LIT>' , '<STR_LIT>' ) + '<STR_LIT>' <EOL> if '<STR_LIT:*>' in arg : <EOL> given_files += [ rst for rst in api_files <EOL> if fnmatch . fnmatch ( rst , arg ) ] <EOL> elif arg in api_files : <EOL> given_files . append ( arg ) <EOL> api_files = given_files <EOL> rst_basenames = sorted ( f [ : - <NUM_LIT:4> ] for f in rst_files ) <EOL> for rst in api_files : <EOL> basename = rst . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if verbose or len ( api_files ) > <NUM_LIT:1> : <EOL> print ( "<STR_LIT>" % rst ) <EOL> check_api_doc ( basename , verbose , only_documented , <EOL> any ( f . startswith ( basename ) and f != basename <EOL> for f in rst_basenames ) ) <EOL> def check_api_doc ( basename , verbose , only_documented , has_submodules ) : <EOL> module_name = basename . replace ( '<STR_LIT:_>' , '<STR_LIT:.>' ) <EOL> try : <EOL> module = __import__ ( module_name , globals ( ) , { } , [ '<STR_LIT>' ] ) <EOL> except ImportError as e : <EOL> print ( "<STR_LIT>" % ( basename , e ) ) <EOL> return <EOL> all = getattr ( module , '<STR_LIT>' , None ) <EOL> if not all : <EOL> print ( "<STR_LIT>" <EOL> % module_name ) <EOL> all = get_default_symbols ( module , only_documented , has_submodules ) <EOL> no_apidoc = getattr ( module , '<STR_LIT>' , None ) <EOL> if no_apidoc : <EOL> if isinstance ( no_apidoc , basestring ) : <EOL> no_apidoc = [ s . strip ( ) for s in no_apidoc . split ( ) ] <EOL> all = list ( set ( all ) - set ( no_apidoc ) ) <EOL> symbols , keywords = get_sphinx_documented_symbols ( basename + '<STR_LIT>' ) <EOL> for symbol in sorted ( all ) : <EOL> if symbol in symbols : <EOL> if verbose : <EOL> print ( "<STR_LIT>" <EOL> % ( keywords [ symbols . index ( symbol ) ] , symbol ) ) <EOL> else : <EOL> value = getattr ( module , symbol ) <EOL> cls = getattr ( value , '<STR_LIT>' , None ) <EOL> keyword = '<STR_LIT:data>' <EOL> if cls . __name__ in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> keyword = '<STR_LIT>' <EOL> elif cls . __name__ == '<STR_LIT>' : <EOL> keyword = '<STR_LIT>' <EOL> else : <EOL> keyword = '<STR_LIT:class>' <EOL> print ( "<STR_LIT>" % ( '<STR_LIT>' + keyword , symbol ) ) <EOL> sphinx_doc_re = re . compile ( r'''<STR_LIT>''' , re . MULTILINE | re . VERBOSE ) <EOL> def get_sphinx_documented_symbols ( rst ) : <EOL> with open ( os . path . join ( api_doc , rst ) ) as f : <EOL> doc = f . read ( ) <EOL> symbols , keywords = [ ] , [ ] <EOL> for k , s in sphinx_doc_re . findall ( doc ) : <EOL> symbols . append ( s . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] ) <EOL> keywords . append ( k ) <EOL> return symbols , keywords <EOL> def get_default_symbols ( module , only_documented , has_submodules ) : <EOL> public = get_public_symbols ( module ) - get_imported_symbols ( module , <EOL> has_submodules ) <EOL> all = [ ] <EOL> for symbol in public : <EOL> try : <EOL> __import__ ( symbol ) <EOL> except ImportError : <EOL> all . append ( symbol ) <EOL> if only_documented : <EOL> documented = [ ] <EOL> for symbol in all : <EOL> value = getattr ( module , symbol ) <EOL> if value . __doc__ and ( not getattr ( value , '<STR_LIT>' , None ) or <EOL> value . __doc__ != value . __class__ . __doc__ ) : <EOL> documented . append ( symbol ) <EOL> all = documented <EOL> return all <EOL> def get_public_symbols ( m ) : <EOL> return set ( symbol for symbol in dir ( m ) if not symbol . startswith ( '<STR_LIT:_>' ) ) <EOL> import_from_re = re . compile ( r'''<STR_LIT>''' % ( ( r'<STR_LIT>' , ) * <NUM_LIT:4> ) , re . MULTILINE | re . VERBOSE ) <EOL> remove_original_re = re . compile ( r'<STR_LIT>' , re . MULTILINE ) <EOL> def get_imported_symbols ( module , has_submodules ) : <EOL> src_filename = module . __file__ . replace ( '<STR_LIT:\\>' , '<STR_LIT:/>' ) . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if src_filename . endswith ( '<STR_LIT>' ) and not has_submodules : <EOL> return set ( ) <EOL> with open ( src_filename ) as f : <EOL> src = f . read ( ) <EOL> imported = set ( ) <EOL> for mod , symbol_list in import_from_re . findall ( src ) : <EOL> symbol_list = symbol_list . strip ( ) <EOL> if symbol_list == '<STR_LIT:*>' : <EOL> try : <EOL> imported_module = __import__ ( mod , globals ( ) , { } , [ '<STR_LIT>' ] ) <EOL> symbols = set ( getattr ( imported_module , '<STR_LIT>' , None ) or <EOL> get_public_symbols ( imported_module ) ) <EOL> except ImportError : <EOL> print ( "<STR_LIT>" <EOL> % mod ) <EOL> continue <EOL> else : <EOL> if symbol_list and symbol_list [ <NUM_LIT:0> ] == '<STR_LIT:(>' and symbol_list [ - <NUM_LIT:1> ] == '<STR_LIT:)>' : <EOL> symbol_list = symbol_list [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> symbols = set ( remove_original_re . sub ( '<STR_LIT>' , symbol_list ) <EOL> . replace ( '<STR_LIT:\\>' , '<STR_LIT>' ) . replace ( '<STR_LIT:U+002C>' , '<STR_LIT:U+0020>' ) . split ( ) ) <EOL> imported |= symbols <EOL> return imported <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( sys . argv ) </s>
