diff options
Diffstat (limited to 'Lib/pydoc.py')
-rwxr-xr-x | Lib/pydoc.py | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/Lib/pydoc.py b/Lib/pydoc.py index 410d921..fee6342 100755 --- a/Lib/pydoc.py +++ b/Lib/pydoc.py @@ -24,6 +24,14 @@ and also pops up a little window for controlling it. Run "pydoc -w <name>" to write out the HTML documentation for a module to a file named "<name>.html". + +Module docs for core modules are assumed to be in + + http://www.python.org/doc/current/lib/ + +This can be overridden by setting the PYTHONDOCS environment variable +to a different URL or to a local directory containing the Library +Reference Manual pages. """ __author__ = "Ka-Ping Yee <ping@lfw.org>" @@ -295,6 +303,33 @@ class Doc: docmodule = docclass = docroutine = docother = fail + def getdocloc(self, object): + """Return the location of module docs or None""" + + try: + file = inspect.getabsfile(object) + except TypeError: + file = '(built-in)' + + docloc = os.environ.get("PYTHONDOCS", + "http://www.python.org/doc/current/lib") + basedir = os.path.join(sys.exec_prefix, "lib", + "python"+sys.version[0:3]) + if (isinstance(object, type(os)) and + (object.__name__ in ('errno', 'exceptions', 'gc', 'imp', + 'marshal', 'posix', 'signal', 'sys', + 'thread', 'zipimport') or + (file.startswith(basedir) and + not file.startswith(os.path.join(basedir, 'site-packages'))))): + if docloc.startswith("http://"): + docloc = (docloc.rstrip("/") + + "/module-%s.html" % object.__name__) + else: + docloc = os.path.join(docloc, "module-%s.html" % name) + else: + docloc = None + return docloc + # -------------------------------------------- HTML documentation generator class HTMLRepr(Repr): @@ -535,8 +570,14 @@ class HTMLDoc(Doc): info.append(self.escape(str(object.__date__))) if info: head = head + ' (%s)' % join(info, ', ') + docloc = self.getdocloc(object) + if docloc is not None: + docloc = '<br><a href="%(docloc)s">Module Docs</a>' % locals() + else: + docloc = '' result = self.heading( - head, '#ffffff', '#7799ee', '<a href=".">index</a><br>' + filelink) + head, '#ffffff', '#7799ee', + '<a href=".">index</a><br>' + filelink + docloc) modules = inspect.getmembers(object, inspect.ismodule) @@ -950,6 +991,11 @@ class TextDoc(Doc): 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) |