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

Ka-Ping Yee ping@users.sourceforge.net
Thu, 01 Mar 2001 17:19:16 -0800


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

Modified Files:
	pydoc.py 
Log Message:
Use imp.get_suffixes to determine a module name in modulename(file).
When possible, display strings containing backslashes using r'' notation.


Index: pydoc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pydoc.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -r1.10 -r1.11
*** pydoc.py	2001/03/01 19:31:25	1.10
--- pydoc.py	2001/03/02 01:19:14	1.11
***************
*** 128,135 ****
      """Return the Python module name for a given path, or None."""
      filename = os.path.basename(path)
!     for ending in ['.py', '.pyc', '.pyd', '.pyo',
!                    'module.so', 'module.so.1', '.so']:
!         if len(filename) > len(ending) and filename[-len(ending):] == ending:
!             return filename[:-len(ending)]
  
  class DocImportError(Exception):
--- 128,138 ----
      """Return the Python module name for a given path, or None."""
      filename = os.path.basename(path)
!     suffixes = map(lambda (suffix, mode, kind): (len(suffix), suffix),
!                    imp.get_suffixes())
!     suffixes.sort()
!     suffixes.reverse() # try longest suffixes first, in case they overlap
!     for length, suffix in suffixes:
!         if len(filename) > length and filename[-length:] == suffix:
!             return filename[:-length]
  
  class DocImportError(Exception):
***************
*** 206,212 ****
  
      def repr_string(self, x, level):
!         text = self.escape(cram(x, self.maxstring))
!         return re.sub(r'((\\[\\abfnrtv]|\\x..|\\u....)+)',
!                       r'<font color="#c040c0">\1</font>', repr(text))
  
      def repr_instance(self, x, level):
--- 209,221 ----
  
      def repr_string(self, x, level):
!         test = cram(x, self.maxstring)
!         testrepr = repr(test)
!         if '\\' in test and '\\' not in replace(testrepr, (r'\\', '')):
!             # Backslashes are only literal in the string and are never
!             # needed to make any special characters, so show a raw string.
!             return 'r' + testrepr[0] + self.escape(test) + testrepr[0]
!         return re.sub(r'((\\[\\abfnrtv\'"]|\\x..|\\u....)+)',
!                       r'<font color="#c040c0">\1</font>',
!                       self.escape(testrepr))
  
      def repr_instance(self, x, level):
***************
*** 596,599 ****
--- 605,617 ----
          else:
              return cram(stripid(repr(x)), self.maxother)
+ 
+     def repr_string(self, x, level):
+         test = cram(x, self.maxstring)
+         testrepr = repr(test)
+         if '\\' in test and '\\' not in replace(testrepr, (r'\\', '')):
+             # Backslashes are only literal in the string and are never
+             # needed to make any special characters, so show a raw string.
+             return 'r' + testrepr[0] + test + testrepr[0]
+         return testrepr
  
      def repr_instance(self, x, level):