[Python-checkins] python/dist/src/Lib pydoc.py,1.67,1.68

ping@users.sourceforge.net ping@users.sourceforge.net
Sun, 11 Aug 2002 08:11:36 -0700


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

Modified Files:
	pydoc.py 
Log Message:
Extend stripid() to handle strings ending in more than one '>'.
Add resolve() to handle looking up objects and names (fix SF bug 586931).
Add a nicer error message when given a filename that doesn't exist.


Index: pydoc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pydoc.py,v
retrieving revision 1.67
retrieving revision 1.68
diff -C2 -d -r1.67 -r1.68
*** pydoc.py	9 Aug 2002 16:37:33 -0000	1.67
--- pydoc.py	11 Aug 2002 15:11:33 -0000	1.68
***************
*** 108,114 ****
      """Remove the hexadecimal id from a Python object representation."""
      # The behaviour of %p is implementation-dependent; we check two cases.
!     for pattern in [' at 0x[0-9a-f]{6,}>$', ' at [0-9A-F]{8,}>$']:
          if re.search(pattern, repr(Exception)):
!             return re.sub(pattern, '>', text)
      return text
  
--- 108,114 ----
      """Remove the hexadecimal id from a Python object representation."""
      # The behaviour of %p is implementation-dependent; we check two cases.
!     for pattern in [' at 0x[0-9a-f]{6,}(>+)$', ' at [0-9A-F]{8,}(>+)$']:
          if re.search(pattern, repr(Exception)):
!             return re.sub(pattern, '\\1', text)
      return text
  
***************
*** 1326,1368 ****
  html = HTMLDoc()
  
! def doc(thing, title='Python Library Documentation: %s', forceload=0):
!     """Display text documentation, given an object or a path to an object."""
!     suffix, name = '', None
!     if type(thing) is type(''):
!         try:
!             object = locate(thing, forceload)
!         except ErrorDuringImport, value:
!             print value
!             return
          if not object:
!             print 'no Python documentation found for %s' % repr(thing)
!             return
!         parts = split(thing, '.')
!         if len(parts) > 1: suffix = ' in ' + join(parts[:-1], '.')
!         name = parts[-1]
!         thing = object
  
!     desc = describe(thing)
!     module = inspect.getmodule(thing)
!     if not suffix and module and module is not thing:
!         suffix = ' in module ' + module.__name__
!     pager(title % (desc + suffix) + '\n\n' + text.document(thing, name))
  
! def writedoc(key, forceload=0):
      """Write HTML documentation to a file in the current directory."""
      try:
!         object = locate(key, forceload)
!     except ErrorDuringImport, value:
          print value
-     else:
-         if object:
-             page = html.page(describe(object),
-                              html.document(object, object.__name__))
-             file = open(key + '.html', 'w')
-             file.write(page)
-             file.close()
-             print 'wrote', key + '.html'
-         else:
-             print 'no Python documentation found for %s' % repr(key)
  
  def writedocs(dir, pkgpath='', done=None):
--- 1326,1364 ----
  html = HTMLDoc()
  
! def resolve(thing, forceload=0):
!     """Given an object or a path to an object, get the object and its name."""
!     if isinstance(thing, str):
!         object = locate(thing, forceload)
          if not object:
!             raise ImportError, 'no Python documentation found for %r' % thing
!         return object, thing
!     else:
!         return thing, getattr(thing, '__name__', None)
  
! def doc(thing, title='Python Library Documentation: %s', forceload=0):
!     """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__
!         pager(title % desc + '\n\n' + text.document(object, name))
!     except (ImportError, ErrorDuringImport), value:
!         print value
  
! def writedoc(thing, forceload=0):
      """Write HTML documentation to a file in the current directory."""
      try:
!         object, name = resolve(thing, forceload)
!         page = html.page(describe(object), html.document(object, name))
!         file = open(name + '.html', 'w')
!         file.write(page)
!         file.close()
!         print 'wrote', name + '.html'
!     except (ImportError, ErrorDuringImport), value:
          print value
  
  def writedocs(dir, pkgpath='', done=None):
***************
*** 2035,2039 ****
  
  def ispath(x):
!     return type(x) is types.StringType and find(x, os.sep) >= 0
  
  def cli():
--- 2031,2035 ----
  
  def ispath(x):
!     return isinstance(x, str) and find(x, os.sep) >= 0
  
  def cli():
***************
*** 2075,2078 ****
--- 2071,2077 ----
          if not args: raise BadUsage
          for arg in args:
+             if ispath(arg) and not os.path.exists(arg):
+                 print 'file %r does not exist' % arg
+                 break
              try:
                  if ispath(arg) and os.path.isfile(arg):