mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	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().
This commit is contained in:
		
							parent
							
								
									2922ea8235
								
							
						
					
					
						commit
						1d384634bf
					
				
					 1 changed files with 24 additions and 14 deletions
				
			
		
							
								
								
									
										38
									
								
								Lib/pydoc.py
									
										
									
									
									
								
							
							
						
						
									
										38
									
								
								Lib/pydoc.py
									
										
									
									
									
								
							| 
						 | 
					@ -1,5 +1,5 @@
 | 
				
			||||||
#!/usr/bin/env python
 | 
					#!/usr/bin/env python
 | 
				
			||||||
"""Generate Python documentation in HTML or as text for interactive use.
 | 
					"""Generate Python documentation in HTML or text for interactive use.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
At the shell command line outside of Python, run "pydoc <name>" to show
 | 
					At the shell command line outside of Python, run "pydoc <name>" to show
 | 
				
			||||||
documentation on something.  <name> may be the name of a Python function,
 | 
					documentation on something.  <name> may be the name of a Python function,
 | 
				
			||||||
| 
						 | 
					@ -74,10 +74,13 @@ def index(dir):
 | 
				
			||||||
def pathdirs():
 | 
					def pathdirs():
 | 
				
			||||||
    """Convert sys.path into a list of absolute, existing, unique paths."""
 | 
					    """Convert sys.path into a list of absolute, existing, unique paths."""
 | 
				
			||||||
    dirs = []
 | 
					    dirs = []
 | 
				
			||||||
 | 
					    normdirs = []
 | 
				
			||||||
    for dir in sys.path:
 | 
					    for dir in sys.path:
 | 
				
			||||||
        dir = os.path.abspath(dir or '.')
 | 
					        dir = os.path.abspath(dir or '.')
 | 
				
			||||||
        if dir not in dirs and os.path.isdir(dir):
 | 
					        normdir = os.path.normcase(dir)
 | 
				
			||||||
 | 
					        if normdir not in normdirs and os.path.isdir(dir):
 | 
				
			||||||
            dirs.append(dir)
 | 
					            dirs.append(dir)
 | 
				
			||||||
 | 
					            normdirs.append(normdir)
 | 
				
			||||||
    return dirs
 | 
					    return dirs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def getdoc(object):
 | 
					def getdoc(object):
 | 
				
			||||||
| 
						 | 
					@ -116,9 +119,13 @@ def cram(text, maxlen):
 | 
				
			||||||
        return text[:pre] + '...' + text[len(text)-post:]
 | 
					        return text[:pre] + '...' + text[len(text)-post:]
 | 
				
			||||||
    return text
 | 
					    return text
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def cleanid(text):
 | 
					def stripid(text):
 | 
				
			||||||
    """Remove the hexadecimal id from a Python object representation."""
 | 
					    """Remove the hexadecimal id from a Python object representation."""
 | 
				
			||||||
    return re.sub(' at 0x[0-9a-f]{5,}>$', '>', text)
 | 
					    # 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):
 | 
					def modulename(path):
 | 
				
			||||||
    """Return the Python module name for a given path, or None."""
 | 
					    """Return the Python module name for a given path, or None."""
 | 
				
			||||||
| 
						 | 
					@ -204,7 +211,7 @@ def repr1(self, x, level):
 | 
				
			||||||
        if hasattr(self, methodname):
 | 
					        if hasattr(self, methodname):
 | 
				
			||||||
            return getattr(self, methodname)(x, level)
 | 
					            return getattr(self, methodname)(x, level)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            return self.escape(cram(cleanid(repr(x)), self.maxother))
 | 
					            return self.escape(cram(stripid(repr(x)), self.maxother))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def repr_string(self, x, level):
 | 
					    def repr_string(self, x, level):
 | 
				
			||||||
        text = self.escape(cram(x, self.maxstring))
 | 
					        text = self.escape(cram(x, self.maxstring))
 | 
				
			||||||
