--- pydoc.py 2006-07-28 18:28:50.328125000 +0200 +++ pydoc2.py 2006-07-28 18:32:37.718750000 +0200 @@ -1458,27 +1458,31 @@ else: return thing, getattr(thing, '__name__', None) -def doc(thing, title='Python Library Documentation: %s', forceload=0): +def render_doc(thing, title='Python Library Documentation: %s', forceload=0): + """Generates the documentation text""" + object, name = resolve(thing, forceload) + desc = describe(object) + module = inspect.getmodule(object) + if name and '.' in name: + desc += ' in ' + name[:name.rfind('.')] + elif module and module is not object: + desc += ' in module ' + module.__name__ + if not (inspect.ismodule(object) or + inspect.isclass(object) or + inspect.isroutine(object) or + inspect.isgetsetdescriptor(object) or + inspect.ismemberdescriptor(object) or + isinstance(object, property)): + # If the passed object is a piece of data or an instance, + # document its available methods instead of its value. + object = type(object) + desc += ' object' + return title % desc + '\n\n' + text.document(object, name) + +def doc(*args, **kwargs): """Display text documentation, given an object or a path to an object.""" try: - object, name = resolve(thing, forceload) - desc = describe(object) - module = inspect.getmodule(object) - if name and '.' in name: - desc += ' in ' + name[:name.rfind('.')] - elif module and module is not object: - desc += ' in module ' + module.__name__ - if not (inspect.ismodule(object) or - inspect.isclass(object) or - inspect.isroutine(object) or - inspect.isgetsetdescriptor(object) or - inspect.ismemberdescriptor(object) or - isinstance(object, property)): - # If the passed object is a piece of data or an instance, - # document its available methods instead of its value. - object = type(object) - desc += ' object' - pager(title % desc + '\n\n' + text.document(object, name)) + pager(render_doc(*args, **kwargs)) except (ImportError, ErrorDuringImport), value: print value