def synopsis(filename, cache={}):
 mtime = os.stat(filename).st_mtime
 (lastupdate, result) = cache.get(filename, (0, None))
 if (lastupdate < mtime):
  info = inspect.getmoduleinfo(filename)
  try:
   file = open(filename)
  except IOError:
   return None
  if (info and ('b' in info[2])):
   try:
    module = imp.load_module('__temp__', file, filename, info[1:])
   except:
    return None
   result = (module.__doc__ or '').splitlines()[0]
   del sys.modules['__temp__']
  else:
   result = source_synopsis(file)
   file.close()
  cache[filename] = (mtime, result)
 return result

def synopsis ( filename , cache = { } ) : mtime = os . stat ( filename ) . st_mtime ( lastupdate , result ) = cache . get ( filename , ( 0 , None ) ) if ( lastupdate < mtime ) : info = inspect . getmoduleinfo ( filename ) try : file = open ( filename ) except IOError : return None if ( info and ( 'b' in info [ 2 ] ) ) : try : module = imp . load_module ( '__temp__' , file , filename , info [ 1 : ] ) except : return None result = ( module . __doc__ or '' ) . splitlines ( ) [ 0 ] del sys . modules [ '__temp__' ] else : result = source_synopsis ( file ) file . close ( ) cache [ filename ] = ( mtime , result ) return result
get the one-line summary out of a module file .