[Python-checkins] python/dist/src/Lib pydoc.py,1.86,1.87

montanaro at users.sourceforge.net montanaro at users.sourceforge.net
Wed Sep 10 10:47:53 EDT 2003


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv6144

Modified Files:
	pydoc.py 
Log Message:
display link to module docs when it looks like the object module is a core
module


Index: pydoc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pydoc.py,v
retrieving revision 1.86
retrieving revision 1.87
diff -C2 -d -r1.86 -r1.87
*** pydoc.py	27 Jun 2003 15:45:41 -0000	1.86
--- pydoc.py	10 Sep 2003 16:47:51 -0000	1.87
***************
*** 25,28 ****
--- 25,36 ----
  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.
  """
  
***************
*** 296,299 ****
--- 304,334 ----
      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
  
***************
*** 536,541 ****
          if info:
              head = head + ' (%s)' % join(info, ', ')
          result = self.heading(
!             head, '#ffffff', '#7799ee', '<a href=".">index</a><br>' + filelink)
  
          modules = inspect.getmembers(object, inspect.ismodule)
--- 571,582 ----
          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 + docloc)
  
          modules = inspect.getmembers(object, inspect.ismodule)
***************
*** 951,954 ****
--- 992,1000 ----
              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)





More information about the Python-checkins mailing list