<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> __all__ = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> def getline ( filename , lineno , module_globals = None ) : <EOL> lines = getlines ( filename , module_globals ) <EOL> if <NUM_LIT:1> <= lineno <= len ( lines ) : <EOL> return lines [ lineno - <NUM_LIT:1> ] <EOL> else : <EOL> return '<STR_LIT>' <EOL> cache = { } <EOL> def clearcache ( ) : <EOL> """<STR_LIT>""" <EOL> global cache <EOL> cache = { } <EOL> def getlines ( filename , module_globals = None ) : <EOL> """<STR_LIT>""" <EOL> if filename in cache : <EOL> return cache [ filename ] [ <NUM_LIT:2> ] <EOL> else : <EOL> return updatecache ( filename , module_globals ) <EOL> def checkcache ( filename = None ) : <EOL> """<STR_LIT>""" <EOL> if filename is None : <EOL> filenames = cache . keys ( ) <EOL> else : <EOL> if filename in cache : <EOL> filenames = [ filename ] <EOL> else : <EOL> return <EOL> for filename in filenames : <EOL> size , mtime , lines , fullname = cache [ filename ] <EOL> if mtime is None : <EOL> continue <EOL> try : <EOL> stat = os . stat ( fullname ) <EOL> except os . error : <EOL> del cache [ filename ] <EOL> continue <EOL> if size != stat . st_size or mtime != stat . st_mtime : <EOL> del cache [ filename ] <EOL> def updatecache ( filename , module_globals = None ) : <EOL> """<STR_LIT>""" <EOL> if filename in cache : <EOL> del cache [ filename ] <EOL> if not filename or filename [ <NUM_LIT:0> ] + filename [ - <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> return [ ] <EOL> fullname = filename <EOL> try : <EOL> stat = os . stat ( fullname ) <EOL> except os . error , msg : <EOL> basename = os . path . split ( filename ) [ <NUM_LIT:1> ] <EOL> if module_globals and '<STR_LIT>' in module_globals : <EOL> name = module_globals . get ( '<STR_LIT>' ) <EOL> loader = module_globals [ '<STR_LIT>' ] <EOL> get_source = getattr ( loader , '<STR_LIT>' , None ) <EOL> if name and get_source : <EOL> if basename . startswith ( name . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] + '<STR_LIT:.>' ) : <EOL> try : <EOL> data = get_source ( name ) <EOL> except ( ImportError , IOError ) : <EOL> pass <EOL> else : <EOL> if data is None : <EOL> return [ ] <EOL> cache [ filename ] = ( <EOL> len ( data ) , None , <EOL> [ line + '<STR_LIT:\n>' for line in data . splitlines ( ) ] , fullname <EOL> ) <EOL> return cache [ filename ] [ <NUM_LIT:2> ] <EOL> for dirname in sys . path : <EOL> try : <EOL> fullname = os . path . join ( dirname , basename ) <EOL> except ( TypeError , AttributeError ) : <EOL> pass <EOL> else : <EOL> try : <EOL> stat = os . stat ( fullname ) <EOL> break <EOL> except os . error : <EOL> pass <EOL> else : <EOL> return [ ] <EOL> try : <EOL> fp = open ( fullname , '<STR_LIT>' ) <EOL> lines = fp . readlines ( ) <EOL> fp . close ( ) <EOL> except IOError , msg : <EOL> return [ ] <EOL> size , mtime = stat . st_size , stat . st_mtime <EOL> cache [ filename ] = size , mtime , lines , fullname <EOL> return lines </s>
