[Python-checkins] CVS: python/dist/src/Lib pydoc.py,1.7,1.8

Ka-Ping Yee ping@users.sourceforge.net
Wed, 28 Feb 2001 16:24:34 -0800


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

Modified Files:
	pydoc.py 
Log Message:
Normalize case of paths in sys.path to avoid duplicates on Windows.
Handle <... at 001B6378> like <... at 0x120f80> (%p is platform-dependent).
Fix RCS version tag handling.
Move __main__ behaviour into a function, pydoc.cli().


Index: pydoc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pydoc.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** pydoc.py	2001/02/28 08:26:44	1.7
--- pydoc.py	2001/03/01 00:24:32	1.8
***************
*** 1,4 ****
  #!/usr/bin/env python
! """Generate Python documentation in HTML or as text for interactive use.
  
  At the shell command line outside of Python, run "pydoc <name>" to show
--- 1,4 ----
  #!/usr/bin/env python
! """Generate Python documentation in HTML or text for interactive use.
  
  At the shell command line outside of Python, run "pydoc <name>" to show
***************
*** 75,82 ****
      """Convert sys.path into a list of absolute, existing, unique paths."""
      dirs = []
      for dir in sys.path:
          dir = os.path.abspath(dir or '.')
!         if dir not in dirs and os.path.isdir(dir):
              dirs.append(dir)
      return dirs
  
--- 75,85 ----
      """Convert sys.path into a list of absolute, existing, unique paths."""
      dirs = []
+     normdirs = []
      for dir in sys.path:
          dir = os.path.abspath(dir or '.')
!         normdir = os.path.normcase(dir)
!         if normdir not in normdirs and os.path.isdir(dir):
              dirs.append(dir)
+             normdirs.append(normdir)
      return dirs
  
***************
*** 117,123 ****
      return text
  
! def cleanid(text):
      """Remove the hexadecimal id from a Python object representation."""
!     return re.sub(' at 0x[0-9a-f]{5,}>$', '>', text)
  
  def modulename(path):
--- 120,130 ----
      return text
  
! def stripid(text):
      """Remove the hexadecimal id from a Python object representation."""
!     # The behaviour of %p is implementation-dependent, so we need an example.
!     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
  
  def modulename(path):
***************
*** 205,209 ****
              return getattr(self, methodname)(x, level)
          else:
!             return self.escape(cram(cleanid(repr(x)), self.maxother))
  
      def repr_string(self, x, level):
--- 212,216 ----
              return getattr(self, methodname)(x, level)
          else:
!             return self.escape(cram(stripid(repr(x)), self.maxother))
  
      def repr_string(self, x, level):
***************
*** 214,218 ****
      def repr_instance(self, x, level):
          try:
!             return cram(cleanid(repr(x)), self.maxstring)
          except:
              return self.escape('<%s instance>' % x.__class__.__name__)
--- 221,225 ----
      def repr_instance(self, x, level):
          try:
!             return cram(stripid(repr(x)), self.maxstring)
          except:
              return self.escape('<%s instance>' % x.__class__.__name__)
***************
*** 387,392 ****
          head = '<br><big><big><strong>&nbsp;%s</strong></big></big>' % name
          try:
!             file = inspect.getsourcefile(object)
!             filelink = '<a href="file:%s">%s</a>' % (file, file)
          except TypeError:
              filelink = '(built-in)'
--- 394,399 ----
          head = '<br><big><big><strong>&nbsp;%s</strong></big></big>' % name
          try:
!             path = os.path.abspath(inspect.getfile(object))
!             filelink = '<a href="file:%s">%s</a>' % (path, path)
          except TypeError:
              filelink = '(built-in)'
***************
*** 396,400 ****
              if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
                  version = strip(version[11:-1])
!             info.append('version: %s' % self.escape(version))
          if hasattr(object, '__date__'):
              info.append(self.escape(str(object.__date__)))
--- 403,407 ----
              if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
                  version = strip(version[11:-1])
!             info.append('version %s' % self.escape(version))
          if hasattr(object, '__date__'):
              info.append(self.escape(str(object.__date__)))
***************
*** 599,607 ****
              return getattr(self, methodname)(x, level)
          else:
!             return cram(cleanid(repr(x)), self.maxother)
  
      def repr_instance(self, x, level):
          try:
!             return cram(cleanid(repr(x)), self.maxstring)
          except:
              return '<%s instance>' % x.__class__.__name__
--- 606,614 ----
              return getattr(self, methodname)(x, level)
          else:
!             return cram(stripid(repr(x)), self.maxother)
  
      def repr_instance(self, x, level):
          try:
!             return cram(stripid(repr(x)), self.maxstring)
          except:
              return '<%s instance>' % x.__class__.__name__
***************
*** 720,725 ****
          if hasattr(object, '__version__'):
              version = str(object.__version__)
!             if version[:11] == '$Revision$':
!                 version = version[11:-1]
              result = result + self.section('VERSION', version)
          if hasattr(object, '__date__'):
--- 727,732 ----
          if hasattr(object, '__version__'):
              version = str(object.__version__)
!             if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
!                 version = strip(version[11:-1])
              result = result + self.section('VERSION', version)
          if hasattr(object, '__date__'):
***************
*** 1110,1114 ****
  # -------------------------------------------------- command-line interface
  
! if __name__ == '__main__':
      import getopt
      class BadUsage: pass
--- 1117,1121 ----
  # -------------------------------------------------- command-line interface
  
! def cli():
      import getopt
      class BadUsage: pass
***************
*** 1181,1182 ****
--- 1188,1192 ----
      under a given directory to files in the current directory.
  """ % ((sys.argv[0],) * 5)
+ 
+ if __name__ == '__main__':
+     cli()