'Produce text documentation for a given module object.'

def docmodule(self, object, name=None, mod=None):

    name = object.__name__
    (synop, desc) = splitdoc(getdoc(object))
    result = self.section('NAME', (name + (synop and ('    -    ' + synop))))
    try:
        all = object.__all__
    except AttributeError:
        all = None
    try:
        file = inspect.getabsfile(object)
    except TypeError:
        file = '(built-in)'
    result = (result + self.section('FILE', file))
    docloc = self.getdocloc(object)
    if (docloc is not None):
        result = (result + self.section('MODULE    DOCS', docloc))
    if desc:
        result = (result + self.section('DESCRIPTION', desc))
    classes = []
    for (key, value) in inspect.getmembers(object, inspect.isclass):
        if ((all is not None) or ((inspect.getmodule(value) or object) is object)):
            if visiblename(key, all, object):
                classes.append((key, value))
    funcs = []
    for (key, value) in inspect.getmembers(object, inspect.isroutine):
        if ((all is not None) or inspect.isbuiltin(value) or (inspect.getmodule(value) is object)):
            if visiblename(key, all, object):
                funcs.append((key, value))
    data = []
    for (key, value) in inspect.getmembers(object, isdata):
        if visiblename(key, all, object):
            data.append((key, value))
    modpkgs = []
    modpkgs_names = set()
    if hasattr(object, '__path__'):
        for (importer, modname, ispkg) in pkgutil.iter_modules(object.__path__):
            modpkgs_names.add(modname)
            if ispkg:
                modpkgs.append((modname + '    (package)'))
            else:
                modpkgs.append(modname)
        modpkgs.sort()
        result = (result + self.section('PACKAGE    CONTENTS', join(modpkgs, '\n')))
    submodules = []
    for (key, value) in inspect.getmembers(object, inspect.ismodule):
        if (value.__name__.startswith((name + '.')) and (key not in modpkgs_names)):
            submodules.append(key)
    if submodules:
        submodules.sort()
        result = (result + self.section('SUBMODULES', join(submodules, '\n')))
    if classes:
        classlist = map((lambda key_value: key_value[1]), classes)
        contents = [self.formattree(inspect.getclasstree(classlist, 1), name)]
        for (key, value) in classes:
            contents.append(self.document(value, key, name))
        result = (result + self.section('CLASSES', join(contents, '\n')))
    if funcs:
        contents = []
        for (key, value) in funcs:
            contents.append(self.document(value, key, name))
        result = (result + self.section('FUNCTIONS', join(contents, '\n')))
    if data:
        contents = []
        for (key, value) in data:
            contents.append(self.docother(value, key, name, maxlen=70))
        result = (result + self.section('DATA', join(contents, '\n')))
    if hasattr(object, '__version__'):
        version = _binstr(object.__version__)
        if ((version[:11] == ('$' + 'Revision:    ')) and (version[(-1):] == '$')):
            version = strip(version[11:(-1)])
        result = (result + self.section('VERSION', version))
    if hasattr(object, '__date__'):
        result = (result + self.section('DATE', _binstr(object.__date__)))
    if hasattr(object, '__author__'):
        result = (result + self.section('AUTHOR', _binstr(object.__author__)))
    if hasattr(object, '__credits__'):
        result = (result + self.section('CREDITS', _binstr(object.__credits__)))
    return result
