def __init__(self, module, docfilter=None):
name = getattr(module, '<STR_LIT>', module.__name__)<EOL>super(Module, self).__init__(name, module, inspect.getdoc(module))<EOL>self._filtering = docfilter is not None<EOL>self._docfilter = (lambda _: True) if docfilter is None else docfilter<EOL>self._allsubmodules = False<EOL>self.doc = {}<EOL>"""<STR_LIT>"""<EOL>self.refdoc = {}<EOL>"""<STR_LIT>"""<EOL>vardocs = {}<EOL>try:<EOL><INDENT>tree = ast.parse(inspect.getsource(self.module))<EOL>vardocs = _var_docstrings(tree, self, cls=None)<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>self._declared_variables = vardocs.keys()<EOL>public = self.__public_objs()<EOL>for name, obj in public.items():<EOL><INDENT>if name in self.doc and not self.doc[name].is_empty():<EOL><INDENT>continue<EOL><DEDENT>if inspect.isfunction(obj) or inspect.isbuiltin(obj):<EOL><INDENT>self.doc[name] = Function(name, self, obj)<EOL><DEDENT>elif inspect.ismethod(obj):<EOL><INDENT>self.doc[name] = Function(name, self, obj)<EOL><DEDENT>elif inspect.isclass(obj):<EOL><INDENT>self.doc[name] = Class(name, self, obj)<EOL><DEDENT>elif inspect.ismodule(obj):<EOL><INDENT>if obj is not self.module and(self.__is_exported(name, obj)<EOL>or self.is_submodule(obj.__name__)):<EOL><INDENT>self.doc[name] = self.__new_submodule(name, obj)<EOL><DEDENT><DEDENT>elif name in vardocs:<EOL><INDENT>self.doc[name] = vardocs[name]<EOL><DEDENT>else:<EOL><INDENT>self.doc[name] = Variable(name, self, '<STR_LIT>', cls=None)<EOL><DEDENT><DEDENT>if not hasattr(self.module, '<STR_LIT>')and not hasattr(self.module, '<STR_LIT>'):<EOL><INDENT>pkgdir = []<EOL><DEDENT>else:<EOL><INDENT>pkgdir = getattr(self.module, '<STR_LIT>',<EOL>[path.dirname(self.module.__file__)])<EOL><DEDENT>if self.is_package():<EOL><INDENT>for (_, root, _) in pkgutil.iter_modules(pkgdir):<EOL><INDENT>if root in self.doc:<EOL><INDENT>continue<EOL><DEDENT>if not self._allsubmodulesand not self.__is_exported(root, self.module):<EOL><INDENT>continue<EOL><DEDENT>fullname = '<STR_LIT>' % (self.name, root)<EOL>m = _safe_import(fullname)<EOL>if m is None:<EOL><INDENT>continue<EOL><DEDENT>self.doc[root] = self.__new_submodule(root, m)<EOL><DEDENT><DEDENT>for docobj in self.doc.values():<EOL><INDENT>if isinstance(docobj, Class):<EOL><INDENT>docobj._fill_inheritance()<EOL><DEDENT><DEDENT>for basename, docobj in self.doc.items():<EOL><INDENT>self.refdoc[docobj.refname] = docobj<EOL>if isinstance(docobj, Class):<EOL><INDENT>for v in docobj.class_variables():<EOL><INDENT>self.refdoc[v.refname] = v<EOL><DEDENT>for v in docobj.instance_variables():<EOL><INDENT>self.refdoc[v.refname] = v<EOL><DEDENT>for f in docobj.methods():<EOL><INDENT>self.refdoc[f.refname] = f<EOL><DEDENT>for f in docobj.functions():<EOL><INDENT>self.refdoc[f.refname] = f<EOL><DEDENT><DEDENT><DEDENT>for name, docstring in getattr(self.module, '<STR_LIT>', {}).items():<EOL><INDENT>refname = '<STR_LIT>' % (self.refname, name)<EOL>if docstring is None:<EOL><INDENT>self.doc.pop(name, None)<EOL>self.refdoc.pop(refname, None)<EOL>continue<EOL><DEDENT>dobj = self.find_ident(refname)<EOL>if isinstance(dobj, External):<EOL><INDENT>continue<EOL><DEDENT>dobj.docstring = inspect.cleandoc(docstring)<EOL><DEDENT>
Creates a `Module` documentation object given the actual
module Python object.

`docfilter` is an optional predicate that controls which
documentation objects are returned in the following
methods: `pydoc.Module.classes`, `pydoc.Module.functions`,
`pydoc.Module.variables` and `pydoc.Module.submodules`. The
filter is propagated to the analogous methods on a `pydoc.Class`
object.