| 
						 | 
					@ -213,7 +220,7 @@ def repr_string(self, x, level):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def repr_instance(self, x, level):
 | 
					    def repr_instance(self, x, level):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            return cram(cleanid(repr(x)), self.maxstring)
 | 
					            return cram(stripid(repr(x)), self.maxstring)
 | 
				
			||||||
        except:
 | 
					        except:
 | 
				
			||||||
            return self.escape('<%s instance>' % x.__class__.__name__)
 | 
					            return self.escape('<%s instance>' % x.__class__.__name__)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -386,8 +393,8 @@ def docmodule(self, object):
 | 
				
			||||||
        result = ''
 | 
					        result = ''
 | 
				
			||||||
        head = '<br><big><big><strong> %s</strong></big></big>' % name
 | 
					        head = '<br><big><big><strong> %s</strong></big></big>' % name
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            file = inspect.getsourcefile(object)
 | 
					            path = os.path.abspath(inspect.getfile(object))
 | 
				
			||||||
            filelink = '<a href="file:%s">%s</a>' % (file, file)
 | 
					            filelink = '<a href="file:%s">%s</a>' % (path, path)
 | 
				
			||||||
        except TypeError:
 | 
					        except TypeError:
 | 
				
			||||||
            filelink = '(built-in)'
 | 
					            filelink = '(built-in)'
 | 
				
			||||||
        info = []
 | 
					        info = []
 | 
				
			||||||
| 
						 | 
					@ -395,7 +402,7 @@ def docmodule(self, object):
 | 
				
			||||||
            version = str(object.__version__)
 | 
					            version = str(object.__version__)
 | 
				
			||||||
            if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
 | 
					            if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
 | 
				
			||||||
                version = strip(version[11:-1])
 | 
					                version = strip(version[11:-1])
 | 
				
			||||||
            info.append('version: %s' % self.escape(version))
 | 
					            info.append('version %s' % self.escape(version))
 | 
				
			||||||
        if hasattr(object, '__date__'):
 | 
					        if hasattr(object, '__date__'):
 | 
				
			||||||
            info.append(self.escape(str(object.__date__)))
 | 
					            info.append(self.escape(str(object.__date__)))
 | 
				
			||||||
        if info:
 | 
					        if info:
 | 
				
			||||||
| 
						 | 
					@ -598,11 +605,11 @@ def repr1(self, x, level):
 | 
				
			||||||
        if hasattr(self, methodname):
 | 
					        if hasattr(self, methodname):
 | 
				
			||||||
            return getattr(self, methodname)(x, level)
 | 
					            return getattr(self, methodname)(x, level)
 | 
				
			||||||
        else:
 | 
					        else:
 | 
				
			||||||
            return cram(cleanid(repr(x)), self.maxother)
 | 
					            return cram(stripid(repr(x)), self.maxother)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def repr_instance(self, x, level):
 | 
					    def repr_instance(self, x, level):
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            return cram(cleanid(repr(x)), self.maxstring)
 | 
					            return cram(stripid(repr(x)), self.maxstring)
 | 
				
			||||||
        except:
 | 
					        except:
 | 
				
			||||||
            return '<%s instance>' % x.__class__.__name__
 | 
					            return '<%s instance>' % x.__class__.__name__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -719,8 +726,8 @@ def docmodule(self, object):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if hasattr(object, '__version__'):
 | 
					        if hasattr(object, '__version__'):
 | 
				
			||||||
            version = str(object.__version__)
 | 
					            version = str(object.__version__)
 | 
				
			||||||
            if version[:11] == '$Revision$':
 | 
					            if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
 | 
				
			||||||
                version = version[11:-1]
 | 
					                version = strip(version[11:-1])
 | 
				
			||||||
            result = result + self.section('VERSION', version)
 | 
					            result = result + self.section('VERSION', version)
 | 
				
			||||||
        if hasattr(object, '__date__'):
 | 
					        if hasattr(object, '__date__'):
 | 
				
			||||||
            result = result + self.section('DATE', str(object.__date__))
 | 
					            result = result + self.section('DATE', str(object.__date__))
 | 
				
			||||||
| 
						 | 
					@ -1109,7 +1116,7 @@ def server_activate(self):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# -------------------------------------------------- command-line interface
 | 
					# -------------------------------------------------- command-line interface
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					def cli():
 | 
				
			||||||
    import getopt
 | 
					    import getopt
 | 
				
			||||||
    class BadUsage: pass
 | 
					    class BadUsage: pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1180,3 +1187,6 @@ def ready(port=port):
 | 
				
			||||||
    Write out the HTML documentation for all modules in the tree
 | 
					    Write out the HTML documentation for all modules in the tree
 | 
				
			||||||
    under a given directory to files in the current directory.
 | 
					    under a given directory to files in the current directory.
 | 
				
			||||||
""" % ((sys.argv[0],) * 5)
 | 
					""" % ((sys.argv[0],) * 5)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if __name__ == '__main__':
 | 
				
			||||||
 | 
					    cli()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue