Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
pydoc.ModuleScanner Class Reference

List of all members.

Public Member Functions

def run

Public Attributes

 quit

Detailed Description

An interruptible scanner that searches module synopses.

Definition at line 1976 of file pydoc.py.


Member Function Documentation

def pydoc.ModuleScanner.run (   self,
  callback,
  key = None,
  completer = None,
  onerror = None 
)

Definition at line 1979 of file pydoc.py.

01979 
01980     def run(self, callback, key=None, completer=None, onerror=None):
01981         if key: key = key.lower()
01982         self.quit = False
01983         seen = {}
01984 
01985         for modname in sys.builtin_module_names:
01986             if modname != '__main__':
01987                 seen[modname] = 1
01988                 if key is None:
01989                     callback(None, modname, '')
01990                 else:
01991                     name = __import__(modname).__doc__ or ''
01992                     desc = name.split('\n')[0]
01993                     name = modname + ' - ' + desc
01994                     if name.lower().find(key) >= 0:
01995                         callback(None, modname, desc)
01996 
01997         for importer, modname, ispkg in pkgutil.walk_packages(onerror=onerror):
01998             if self.quit:
01999                 break
02000 
02001             # XXX Skipping this file is a workaround for a bug
02002             # that causes python to crash with a segfault.
02003             # http://bugs.python.org/issue9319
02004             #
02005             # TODO Remove this once the bug is fixed.
02006             if modname in {'test.badsyntax_pep3120', 'badsyntax_pep3120'}:
02007                 continue
02008 
02009             if key is None:
02010                 callback(None, modname, '')
02011             else:
02012                 try:
02013                     loader = importer.find_module(modname)
02014                 except SyntaxError:
02015                     # raised by tests for bad coding cookies or BOM
02016                     continue
02017                 if hasattr(loader, 'get_source'):
02018                     try:
02019                         source = loader.get_source(modname)
02020                     except UnicodeDecodeError:
02021                         if onerror:
02022                             onerror(modname)
02023                         continue
02024                     desc = source_synopsis(io.StringIO(source)) or ''
02025                     if hasattr(loader, 'get_filename'):
02026                         path = loader.get_filename(modname)
02027                     else:
02028                         path = None
02029                 else:
02030                     try:
02031                         module = loader.load_module(modname)
02032                     except ImportError:
02033                         if onerror:
02034                             onerror(modname)
02035                         continue
02036                     desc = (module.__doc__ or '').splitlines()[0]
02037                     path = getattr(module,'__file__',None)
02038                 name = modname + ' - ' + desc
02039                 if name.lower().find(key) >= 0:
02040                     callback(path, modname, desc)
02041 
02042         if completer:
02043             completer()

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1981 of file pydoc.py.


The documentation for this class was generated from the following file: