annotate Lib/pydoc.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 501651b93cb0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1 #!/usr/bin/env python
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
2 # -*- coding: latin-1 -*-
16875
10b84060b7f3 Normalize case of paths in sys.path to avoid duplicates on Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 16833
diff changeset
3 """Generate Python documentation in HTML or text for interactive use.
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
4
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
5 In the Python interpreter, do "from pydoc import help" to provide online
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
6 help. Calling help(thing) on a Python object documents the object.
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
7
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
8 Or, at the shell command line outside of Python:
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
9
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
10 Run "pydoc <name>" to show documentation on something. <name> may be
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
11 the name of a function, module, package, or a dotted reference to a
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
12 class or function within a module or module in a package. If the
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
13 argument contains a path segment delimiter (e.g. slash on Unix,
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
14 backslash on Windows) it is treated as the path to a Python source file.
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
15
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
16 Run "pydoc -k <keyword>" to search for a keyword in the synopsis lines
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
17 of all available modules.
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
18
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
19 Run "pydoc -p <port>" to start an HTTP server on a given port on the
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
20 local machine to generate documentation web pages.
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
21
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
22 For platforms without a command line, "pydoc -g" starts the HTTP server
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
23 and also pops up a little window for controlling it.
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
24
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
25 Run "pydoc -w <name>" to write out the HTML documentation for a module
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
26 to a file named "<name>.html".
30396
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
27
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
28 Module docs for core modules are assumed to be in
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
29
44845
27dac16541d9 Adapt pydoc to new doc URLs.
Georg Brandl <georg@python.org>
parents: 44660
diff changeset
30 http://docs.python.org/library/
30396
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
31
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
32 This can be overridden by setting the PYTHONDOCS environment variable
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
33 to a different URL or to a local directory containing the Library
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
34 Reference Manual pages.
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
35 """
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
36
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
37 __author__ = "Ka-Ping Yee <ping@lfw.org>"
16811
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
38 __date__ = "26 February 2001"
35742
1c4d192f1568 Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 35663
diff changeset
39
71539
f15442543e24 Fix closes Issue11439 - Handle the SVN Keywords in 2.7 by replacing them with a high number so that code relying on them does not break.
Senthil Kumaran <senthil@uthcode.com>
parents: 71533
diff changeset
40 __version__ = "$Revision: 88564 $"
33991
f13ce0bb606c Back out rev 1.96; see #1009389.
Martin v. Löwis <martin@v.loewis.de>
parents: 33935
diff changeset
41 __credits__ = """Guido van Rossum, for an excellent programming language.
16818
fd2a869769b2 Acknowledgements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16813
diff changeset
42 Tommy Burnette, the original creator of manpy.
16811
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
43 Paul Prescod, for all his work on onlinehelp.
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
44 Richard Chamberlain, for the first implementation of textdoc.
34299
df380e196c4b SF patch #1094007: Remove witty comment in pydoc.py
Raymond Hettinger <python@rcn.com>
parents: 33991
diff changeset
45 """
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
46
17371
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
47 # Known bugs that can't be fixed here:
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
48 # - imp.load_module() cannot be prevented from clobbering existing
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
49 # loaded modules, so calling synopsis() on a binary module file
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
50 # changes the contents of any existing module with the same name.
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
51 # - If the __file__ attribute on a module is a relative path and
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
52 # the current directory is changed with os.chdir(), an incorrect
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
53 # path will be displayed.
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
54
72770
3acf90f71178 Issue #7425: Prevent pydoc -k failures due to module import errors.
Ned Deily <nad@acm.org>
parents: 71599
diff changeset
55 import sys, imp, os, re, types, inspect, __builtin__, pkgutil, warnings
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
56 from repr import Repr
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
57 from string import expandtabs, find, join, lower, split, strip, rfind, rstrip
54827
e7371353a302 Merged revisions 73529 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents: 54377
diff changeset
58 from traceback import extract_tb
37821
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
59 try:
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
60 from collections import deque
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
61 except ImportError:
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
62 # Python 2.3 compatibility
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
63 class deque(list):
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
64 def popleft(self):
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
65 return self.pop(0)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
66
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
67 # --------------------------------------------------------- common routines
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
68
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
69 def pathdirs():
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
70 """Convert sys.path into a list of absolute, existing, unique paths."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
71 dirs = []
16875
10b84060b7f3 Normalize case of paths in sys.path to avoid duplicates on Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 16833
diff changeset
72 normdirs = []
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
73 for dir in sys.path:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
74 dir = os.path.abspath(dir or '.')
16875
10b84060b7f3 Normalize case of paths in sys.path to avoid duplicates on Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 16833
diff changeset
75 normdir = os.path.normcase(dir)
10b84060b7f3 Normalize case of paths in sys.path to avoid duplicates on Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 16833
diff changeset
76 if normdir not in normdirs and os.path.isdir(dir):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
77 dirs.append(dir)
16875
10b84060b7f3 Normalize case of paths in sys.path to avoid duplicates on Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 16833
diff changeset
78 normdirs.append(normdir)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
79 return dirs
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
80
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
81 def getdoc(object):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
82 """Get the doc string or comments for an object."""
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
83 result = inspect.getdoc(object) or inspect.getcomments(object)
16928
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
84 return result and re.sub('^ *\n', '', rstrip(result)) or ''
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
85
17371
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
86 def splitdoc(doc):
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
87 """Split a doc string into a synopsis line (if any) and the rest."""
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
88 lines = split(strip(doc), '\n')
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
89 if len(lines) == 1:
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
90 return lines[0], ''
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
91 elif len(lines) >= 2 and not rstrip(lines[1]):
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
92 return lines[0], join(lines[2:], '\n')
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
93 return '', join(lines, '\n')
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
94
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
95 def classname(object, modname):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
96 """Get a class name and qualify it with a module name if necessary."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
97 name = object.__name__
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
98 if object.__module__ != modname:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
99 name = object.__module__ + '.' + name
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
100 return name
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
101
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
102 def isdata(object):
35277
6ebc423f2d81 That was one too much.
Georg Brandl <georg@python.org>
parents: 35276
diff changeset
103 """Check if an object is of a type that probably means it's data."""
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
104 return not (inspect.ismodule(object) or inspect.isclass(object) or
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
105 inspect.isroutine(object) or inspect.isframe(object) or
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
106 inspect.istraceback(object) or inspect.iscode(object))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
107
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
108 def replace(text, *pairs):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
109 """Do a series of global replacements on a string."""
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
110 while pairs:
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
111 text = join(split(text, pairs[0]), pairs[1])
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
112 pairs = pairs[2:]
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
113 return text
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
114
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
115 def cram(text, maxlen):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
116 """Omit part of a string if needed to make it fit in a maximum length."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
117 if len(text) > maxlen:
25871
cb910c394927 Explicitly use floor division
Raymond Hettinger <python@rcn.com>
parents: 25454
diff changeset
118 pre = max(0, (maxlen-3)//2)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
119 post = max(0, maxlen-3-pre)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
120 return text[:pre] + '...' + text[len(text)-post:]
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
121 return text
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
122
32382
cde2feab7fe0 Change pydoc.stripid() be able to match against 64-bit addresses by having
Brett Cannon <bcannon@gmail.com>
parents: 32380
diff changeset
123 _re_stripid = re.compile(r' at 0x[0-9a-f]{6,16}(>+)$', re.IGNORECASE)
16875
10b84060b7f3 Normalize case of paths in sys.path to avoid duplicates on Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 16833
diff changeset
124 def stripid(text):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
125 """Remove the hexadecimal id from a Python object representation."""
32380
c6ab0f88895a pydoc.stripid() is now case-insensitive for its regex to support platforms that
Brett Cannon <bcannon@gmail.com>
parents: 32321
diff changeset
126 # The behaviour of %p is implementation-dependent in terms of case.
58925
eecf1bef052d Merged revisions 78207 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 57282
diff changeset
127 return _re_stripid.sub(r'\1', text)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
128
32380
c6ab0f88895a pydoc.stripid() is now case-insensitive for its regex to support platforms that
Brett Cannon <bcannon@gmail.com>
parents: 32321
diff changeset
129 def _is_some_method(obj):
c6ab0f88895a pydoc.stripid() is now case-insensitive for its regex to support platforms that
Brett Cannon <bcannon@gmail.com>
parents: 32321
diff changeset
130 return inspect.ismethod(obj) or inspect.ismethoddescriptor(obj)
19989
cec9e25af121 After much thrashing, I believe this is a truly minimal patch to teach
Tim Peters <tim.peters@gmail.com>
parents: 18816
diff changeset
131
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
132 def allmethods(cl):
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
133 methods = {}
19989
cec9e25af121 After much thrashing, I believe this is a truly minimal patch to teach
Tim Peters <tim.peters@gmail.com>
parents: 18816
diff changeset
134 for key, value in inspect.getmembers(cl, _is_some_method):
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
135 methods[key] = 1
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
136 for base in cl.__bases__:
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
137 methods.update(allmethods(base)) # all your base are belong to us
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
138 for key in methods.keys():
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
139 methods[key] = getattr(cl, key)
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
140 return methods
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
141
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
142 def _split_list(s, predicate):
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
143 """Split sequence s via predicate, and return pair ([true], [false]).
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
144
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
145 The return value is a 2-tuple of lists,
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
146 ([x for x in s if predicate(x)],
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
147 [x for x in s if not predicate(x)])
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
148 """
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
149
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
150 yes = []
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
151 no = []
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
152 for x in s:
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
153 if predicate(x):
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
154 yes.append(x)
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
155 else:
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
156 no.append(x)
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
157 return yes, no
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
158
68941
46aaa365111f Issue #11666: Teach pydoc to display full help for named tuples
Raymond Hettinger <python@rcn.com>
parents: 68256
diff changeset
159 def visiblename(name, all=None, obj=None):
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
160 """Decide whether to show documentation on a variable."""
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
161 # Certain special names are redundant.
47873
5d8f47005b73 Issue 3190: pydoc now hides module __package__ attributes
Nick Coghlan <ncoghlan@gmail.com>
parents: 47431
diff changeset
162 _hidden_names = ('__builtins__', '__doc__', '__file__', '__path__',
5d8f47005b73 Issue 3190: pydoc now hides module __package__ attributes
Nick Coghlan <ncoghlan@gmail.com>
parents: 47431
diff changeset
163 '__module__', '__name__', '__slots__', '__package__')
5d8f47005b73 Issue 3190: pydoc now hides module __package__ attributes
Nick Coghlan <ncoghlan@gmail.com>
parents: 47431
diff changeset
164 if name in _hidden_names: return 0
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
165 # Private names are hidden, but special names are displayed.
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
166 if name.startswith('__') and name.endswith('__'): return 1
68941
46aaa365111f Issue #11666: Teach pydoc to display full help for named tuples
Raymond Hettinger <python@rcn.com>
parents: 68256
diff changeset
167 # Namedtuples have public fields and methods with a single leading underscore
46aaa365111f Issue #11666: Teach pydoc to display full help for named tuples
Raymond Hettinger <python@rcn.com>
parents: 68256
diff changeset
168 if name.startswith('_') and hasattr(obj, '_fields'):
46aaa365111f Issue #11666: Teach pydoc to display full help for named tuples
Raymond Hettinger <python@rcn.com>
parents: 68256
diff changeset
169 return 1
32321
b0f454f558e5 Respect a module's __all__ attribute. Closes #969938.
Skip Montanaro <skip@pobox.com>
parents: 32288
diff changeset
170 if all is not None:
b0f454f558e5 Respect a module's __all__ attribute. Closes #969938.
Skip Montanaro <skip@pobox.com>
parents: 32288
diff changeset
171 # only document that which the programmer exported in __all__
b0f454f558e5 Respect a module's __all__ attribute. Closes #969938.
Skip Montanaro <skip@pobox.com>
parents: 32288
diff changeset
172 return name in all
b0f454f558e5 Respect a module's __all__ attribute. Closes #969938.
Skip Montanaro <skip@pobox.com>
parents: 32288
diff changeset
173 else:
b0f454f558e5 Respect a module's __all__ attribute. Closes #969938.
Skip Montanaro <skip@pobox.com>
parents: 32288
diff changeset
174 return not name.startswith('_')
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
175
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
176 def classify_class_attrs(object):
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
177 """Wrap inspect.classify_class_attrs, with fixup for data descriptors."""
48141
4e6a0ae1a8e7 Silence SyntaxWarning and DeprecationWarning in pydoc triggered by tuple
Brett Cannon <bcannon@gmail.com>
parents: 47987
diff changeset
178 def fixup(data):
4e6a0ae1a8e7 Silence SyntaxWarning and DeprecationWarning in pydoc triggered by tuple
Brett Cannon <bcannon@gmail.com>
parents: 47987
diff changeset
179 name, kind, cls, value = data
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
180 if inspect.isdatadescriptor(value):
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
181 kind = 'data descriptor'
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
182 return name, kind, cls, value
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
183 return map(fixup, inspect.classify_class_attrs(object))
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
184
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
185 # ----------------------------------------------------- module manipulation
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
186
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
187 def ispackage(path):
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
188 """Guess whether a path refers to a package directory."""
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
189 if os.path.isdir(path):
34545
9d66fba78444 Replace list of constants with tuples of constants.
Raymond Hettinger <python@rcn.com>
parents: 34369
diff changeset
190 for ext in ('.py', '.pyc', '.pyo'):
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
191 if os.path.isfile(os.path.join(path, '__init__' + ext)):
22830
a9dd5e6d6805 Convert a pile of obvious "yes/no" functions to return bool.
Tim Peters <tim.peters@gmail.com>
parents: 22506
diff changeset
192 return True
a9dd5e6d6805 Convert a pile of obvious "yes/no" functions to return bool.
Tim Peters <tim.peters@gmail.com>
parents: 22506
diff changeset
193 return False
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
194
37821
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
195 def source_synopsis(file):
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
196 line = file.readline()
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
197 while line[:1] == '#' or not strip(line):
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
198 line = file.readline()
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
199 if not line: break
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
200 line = strip(line)
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
201 if line[:4] == 'r"""': line = line[1:]
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
202 if line[:3] == '"""':
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
203 line = line[3:]
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
204 if line[-1:] == '\\': line = line[:-1]
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
205 while not strip(line):
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
206 line = file.readline()
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
207 if not line: break
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
208 result = strip(split(line, '"""')[0])
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
209 else: result = None
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
210 return result
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
211
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
212 def synopsis(filename, cache={}):
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
213 """Get the one-line summary out of a module file."""
23625
65cf478950ff Replaced obsolete stat module constants with equivalent attributes
Raymond Hettinger <python@rcn.com>
parents: 23620
diff changeset
214 mtime = os.stat(filename).st_mtime
71533
2229b0422369 - Issue #12603: Fix pydoc.synopsis() on files with non-negative st_mtime.
Charles-François Natali <neologix@free.fr>
parents: 70395
diff changeset
215 lastupdate, result = cache.get(filename, (None, None))
2229b0422369 - Issue #12603: Fix pydoc.synopsis() on files with non-negative st_mtime.
Charles-François Natali <neologix@free.fr>
parents: 70395
diff changeset
216 if lastupdate is None or lastupdate < mtime:
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
217 info = inspect.getmoduleinfo(filename)
36893
4b347c654635 Fix pydoc.synopsis() so that it doesn't error out with an unreadable
Georg Brandl <georg@python.org>
parents: 36545
diff changeset
218 try:
4b347c654635 Fix pydoc.synopsis() so that it doesn't error out with an unreadable
Georg Brandl <georg@python.org>
parents: 36545
diff changeset
219 file = open(filename)
4b347c654635 Fix pydoc.synopsis() so that it doesn't error out with an unreadable
Georg Brandl <georg@python.org>
parents: 36545
diff changeset
220 except IOError:
4b347c654635 Fix pydoc.synopsis() so that it doesn't error out with an unreadable
Georg Brandl <georg@python.org>
parents: 36545
diff changeset
221 # module can't be opened, so skip it
4b347c654635 Fix pydoc.synopsis() so that it doesn't error out with an unreadable
Georg Brandl <georg@python.org>
parents: 36545
diff changeset
222 return None
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
223 if info and 'b' in info[2]: # binary modules have to be imported
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
224 try: module = imp.load_module('__temp__', file, filename, info[1:])
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
225 except: return None
37821
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
226 result = (module.__doc__ or '').splitlines()[0]
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
227 del sys.modules['__temp__']
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
228 else: # text modules can be directly examined
37821
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
229 result = source_synopsis(file)
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
230 file.close()
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
231 cache[filename] = (mtime, result)
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
232 return result
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
233
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
234 class ErrorDuringImport(Exception):
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
235 """Errors that occurred while trying to import something to document it."""
48141
4e6a0ae1a8e7 Silence SyntaxWarning and DeprecationWarning in pydoc triggered by tuple
Brett Cannon <bcannon@gmail.com>
parents: 47987
diff changeset
236 def __init__(self, filename, exc_info):
4e6a0ae1a8e7 Silence SyntaxWarning and DeprecationWarning in pydoc triggered by tuple
Brett Cannon <bcannon@gmail.com>
parents: 47987
diff changeset
237 exc, value, tb = exc_info
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
238 self.filename = filename
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
239 self.exc = exc
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
240 self.value = value
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
241 self.tb = tb
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
242
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
243 def __str__(self):
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
244 exc = self.exc
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
245 if type(exc) is types.ClassType:
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
246 exc = exc.__name__
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
247 return 'problem in %s - %s: %s' % (self.filename, exc, self.value)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
248
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
249 def importfile(path):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
250 """Import a Python source file or compiled file given its path."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
251 magic = imp.get_magic()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
252 file = open(path, 'r')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
253 if file.read(len(magic)) == magic:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
254 kind = imp.PY_COMPILED
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
255 else:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
256 kind = imp.PY_SOURCE
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
257 file.close()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
258 filename = os.path.basename(path)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
259 name, ext = os.path.splitext(filename)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
260 file = open(path, 'r')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
261 try:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
262 module = imp.load_module(name, file, path, (ext, 'r', kind))
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
263 except:
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
264 raise ErrorDuringImport(path, sys.exc_info())
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
265 file.close()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
266 return module
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
267
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
268 def safeimport(path, forceload=0, cache={}):
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
269 """Import a module; handle errors; return None if the module isn't found.
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
270
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
271 If the module *is* found but an exception occurs, it's wrapped in an
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
272 ErrorDuringImport exception and reraised. Unlike __import__, if a
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
273 package path is specified, the module at the end of the path is returned,
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
274 not the package at the beginning. If the optional 'forceload' argument
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
275 is 1, we reload the module from disk (unless it's a dynamic extension)."""
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
276 try:
35838
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
277 # If forceload is 1 and the module has been previously loaded from
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
278 # disk, we always have to reload the module. Checking the file's
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
279 # mtime isn't good enough (e.g. the module could contain a class
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
280 # that inherits from another module that has changed).
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
281 if forceload and path in sys.modules:
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
282 if path not in sys.builtin_module_names:
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
283 # Avoid simply calling reload() because it leaves names in
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
284 # the currently loaded module lying around if they're not
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
285 # defined in the new source file. Instead, remove the
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
286 # module from sys.modules and re-import. Also remove any
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
287 # submodules because they won't appear in the newly loaded
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
288 # module's namespace if they're already in sys.modules.
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
289 subs = [m for m in sys.modules if m.startswith(path + '.')]
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
290 for key in [path] + subs:
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
291 # Prevent garbage collection.
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
292 cache[key] = sys.modules[key]
49baf8b04681 Fix SF bug #417833 (pydoc HTTP reload failure) by removing from
Ka-Ping Yee <ping@zesty.ca>
parents: 35837
diff changeset
293 del sys.modules[key]
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
294 module = __import__(path)
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
295 except:
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
296 # Did the error occur before or after the module was found?
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
297 (exc, value, tb) = info = sys.exc_info()
23620
a1de0bab5475 SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents: 23501
diff changeset
298 if path in sys.modules:
35806
44fe157255bc fix typos, mostly in comments
Fred Drake <fdrake@acm.org>
parents: 35742
diff changeset
299 # An error occurred while executing the imported module.
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
300 raise ErrorDuringImport(sys.modules[path].__file__, info)
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
301 elif exc is SyntaxError:
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
302 # A SyntaxError occurred before we could execute the module.
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
303 raise ErrorDuringImport(value.filename, info)
54827
e7371353a302 Merged revisions 73529 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents: 54377
diff changeset
304 elif exc is ImportError and extract_tb(tb)[-1][2]=='safeimport':
e7371353a302 Merged revisions 73529 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents: 54377
diff changeset
305 # The import error occurred directly in this function,
e7371353a302 Merged revisions 73529 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents: 54377
diff changeset
306 # which means there is no such module in the path.
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
307 return None
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
308 else:
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
309 # Some other error occurred during the importing process.
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
310 raise ErrorDuringImport(path, sys.exc_info())
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
311 for part in split(path, '.')[1:]:
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
312 try: module = getattr(module, part)
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
313 except AttributeError: return None
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
314 return module
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
315
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
316 # ---------------------------------------------------- formatter base class
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
317
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
318 class Doc:
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
319 def document(self, object, name=None, *args):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
320 """Generate documentation for an object."""
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
321 args = (object, name) + args
29409
29760056884a Have pydoc try handling an object as "other" if the object does not act the way
Brett Cannon <bcannon@gmail.com>
parents: 29267
diff changeset
322 # 'try' clause is to attempt to handle the possibility that inspect
29760056884a Have pydoc try handling an object as "other" if the object does not act the way
Brett Cannon <bcannon@gmail.com>
parents: 29267
diff changeset
323 # identifies something in a way that pydoc itself has issues handling;
29760056884a Have pydoc try handling an object as "other" if the object does not act the way
Brett Cannon <bcannon@gmail.com>
parents: 29267
diff changeset
324 # think 'super' and how it is a descriptor (which raises the exception
29760056884a Have pydoc try handling an object as "other" if the object does not act the way
Brett Cannon <bcannon@gmail.com>
parents: 29267
diff changeset
325 # by lacking a __name__ attribute) and an instance.
39226
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
326 if inspect.isgetsetdescriptor(object): return self.docdata(*args)
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
327 if inspect.ismemberdescriptor(object): return self.docdata(*args)
29409
29760056884a Have pydoc try handling an object as "other" if the object does not act the way
Brett Cannon <bcannon@gmail.com>
parents: 29267
diff changeset
328 try:
29760056884a Have pydoc try handling an object as "other" if the object does not act the way
Brett Cannon <bcannon@gmail.com>
parents: 29267
diff changeset
329 if inspect.ismodule(object): return self.docmodule(*args)
29760056884a Have pydoc try handling an object as "other" if the object does not act the way
Brett Cannon <bcannon@gmail.com>
parents: 29267
diff changeset
330 if inspect.isclass(object): return self.docclass(*args)
29760056884a Have pydoc try handling an object as "other" if the object does not act the way
Brett Cannon <bcannon@gmail.com>
parents: 29267
diff changeset
331 if inspect.isroutine(object): return self.docroutine(*args)
29760056884a Have pydoc try handling an object as "other" if the object does not act the way
Brett Cannon <bcannon@gmail.com>
parents: 29267
diff changeset
332 except AttributeError:
29760056884a Have pydoc try handling an object as "other" if the object does not act the way
Brett Cannon <bcannon@gmail.com>
parents: 29267
diff changeset
333 pass
33935
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
334 if isinstance(object, property): return self.docproperty(*args)
28089
14f65d661084 Get rid of many apply() calls.
Guido van Rossum <guido@python.org>
parents: 27904
diff changeset
335 return self.docother(*args)
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
336
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
337 def fail(self, object, name=None, *args):
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
338 """Raise an exception for unimplemented types."""
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
339 message = "don't know how to document object%s of type %s" % (
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
340 name and ' ' + repr(name), type(object).__name__)
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
341 raise TypeError, message
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
342
39226
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
343 docmodule = docclass = docroutine = docother = docproperty = docdata = fail
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
344
30396
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
345 def getdocloc(self, object):
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
346 """Return the location of module docs or None"""
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
347
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
348 try:
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
349 file = inspect.getabsfile(object)
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
350 except TypeError:
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
351 file = '(built-in)'
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
352
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
353 docloc = os.environ.get("PYTHONDOCS",
44845
27dac16541d9 Adapt pydoc to new doc URLs.
Georg Brandl <georg@python.org>
parents: 44660
diff changeset
354 "http://docs.python.org/library")
30396
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
355 basedir = os.path.join(sys.exec_prefix, "lib",
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
356 "python"+sys.version[0:3])
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
357 if (isinstance(object, type(os)) and
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
358 (object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
359 'marshal', 'posix', 'signal', 'sys',
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
360 'thread', 'zipimport') or
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
361 (file.startswith(basedir) and
60096
ef6ebc06a786 Merged revisions 79518 via svnmerge from
Brian Curtin <brian.curtin@gmail.com>
parents: 58925
diff changeset
362 not file.startswith(os.path.join(basedir, 'site-packages')))) and
60121
a4dad218c6e3 Merged revisions 79543 via svnmerge from
Brian Curtin <brian.curtin@gmail.com>
parents: 60107
diff changeset
363 object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
30396
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
364 if docloc.startswith("http://"):
44845
27dac16541d9 Adapt pydoc to new doc URLs.
Georg Brandl <georg@python.org>
parents: 44660
diff changeset
365 docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__)
30396
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
366 else:
44845
27dac16541d9 Adapt pydoc to new doc URLs.
Georg Brandl <georg@python.org>
parents: 44660
diff changeset
367 docloc = os.path.join(docloc, object.__name__ + ".html")
30396
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
368 else:
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
369 docloc = None
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
370 return docloc
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
371
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
372 # -------------------------------------------- HTML documentation generator
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
373
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
374 class HTMLRepr(Repr):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
375 """Class for safely making an HTML representation of a Python object."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
376 def __init__(self):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
377 Repr.__init__(self)
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
378 self.maxlist = self.maxtuple = 20
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
379 self.maxdict = 10
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
380 self.maxstring = self.maxother = 100
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
381
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
382 def escape(self, text):
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
383 return replace(text, '&', '&amp;', '<', '&lt;', '>', '&gt;')
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
384
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
385 def repr(self, object):
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
386 return Repr.repr(self, object)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
387
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
388 def repr1(self, x, level):
29603
fea8dee27332 (HTML|Text)Repr.repr1: Guard against objects whos types have no __name__
Skip Montanaro <skip@pobox.com>
parents: 29463
diff changeset
389 if hasattr(type(x), '__name__'):
fea8dee27332 (HTML|Text)Repr.repr1: Guard against objects whos types have no __name__
Skip Montanaro <skip@pobox.com>
parents: 29463
diff changeset
390 methodname = 'repr_' + join(split(type(x).__name__), '_')
fea8dee27332 (HTML|Text)Repr.repr1: Guard against objects whos types have no __name__
Skip Montanaro <skip@pobox.com>
parents: 29463
diff changeset
391 if hasattr(self, methodname):
fea8dee27332 (HTML|Text)Repr.repr1: Guard against objects whos types have no __name__
Skip Montanaro <skip@pobox.com>
parents: 29463
diff changeset
392 return getattr(self, methodname)(x, level)
fea8dee27332 (HTML|Text)Repr.repr1: Guard against objects whos types have no __name__
Skip Montanaro <skip@pobox.com>
parents: 29463
diff changeset
393 return self.escape(cram(stripid(repr(x)), self.maxother))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
394
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
395 def repr_string(self, x, level):
16923
5ab4da6ad4fc Use imp.get_suffixes to determine a module name in modulename(file).
Ka-Ping Yee <ping@zesty.ca>
parents: 16908
diff changeset
396 test = cram(x, self.maxstring)
5ab4da6ad4fc Use imp.get_suffixes to determine a module name in modulename(file).
Ka-Ping Yee <ping@zesty.ca>
parents: 16908
diff changeset
397 testrepr = repr(test)
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
398 if '\\' in test and '\\' not in replace(testrepr, r'\\', ''):
16923
5ab4da6ad4fc Use imp.get_suffixes to determine a module name in modulename(file).
Ka-Ping Yee <ping@zesty.ca>
parents: 16908
diff changeset
399 # Backslashes are only literal in the string and are never
5ab4da6ad4fc Use imp.get_suffixes to determine a module name in modulename(file).
Ka-Ping Yee <ping@zesty.ca>
parents: 16908
diff changeset
400 # needed to make any special characters, so show a raw string.
5ab4da6ad4fc Use imp.get_suffixes to determine a module name in modulename(file).
Ka-Ping Yee <ping@zesty.ca>
parents: 16908
diff changeset
401 return 'r' + testrepr[0] + self.escape(test) + testrepr[0]
17371
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
402 return re.sub(r'((\\[\\abfnrtv\'"]|\\[0-9]..|\\x..|\\u....)+)',
16923
5ab4da6ad4fc Use imp.get_suffixes to determine a module name in modulename(file).
Ka-Ping Yee <ping@zesty.ca>
parents: 16908
diff changeset
403 r'<font color="#c040c0">\1</font>',
5ab4da6ad4fc Use imp.get_suffixes to determine a module name in modulename(file).
Ka-Ping Yee <ping@zesty.ca>
parents: 16908
diff changeset
404 self.escape(testrepr))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
405
22169
4d5becc6902b add repr_str as alias for repr_string in both HTMLRepr and TextRepr classes
Skip Montanaro <skip@pobox.com>
parents: 22117
diff changeset
406 repr_str = repr_string
4d5becc6902b add repr_str as alias for repr_string in both HTMLRepr and TextRepr classes
Skip Montanaro <skip@pobox.com>
parents: 22117
diff changeset
407
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
408 def repr_instance(self, x, level):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
409 try:
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
410 return self.escape(cram(stripid(repr(x)), self.maxstring))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
411 except:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
412 return self.escape('<%s instance>' % x.__class__.__name__)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
413
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
414 repr_unicode = repr_string
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
415
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
416 class HTMLDoc(Doc):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
417 """Formatter class for HTML documentation."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
418
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
419 # ------------------------------------------- HTML formatting utilities
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
420
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
421 _repr_instance = HTMLRepr()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
422 repr = _repr_instance.repr
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
423 escape = _repr_instance.escape
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
424
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
425 def page(self, title, contents):
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
426 """Format an HTML page."""
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
427 return '''
53034
0327504a4f6a Merged revisions 71443 via svnmerge from
Matthias Klose <doko@ubuntu.com>
parents: 50424
diff changeset
428 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
429 <html><head><title>Python: %s</title>
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
430 </head><body bgcolor="#f0f0f8">
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
431 %s
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
432 </body></html>''' % (title, contents)
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
433
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
434 def heading(self, title, fgcol, bgcol, extras=''):
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
435 """Format a page heading."""
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
436 return '''
20783
a2b11d00b697 SF patch #474485: pydoc generates some bad html, from Rich Salz.
Tim Peters <tim.peters@gmail.com>
parents: 20538
diff changeset
437 <table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="heading">
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
438 <tr bgcolor="%s">
20074
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
439 <td valign=bottom>&nbsp;<br>
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
440 <font color="%s" face="helvetica, arial">&nbsp;<br>%s</font></td
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
441 ><td align=right valign=bottom
17182
5ee3543ea33f Small formatting improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 17181
diff changeset
442 ><font color="%s" face="helvetica, arial">%s</font></td></tr></table>
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
443 ''' % (bgcol, fgcol, title, fgcol, extras or '&nbsp;')
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
444
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
445 def section(self, title, fgcol, bgcol, contents, width=6,
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
446 prelude='', marginalia=None, gap='&nbsp;'):
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
447 """Format a section with a heading."""
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
448 if marginalia is None:
17371
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
449 marginalia = '<tt>' + '&nbsp;' * width + '</tt>'
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
450 result = '''<p>
20783
a2b11d00b697 SF patch #474485: pydoc generates some bad html, from Rich Salz.
Tim Peters <tim.peters@gmail.com>
parents: 20538
diff changeset
451 <table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
452 <tr bgcolor="%s">
20074
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
453 <td colspan=3 valign=bottom>&nbsp;<br>
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
454 <font color="%s" face="helvetica, arial">%s</font></td></tr>
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
455 ''' % (bgcol, fgcol, title)
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
456 if prelude:
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
457 result = result + '''
17182
5ee3543ea33f Small formatting improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 17181
diff changeset
458 <tr bgcolor="%s"><td rowspan=2>%s</td>
5ee3543ea33f Small formatting improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 17181
diff changeset
459 <td colspan=2>%s</td></tr>
5ee3543ea33f Small formatting improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 17181
diff changeset
460 <tr><td>%s</td>''' % (bgcol, marginalia, prelude, gap)
5ee3543ea33f Small formatting improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 17181
diff changeset
461 else:
5ee3543ea33f Small formatting improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 17181
diff changeset
462 result = result + '''
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
463 <tr><td bgcolor="%s">%s</td><td>%s</td>''' % (bgcol, marginalia, gap)
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
464
17371
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
465 return result + '\n<td width="100%%">%s</td></tr></table>' % contents
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
466
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
467 def bigsection(self, title, *args):
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
468 """Format a section with a big heading."""
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
469 title = '<big><strong>%s</strong></big>' % title
28089
14f65d661084 Get rid of many apply() calls.
Guido van Rossum <guido@python.org>
parents: 27904
diff changeset
470 return self.section(title, *args)
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
471
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
472 def preformat(self, text):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
473 """Format literal preformatted text."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
474 text = self.escape(expandtabs(text))
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
475 return replace(text, '\n\n', '\n \n', '\n\n', '\n \n',
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
476 ' ', '&nbsp;', '\n', '<br>\n')
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
477
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
478 def multicolumn(self, list, format, cols=4):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
479 """Format a list of items into a multi-column list."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
480 result = ''
70395
7724b53510c4 Close #12182: Fix pydoc.HTMLDoc.multicolumn() if Python uses the new (true)
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68941
diff changeset
481 rows = (len(list)+cols-1)//cols
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
482 for col in range(cols):
70395
7724b53510c4 Close #12182: Fix pydoc.HTMLDoc.multicolumn() if Python uses the new (true)
Victor Stinner <victor.stinner@haypocalc.com>
parents: 68941
diff changeset
483 result = result + '<td width="%d%%" valign=top>' % (100//cols)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
484 for i in range(rows*col, rows*col+rows):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
485 if i < len(list):
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
486 result = result + format(list[i]) + '<br>\n'
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
487 result = result + '</td>'
20783
a2b11d00b697 SF patch #474485: pydoc generates some bad html, from Rich Salz.
Tim Peters <tim.peters@gmail.com>
parents: 20538
diff changeset
488 return '<table width="100%%" summary="list"><tr>%s</tr></table>' % result
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
489
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
490 def grey(self, text): return '<font color="#909090">%s</font>' % text
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
491
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
492 def namelink(self, name, *dicts):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
493 """Make a link for an identifier, given name-to-URL mappings."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
494 for dict in dicts:
23620
a1de0bab5475 SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents: 23501
diff changeset
495 if name in dict:
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
496 return '<a href="%s">%s</a>' % (dict[name], name)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
497 return name
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
498
17457
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
499 def classlink(self, object, modname):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
500 """Make a link for a class."""
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
501 name, module = object.__name__, sys.modules.get(object.__module__)
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
502 if hasattr(module, name) and getattr(module, name) is object:
17457
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
503 return '<a href="%s.html#%s">%s</a>' % (
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
504 module.__name__, name, classname(object, modname))
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
505 return classname(object, modname)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
506
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
507 def modulelink(self, object):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
508 """Make a link for a module."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
509 return '<a href="%s.html">%s</a>' % (object.__name__, object.__name__)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
510
48141
4e6a0ae1a8e7 Silence SyntaxWarning and DeprecationWarning in pydoc triggered by tuple
Brett Cannon <bcannon@gmail.com>
parents: 47987
diff changeset
511 def modpkglink(self, data):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
512 """Make a link for a module or package to display in an index."""
48141
4e6a0ae1a8e7 Silence SyntaxWarning and DeprecationWarning in pydoc triggered by tuple
Brett Cannon <bcannon@gmail.com>
parents: 47987
diff changeset
513 name, path, ispackage, shadowed = data
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
514 if shadowed:
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
515 return self.grey(name)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
516 if path:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
517 url = '%s.%s.html' % (path, name)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
518 else:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
519 url = '%s.html' % name
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
520 if ispackage:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
521 text = '<strong>%s</strong>&nbsp;(package)' % name
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
522 else:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
523 text = name
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
524 return '<a href="%s">%s</a>' % (url, text)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
525
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
526 def markup(self, text, escape=None, funcs={}, classes={}, methods={}):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
527 """Mark up some plain text, given a context of symbols to look for.
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
528 Each context dictionary maps object names to anchor names."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
529 escape = escape or self.escape
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
530 results = []
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
531 here = 0
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
532 pattern = re.compile(r'\b((http|ftp)://\S+[\w/]|'
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
533 r'RFC[- ]?(\d+)|'
17230
45cda1b39355 Fix some reloading problems (still more work needed).
Ka-Ping Yee <ping@zesty.ca>
parents: 17184
diff changeset
534 r'PEP[- ]?(\d+)|'
22504
25e2b580b2cf Remove unnecessary \b. It was causing the RE to miss the tailing
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22169
diff changeset
535 r'(self\.)?(\w+))')
22867
e2f2187c3d2c Partial introduction of bools where appropriate.
Guido van Rossum <guido@python.org>
parents: 22830
diff changeset
536 while True:
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
537 match = pattern.search(text, here)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
538 if not match: break
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
539 start, end = match.span()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
540 results.append(escape(text[here:start]))
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
541
17230
45cda1b39355 Fix some reloading problems (still more work needed).
Ka-Ping Yee <ping@zesty.ca>
parents: 17184
diff changeset
542 all, scheme, rfc, pep, selfdot, name = match.groups()
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
543 if scheme:
22506
e94eddecf330 Quote href properly.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22504
diff changeset
544 url = escape(all).replace('"', '&quot;')
e94eddecf330 Quote href properly.
Neil Schemenauer <nascheme@enme.ucalgary.ca>
parents: 22504
diff changeset
545 results.append('<a href="%s">%s</a>' % (url, url))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
546 elif rfc:
17230
45cda1b39355 Fix some reloading problems (still more work needed).
Ka-Ping Yee <ping@zesty.ca>
parents: 17184
diff changeset
547 url = 'http://www.rfc-editor.org/rfc/rfc%d.txt' % int(rfc)
45cda1b39355 Fix some reloading problems (still more work needed).
Ka-Ping Yee <ping@zesty.ca>
parents: 17184
diff changeset
548 results.append('<a href="%s">%s</a>' % (url, escape(all)))
45cda1b39355 Fix some reloading problems (still more work needed).
Ka-Ping Yee <ping@zesty.ca>
parents: 17184
diff changeset
549 elif pep:
45169
b011366102db Update PEP URL.
Andrew M. Kuchling <amk@amk.ca>
parents: 45014
diff changeset
550 url = 'http://www.python.org/dev/peps/pep-%04d/' % int(pep)
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
551 results.append('<a href="%s">%s</a>' % (url, escape(all)))
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
552 elif text[end:end+1] == '(':
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
553 results.append(self.namelink(name, methods, funcs, classes))
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
554 elif selfdot:
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
555 results.append('self.<strong>%s</strong>' % name)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
556 else:
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
557 results.append(self.namelink(name, classes))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
558 here = end
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
559 results.append(escape(text[here:]))
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
560 return join(results, '')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
561
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
562 # ---------------------------------------------- type-specific routines
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
563
17457
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
564 def formattree(self, tree, modname, parent=None):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
565 """Produce HTML for a class tree as given by inspect.getclasstree()."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
566 result = ''
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
567 for entry in tree:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
568 if type(entry) is type(()):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
569 c, bases = entry
20074
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
570 result = result + '<dt><font face="helvetica, arial">'
17457
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
571 result = result + self.classlink(c, modname)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
572 if bases and bases != (parent,):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
573 parents = []
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
574 for base in bases:
17457
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
575 parents.append(self.classlink(base, modname))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
576 result = result + '(' + join(parents, ', ') + ')'
20074
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
577 result = result + '\n</font></dt>'
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
578 elif type(entry) is type([]):
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
579 result = result + '<dd>\n%s</dd>\n' % self.formattree(
17457
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
580 entry, modname, c)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
581 return '<dl>\n%s</dl>\n' % result
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
582
20538
fe1b6ce4eb93 SF bug [#472347] pydoc and properties.
Tim Peters <tim.peters@gmail.com>
parents: 20125
diff changeset
583 def docmodule(self, object, name=None, mod=None, *ignored):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
584 """Produce HTML documentation for a module object."""
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
585 name = object.__name__ # ignore the passed-in name
32321
b0f454f558e5 Respect a module's __all__ attribute. Closes #969938.
Skip Montanaro <skip@pobox.com>
parents: 32288
diff changeset
586 try:
b0f454f558e5 Respect a module's __all__ attribute. Closes #969938.
Skip Montanaro <skip@pobox.com>
parents: 32288
diff changeset
587 all = object.__all__
b0f454f558e5 Respect a module's __all__ attribute. Closes #969938.
Skip Montanaro <skip@pobox.com>
parents: 32288
diff changeset
588 except AttributeError:
b0f454f558e5 Respect a module's __all__ attribute. Closes #969938.
Skip Montanaro <skip@pobox.com>
parents: 32288
diff changeset
589 all = None
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
590 parts = split(name, '.')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
591 links = []
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
592 for i in range(len(parts)-1):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
593 links.append(
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
594 '<a href="%s.html"><font color="#ffffff">%s</font></a>' %
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
595 (join(parts[:i+1], '.'), parts[i]))
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
596 linkedname = join(links + parts[-1:], '.')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
597 head = '<big><big><strong>%s</strong></big></big>' % linkedname
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
598 try:
16928
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
599 path = inspect.getabsfile(object)
17484
7e829dd03f97 Use nturl2path to generate a file: URL to source files in Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 17476
diff changeset
600 url = path
7e829dd03f97 Use nturl2path to generate a file: URL to source files in Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 17476
diff changeset
601 if sys.platform == 'win32':
7e829dd03f97 Use nturl2path to generate a file: URL to source files in Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 17476
diff changeset
602 import nturl2path
7e829dd03f97 Use nturl2path to generate a file: URL to source files in Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 17476
diff changeset
603 url = nturl2path.pathname2url(path)
7e829dd03f97 Use nturl2path to generate a file: URL to source files in Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 17476
diff changeset
604 filelink = '<a href="file:%s">%s</a>' % (url, path)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
605 except TypeError:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
606 filelink = '(built-in)'
16811
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
607 info = []
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
608 if hasattr(object, '__version__'):
16811
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
609 version = str(object.__version__)
16813
c3fb044d7e6f Fix $Revision$ processing so it doesn't get eaten by CVS!
Ka-Ping Yee <ping@zesty.ca>
parents: 16812
diff changeset
610 if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
c3fb044d7e6f Fix $Revision$ processing so it doesn't get eaten by CVS!
Ka-Ping Yee <ping@zesty.ca>
parents: 16812
diff changeset
611 version = strip(version[11:-1])
16875
10b84060b7f3 Normalize case of paths in sys.path to avoid duplicates on Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 16833
diff changeset
612 info.append('version %s' % self.escape(version))
16811
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
613 if hasattr(object, '__date__'):
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
614 info.append(self.escape(str(object.__date__)))
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
615 if info:
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
616 head = head + ' (%s)' % join(info, ', ')
30396
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
617 docloc = self.getdocloc(object)
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
618 if docloc is not None:
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
619 docloc = '<br><a href="%(docloc)s">Module Docs</a>' % locals()
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
620 else:
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
621 docloc = ''
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
622 result = self.heading(
30396
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
623 head, '#ffffff', '#7799ee',
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
624 '<a href=".">index</a><br>' + filelink + docloc)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
625
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
626 modules = inspect.getmembers(object, inspect.ismodule)
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
627
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
628 classes, cdict = [], {}
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
629 for key, value in inspect.getmembers(object, inspect.isclass):
33336
84fbaaa20358 Patch #934356: if a module defines __all__, believe that rather than using
Johannes Gijsbers <jlg@dds.nl>
parents: 33225
diff changeset
630 # if __all__ exists, believe it. Otherwise use old heuristic.
84fbaaa20358 Patch #934356: if a module defines __all__, believe that rather than using
Johannes Gijsbers <jlg@dds.nl>
parents: 33225
diff changeset
631 if (all is not None or
84fbaaa20358 Patch #934356: if a module defines __all__, believe that rather than using
Johannes Gijsbers <jlg@dds.nl>
parents: 33225
diff changeset
632 (inspect.getmodule(value) or object) is object):
68941
46aaa365111f Issue #11666: Teach pydoc to display full help for named tuples
Raymond Hettinger <python@rcn.com>
parents: 68256
diff changeset
633 if visiblename(key, all, object):
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
634 classes.append((key, value))
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
635 cdict[key] = cdict[value] = '#' + key
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
636 for key, value in classes:
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
637 for base in value.__bases__:
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
638 key, modname = base.__name__, base.__module__
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
639 module = sys.modules.get(modname)
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
640 if modname != name and module and hasattr(module, key):
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
641 if getattr(module, key) is base:
23620
a1de0bab5475 SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents: 23501
diff changeset
642 if not key in cdict:
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
643 cdict[key] = cdict[base] = modname + '.html#' + key
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
644 funcs, fdict = [], {}
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
645 for key, value in inspect.getmembers(object, inspect.isroutine):
33336
84fbaaa20358 Patch #934356: if a module defines __all__, believe that rather than using
Johannes Gijsbers <jlg@dds.nl>
parents: 33225
diff changeset
646 # if __all__ exists, believe it. Otherwise use old heuristic.
84fbaaa20358 Patch #934356: if a module defines __all__, believe that rather than using
Johannes Gijsbers <jlg@dds.nl>
parents: 33225
diff changeset
647 if (all is not None or
84fbaaa20358 Patch #934356: if a module defines __all__, believe that rather than using
Johannes Gijsbers <jlg@dds.nl>
parents: 33225
diff changeset
648 inspect.isbuiltin(value) or inspect.getmodule(value) is object):
68941
46aaa365111f Issue #11666: Teach pydoc to display full help for named tuples
Raymond Hettinger <python@rcn.com>
parents: 68256
diff changeset
649 if visiblename(key, all, object):
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
650 funcs.append((key, value))
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
651 fdict[key] = '#-' + key
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
652 if inspect.isfunction(value): fdict[value] = fdict[key]
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
653 data = []
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
654 for key, value in inspect.getmembers(object, isdata):
68941
46aaa365111f Issue #11666: Teach pydoc to display full help for named tuples
Raymond Hettinger <python@rcn.com>
parents: 68256
diff changeset
655 if visiblename(key, all, object):
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
656 data.append((key, value))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
657
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
658 doc = self.markup(getdoc(object), self.preformat, fdict, cdict)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
659 doc = doc and '<tt>%s</tt>' % doc
20074
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
660 result = result + '<p>%s</p>\n' % doc
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
661
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
662 if hasattr(object, '__path__'):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
663 modpkgs = []
37821
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
664 for importer, modname, ispkg in pkgutil.iter_modules(object.__path__):
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
665 modpkgs.append((modname, name, ispkg, 0))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
666 modpkgs.sort()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
667 contents = self.multicolumn(modpkgs, self.modpkglink)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
668 result = result + self.bigsection(
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
669 'Package Contents', '#ffffff', '#aa55cc', contents)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
670 elif modules:
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
671 contents = self.multicolumn(
48141
4e6a0ae1a8e7 Silence SyntaxWarning and DeprecationWarning in pydoc triggered by tuple
Brett Cannon <bcannon@gmail.com>
parents: 47987
diff changeset
672 modules, lambda key_value, s=self: s.modulelink(key_value[1]))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
673 result = result + self.bigsection(
45385
3d2ff0146574 #2133: fix HTML color spec.
Georg Brandl <georg@python.org>
parents: 45169
diff changeset
674 'Modules', '#ffffff', '#aa55cc', contents)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
675
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
676 if classes:
48141
4e6a0ae1a8e7 Silence SyntaxWarning and DeprecationWarning in pydoc triggered by tuple
Brett Cannon <bcannon@gmail.com>
parents: 47987
diff changeset
677 classlist = map(lambda key_value: key_value[1], classes)
17457
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
678 contents = [
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
679 self.formattree(inspect.getclasstree(classlist, 1), name)]
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
680 for key, value in classes:
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
681 contents.append(self.document(value, key, name, fdict, cdict))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
682 result = result + self.bigsection(
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
683 'Classes', '#ffffff', '#ee77aa', join(contents))
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
684 if funcs:
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
685 contents = []
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
686 for key, value in funcs:
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
687 contents.append(self.document(value, key, name, fdict, cdict))
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
688 result = result + self.bigsection(
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
689 'Functions', '#ffffff', '#eeaa77', join(contents))
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
690 if data:
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
691 contents = []
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
692 for key, value in data:
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
693 contents.append(self.document(value, key))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
694 result = result + self.bigsection(
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
695 'Data', '#ffffff', '#55aa55', join(contents, '<br>\n'))
16811
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
696 if hasattr(object, '__author__'):
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
697 contents = self.markup(str(object.__author__), self.preformat)
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
698 result = result + self.bigsection(
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
699 'Author', '#ffffff', '#7799ee', contents)
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
700 if hasattr(object, '__credits__'):
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
701 contents = self.markup(str(object.__credits__), self.preformat)
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
702 result = result + self.bigsection(
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
703 'Credits', '#ffffff', '#7799ee', contents)
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
704
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
705 return result
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
706
20538
fe1b6ce4eb93 SF bug [#472347] pydoc and properties.
Tim Peters <tim.peters@gmail.com>
parents: 20125
diff changeset
707 def docclass(self, object, name=None, mod=None, funcs={}, classes={},
fe1b6ce4eb93 SF bug [#472347] pydoc and properties.
Tim Peters <tim.peters@gmail.com>
parents: 20125
diff changeset
708 *ignored):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
709 """Produce HTML documentation for a class object."""
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
710 realname = object.__name__
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
711 name = name or realname
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
712 bases = object.__bases__
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
713
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
714 contents = []
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
715 push = contents.append
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
716
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
717 # Cute little class to pump out a horizontal rule between sections.
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
718 class HorizontalRule:
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
719 def __init__(self):
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
720 self.needone = 0
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
721 def maybe(self):
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
722 if self.needone:
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
723 push('<hr>\n')
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
724 self.needone = 1
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
725 hr = HorizontalRule()
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
726
20120
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
727 # List the mro, if non-trivial.
31436
63fa60f2d61c * Move collections.deque() in from the sandbox
Raymond Hettinger <python@rcn.com>
parents: 30821
diff changeset
728 mro = deque(inspect.getmro(object))
20120
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
729 if len(mro) > 2:
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
730 hr.maybe()
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
731 push('<dl><dt>Method resolution order:</dt>\n')
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
732 for base in mro:
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
733 push('<dd>%s</dd>\n' % self.classlink(base,
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
734 object.__module__))
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
735 push('</dl>\n')
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
736
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
737 def spill(msg, attrs, predicate):
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
738 ok, attrs = _split_list(attrs, predicate)
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
739 if ok:
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
740 hr.maybe()
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
741 push(msg)
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
742 for name, kind, homecls, value in ok:
74106
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
743 try:
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
744 value = getattr(object, name)
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
745 except Exception:
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
746 # Some descriptors may meet a failure in their __get__.
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
747 # (bug #1785)
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
748 push(self._docdescriptor(name, value, mod))
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
749 else:
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
750 push(self.document(value, name, mod,
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
751 funcs, classes, mdict, object))
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
752 push('\n')
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
753 return attrs
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
754
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
755 def spilldescriptors(msg, attrs, predicate):
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
756 ok, attrs = _split_list(attrs, predicate)
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
757 if ok:
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
758 hr.maybe()
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
759 push(msg)
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
760 for name, kind, homecls, value in ok:
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
761 push(self._docdescriptor(name, value, mod))
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
762 return attrs
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
763
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
764 def spilldata(msg, attrs, predicate):
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
765 ok, attrs = _split_list(attrs, predicate)
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
766 if ok:
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
767 hr.maybe()
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
768 push(msg)
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
769 for name, kind, homecls, value in ok:
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
770 base = self.docother(getattr(object, name), name, mod)
48141
4e6a0ae1a8e7 Silence SyntaxWarning and DeprecationWarning in pydoc triggered by tuple
Brett Cannon <bcannon@gmail.com>
parents: 47987
diff changeset
771 if (hasattr(value, '__call__') or
4e6a0ae1a8e7 Silence SyntaxWarning and DeprecationWarning in pydoc triggered by tuple
Brett Cannon <bcannon@gmail.com>
parents: 47987
diff changeset
772 inspect.isdatadescriptor(value)):
23501
62688d6ac387 In both spilldata() functions, pretend that the docstring for
Guido van Rossum <guido@python.org>
parents: 22867
diff changeset
773 doc = getattr(value, "__doc__", None)
62688d6ac387 In both spilldata() functions, pretend that the docstring for
Guido van Rossum <guido@python.org>
parents: 22867
diff changeset
774 else:
62688d6ac387 In both spilldata() functions, pretend that the docstring for
Guido van Rossum <guido@python.org>
parents: 22867
diff changeset
775 doc = None
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
776 if doc is None:
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
777 push('<dl><dt>%s</dl>\n' % base)
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
778 else:
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
779 doc = self.markup(getdoc(value), self.preformat,
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
780 funcs, classes, mdict)
20074
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
781 doc = '<dd><tt>%s</tt>' % doc
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
782 push('<dl><dt>%s%s</dl>\n' % (base, doc))
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
783 push('\n')
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
784 return attrs
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
785
68941
46aaa365111f Issue #11666: Teach pydoc to display full help for named tuples
Raymond Hettinger <python@rcn.com>
parents: 68256
diff changeset
786 attrs = filter(lambda data: visiblename(data[0], obj=object),
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
787 classify_class_attrs(object))
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
788 mdict = {}
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
789 for key, kind, homecls, value in attrs:
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
790 mdict[key] = anchor = '#' + name + '-' + key
74106
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
791 try:
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
792 value = getattr(object, name)
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
793 except Exception:
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
794 # Some descriptors may meet a failure in their __get__.
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
795 # (bug #1785)
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
796 pass
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
797 try:
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
798 # The value may not be hashable (e.g., a data attr with
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
799 # a dict or list value).
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
800 mdict[value] = anchor
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
801 except TypeError:
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
802 pass
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
803
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
804 while attrs:
20124
9c2b9b76a08e List class attrs in MRO order of defining class instead of by alphabetic
Tim Peters <tim.peters@gmail.com>
parents: 20123
diff changeset
805 if mro:
31436
63fa60f2d61c * Move collections.deque() in from the sandbox
Raymond Hettinger <python@rcn.com>
parents: 30821
diff changeset
806 thisclass = mro.popleft()
20124
9c2b9b76a08e List class attrs in MRO order of defining class instead of by alphabetic
Tim Peters <tim.peters@gmail.com>
parents: 20123
diff changeset
807 else:
9c2b9b76a08e List class attrs in MRO order of defining class instead of by alphabetic
Tim Peters <tim.peters@gmail.com>
parents: 20123
diff changeset
808 thisclass = attrs[0][2]
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
809 attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass)
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
810
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
811 if thisclass is __builtin__.object:
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
812 attrs = inherited
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
813 continue
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
814 elif thisclass is object:
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
815 tag = 'defined here'
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
816 else:
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
817 tag = 'inherited from %s' % self.classlink(thisclass,
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
818 object.__module__)
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
819 tag += ':<br>\n'
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
820
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
821 # Sort attrs by name.
37821
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
822 try:
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
823 attrs.sort(key=lambda t: t[0])
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
824 except TypeError:
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
825 attrs.sort(lambda t1, t2: cmp(t1[0], t2[0])) # 2.3 compat
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
826
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
827 # Pump out the attrs, segregated by kind.
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
828 attrs = spill('Methods %s' % tag, attrs,
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
829 lambda t: t[1] == 'method')
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
830 attrs = spill('Class methods %s' % tag, attrs,
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
831 lambda t: t[1] == 'class method')
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
832 attrs = spill('Static methods %s' % tag, attrs,
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
833 lambda t: t[1] == 'static method')
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
834 attrs = spilldescriptors('Data descriptors %s' % tag, attrs,
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
835 lambda t: t[1] == 'data descriptor')
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
836 attrs = spilldata('Data and other attributes %s' % tag, attrs,
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
837 lambda t: t[1] == 'data')
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
838 assert attrs == []
20124
9c2b9b76a08e List class attrs in MRO order of defining class instead of by alphabetic
Tim Peters <tim.peters@gmail.com>
parents: 20123
diff changeset
839 attrs = inherited
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
840
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
841 contents = ''.join(contents)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
842
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
843 if name == realname:
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
844 title = '<a name="%s">class <strong>%s</strong></a>' % (
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
845 name, realname)
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
846 else:
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
847 title = '<strong>%s</strong> = <a name="%s">class %s</a>' % (
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
848 name, name, realname)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
849 if bases:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
850 parents = []
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
851 for base in bases:
17457
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
852 parents.append(self.classlink(base, object.__module__))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
853 title = title + '(%s)' % join(parents, ', ')
20074
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
854 doc = self.markup(getdoc(object), self.preformat, funcs, classes, mdict)
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
855 doc = doc and '<tt>%s<br>&nbsp;</tt>' % doc
20120
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
856
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
857 return self.section(title, '#000000', '#ffc8d8', contents, 3, doc)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
858
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
859 def formatvalue(self, object):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
860 """Format an argument default value as text."""
20074
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
861 return self.grey('=' + self.repr(object))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
862
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
863 def docroutine(self, object, name=None, mod=None,
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
864 funcs={}, classes={}, methods={}, cl=None):
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
865 """Produce HTML documentation for a function or method object."""
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
866 realname = object.__name__
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
867 name = name or realname
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
868 anchor = (cl and cl.__name__ or '') + '-' + name
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
869 note = ''
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
870 skipdocs = 0
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
871 if inspect.ismethod(object):
17456
3bda59071389 Fix call to ModuleScanner from GUI search interface.
Ka-Ping Yee <ping@zesty.ca>
parents: 17452
diff changeset
872 imclass = object.im_class
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
873 if cl:
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
874 if imclass is not cl:
17457
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
875 note = ' from ' + self.classlink(imclass, mod)
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
876 else:
41176
d311013a1638 Patch #1194449: correctly detect unbound methods in pydoc.
Georg Brandl <georg@python.org>
parents: 41148
diff changeset
877 if object.im_self is not None:
17457
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
878 note = ' method of %s instance' % self.classlink(
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
879 object.im_self.__class__, mod)
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
880 else:
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
881 note = ' unbound %s method' % self.classlink(imclass,mod)
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
882 object = object.im_func
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
883
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
884 if name == realname:
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
885 title = '<a name="%s"><strong>%s</strong></a>' % (anchor, realname)
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
886 else:
23620
a1de0bab5475 SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents: 23501
diff changeset
887 if (cl and realname in cl.__dict__ and
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
888 cl.__dict__[realname] is object):
17184
56d195f21b4f Browser compatibility fixes.
Ka-Ping Yee <ping@zesty.ca>
parents: 17182
diff changeset
889 reallink = '<a href="#%s">%s</a>' % (
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
890 cl.__name__ + '-' + realname, realname)
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
891 skipdocs = 1
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
892 else:
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
893 reallink = realname
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
894 title = '<a name="%s"><strong>%s</strong></a> = %s' % (
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
895 anchor, name, reallink)
19993
28ef22a2598e Since inspect.isfunction(obj) is a precondition for calling
Tim Peters <tim.peters@gmail.com>
parents: 19989
diff changeset
896 if inspect.isfunction(object):
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
897 args, varargs, varkw, defaults = inspect.getargspec(object)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
898 argspec = inspect.formatargspec(
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
899 args, varargs, varkw, defaults, formatvalue=self.formatvalue)
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
900 if realname == '<lambda>':
20783
a2b11d00b697 SF patch #474485: pydoc generates some bad html, from Rich Salz.
Tim Peters <tim.peters@gmail.com>
parents: 20538
diff changeset
901 title = '<strong>%s</strong> <em>lambda</em> ' % name
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
902 argspec = argspec[1:-1] # remove parentheses
19993
28ef22a2598e Since inspect.isfunction(obj) is a precondition for calling
Tim Peters <tim.peters@gmail.com>
parents: 19989
diff changeset
903 else:
28ef22a2598e Since inspect.isfunction(obj) is a precondition for calling
Tim Peters <tim.peters@gmail.com>
parents: 19989
diff changeset
904 argspec = '(...)'
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
905
20074
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
906 decl = title + argspec + (note and self.grey(
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
907 '<font face="helvetica, arial">%s</font>' % note))
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
908
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
909 if skipdocs:
20074
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
910 return '<dl><dt>%s</dt></dl>\n' % decl
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
911 else:
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
912 doc = self.markup(
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
913 getdoc(object), self.preformat, funcs, classes, methods)
20074
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
914 doc = doc and '<dd><tt>%s</tt></dd>' % doc
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
915 return '<dl><dt>%s</dt>%s</dl>\n' % (decl, doc)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
916
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
917 def _docdescriptor(self, name, value, mod):
33935
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
918 results = []
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
919 push = results.append
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
920
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
921 if name:
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
922 push('<dl><dt><strong>%s</strong></dt>\n' % name)
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
923 if value.__doc__ is not None:
34618
c99ae8635f3b Use getdoc(object) instead of object.__doc__ to fix indentation problems.
Ka-Ping Yee <ping@zesty.ca>
parents: 34545
diff changeset
924 doc = self.markup(getdoc(value), self.preformat)
33935
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
925 push('<dd><tt>%s</tt></dd>\n' % doc)
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
926 push('</dl>\n')
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
927
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
928 return ''.join(results)
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
929
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
930 def docproperty(self, object, name=None, mod=None, cl=None):
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
931 """Produce html documentation for a property."""
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
932 return self._docdescriptor(name, object, mod)
33935
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
933
20538
fe1b6ce4eb93 SF bug [#472347] pydoc and properties.
Tim Peters <tim.peters@gmail.com>
parents: 20125
diff changeset
934 def docother(self, object, name=None, mod=None, *ignored):
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
935 """Produce HTML documentation for a data object."""
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
936 lhs = name and '<strong>%s</strong> = ' % name or ''
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
937 return lhs + self.repr(object)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
938
39226
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
939 def docdata(self, object, name=None, mod=None, cl=None):
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
940 """Produce html documentation for a data descriptor."""
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
941 return self._docdescriptor(name, object, mod)
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
942
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
943 def index(self, dir, shadowed=None):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
944 """Generate an HTML index for a directory of modules."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
945 modpkgs = []
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
946 if shadowed is None: shadowed = {}
37821
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
947 for importer, name, ispkg in pkgutil.iter_modules([dir]):
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
948 modpkgs.append((name, '', ispkg, name in shadowed))
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
949 shadowed[name] = 1
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
950
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
951 modpkgs.sort()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
952 contents = self.multicolumn(modpkgs, self.modpkglink)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
953 return self.bigsection(dir, '#ffffff', '#ee77aa', contents)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
954
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
955 # -------------------------------------------- text documentation generator
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
956
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
957 class TextRepr(Repr):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
958 """Class for safely making a text representation of a Python object."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
959 def __init__(self):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
960 Repr.__init__(self)
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
961 self.maxlist = self.maxtuple = 20
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
962 self.maxdict = 10
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
963 self.maxstring = self.maxother = 100
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
964
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
965 def repr1(self, x, level):
29603
fea8dee27332 (HTML|Text)Repr.repr1: Guard against objects whos types have no __name__
Skip Montanaro <skip@pobox.com>
parents: 29463
diff changeset
966 if hasattr(type(x), '__name__'):
fea8dee27332 (HTML|Text)Repr.repr1: Guard against objects whos types have no __name__
Skip Montanaro <skip@pobox.com>
parents: 29463
diff changeset
967 methodname = 'repr_' + join(split(type(x).__name__), '_')
fea8dee27332 (HTML|Text)Repr.repr1: Guard against objects whos types have no __name__
Skip Montanaro <skip@pobox.com>
parents: 29463
diff changeset
968 if hasattr(self, methodname):
fea8dee27332 (HTML|Text)Repr.repr1: Guard against objects whos types have no __name__
Skip Montanaro <skip@pobox.com>
parents: 29463
diff changeset
969 return getattr(self, methodname)(x, level)
fea8dee27332 (HTML|Text)Repr.repr1: Guard against objects whos types have no __name__
Skip Montanaro <skip@pobox.com>
parents: 29463
diff changeset
970 return cram(stripid(repr(x)), self.maxother)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
971
16923
5ab4da6ad4fc Use imp.get_suffixes to determine a module name in modulename(file).
Ka-Ping Yee <ping@zesty.ca>
parents: 16908
diff changeset
972 def repr_string(self, x, level):
5ab4da6ad4fc Use imp.get_suffixes to determine a module name in modulename(file).
Ka-Ping Yee <ping@zesty.ca>
parents: 16908
diff changeset
973 test = cram(x, self.maxstring)
5ab4da6ad4fc Use imp.get_suffixes to determine a module name in modulename(file).
Ka-Ping Yee <ping@zesty.ca>
parents: 16908
diff changeset
974 testrepr = repr(test)
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
975 if '\\' in test and '\\' not in replace(testrepr, r'\\', ''):
16923
5ab4da6ad4fc Use imp.get_suffixes to determine a module name in modulename(file).
Ka-Ping Yee <ping@zesty.ca>
parents: 16908
diff changeset
976 # Backslashes are only literal in the string and are never
5ab4da6ad4fc Use imp.get_suffixes to determine a module name in modulename(file).
Ka-Ping Yee <ping@zesty.ca>
parents: 16908
diff changeset
977 # needed to make any special characters, so show a raw string.
5ab4da6ad4fc Use imp.get_suffixes to determine a module name in modulename(file).
Ka-Ping Yee <ping@zesty.ca>
parents: 16908
diff changeset
978 return 'r' + testrepr[0] + test + testrepr[0]
5ab4da6ad4fc Use imp.get_suffixes to determine a module name in modulename(file).
Ka-Ping Yee <ping@zesty.ca>
parents: 16908
diff changeset
979 return testrepr
5ab4da6ad4fc Use imp.get_suffixes to determine a module name in modulename(file).
Ka-Ping Yee <ping@zesty.ca>
parents: 16908
diff changeset
980
22169
4d5becc6902b add repr_str as alias for repr_string in both HTMLRepr and TextRepr classes
Skip Montanaro <skip@pobox.com>
parents: 22117
diff changeset
981 repr_str = repr_string
4d5becc6902b add repr_str as alias for repr_string in both HTMLRepr and TextRepr classes
Skip Montanaro <skip@pobox.com>
parents: 22117
diff changeset
982
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
983 def repr_instance(self, x, level):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
984 try:
16875
10b84060b7f3 Normalize case of paths in sys.path to avoid duplicates on Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 16833
diff changeset
985 return cram(stripid(repr(x)), self.maxstring)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
986 except:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
987 return '<%s instance>' % x.__class__.__name__
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
988
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
989 class TextDoc(Doc):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
990 """Formatter class for text documentation."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
991
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
992 # ------------------------------------------- text formatting utilities
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
993
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
994 _repr_instance = TextRepr()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
995 repr = _repr_instance.repr
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
996
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
997 def bold(self, text):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
998 """Format a string in bold by overstriking."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
999 return join(map(lambda ch: ch + '\b' + ch, text), '')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1000
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1001 def indent(self, text, prefix=' '):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1002 """Indent text by prepending a given prefix to each line."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1003 if not text: return ''
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1004 lines = split(text, '\n')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1005 lines = map(lambda line, prefix=prefix: prefix + line, lines)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1006 if lines: lines[-1] = rstrip(lines[-1])
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1007 return join(lines, '\n')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1008
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1009 def section(self, title, contents):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1010 """Format a section with a given heading."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1011 return self.bold(title) + '\n' + rstrip(self.indent(contents)) + '\n\n'
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1012
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1013 # ---------------------------------------------- type-specific routines
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1014
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1015 def formattree(self, tree, modname, parent=None, prefix=''):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1016 """Render in text a class tree as returned by inspect.getclasstree()."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1017 result = ''
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1018 for entry in tree:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1019 if type(entry) is type(()):
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1020 c, bases = entry
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1021 result = result + prefix + classname(c, modname)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1022 if bases and bases != (parent,):
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1023 parents = map(lambda c, m=modname: classname(c, m), bases)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1024 result = result + '(%s)' % join(parents, ', ')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1025 result = result + '\n'
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1026 elif type(entry) is type([]):
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1027 result = result + self.formattree(
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1028 entry, modname, c, prefix + ' ')
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1029 return result
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1030
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1031 def docmodule(self, object, name=None, mod=None):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1032 """Produce text documentation for a given module object."""
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1033 name = object.__name__ # ignore the passed-in name
17371
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
1034 synop, desc = splitdoc(getdoc(object))
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
1035 result = self.section('NAME', name + (synop and ' - ' + synop))
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1036
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1037 try:
32321
b0f454f558e5 Respect a module's __all__ attribute. Closes #969938.
Skip Montanaro <skip@pobox.com>
parents: 32288
diff changeset
1038 all = object.__all__
b0f454f558e5 Respect a module's __all__ attribute. Closes #969938.
Skip Montanaro <skip@pobox.com>
parents: 32288
diff changeset
1039 except AttributeError:
b0f454f558e5 Respect a module's __all__ attribute. Closes #969938.
Skip Montanaro <skip@pobox.com>
parents: 32288
diff changeset
1040 all = None
b0f454f558e5 Respect a module's __all__ attribute. Closes #969938.
Skip Montanaro <skip@pobox.com>
parents: 32288
diff changeset
1041
b0f454f558e5 Respect a module's __all__ attribute. Closes #969938.
Skip Montanaro <skip@pobox.com>
parents: 32288
diff changeset
1042 try:
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1043 file = inspect.getabsfile(object)
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1044 except TypeError:
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1045 file = '(built-in)'
16928
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
1046 result = result + self.section('FILE', file)
30396
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
1047
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
1048 docloc = self.getdocloc(object)
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
1049 if docloc is not None:
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
1050 result = result + self.section('MODULE DOCS', docloc)
e44a359c898e display link to module docs when it looks like the object module is a core
Skip Montanaro <skip@pobox.com>
parents: 29603
diff changeset
1051
17371
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
1052 if desc:
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
1053 result = result + self.section('DESCRIPTION', desc)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1054
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1055 classes = []
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1056 for key, value in inspect.getmembers(object, inspect.isclass):
33336
84fbaaa20358 Patch #934356: if a module defines __all__, believe that rather than using
Johannes Gijsbers <jlg@dds.nl>
parents: 33225
diff changeset
1057 # if __all__ exists, believe it. Otherwise use old heuristic.
84fbaaa20358 Patch #934356: if a module defines __all__, believe that rather than using
Johannes Gijsbers <jlg@dds.nl>
parents: 33225
diff changeset
1058 if (all is not None
84fbaaa20358 Patch #934356: if a module defines __all__, believe that rather than using
Johannes Gijsbers <jlg@dds.nl>
parents: 33225
diff changeset
1059 or (inspect.getmodule(value) or object) is object):
68941
46aaa365111f Issue #11666: Teach pydoc to display full help for named tuples
Raymond Hettinger <python@rcn.com>
parents: 68256
diff changeset
1060 if visiblename(key, all, object):
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
1061 classes.append((key, value))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1062 funcs = []
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1063 for key, value in inspect.getmembers(object, inspect.isroutine):
33336
84fbaaa20358 Patch #934356: if a module defines __all__, believe that rather than using
Johannes Gijsbers <jlg@dds.nl>
parents: 33225
diff changeset
1064 # if __all__ exists, believe it. Otherwise use old heuristic.
84fbaaa20358 Patch #934356: if a module defines __all__, believe that rather than using
Johannes Gijsbers <jlg@dds.nl>
parents: 33225
diff changeset
1065 if (all is not None or
84fbaaa20358 Patch #934356: if a module defines __all__, believe that rather than using
Johannes Gijsbers <jlg@dds.nl>
parents: 33225
diff changeset
1066 inspect.isbuiltin(value) or inspect.getmodule(value) is object):
68941
46aaa365111f Issue #11666: Teach pydoc to display full help for named tuples
Raymond Hettinger <python@rcn.com>
parents: 68256
diff changeset
1067 if visiblename(key, all, object):
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
1068 funcs.append((key, value))
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1069 data = []
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1070 for key, value in inspect.getmembers(object, isdata):
68941
46aaa365111f Issue #11666: Teach pydoc to display full help for named tuples
Raymond Hettinger <python@rcn.com>
parents: 68256
diff changeset
1071 if visiblename(key, all, object):
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1072 data.append((key, value))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1073
44860
c3d9e57e71f2 #1715: include sub-extension modules in pydoc text output.
Georg Brandl <georg@python.org>
parents: 44845
diff changeset
1074 modpkgs = []
c3d9e57e71f2 #1715: include sub-extension modules in pydoc text output.
Georg Brandl <georg@python.org>
parents: 44845
diff changeset
1075 modpkgs_names = set()
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1076 if hasattr(object, '__path__'):
37821
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1077 for importer, modname, ispkg in pkgutil.iter_modules(object.__path__):
44860
c3d9e57e71f2 #1715: include sub-extension modules in pydoc text output.
Georg Brandl <georg@python.org>
parents: 44845
diff changeset
1078 modpkgs_names.add(modname)
37821
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1079 if ispkg:
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1080 modpkgs.append(modname + ' (package)')
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1081 else:
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1082 modpkgs.append(modname)
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1083
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1084 modpkgs.sort()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1085 result = result + self.section(
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1086 'PACKAGE CONTENTS', join(modpkgs, '\n'))
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1087
44860
c3d9e57e71f2 #1715: include sub-extension modules in pydoc text output.
Georg Brandl <georg@python.org>
parents: 44845
diff changeset
1088 # Detect submodules as sometimes created by C extensions
c3d9e57e71f2 #1715: include sub-extension modules in pydoc text output.
Georg Brandl <georg@python.org>
parents: 44845
diff changeset
1089 submodules = []
c3d9e57e71f2 #1715: include sub-extension modules in pydoc text output.
Georg Brandl <georg@python.org>
parents: 44845
diff changeset
1090 for key, value in inspect.getmembers(object, inspect.ismodule):
c3d9e57e71f2 #1715: include sub-extension modules in pydoc text output.
Georg Brandl <georg@python.org>
parents: 44845
diff changeset
1091 if value.__name__.startswith(name + '.') and key not in modpkgs_names:
c3d9e57e71f2 #1715: include sub-extension modules in pydoc text output.
Georg Brandl <georg@python.org>
parents: 44845
diff changeset
1092 submodules.append(key)
c3d9e57e71f2 #1715: include sub-extension modules in pydoc text output.
Georg Brandl <georg@python.org>
parents: 44845
diff changeset
1093 if submodules:
c3d9e57e71f2 #1715: include sub-extension modules in pydoc text output.
Georg Brandl <georg@python.org>
parents: 44845
diff changeset
1094 submodules.sort()
c3d9e57e71f2 #1715: include sub-extension modules in pydoc text output.
Georg Brandl <georg@python.org>
parents: 44845
diff changeset
1095 result = result + self.section(
c3d9e57e71f2 #1715: include sub-extension modules in pydoc text output.
Georg Brandl <georg@python.org>
parents: 44845
diff changeset
1096 'SUBMODULES', join(submodules, '\n'))
c3d9e57e71f2 #1715: include sub-extension modules in pydoc text output.
Georg Brandl <georg@python.org>
parents: 44845
diff changeset
1097
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1098 if classes:
48141
4e6a0ae1a8e7 Silence SyntaxWarning and DeprecationWarning in pydoc triggered by tuple
Brett Cannon <bcannon@gmail.com>
parents: 47987
diff changeset
1099 classlist = map(lambda key_value: key_value[1], classes)
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1100 contents = [self.formattree(
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1101 inspect.getclasstree(classlist, 1), name)]
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1102 for key, value in classes:
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1103 contents.append(self.document(value, key, name))
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1104 result = result + self.section('CLASSES', join(contents, '\n'))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1105
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1106 if funcs:
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1107 contents = []
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1108 for key, value in funcs:
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1109 contents.append(self.document(value, key, name))
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1110 result = result + self.section('FUNCTIONS', join(contents, '\n'))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1111
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1112 if data:
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1113 contents = []
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1114 for key, value in data:
35663
5611db451a39 bug [ 729103 ] Cannot retrieve name of super object
Georg Brandl <georg@python.org>
parents: 35277
diff changeset
1115 contents.append(self.docother(value, key, name, maxlen=70))
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1116 result = result + self.section('DATA', join(contents, '\n'))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1117
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1118 if hasattr(object, '__version__'):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1119 version = str(object.__version__)
16875
10b84060b7f3 Normalize case of paths in sys.path to avoid duplicates on Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 16833
diff changeset
1120 if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
10b84060b7f3 Normalize case of paths in sys.path to avoid duplicates on Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 16833
diff changeset
1121 version = strip(version[11:-1])
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1122 result = result + self.section('VERSION', version)
16811
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
1123 if hasattr(object, '__date__'):
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
1124 result = result + self.section('DATE', str(object.__date__))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1125 if hasattr(object, '__author__'):
16811
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
1126 result = result + self.section('AUTHOR', str(object.__author__))
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
1127 if hasattr(object, '__credits__'):
1d1bf6813ee5 Add display of $Revision $ and credits.
Ka-Ping Yee <ping@zesty.ca>
parents: 16791
diff changeset
1128 result = result + self.section('CREDITS', str(object.__credits__))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1129 return result
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1130
68014
d356649504f9 Merged revisions 86881,86887,86913-86915,86933,86943,86960,86964,86974,86980,86996,87008 via svnmerge from
Georg Brandl <georg@python.org>
parents: 67532
diff changeset
1131 def docclass(self, object, name=None, mod=None, *ignored):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1132 """Produce text documentation for a given class object."""
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1133 realname = object.__name__
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1134 name = name or realname
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1135 bases = object.__bases__
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1136
20120
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
1137 def makename(c, m=object.__module__):
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
1138 return classname(c, m)
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
1139
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1140 if name == realname:
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1141 title = 'class ' + self.bold(realname)
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1142 else:
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1143 title = self.bold(name) + ' = class ' + realname
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1144 if bases:
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
1145 parents = map(makename, bases)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1146 title = title + '(%s)' % join(parents, ', ')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1147
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1148 doc = getdoc(object)
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1149 contents = doc and [doc + '\n'] or []
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1150 push = contents.append
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1151
20120
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
1152 # List the mro, if non-trivial.
31436
63fa60f2d61c * Move collections.deque() in from the sandbox
Raymond Hettinger <python@rcn.com>
parents: 30821
diff changeset
1153 mro = deque(inspect.getmro(object))
20120
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
1154 if len(mro) > 2:
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
1155 push("Method resolution order:")
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
1156 for base in mro:
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
1157 push(' ' + makename(base))
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
1158 push('')
0176f61af845 Display a class's method resolution order, if it's non-trivial. "Trivial"
Tim Peters <tim.peters@gmail.com>
parents: 20079
diff changeset
1159
20072
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1160 # Cute little class to pump out a horizontal rule between sections.
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1161 class HorizontalRule:
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1162 def __init__(self):
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1163 self.needone = 0
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1164 def maybe(self):
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1165 if self.needone:
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1166 push('-' * 70)
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1167 self.needone = 1
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1168 hr = HorizontalRule()
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1169
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1170 def spill(msg, attrs, predicate):
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
1171 ok, attrs = _split_list(attrs, predicate)
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1172 if ok:
20072
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1173 hr.maybe()
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1174 push(msg)
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1175 for name, kind, homecls, value in ok:
74106
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
1176 try:
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
1177 value = getattr(object, name)
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
1178 except Exception:
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
1179 # Some descriptors may meet a failure in their __get__.
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
1180 # (bug #1785)
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
1181 push(self._docdescriptor(name, value, mod))
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
1182 else:
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
1183 push(self.document(value,
13f56cd8dec1 Issue #1785: Fix inspect and pydoc with misbehaving descriptors.
Antoine Pitrou <solipsis@pitrou.net>
parents: 72770
diff changeset
1184 name, mod, object))
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1185 return attrs
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1186
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
1187 def spilldescriptors(msg, attrs, predicate):
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
1188 ok, attrs = _split_list(attrs, predicate)
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1189 if ok:
20072
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1190 hr.maybe()
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1191 push(msg)
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1192 for name, kind, homecls, value in ok:
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
1193 push(self._docdescriptor(name, value, mod))
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1194 return attrs
20050
6e93a1586800 Try to do for pydoc's GUI mode what the earlier checkin did for text
Tim Peters <tim.peters@gmail.com>
parents: 20048
diff changeset
1195
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
1196 def spilldata(msg, attrs, predicate):
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
1197 ok, attrs = _split_list(attrs, predicate)
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1198 if ok:
20072
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1199 hr.maybe()
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1200 push(msg)
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1201 for name, kind, homecls, value in ok:
48141
4e6a0ae1a8e7 Silence SyntaxWarning and DeprecationWarning in pydoc triggered by tuple
Brett Cannon <bcannon@gmail.com>
parents: 47987
diff changeset
1202 if (hasattr(value, '__call__') or
4e6a0ae1a8e7 Silence SyntaxWarning and DeprecationWarning in pydoc triggered by tuple
Brett Cannon <bcannon@gmail.com>
parents: 47987
diff changeset
1203 inspect.isdatadescriptor(value)):
34618
c99ae8635f3b Use getdoc(object) instead of object.__doc__ to fix indentation problems.
Ka-Ping Yee <ping@zesty.ca>
parents: 34545
diff changeset
1204 doc = getdoc(value)
23501
62688d6ac387 In both spilldata() functions, pretend that the docstring for
Guido van Rossum <guido@python.org>
parents: 22867
diff changeset
1205 else:
62688d6ac387 In both spilldata() functions, pretend that the docstring for
Guido van Rossum <guido@python.org>
parents: 22867
diff changeset
1206 doc = None
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1207 push(self.docother(getattr(object, name),
35663
5611db451a39 bug [ 729103 ] Cannot retrieve name of super object
Georg Brandl <georg@python.org>
parents: 35277
diff changeset
1208 name, mod, maxlen=70, doc=doc) + '\n')
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1209 return attrs
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1210
68941
46aaa365111f Issue #11666: Teach pydoc to display full help for named tuples
Raymond Hettinger <python@rcn.com>
parents: 68256
diff changeset
1211 attrs = filter(lambda data: visiblename(data[0], obj=object),
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
1212 classify_class_attrs(object))
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
1213 while attrs:
20124
9c2b9b76a08e List class attrs in MRO order of defining class instead of by alphabetic
Tim Peters <tim.peters@gmail.com>
parents: 20123
diff changeset
1214 if mro:
31436
63fa60f2d61c * Move collections.deque() in from the sandbox
Raymond Hettinger <python@rcn.com>
parents: 30821
diff changeset
1215 thisclass = mro.popleft()
20124
9c2b9b76a08e List class attrs in MRO order of defining class instead of by alphabetic
Tim Peters <tim.peters@gmail.com>
parents: 20123
diff changeset
1216 else:
9c2b9b76a08e List class attrs in MRO order of defining class instead of by alphabetic
Tim Peters <tim.peters@gmail.com>
parents: 20123
diff changeset
1217 thisclass = attrs[0][2]
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
1218 attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass)
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
1219
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
1220 if thisclass is __builtin__.object:
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
1221 attrs = inherited
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
1222 continue
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
1223 elif thisclass is object:
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1224 tag = "defined here"
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1225 else:
20051
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
1226 tag = "inherited from %s" % classname(thisclass,
4966cf793b44 More work on class display:
Tim Peters <tim.peters@gmail.com>
parents: 20050
diff changeset
1227 object.__module__)
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1228
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1229 # Sort attrs by name.
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
1230 attrs.sort()
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1231
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1232 # Pump out the attrs, segregated by kind.
20072
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1233 attrs = spill("Methods %s:\n" % tag, attrs,
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1234 lambda t: t[1] == 'method')
20072
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1235 attrs = spill("Class methods %s:\n" % tag, attrs,
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1236 lambda t: t[1] == 'class method')
20072
399d777af048 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
Tim Peters <tim.peters@gmail.com>
parents: 20051
diff changeset
1237 attrs = spill("Static methods %s:\n" % tag, attrs,
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1238 lambda t: t[1] == 'static method')
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
1239 attrs = spilldescriptors("Data descriptors %s:\n" % tag, attrs,
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
1240 lambda t: t[1] == 'data descriptor')
28420
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
1241 attrs = spilldata("Data and other attributes %s:\n" % tag, attrs,
30d1c848d2b0 Hide private names beginning with _ (but don't hide __special__ names).
Ka-Ping Yee <ping@zesty.ca>
parents: 28124
diff changeset
1242 lambda t: t[1] == 'data')
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1243 assert attrs == []
20124
9c2b9b76a08e List class attrs in MRO order of defining class instead of by alphabetic
Tim Peters <tim.peters@gmail.com>
parents: 20123
diff changeset
1244 attrs = inherited
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1245
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1246 contents = '\n'.join(contents)
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1247 if not contents:
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1248 return title + '\n'
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1249 return title + '\n' + self.indent(rstrip(contents), ' | ') + '\n'
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1250
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1251 def formatvalue(self, object):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1252 """Format an argument default value as text."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1253 return '=' + self.repr(object)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1254
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1255 def docroutine(self, object, name=None, mod=None, cl=None):
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1256 """Produce text documentation for a function or method object."""
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1257 realname = object.__name__
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1258 name = name or realname
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1259 note = ''
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
1260 skipdocs = 0
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1261 if inspect.ismethod(object):
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1262 imclass = object.im_class
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
1263 if cl:
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1264 if imclass is not cl:
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1265 note = ' from ' + classname(imclass, mod)
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
1266 else:
41176
d311013a1638 Patch #1194449: correctly detect unbound methods in pydoc.
Georg Brandl <georg@python.org>
parents: 41148
diff changeset
1267 if object.im_self is not None:
17457
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
1268 note = ' method of %s instance' % classname(
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
1269 object.im_self.__class__, mod)
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
1270 else:
66a7c8c8dd27 Fix linking to classes (in class tree, and add links on unbound methods).
Ka-Ping Yee <ping@zesty.ca>
parents: 17456
diff changeset
1271 note = ' unbound %s method' % classname(imclass,mod)
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1272 object = object.im_func
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1273
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1274 if name == realname:
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1275 title = self.bold(realname)
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1276 else:
23620
a1de0bab5475 SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents: 23501
diff changeset
1277 if (cl and realname in cl.__dict__ and
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
1278 cl.__dict__[realname] is object):
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
1279 skipdocs = 1
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1280 title = self.bold(name) + ' = ' + realname
19993
28ef22a2598e Since inspect.isfunction(obj) is a precondition for calling
Tim Peters <tim.peters@gmail.com>
parents: 19989
diff changeset
1281 if inspect.isfunction(object):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1282 args, varargs, varkw, defaults = inspect.getargspec(object)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1283 argspec = inspect.formatargspec(
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1284 args, varargs, varkw, defaults, formatvalue=self.formatvalue)
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1285 if realname == '<lambda>':
36545
1232e87cb816 The names of lambda functions are now properly displayed in pydoc.
Georg Brandl <georg@python.org>
parents: 35838
diff changeset
1286 title = self.bold(name) + ' lambda '
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1287 argspec = argspec[1:-1] # remove parentheses
19993
28ef22a2598e Since inspect.isfunction(obj) is a precondition for calling
Tim Peters <tim.peters@gmail.com>
parents: 19989
diff changeset
1288 else:
28ef22a2598e Since inspect.isfunction(obj) is a precondition for calling
Tim Peters <tim.peters@gmail.com>
parents: 19989
diff changeset
1289 argspec = '(...)'
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1290 decl = title + argspec + note
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1291
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
1292 if skipdocs:
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
1293 return decl + '\n'
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1294 else:
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
1295 doc = getdoc(object) or ''
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
1296 return decl + '\n' + (doc and rstrip(self.indent(doc)) + '\n')
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1297
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
1298 def _docdescriptor(self, name, value, mod):
33935
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
1299 results = []
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
1300 push = results.append
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
1301
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
1302 if name:
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
1303 push(self.bold(name))
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
1304 push('\n')
33935
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
1305 doc = getdoc(value) or ''
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
1306 if doc:
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
1307 push(self.indent(doc))
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
1308 push('\n')
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
1309 return ''.join(results)
33935
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
1310
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
1311 def docproperty(self, object, name=None, mod=None, cl=None):
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
1312 """Produce text documentation for a property."""
34369
ff73e15a3fb9 Patch #936774: unify the display of data descriptors, including slots,
Johannes Gijsbers <jlg@dds.nl>
parents: 34299
diff changeset
1313 return self._docdescriptor(name, object, mod)
33935
ab73217730db Patch #1061931 / bug #971872: factor out part of spillproperties, so
Johannes Gijsbers <jlg@dds.nl>
parents: 33336
diff changeset
1314
39226
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
1315 def docdata(self, object, name=None, mod=None, cl=None):
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
1316 """Produce text documentation for a data descriptor."""
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
1317 return self._docdescriptor(name, object, mod)
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
1318
35663
5611db451a39 bug [ 729103 ] Cannot retrieve name of super object
Georg Brandl <georg@python.org>
parents: 35277
diff changeset
1319 def docother(self, object, name=None, mod=None, parent=None, maxlen=None, doc=None):
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1320 """Produce text documentation for a data object."""
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1321 repr = self.repr(object)
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1322 if maxlen:
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1323 line = (name and name + ' = ' or '') + repr
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1324 chop = maxlen - len(line)
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1325 if chop < 0: repr = repr[:chop] + '...'
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1326 line = (name and self.bold(name) + ' = ' or '') + repr
20048
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1327 if doc is not None:
6310837ca534 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
Tim Peters <tim.peters@gmail.com>
parents: 19993
diff changeset
1328 line += '\n' + self.indent(str(doc))
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1329 return line
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1330
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1331 # --------------------------------------------------------- user interfaces
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1332
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1333 def pager(text):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1334 """The first time this is called, determine what kind of pager to use."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1335 global pager
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1336 pager = getpager()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1337 pager(text)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1338
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1339 def getpager():
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1340 """Decide what method to use for paging through text."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1341 if type(sys.stdout) is not types.FileType:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1342 return plainpager
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1343 if not sys.stdin.isatty() or not sys.stdout.isatty():
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1344 return plainpager
23620
a1de0bab5475 SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents: 23501
diff changeset
1345 if 'PAGER' in os.environ:
17371
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
1346 if sys.platform == 'win32': # pipes completely broken in Windows
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1347 return lambda text: tempfilepager(plain(text), os.environ['PAGER'])
34545
9d66fba78444 Replace list of constants with tuples of constants.
Raymond Hettinger <python@rcn.com>
parents: 34369
diff changeset
1348 elif os.environ.get('TERM') in ('dumb', 'emacs'):
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1349 return lambda text: pipepager(plain(text), os.environ['PAGER'])
17371
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
1350 else:
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1351 return lambda text: pipepager(text, os.environ['PAGER'])
35837
a8649869cb60 Accept patch to resolve SF bug #651124.
Ka-Ping Yee <ping@zesty.ca>
parents: 35806
diff changeset
1352 if os.environ.get('TERM') in ('dumb', 'emacs'):
a8649869cb60 Accept patch to resolve SF bug #651124.
Ka-Ping Yee <ping@zesty.ca>
parents: 35806
diff changeset
1353 return plainpager
22117
1046964896a1 OS/2 more program behaves like Win32 more
Andrew MacIntyre <andymac@bullseye.apana.org.au>
parents: 20783
diff changeset
1354 if sys.platform == 'win32' or sys.platform.startswith('os2'):
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1355 return lambda text: tempfilepager(plain(text), 'more <')
25454
4d367872fcc6 try executing 'less' in a parenthesized subshell - prevents systems like
Skip Montanaro <skip@pobox.com>
parents: 24977
diff changeset
1356 if hasattr(os, 'system') and os.system('(less) 2>/dev/null') == 0:
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1357 return lambda text: pipepager(text, 'less')
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1358
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1359 import tempfile
24710
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24606
diff changeset
1360 (fd, filename) = tempfile.mkstemp()
11c701038805 Massive changes from SF 589982 (tempfile.py rewrite, by Zack
Guido van Rossum <guido@python.org>
parents: 24606
diff changeset
1361 os.close(fd)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1362 try:
47987
ebe932329246 #3045: fix pydoc behavior for TEMP path with spaces.
Georg Brandl <georg@python.org>
parents: 47873
diff changeset
1363 if hasattr(os, 'system') and os.system('more "%s"' % filename) == 0:
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1364 return lambda text: pipepager(text, 'more')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1365 else:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1366 return ttypager
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1367 finally:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1368 os.unlink(filename)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1369
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1370 def plain(text):
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1371 """Remove boldface formatting from text."""
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1372 return re.sub('.\b', '', text)
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1373
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1374 def pipepager(text, cmd):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1375 """Page through text by feeding it to another program."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1376 pipe = os.popen(cmd, 'w')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1377 try:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1378 pipe.write(text)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1379 pipe.close()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1380 except IOError:
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1381 pass # Ignore broken pipes caused by quitting the pager program.
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1382
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1383 def tempfilepager(text, cmd):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1384 """Page through text by invoking a program on a temporary file."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1385 import tempfile
27743
b331e5e5cc4a SF bug 666444: 'help' makes linefeed only under Win32.
Tim Peters <tim.peters@gmail.com>
parents: 26814
diff changeset
1386 filename = tempfile.mktemp()
b331e5e5cc4a SF bug 666444: 'help' makes linefeed only under Win32.
Tim Peters <tim.peters@gmail.com>
parents: 26814
diff changeset
1387 file = open(filename, 'w')
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1388 file.write(text)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1389 file.close()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1390 try:
47987
ebe932329246 #3045: fix pydoc behavior for TEMP path with spaces.
Georg Brandl <georg@python.org>
parents: 47873
diff changeset
1391 os.system(cmd + ' "' + filename + '"')
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1392 finally:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1393 os.unlink(filename)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1394
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1395 def ttypager(text):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1396 """Page through text on a text terminal."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1397 lines = split(plain(text), '\n')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1398 try:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1399 import tty
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1400 fd = sys.stdin.fileno()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1401 old = tty.tcgetattr(fd)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1402 tty.setcbreak(fd)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1403 getchar = lambda: sys.stdin.read(1)
16819
53e8ebd11620 Macintosh compatibility.
Ka-Ping Yee <ping@zesty.ca>
parents: 16818
diff changeset
1404 except (ImportError, AttributeError):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1405 tty = None
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1406 getchar = lambda: sys.stdin.readline()[:-1][:1]
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1407
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1408 try:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1409 r = inc = os.environ.get('LINES', 25) - 1
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1410 sys.stdout.write(join(lines[:inc], '\n') + '\n')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1411 while lines[r:]:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1412 sys.stdout.write('-- more --')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1413 sys.stdout.flush()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1414 c = getchar()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1415
34545
9d66fba78444 Replace list of constants with tuples of constants.
Raymond Hettinger <python@rcn.com>
parents: 34369
diff changeset
1416 if c in ('q', 'Q'):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1417 sys.stdout.write('\r \r')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1418 break
34545
9d66fba78444 Replace list of constants with tuples of constants.
Raymond Hettinger <python@rcn.com>
parents: 34369
diff changeset
1419 elif c in ('\r', '\n'):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1420 sys.stdout.write('\r \r' + lines[r] + '\n')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1421 r = r + 1
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1422 continue
34545
9d66fba78444 Replace list of constants with tuples of constants.
Raymond Hettinger <python@rcn.com>
parents: 34369
diff changeset
1423 if c in ('b', 'B', '\x1b'):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1424 r = r - inc - inc
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1425 if r < 0: r = 0
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1426 sys.stdout.write('\n' + join(lines[r:r+inc], '\n') + '\n')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1427 r = r + inc
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1428
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1429 finally:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1430 if tty:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1431 tty.tcsetattr(fd, tty.TCSAFLUSH, old)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1432
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1433 def plainpager(text):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1434 """Simply print unformatted text. This is the ultimate fallback."""
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1435 sys.stdout.write(plain(text))
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1436
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1437 def describe(thing):
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
1438 """Produce a short description of the given thing."""
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1439 if inspect.ismodule(thing):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1440 if thing.__name__ in sys.builtin_module_names:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1441 return 'built-in module ' + thing.__name__
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1442 if hasattr(thing, '__path__'):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1443 return 'package ' + thing.__name__
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1444 else:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1445 return 'module ' + thing.__name__
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1446 if inspect.isbuiltin(thing):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1447 return 'built-in function ' + thing.__name__
39226
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
1448 if inspect.isgetsetdescriptor(thing):
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
1449 return 'getset descriptor %s.%s.%s' % (
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
1450 thing.__objclass__.__module__, thing.__objclass__.__name__,
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
1451 thing.__name__)
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
1452 if inspect.ismemberdescriptor(thing):
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
1453 return 'member descriptor %s.%s.%s' % (
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
1454 thing.__objclass__.__module__, thing.__objclass__.__name__,
28cdd43e0569 Patch #1520294: Support for getset and member descriptors in types.py,
Barry Warsaw <barry@python.org>
parents: 37821
diff changeset
1455 thing.__name__)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1456 if inspect.isclass(thing):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1457 return 'class ' + thing.__name__
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1458 if inspect.isfunction(thing):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1459 return 'function ' + thing.__name__
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1460 if inspect.ismethod(thing):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1461 return 'method ' + thing.__name__
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1462 if type(thing) is types.InstanceType:
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1463 return 'instance of ' + thing.__class__.__name__
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1464 return type(thing).__name__
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1465
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1466 def locate(path, forceload=0):
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1467 """Locate an object by name or dotted path, importing as necessary."""
27904
9bdaccd8a908 Fix for SF 686380, from SF patch 686771 by Ping. (errors trying to
Guido van Rossum <guido@python.org>
parents: 27759
diff changeset
1468 parts = [part for part in split(path, '.') if part]
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1469 module, n = None, 0
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1470 while n < len(parts):
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1471 nextmodule = safeimport(join(parts[:n+1], '.'), forceload)
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1472 if nextmodule: module, n = nextmodule, n + 1
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1473 else: break
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1474 if module:
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1475 object = module
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1476 else:
71599
68df566cbf92 Make “pydoc somebuiltin.somemethod” work (#8887)
Éric Araujo <merwok@netwok.org>
parents: 71539
diff changeset
1477 object = __builtin__
68df566cbf92 Make “pydoc somebuiltin.somemethod” work (#8887)
Éric Araujo <merwok@netwok.org>
parents: 71539
diff changeset
1478 for part in parts[n:]:
68df566cbf92 Make “pydoc somebuiltin.somemethod” work (#8887)
Éric Araujo <merwok@netwok.org>
parents: 71539
diff changeset
1479 try:
68df566cbf92 Make “pydoc somebuiltin.somemethod” work (#8887)
Éric Araujo <merwok@netwok.org>
parents: 71539
diff changeset
1480 object = getattr(object, part)
68df566cbf92 Make “pydoc somebuiltin.somemethod” work (#8887)
Éric Araujo <merwok@netwok.org>
parents: 71539
diff changeset
1481 except AttributeError:
68df566cbf92 Make “pydoc somebuiltin.somemethod” work (#8887)
Éric Araujo <merwok@netwok.org>
parents: 71539
diff changeset
1482 return None
68df566cbf92 Make “pydoc somebuiltin.somemethod” work (#8887)
Éric Araujo <merwok@netwok.org>
parents: 71539
diff changeset
1483 return object
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1484
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1485 # --------------------------------------- interactive interpreter interface
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1486
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1487 text = TextDoc()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1488 html = HTMLDoc()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1489
40630
3d79bc6ed6ec Handle old-style instances more gracefully (display documentation on
Ka-Ping Yee <ping@zesty.ca>
parents: 40479
diff changeset
1490 class _OldStyleClass: pass
3d79bc6ed6ec Handle old-style instances more gracefully (display documentation on
Ka-Ping Yee <ping@zesty.ca>
parents: 40479
diff changeset
1491 _OLD_INSTANCE_TYPE = type(_OldStyleClass())
3d79bc6ed6ec Handle old-style instances more gracefully (display documentation on
Ka-Ping Yee <ping@zesty.ca>
parents: 40479
diff changeset
1492
24740
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1493 def resolve(thing, forceload=0):
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1494 """Given an object or a path to an object, get the object and its name."""
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1495 if isinstance(thing, str):
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1496 object = locate(thing, forceload)
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1497 if not object:
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1498 raise ImportError, 'no Python documentation found for %r' % thing
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1499 return object, thing
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1500 else:
76499
501651b93cb0 #14638: pydoc now treats non-str __name__ as None instead of raising
R David Murray <rdmurray@bitdance.com>
parents: 76017
diff changeset
1501 name = getattr(thing, '__name__', None)
501651b93cb0 #14638: pydoc now treats non-str __name__ as None instead of raising
R David Murray <rdmurray@bitdance.com>
parents: 76017
diff changeset
1502 return thing, name if isinstance(name, str) else None
24740
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1503
41166
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1504 def render_doc(thing, title='Python Library Documentation: %s', forceload=0):
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1505 """Render text documentation, given an object or a path to an object."""
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1506 object, name = resolve(thing, forceload)
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1507 desc = describe(object)
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1508 module = inspect.getmodule(object)
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1509 if name and '.' in name:
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1510 desc += ' in ' + name[:name.rfind('.')]
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1511 elif module and module is not object:
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1512 desc += ' in module ' + module.__name__
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1513 if type(object) is _OLD_INSTANCE_TYPE:
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1514 # If the passed object is an instance of an old-style class,
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1515 # document its available methods instead of its value.
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1516 object = object.__class__
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1517 elif not (inspect.ismodule(object) or
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1518 inspect.isclass(object) or
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1519 inspect.isroutine(object) or
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1520 inspect.isgetsetdescriptor(object) or
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1521 inspect.ismemberdescriptor(object) or
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1522 isinstance(object, property)):
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1523 # If the passed object is a piece of data or an instance,
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1524 # document its available methods instead of its value.
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1525 object = type(object)
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1526 desc += ' object'
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1527 return title % desc + '\n\n' + text.document(object, name)
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1528
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1529 def doc(thing, title='Python Library Documentation: %s', forceload=0):
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1530 """Display text documentation, given an object or a path to an object."""
24740
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1531 try:
41166
4a79dd15ba59 Patch #1530482: add pydoc.render_doc() which returns the documentation
Georg Brandl <georg@python.org>
parents: 41147
diff changeset
1532 pager(render_doc(thing, title, forceload))
24740
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1533 except (ImportError, ErrorDuringImport), value:
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1534 print value
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1535
24740
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1536 def writedoc(thing, forceload=0):
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1537 """Write HTML documentation to a file in the current directory."""
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1538 try:
24740
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1539 object, name = resolve(thing, forceload)
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1540 page = html.page(describe(object), html.document(object, name))
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1541 file = open(name + '.html', 'w')
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1542 file.write(page)
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1543 file.close()
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1544 print 'wrote', name + '.html'
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
1545 except (ImportError, ErrorDuringImport), value:
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1546 print value
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1547
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1548 def writedocs(dir, pkgpath='', done=None):
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
1549 """Write out HTML documentation for all modules in a directory tree."""
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1550 if done is None: done = {}
37821
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1551 for importer, modname, ispkg in pkgutil.walk_packages([dir], pkgpath):
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1552 writedoc(modname)
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1553 return
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1554
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1555 class Helper:
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1556
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1557 # These dictionaries map a topic name to either an alias, or a tuple
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1558 # (label, seealso-items). The "label" is the label of the corresponding
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1559 # section in the .rst file under Doc/ and an index into the dictionary
53461
64110c0ad530 Move pydoc_topics module to its own subdirectory, so that no generated code is in Lib/.
Georg Brandl <georg@python.org>
parents: 53034
diff changeset
1560 # in pydoc_data/topics.py.
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1561 #
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1562 # CAUTION: if you change one of these dictionaries, be sure to adapt the
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1563 # list of needed labels in Doc/tools/sphinxext/pyspecific.py and
53461
64110c0ad530 Move pydoc_topics module to its own subdirectory, so that no generated code is in Lib/.
Georg Brandl <georg@python.org>
parents: 53034
diff changeset
1564 # regenerate the pydoc_data/topics.py file by running
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1565 # make pydoc-topics
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1566 # in Doc/ and copying the output file into the Lib/ directory.
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1567
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1568 keywords = {
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1569 'and': 'BOOLEAN',
41148
ade8d1c81009 Patch #1542681: add entries for "with", "as" and "CONTEXTMANAGERS" to
Georg Brandl <georg@python.org>
parents: 40479
diff changeset
1570 'as': 'with',
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1571 'assert': ('assert', ''),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1572 'break': ('break', 'while for'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1573 'class': ('class', 'CLASSES SPECIALMETHODS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1574 'continue': ('continue', 'while for'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1575 'def': ('function', ''),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1576 'del': ('del', 'BASICMETHODS'),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1577 'elif': 'if',
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1578 'else': ('else', 'while for'),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1579 'except': 'try',
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1580 'exec': ('exec', ''),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1581 'finally': 'try',
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1582 'for': ('for', 'break continue while'),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1583 'from': 'import',
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1584 'global': ('global', 'NAMESPACES'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1585 'if': ('if', 'TRUTHVALUE'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1586 'import': ('import', 'MODULES'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1587 'in': ('in', 'SEQUENCEMETHODS2'),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1588 'is': 'COMPARISON',
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1589 'lambda': ('lambda', 'FUNCTIONS'),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1590 'not': 'BOOLEAN',
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1591 'or': 'BOOLEAN',
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1592 'pass': ('pass', ''),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1593 'print': ('print', ''),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1594 'raise': ('raise', 'EXCEPTIONS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1595 'return': ('return', 'FUNCTIONS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1596 'try': ('try', 'EXCEPTIONS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1597 'while': ('while', 'break continue if TRUTHVALUE'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1598 'with': ('with', 'CONTEXTMANAGERS EXCEPTIONS yield'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1599 'yield': ('yield', ''),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1600 }
50424
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1601 # Either add symbols to this dictionary or to the symbols dictionary
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1602 # directly: Whichever is easier. They are merged later.
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1603 _symbols_inverse = {
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1604 'STRINGS' : ("'", "'''", "r'", "u'", '"""', '"', 'r"', 'u"'),
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1605 'OPERATORS' : ('+', '-', '*', '**', '/', '//', '%', '<<', '>>', '&',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1606 '|', '^', '~', '<', '>', '<=', '>=', '==', '!=', '<>'),
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1607 'COMPARISON' : ('<', '>', '<=', '>=', '==', '!=', '<>'),
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1608 'UNARY' : ('-', '~'),
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1609 'AUGMENTEDASSIGNMENT' : ('+=', '-=', '*=', '/=', '%=', '&=', '|=',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1610 '^=', '<<=', '>>=', '**=', '//='),
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1611 'BITWISE' : ('<<', '>>', '&', '|', '^', '~'),
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1612 'COMPLEX' : ('j', 'J')
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1613 }
50424
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1614 symbols = {
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1615 '%': 'OPERATORS FORMATTING',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1616 '**': 'POWER',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1617 ',': 'TUPLES LISTS FUNCTIONS',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1618 '.': 'ATTRIBUTES FLOAT MODULES OBJECTS',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1619 '...': 'ELLIPSIS',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1620 ':': 'SLICINGS DICTIONARYLITERALS',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1621 '@': 'def class',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1622 '\\': 'STRINGS',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1623 '_': 'PRIVATENAMES',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1624 '__': 'PRIVATENAMES SPECIALMETHODS',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1625 '`': 'BACKQUOTES',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1626 '(': 'TUPLES FUNCTIONS CALLS',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1627 ')': 'TUPLES FUNCTIONS CALLS',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1628 '[': 'LISTS SUBSCRIPTS SLICINGS',
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1629 ']': 'LISTS SUBSCRIPTS SLICINGS'
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1630 }
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1631 for topic, symbols_ in _symbols_inverse.iteritems():
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1632 for symbol in symbols_:
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1633 topics = symbols.get(symbol, topic)
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1634 if topic not in topics:
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1635 topics = topics + ' ' + topic
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1636 symbols[symbol] = topics
17230
45cda1b39355 Fix some reloading problems (still more work needed).
Ka-Ping Yee <ping@zesty.ca>
parents: 17184
diff changeset
1637
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1638 topics = {
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1639 'TYPES': ('types', 'STRINGS UNICODE NUMBERS SEQUENCES MAPPINGS '
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1640 'FUNCTIONS CLASSES MODULES FILES inspect'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1641 'STRINGS': ('strings', 'str UNICODE SEQUENCES STRINGMETHODS FORMATTING '
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1642 'TYPES'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1643 'STRINGMETHODS': ('string-methods', 'STRINGS FORMATTING'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1644 'FORMATTING': ('formatstrings', 'OPERATORS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1645 'UNICODE': ('strings', 'encodings unicode SEQUENCES STRINGMETHODS '
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1646 'FORMATTING TYPES'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1647 'NUMBERS': ('numbers', 'INTEGER FLOAT COMPLEX TYPES'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1648 'INTEGER': ('integers', 'int range'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1649 'FLOAT': ('floating', 'float math'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1650 'COMPLEX': ('imaginary', 'complex cmath'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1651 'SEQUENCES': ('typesseq', 'STRINGMETHODS FORMATTING xrange LISTS'),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1652 'MAPPINGS': 'DICTIONARIES',
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1653 'FUNCTIONS': ('typesfunctions', 'def TYPES'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1654 'METHODS': ('typesmethods', 'class def CLASSES TYPES'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1655 'CODEOBJECTS': ('bltin-code-objects', 'compile FUNCTIONS TYPES'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1656 'TYPEOBJECTS': ('bltin-type-objects', 'types TYPES'),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1657 'FRAMEOBJECTS': 'TYPES',
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1658 'TRACEBACKS': 'TYPES',
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1659 'NONE': ('bltin-null-object', ''),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1660 'ELLIPSIS': ('bltin-ellipsis-object', 'SLICINGS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1661 'FILES': ('bltin-file-objects', ''),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1662 'SPECIALATTRIBUTES': ('specialattrs', ''),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1663 'CLASSES': ('types', 'class SPECIALMETHODS PRIVATENAMES'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1664 'MODULES': ('typesmodules', 'import'),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1665 'PACKAGES': 'import',
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1666 'EXPRESSIONS': ('operator-summary', 'lambda or and not in is BOOLEAN '
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1667 'COMPARISON BITWISE SHIFTING BINARY FORMATTING POWER '
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1668 'UNARY ATTRIBUTES SUBSCRIPTS SLICINGS CALLS TUPLES '
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1669 'LISTS DICTIONARIES BACKQUOTES'),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1670 'OPERATORS': 'EXPRESSIONS',
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1671 'PRECEDENCE': 'EXPRESSIONS',
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1672 'OBJECTS': ('objects', 'TYPES'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1673 'SPECIALMETHODS': ('specialnames', 'BASICMETHODS ATTRIBUTEMETHODS '
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1674 'CALLABLEMETHODS SEQUENCEMETHODS1 MAPPINGMETHODS '
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1675 'SEQUENCEMETHODS2 NUMBERMETHODS CLASSES'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1676 'BASICMETHODS': ('customization', 'cmp hash repr str SPECIALMETHODS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1677 'ATTRIBUTEMETHODS': ('attribute-access', 'ATTRIBUTES SPECIALMETHODS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1678 'CALLABLEMETHODS': ('callable-types', 'CALLS SPECIALMETHODS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1679 'SEQUENCEMETHODS1': ('sequence-types', 'SEQUENCES SEQUENCEMETHODS2 '
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1680 'SPECIALMETHODS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1681 'SEQUENCEMETHODS2': ('sequence-methods', 'SEQUENCES SEQUENCEMETHODS1 '
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1682 'SPECIALMETHODS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1683 'MAPPINGMETHODS': ('sequence-types', 'MAPPINGS SPECIALMETHODS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1684 'NUMBERMETHODS': ('numeric-types', 'NUMBERS AUGMENTEDASSIGNMENT '
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1685 'SPECIALMETHODS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1686 'EXECUTION': ('execmodel', 'NAMESPACES DYNAMICFEATURES EXCEPTIONS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1687 'NAMESPACES': ('naming', 'global ASSIGNMENT DELETION DYNAMICFEATURES'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1688 'DYNAMICFEATURES': ('dynamic-features', ''),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1689 'SCOPING': 'NAMESPACES',
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1690 'FRAMES': 'NAMESPACES',
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1691 'EXCEPTIONS': ('exceptions', 'try except finally raise'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1692 'COERCIONS': ('coercion-rules','CONVERSIONS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1693 'CONVERSIONS': ('conversions', 'COERCIONS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1694 'IDENTIFIERS': ('identifiers', 'keywords SPECIALIDENTIFIERS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1695 'SPECIALIDENTIFIERS': ('id-classes', ''),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1696 'PRIVATENAMES': ('atom-identifiers', ''),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1697 'LITERALS': ('atom-literals', 'STRINGS BACKQUOTES NUMBERS '
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1698 'TUPLELITERALS LISTLITERALS DICTIONARYLITERALS'),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1699 'TUPLES': 'SEQUENCES',
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1700 'TUPLELITERALS': ('exprlists', 'TUPLES LITERALS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1701 'LISTS': ('typesseq-mutable', 'LISTLITERALS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1702 'LISTLITERALS': ('lists', 'LISTS LITERALS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1703 'DICTIONARIES': ('typesmapping', 'DICTIONARYLITERALS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1704 'DICTIONARYLITERALS': ('dict', 'DICTIONARIES LITERALS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1705 'BACKQUOTES': ('string-conversions', 'repr str STRINGS LITERALS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1706 'ATTRIBUTES': ('attribute-references', 'getattr hasattr setattr '
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1707 'ATTRIBUTEMETHODS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1708 'SUBSCRIPTS': ('subscriptions', 'SEQUENCEMETHODS1'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1709 'SLICINGS': ('slicings', 'SEQUENCEMETHODS2'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1710 'CALLS': ('calls', 'EXPRESSIONS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1711 'POWER': ('power', 'EXPRESSIONS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1712 'UNARY': ('unary', 'EXPRESSIONS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1713 'BINARY': ('binary', 'EXPRESSIONS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1714 'SHIFTING': ('shifting', 'EXPRESSIONS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1715 'BITWISE': ('bitwise', 'EXPRESSIONS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1716 'COMPARISON': ('comparisons', 'EXPRESSIONS BASICMETHODS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1717 'BOOLEAN': ('booleans', 'EXPRESSIONS TRUTHVALUE'),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1718 'ASSERTION': 'assert',
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1719 'ASSIGNMENT': ('assignment', 'AUGMENTEDASSIGNMENT'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1720 'AUGMENTEDASSIGNMENT': ('augassign', 'NUMBERMETHODS'),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1721 'DELETION': 'del',
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1722 'PRINTING': 'print',
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1723 'RETURNING': 'return',
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1724 'IMPORTING': 'import',
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1725 'CONDITIONAL': 'if',
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1726 'LOOPING': ('compound', 'for while break continue'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1727 'TRUTHVALUE': ('truth', 'if while and or not BASICMETHODS'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1728 'DEBUGGING': ('debugger', 'pdb'),
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1729 'CONTEXTMANAGERS': ('context-managers', 'with'),
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1730 }
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1731
63508
97cb1dd8566e Merged revisions 83392,83426 via svnmerge from
Georg Brandl <georg@python.org>
parents: 60121
diff changeset
1732 def __init__(self, input=None, output=None):
97cb1dd8566e Merged revisions 83392,83426 via svnmerge from
Georg Brandl <georg@python.org>
parents: 60121
diff changeset
1733 self._input = input
97cb1dd8566e Merged revisions 83392,83426 via svnmerge from
Georg Brandl <georg@python.org>
parents: 60121
diff changeset
1734 self._output = output
97cb1dd8566e Merged revisions 83392,83426 via svnmerge from
Georg Brandl <georg@python.org>
parents: 60121
diff changeset
1735
97cb1dd8566e Merged revisions 83392,83426 via svnmerge from
Georg Brandl <georg@python.org>
parents: 60121
diff changeset
1736 input = property(lambda self: self._input or sys.stdin)
97cb1dd8566e Merged revisions 83392,83426 via svnmerge from
Georg Brandl <georg@python.org>
parents: 60121
diff changeset
1737 output = property(lambda self: self._output or sys.stdout)
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1738
17471
24e81b43067d Another pass through the topic table to fill in cross references.
Ka-Ping Yee <ping@zesty.ca>
parents: 17470
diff changeset
1739 def __repr__(self):
17476
25f55b2e38ac Use inspect.stack()[1][3] to tell if Helper.__repr__ is called interactively.
Ka-Ping Yee <ping@zesty.ca>
parents: 17475
diff changeset
1740 if inspect.stack()[1][3] == '?':
17471
24e81b43067d Another pass through the topic table to fill in cross references.
Ka-Ping Yee <ping@zesty.ca>
parents: 17470
diff changeset
1741 self()
24e81b43067d Another pass through the topic table to fill in cross references.
Ka-Ping Yee <ping@zesty.ca>
parents: 17470
diff changeset
1742 return ''
17476
25f55b2e38ac Use inspect.stack()[1][3] to tell if Helper.__repr__ is called interactively.
Ka-Ping Yee <ping@zesty.ca>
parents: 17475
diff changeset
1743 return '<pydoc.Helper instance>'
17471
24e81b43067d Another pass through the topic table to fill in cross references.
Ka-Ping Yee <ping@zesty.ca>
parents: 17470
diff changeset
1744
67532
f827f703ef65 Merged revisions 82547 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64143
diff changeset
1745 _GoInteractive = object()
f827f703ef65 Merged revisions 82547 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64143
diff changeset
1746 def __call__(self, request=_GoInteractive):
f827f703ef65 Merged revisions 82547 via svnmerge from
Alexander Belopolsky <alexander.belopolsky@gmail.com>
parents: 64143
diff changeset
1747 if request is not self._GoInteractive:
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1748 self.help(request)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1749 else:
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1750 self.intro()
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1751 self.interact()
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1752 self.output.write('''
17770
cc8d148c396a Change some text just a little to avoid font-lock hell.
Fred Drake <fdrake@acm.org>
parents: 17487
diff changeset
1753 You are now leaving help and returning to the Python interpreter.
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1754 If you want to ask for help on a particular object directly from the
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1755 interpreter, you can type "help(object)". Executing "help('string')"
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1756 has the same effect as typing a particular string at the help> prompt.
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1757 ''')
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1758
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1759 def interact(self):
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1760 self.output.write('\n')
22867
e2f2187c3d2c Partial introduction of bools where appropriate.
Guido van Rossum <guido@python.org>
parents: 22830
diff changeset
1761 while True:
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1762 try:
33162
208fe719c749 Use readline/raw_input() in pydoc.Helper.interact if available and self.input
Johannes Gijsbers <jlg@dds.nl>
parents: 32382
diff changeset
1763 request = self.getline('help> ')
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1764 if not request: break
33162
208fe719c749 Use readline/raw_input() in pydoc.Helper.interact if available and self.input
Johannes Gijsbers <jlg@dds.nl>
parents: 32382
diff changeset
1765 except (KeyboardInterrupt, EOFError):
208fe719c749 Use readline/raw_input() in pydoc.Helper.interact if available and self.input
Johannes Gijsbers <jlg@dds.nl>
parents: 32382
diff changeset
1766 break
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1767 request = strip(replace(request, '"', '', "'", ''))
34545
9d66fba78444 Replace list of constants with tuples of constants.
Raymond Hettinger <python@rcn.com>
parents: 34369
diff changeset
1768 if lower(request) in ('q', 'quit'): break
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1769 self.help(request)
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1770
33162
208fe719c749 Use readline/raw_input() in pydoc.Helper.interact if available and self.input
Johannes Gijsbers <jlg@dds.nl>
parents: 32382
diff changeset
1771 def getline(self, prompt):
208fe719c749 Use readline/raw_input() in pydoc.Helper.interact if available and self.input
Johannes Gijsbers <jlg@dds.nl>
parents: 32382
diff changeset
1772 """Read one line, using raw_input when available."""
208fe719c749 Use readline/raw_input() in pydoc.Helper.interact if available and self.input
Johannes Gijsbers <jlg@dds.nl>
parents: 32382
diff changeset
1773 if self.input is sys.stdin:
208fe719c749 Use readline/raw_input() in pydoc.Helper.interact if available and self.input
Johannes Gijsbers <jlg@dds.nl>
parents: 32382
diff changeset
1774 return raw_input(prompt)
208fe719c749 Use readline/raw_input() in pydoc.Helper.interact if available and self.input
Johannes Gijsbers <jlg@dds.nl>
parents: 32382
diff changeset
1775 else:
208fe719c749 Use readline/raw_input() in pydoc.Helper.interact if available and self.input
Johannes Gijsbers <jlg@dds.nl>
parents: 32382
diff changeset
1776 self.output.write(prompt)
208fe719c749 Use readline/raw_input() in pydoc.Helper.interact if available and self.input
Johannes Gijsbers <jlg@dds.nl>
parents: 32382
diff changeset
1777 self.output.flush()
208fe719c749 Use readline/raw_input() in pydoc.Helper.interact if available and self.input
Johannes Gijsbers <jlg@dds.nl>
parents: 32382
diff changeset
1778 return self.input.readline()
208fe719c749 Use readline/raw_input() in pydoc.Helper.interact if available and self.input
Johannes Gijsbers <jlg@dds.nl>
parents: 32382
diff changeset
1779
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1780 def help(self, request):
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1781 if type(request) is type(''):
54377
9b8b60bc0f5b Merged revisions 72966 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents: 53034
diff changeset
1782 request = request.strip()
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1783 if request == 'help': self.intro()
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1784 elif request == 'keywords': self.listkeywords()
50424
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1785 elif request == 'symbols': self.listsymbols()
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1786 elif request == 'topics': self.listtopics()
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1787 elif request == 'modules': self.listmodules()
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1788 elif request[:8] == 'modules ':
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1789 self.listmodules(split(request)[1])
50424
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1790 elif request in self.symbols: self.showsymbol(request)
23620
a1de0bab5475 SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents: 23501
diff changeset
1791 elif request in self.keywords: self.showtopic(request)
a1de0bab5475 SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents: 23501
diff changeset
1792 elif request in self.topics: self.showtopic(request)
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1793 elif request: doc(request, 'Help on %s:')
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1794 elif isinstance(request, Helper): self()
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1795 else: doc(request, 'Help on %s:')
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1796 self.output.write('\n')
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1797
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1798 def intro(self):
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1799 self.output.write('''
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1800 Welcome to Python %s! This is the online help utility.
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1801
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1802 If this is your first time using Python, you should definitely check out
76017
b3a7b27953e0 #14434: make tutorial link in 'help' banner version-specific
R David Murray <rdmurray@bitdance.com>
parents: 74106
diff changeset
1803 the tutorial on the Internet at http://docs.python.org/%s/tutorial/.
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1804
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1805 Enter the name of any module, keyword, or topic to get help on writing
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1806 Python programs and using Python modules. To quit this help utility and
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1807 return to the interpreter, just type "quit".
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1808
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1809 To get a list of available modules, keywords, or topics, type "modules",
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1810 "keywords", or "topics". Each module also comes with a one-line summary
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1811 of what it does; to list the modules whose summaries contain a given word
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1812 such as "spam", type "modules spam".
76017
b3a7b27953e0 #14434: make tutorial link in 'help' banner version-specific
R David Murray <rdmurray@bitdance.com>
parents: 74106
diff changeset
1813 ''' % tuple([sys.version[:3]]*2))
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1814
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1815 def list(self, items, columns=4, width=80):
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1816 items = items[:]
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1817 items.sort()
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1818 colw = width / columns
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1819 rows = (len(items) + columns - 1) / columns
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1820 for row in range(rows):
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1821 for col in range(columns):
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1822 i = col * rows + row
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1823 if i < len(items):
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1824 self.output.write(items[i])
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1825 if col < columns - 1:
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1826 self.output.write(' ' + ' ' * (colw-1 - len(items[i])))
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1827 self.output.write('\n')
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1828
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1829 def listkeywords(self):
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1830 self.output.write('''
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1831 Here is a list of the Python keywords. Enter any keyword to get more help.
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1832
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1833 ''')
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1834 self.list(self.keywords.keys())
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1835
50424
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1836 def listsymbols(self):
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1837 self.output.write('''
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1838 Here is a list of the punctuation symbols which Python assigns special meaning
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1839 to. Enter any symbol to get more help.
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1840
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1841 ''')
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1842 self.list(self.symbols.keys())
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1843
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1844 def listtopics(self):
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1845 self.output.write('''
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1846 Here is a list of available topics. Enter any topic name to get more help.
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1847
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1848 ''')
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1849 self.list(self.topics.keys())
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1850
50424
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1851 def showtopic(self, topic, more_xrefs=''):
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1852 try:
53461
64110c0ad530 Move pydoc_topics module to its own subdirectory, so that no generated code is in Lib/.
Georg Brandl <georg@python.org>
parents: 53034
diff changeset
1853 import pydoc_data.topics
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1854 except ImportError:
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1855 self.output.write('''
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1856 Sorry, topic and keyword documentation is not available because the
53461
64110c0ad530 Move pydoc_topics module to its own subdirectory, so that no generated code is in Lib/.
Georg Brandl <georg@python.org>
parents: 53034
diff changeset
1857 module "pydoc_data.topics" could not be found.
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1858 ''')
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1859 return
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1860 target = self.topics.get(topic, self.keywords.get(topic))
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1861 if not target:
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1862 self.output.write('no documentation found for %s\n' % repr(topic))
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1863 return
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1864 if type(target) is type(''):
50424
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1865 return self.showtopic(target, more_xrefs)
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1866
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1867 label, xrefs = target
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1868 try:
53461
64110c0ad530 Move pydoc_topics module to its own subdirectory, so that no generated code is in Lib/.
Georg Brandl <georg@python.org>
parents: 53034
diff changeset
1869 doc = pydoc_data.topics.topics[label]
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1870 except KeyError:
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1871 self.output.write('no documentation found for %s\n' % repr(topic))
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1872 return
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1873 pager(strip(doc) + '\n')
50424
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1874 if more_xrefs:
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1875 xrefs = (xrefs or '') + ' ' + more_xrefs
17472
2888fc60bf9a Word-wrap the list of cross-references.
Ka-Ping Yee <ping@zesty.ca>
parents: 17471
diff changeset
1876 if xrefs:
47431
c0d616f0ad86 Generate pydoc's topic help from the reST docs via Sphinx'
Georg Brandl <georg@python.org>
parents: 47221
diff changeset
1877 import StringIO, formatter
17472
2888fc60bf9a Word-wrap the list of cross-references.
Ka-Ping Yee <ping@zesty.ca>
parents: 17471
diff changeset
1878 buffer = StringIO.StringIO()
2888fc60bf9a Word-wrap the list of cross-references.
Ka-Ping Yee <ping@zesty.ca>
parents: 17471
diff changeset
1879 formatter.DumbWriter(buffer).send_flowing_data(
2888fc60bf9a Word-wrap the list of cross-references.
Ka-Ping Yee <ping@zesty.ca>
parents: 17471
diff changeset
1880 'Related help topics: ' + join(split(xrefs), ', ') + '\n')
2888fc60bf9a Word-wrap the list of cross-references.
Ka-Ping Yee <ping@zesty.ca>
parents: 17471
diff changeset
1881 self.output.write('\n%s\n' % buffer.getvalue())
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1882
50424
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1883 def showsymbol(self, symbol):
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1884 target = self.symbols[symbol]
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1885 topic, _, xrefs = target.partition(' ')
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1886 self.showtopic(topic, xrefs)
df3923c36ec5 Merged revisions 67952-67953,67955,67957-67958,67960-67961,67963,67965,67967,67970-67971,67973,67982,67988,67990,67995,68014,68016,68030,68057,68061,68112,68115-68118,68120-68121,68123-68128 via svnmerge from
Georg Brandl <georg@python.org>
parents: 48901
diff changeset
1887
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1888 def listmodules(self, key=''):
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1889 if key:
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1890 self.output.write('''
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1891 Here is a list of matching modules. Enter any module name to get more help.
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1892
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1893 ''')
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1894 apropos(key)
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1895 else:
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1896 self.output.write('''
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1897 Please wait a moment while I gather a list of all available modules...
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1898
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1899 ''')
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1900 modules = {}
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1901 def callback(path, modname, desc, modules=modules):
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1902 if modname and modname[-9:] == '.__init__':
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1903 modname = modname[:-9] + ' (package)'
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1904 if find(modname, '.') < 0:
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1905 modules[modname] = 1
44660
c73768d977a9 Check in the patch proposed by Ben Hayden (benjhayden) for issue
Ka-Ping Yee <ping@zesty.ca>
parents: 41175
diff changeset
1906 def onerror(modname):
c73768d977a9 Check in the patch proposed by Ben Hayden (benjhayden) for issue
Ka-Ping Yee <ping@zesty.ca>
parents: 41175
diff changeset
1907 callback(None, modname, None)
c73768d977a9 Check in the patch proposed by Ben Hayden (benjhayden) for issue
Ka-Ping Yee <ping@zesty.ca>
parents: 41175
diff changeset
1908 ModuleScanner().run(callback, onerror=onerror)
17452
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1909 self.list(modules.keys())
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1910 self.output.write('''
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1911 Enter any module name to get more help. Or, type "modules spam" to search
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1912 for modules whose descriptions contain the word "spam".
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1913 ''')
1a2fd5c4dcf5 Added a big new Helper class to provide interactive help!
Ka-Ping Yee <ping@zesty.ca>
parents: 17447
diff changeset
1914
63508
97cb1dd8566e Merged revisions 83392,83426 via svnmerge from
Georg Brandl <georg@python.org>
parents: 60121
diff changeset
1915 help = Helper()
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1916
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1917 class Scanner:
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1918 """A generic tree iterator."""
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1919 def __init__(self, roots, children, descendp):
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1920 self.roots = roots[:]
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1921 self.state = []
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1922 self.children = children
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1923 self.descendp = descendp
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1924
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1925 def next(self):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1926 if not self.state:
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1927 if not self.roots:
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1928 return None
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1929 root = self.roots.pop(0)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1930 self.state = [(root, self.children(root))]
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1931 node, children = self.state[-1]
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1932 if not children:
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1933 self.state.pop()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1934 return self.next()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1935 child = children.pop(0)
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
1936 if self.descendp(child):
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1937 self.state.append((child, self.children(child)))
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1938 return child
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1939
37821
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1940
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1941 class ModuleScanner:
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1942 """An interruptible scanner that searches module synopses."""
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1943
44660
c73768d977a9 Check in the patch proposed by Ben Hayden (benjhayden) for issue
Ka-Ping Yee <ping@zesty.ca>
parents: 41175
diff changeset
1944 def run(self, callback, key=None, completer=None, onerror=None):
17442
2d521420db8f Typo fixes and small touches.
Ka-Ping Yee <ping@zesty.ca>
parents: 17441
diff changeset
1945 if key: key = lower(key)
22867
e2f2187c3d2c Partial introduction of bools where appropriate.
Guido van Rossum <guido@python.org>
parents: 22830
diff changeset
1946 self.quit = False
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1947 seen = {}
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1948
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1949 for modname in sys.builtin_module_names:
16928
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
1950 if modname != '__main__':
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
1951 seen[modname] = 1
17442
2d521420db8f Typo fixes and small touches.
Ka-Ping Yee <ping@zesty.ca>
parents: 17441
diff changeset
1952 if key is None:
2d521420db8f Typo fixes and small touches.
Ka-Ping Yee <ping@zesty.ca>
parents: 17441
diff changeset
1953 callback(None, modname, '')
2d521420db8f Typo fixes and small touches.
Ka-Ping Yee <ping@zesty.ca>
parents: 17441
diff changeset
1954 else:
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
1955 desc = split(__import__(modname).__doc__ or '', '\n')[0]
17442
2d521420db8f Typo fixes and small touches.
Ka-Ping Yee <ping@zesty.ca>
parents: 17441
diff changeset
1956 if find(lower(modname + ' - ' + desc), key) >= 0:
2d521420db8f Typo fixes and small touches.
Ka-Ping Yee <ping@zesty.ca>
parents: 17441
diff changeset
1957 callback(None, modname, desc)
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1958
44660
c73768d977a9 Check in the patch proposed by Ben Hayden (benjhayden) for issue
Ka-Ping Yee <ping@zesty.ca>
parents: 41175
diff changeset
1959 for importer, modname, ispkg in pkgutil.walk_packages(onerror=onerror):
37821
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1960 if self.quit:
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1961 break
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1962 if key is None:
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1963 callback(None, modname, '')
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1964 else:
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1965 loader = importer.find_module(modname)
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1966 if hasattr(loader,'get_source'):
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1967 import StringIO
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1968 desc = source_synopsis(
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1969 StringIO.StringIO(loader.get_source(modname))
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1970 ) or ''
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1971 if hasattr(loader,'get_filename'):
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1972 path = loader.get_filename(modname)
17442
2d521420db8f Typo fixes and small touches.
Ka-Ping Yee <ping@zesty.ca>
parents: 17441
diff changeset
1973 else:
37821
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1974 path = None
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1975 else:
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1976 module = loader.load_module(modname)
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1977 desc = (module.__doc__ or '').splitlines()[0]
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1978 path = getattr(module,'__file__',None)
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1979 if find(lower(modname + ' - ' + desc), key) >= 0:
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1980 callback(path, modname, desc)
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1981
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1982 if completer:
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
1983 completer()
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1984
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1985 def apropos(key):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1986 """Print all the one-line module summaries that contain a substring."""
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1987 def callback(path, modname, desc):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1988 if modname[-9:] == '.__init__':
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
1989 modname = modname[:-9] + ' (package)'
17371
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
1990 print modname, desc and '- ' + desc
72770
3acf90f71178 Issue #7425: Prevent pydoc -k failures due to module import errors.
Ned Deily <nad@acm.org>
parents: 71599
diff changeset
1991 def onerror(modname):
3acf90f71178 Issue #7425: Prevent pydoc -k failures due to module import errors.
Ned Deily <nad@acm.org>
parents: 71599
diff changeset
1992 pass
3acf90f71178 Issue #7425: Prevent pydoc -k failures due to module import errors.
Ned Deily <nad@acm.org>
parents: 71599
diff changeset
1993 with warnings.catch_warnings():
3acf90f71178 Issue #7425: Prevent pydoc -k failures due to module import errors.
Ned Deily <nad@acm.org>
parents: 71599
diff changeset
1994 warnings.filterwarnings('ignore') # ignore problems during import
3acf90f71178 Issue #7425: Prevent pydoc -k failures due to module import errors.
Ned Deily <nad@acm.org>
parents: 71599
diff changeset
1995 ModuleScanner().run(callback, key, onerror=onerror)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1996
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1997 # --------------------------------------------------- web browser interface
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
1998
17442
2d521420db8f Typo fixes and small touches.
Ka-Ping Yee <ping@zesty.ca>
parents: 17441
diff changeset
1999 def serve(port, callback=None, completer=None):
17445
f0f0467a3334 Remove forking. Doesn't work in Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 17442
diff changeset
2000 import BaseHTTPServer, mimetools, select
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2001
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2002 # Patch up mimetools.Message so it doesn't break if rfc822 is reloaded.
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2003 class Message(mimetools.Message):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2004 def __init__(self, fp, seekable=1):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2005 Message = self.__class__
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2006 Message.__bases__[0].__bases__[0].__init__(self, fp, seekable)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2007 self.encodingheader = self.getheader('content-transfer-encoding')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2008 self.typeheader = self.getheader('content-type')
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2009 self.parsetype()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2010 self.parseplist()
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2011
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2012 class DocHandler(BaseHTTPServer.BaseHTTPRequestHandler):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2013 def send_document(self, title, contents):
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2014 try:
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2015 self.send_response(200)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2016 self.send_header('Content-Type', 'text/html')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2017 self.end_headers()
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
2018 self.wfile.write(html.page(title, contents))
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2019 except IOError: pass
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2020
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2021 def do_GET(self):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2022 path = self.path
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2023 if path[-5:] == '.html': path = path[:-5]
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2024 if path[:1] == '/': path = path[1:]
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2025 if path and path != '.':
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2026 try:
17470
b4e2b8e9f1e6 Make force-loading optional; don't force-load in interactive mode.
Ka-Ping Yee <ping@zesty.ca>
parents: 17457
diff changeset
2027 obj = locate(path, forceload=1)
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
2028 except ErrorDuringImport, value:
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
2029 self.send_document(path, html.escape(str(value)))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2030 return
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
2031 if obj:
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
2032 self.send_document(describe(obj), html.document(obj, path))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2033 else:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2034 self.send_document(path,
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
2035 'no Python documentation found for %s' % repr(path))
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2036 else:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2037 heading = html.heading(
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2038 '<big><big><strong>Python: Index of Modules</strong></big></big>',
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2039 '#ffffff', '#7799ee')
16928
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2040 def bltinlink(name):
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2041 return '<a href="%s.html">%s</a>' % (name, name)
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
2042 names = filter(lambda x: x != '__main__',
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
2043 sys.builtin_module_names)
16928
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2044 contents = html.multicolumn(names, bltinlink)
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2045 indices = ['<p>' + html.bigsection(
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2046 'Built-in Modules', '#ffffff', '#ee77aa', contents)]
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2047
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2048 seen = {}
37821
3135648026c4 Second phase of refactoring for runpy, pkgutil, pydoc, and setuptools
Phillip J. Eby <pje@telecommunity.com>
parents: 36893
diff changeset
2049 for dir in sys.path:
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2050 indices.append(html.index(dir, seen))
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
2051 contents = heading + join(indices) + '''<p align=right>
20074
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
2052 <font color="#909090" face="helvetica, arial"><strong>
511776d6d7d8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
Tim Peters <tim.peters@gmail.com>
parents: 20073
diff changeset
2053 pydoc</strong> by Ka-Ping Yee &lt;ping@lfw.org&gt;</font>'''
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2054 self.send_document('Index of Modules', contents)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2055
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2056 def log_message(self, *args): pass
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2057
17445
f0f0467a3334 Remove forking. Doesn't work in Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 17442
diff changeset
2058 class DocServer(BaseHTTPServer.HTTPServer):
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2059 def __init__(self, port, callback):
61258
f6785bce54b5 In a number of places code still revers
Ronald Oussoren <ronaldoussoren@mac.com>
parents: 60120
diff changeset
2060 host = 'localhost'
64143
ca557948a5cf Merged revisions 84173 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents: 63442
diff changeset
2061 self.address = (host, port)
16942
af810f08425b Use '127.0.0.1' only on Mac; for other, sane platforms, use 'localhost'.
Ka-Ping Yee <ping@zesty.ca>
parents: 16940
diff changeset
2062 self.url = 'http://%s:%d/' % (host, port)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2063 self.callback = callback
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2064 self.base.__init__(self, self.address, self.handler)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2065
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2066 def serve_until_quit(self):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2067 import select
22867
e2f2187c3d2c Partial introduction of bools where appropriate.
Guido van Rossum <guido@python.org>
parents: 22830
diff changeset
2068 self.quit = False
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2069 while not self.quit:
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2070 rd, wr, ex = select.select([self.socket.fileno()], [], [], 1)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2071 if rd: self.handle_request()
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2072
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2073 def server_activate(self):
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2074 self.base.server_activate(self)
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2075 if self.callback: self.callback(self)
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2076
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2077 DocServer.base = BaseHTTPServer.HTTPServer
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2078 DocServer.handler = DocHandler
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2079 DocHandler.MessageClass = Message
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2080 try:
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
2081 try:
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
2082 DocServer(port, callback).serve_until_quit()
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
2083 except (KeyboardInterrupt, select.error):
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
2084 pass
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
2085 finally:
17442
2d521420db8f Typo fixes and small touches.
Ka-Ping Yee <ping@zesty.ca>
parents: 17441
diff changeset
2086 if completer: completer()
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2087
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2088 # ----------------------------------------------------- graphical interface
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2089
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2090 def gui():
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2091 """Graphical interface (starts web server and pops up a control window)."""
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2092 class GUI:
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2093 def __init__(self, window, port=7464):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2094 self.window = window
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2095 self.server = None
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2096 self.scanner = None
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2097
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2098 import Tkinter
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2099 self.server_frm = Tkinter.Frame(window)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2100 self.title_lbl = Tkinter.Label(self.server_frm,
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2101 text='Starting server...\n ')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2102 self.open_btn = Tkinter.Button(self.server_frm,
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2103 text='open browser', command=self.open, state='disabled')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2104 self.quit_btn = Tkinter.Button(self.server_frm,
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2105 text='quit serving', command=self.quit, state='disabled')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2106
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2107 self.search_frm = Tkinter.Frame(window)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2108 self.search_lbl = Tkinter.Label(self.search_frm, text='Search for')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2109 self.search_ent = Tkinter.Entry(self.search_frm)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2110 self.search_ent.bind('<Return>', self.search)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2111 self.stop_btn = Tkinter.Button(self.search_frm,
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2112 text='stop', pady=0, command=self.stop, state='disabled')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2113 if sys.platform == 'win32':
16940
c28dfe5f87a7 The sys.platform identifier for Windows is just 'win32' (for all varieties).
Ka-Ping Yee <ping@zesty.ca>
parents: 16934
diff changeset
2114 # Trying to hide and show this button crashes under Windows.
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2115 self.stop_btn.pack(side='right')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2116
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2117 self.window.title('pydoc')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2118 self.window.protocol('WM_DELETE_WINDOW', self.quit)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2119 self.title_lbl.pack(side='top', fill='x')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2120 self.open_btn.pack(side='left', fill='x', expand=1)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2121 self.quit_btn.pack(side='right', fill='x', expand=1)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2122 self.server_frm.pack(side='top', fill='x')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2123
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2124 self.search_lbl.pack(side='left')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2125 self.search_ent.pack(side='right', fill='x', expand=1)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2126 self.search_frm.pack(side='top', fill='x')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2127 self.search_ent.focus_set()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2128
16940
c28dfe5f87a7 The sys.platform identifier for Windows is just 'win32' (for all varieties).
Ka-Ping Yee <ping@zesty.ca>
parents: 16934
diff changeset
2129 font = ('helvetica', sys.platform == 'win32' and 8 or 10)
16928
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2130 self.result_lst = Tkinter.Listbox(window, font=font, height=6)
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2131 self.result_lst.bind('<Button-1>', self.select)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2132 self.result_lst.bind('<Double-Button-1>', self.goto)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2133 self.result_scr = Tkinter.Scrollbar(window,
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2134 orient='vertical', command=self.result_lst.yview)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2135 self.result_lst.config(yscrollcommand=self.result_scr.set)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2136
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2137 self.result_frm = Tkinter.Frame(window)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2138 self.goto_btn = Tkinter.Button(self.result_frm,
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2139 text='go to selected', command=self.goto)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2140 self.hide_btn = Tkinter.Button(self.result_frm,
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2141 text='hide results', command=self.hide)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2142 self.goto_btn.pack(side='left', fill='x', expand=1)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2143 self.hide_btn.pack(side='right', fill='x', expand=1)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2144
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2145 self.window.update()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2146 self.minwidth = self.window.winfo_width()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2147 self.minheight = self.window.winfo_height()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2148 self.bigminheight = (self.server_frm.winfo_reqheight() +
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2149 self.search_frm.winfo_reqheight() +
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2150 self.result_lst.winfo_reqheight() +
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2151 self.result_frm.winfo_reqheight())
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2152 self.bigwidth, self.bigheight = self.minwidth, self.bigminheight
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2153 self.expanded = 0
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2154 self.window.wm_geometry('%dx%d' % (self.minwidth, self.minheight))
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2155 self.window.wm_minsize(self.minwidth, self.minheight)
26814
7c8af1979e78 Gracefully delay runtime error up to 1s. Add .willdispatch().
Martin v. Löwis <martin@v.loewis.de>
parents: 25986
diff changeset
2156 self.window.tk.willdispatch()
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2157
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2158 import threading
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
2159 threading.Thread(
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
2160 target=serve, args=(port, self.ready, self.quit)).start()
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2161
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2162 def ready(self, server):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2163 self.server = server
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2164 self.title_lbl.config(
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2165 text='Python documentation server at\n' + server.url)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2166 self.open_btn.config(state='normal')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2167 self.quit_btn.config(state='normal')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2168
16928
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2169 def open(self, event=None, url=None):
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2170 url = url or self.server.url
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2171 try:
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2172 import webbrowser
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2173 webbrowser.open(url)
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2174 except ImportError: # pre-webbrowser.py compatibility
16940
c28dfe5f87a7 The sys.platform identifier for Windows is just 'win32' (for all varieties).
Ka-Ping Yee <ping@zesty.ca>
parents: 16934
diff changeset
2175 if sys.platform == 'win32':
16928
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2176 os.system('start "%s"' % url)
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2177 else:
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2178 rc = os.system('netscape -remote "openURL(%s)" &' % url)
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2179 if rc: os.system('netscape "%s" &' % url)
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2180
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2181 def quit(self, event=None):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2182 if self.server:
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2183 self.server.quit = 1
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2184 self.window.quit()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2185
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2186 def search(self, event=None):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2187 key = self.search_ent.get()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2188 self.stop_btn.pack(side='right')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2189 self.stop_btn.config(state='normal')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2190 self.search_lbl.config(text='Searching for "%s"...' % key)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2191 self.search_ent.forget()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2192 self.search_lbl.pack(side='left')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2193 self.result_lst.delete(0, 'end')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2194 self.goto_btn.config(state='disabled')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2195 self.expand()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2196
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2197 import threading
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2198 if self.scanner:
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2199 self.scanner.quit = 1
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2200 self.scanner = ModuleScanner()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2201 threading.Thread(target=self.scanner.run,
17456
3bda59071389 Fix call to ModuleScanner from GUI search interface.
Ka-Ping Yee <ping@zesty.ca>
parents: 17452
diff changeset
2202 args=(self.update, key, self.done)).start()
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2203
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2204 def update(self, path, modname, desc):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2205 if modname[-9:] == '.__init__':
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2206 modname = modname[:-9] + ' (package)'
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2207 self.result_lst.insert('end',
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2208 modname + ' - ' + (desc or '(no description)'))
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2209
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2210 def stop(self, event=None):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2211 if self.scanner:
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2212 self.scanner.quit = 1
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2213 self.scanner = None
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2214
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2215 def done(self):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2216 self.scanner = None
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2217 self.search_lbl.config(text='Search for')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2218 self.search_lbl.pack(side='left')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2219 self.search_ent.pack(side='right', fill='x', expand=1)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2220 if sys.platform != 'win32': self.stop_btn.forget()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2221 self.stop_btn.config(state='disabled')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2222
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2223 def select(self, event=None):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2224 self.goto_btn.config(state='normal')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2225
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2226 def goto(self, event=None):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2227 selection = self.result_lst.curselection()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2228 if selection:
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2229 modname = split(self.result_lst.get(selection[0]))[0]
16928
02e097f72d47 Clean up the handling of getsourcefile/getabsfile.
Ka-Ping Yee <ping@zesty.ca>
parents: 16923
diff changeset
2230 self.open(url=self.server.url + modname + '.html')
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2231
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2232 def collapse(self):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2233 if not self.expanded: return
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2234 self.result_frm.forget()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2235 self.result_scr.forget()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2236 self.result_lst.forget()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2237 self.bigwidth = self.window.winfo_width()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2238 self.bigheight = self.window.winfo_height()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2239 self.window.wm_geometry('%dx%d' % (self.minwidth, self.minheight))
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2240 self.window.wm_minsize(self.minwidth, self.minheight)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2241 self.expanded = 0
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2242
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2243 def expand(self):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2244 if self.expanded: return
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2245 self.result_frm.pack(side='bottom', fill='x')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2246 self.result_scr.pack(side='right', fill='y')
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2247 self.result_lst.pack(side='top', fill='both', expand=1)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2248 self.window.wm_geometry('%dx%d' % (self.bigwidth, self.bigheight))
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2249 self.window.wm_minsize(self.minwidth, self.bigminheight)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2250 self.expanded = 1
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2251
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2252 def hide(self, event=None):
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2253 self.stop()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2254 self.collapse()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2255
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2256 import Tkinter
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2257 try:
33225
57a66d700c7c Patch #997284: Allow pydoc to work with XP Themes (.manifest file)
Martin v. Löwis <martin@v.loewis.de>
parents: 33224
diff changeset
2258 root = Tkinter.Tk()
57a66d700c7c Patch #997284: Allow pydoc to work with XP Themes (.manifest file)
Martin v. Löwis <martin@v.loewis.de>
parents: 33224
diff changeset
2259 # Tk will crash if pythonw.exe has an XP .manifest
57a66d700c7c Patch #997284: Allow pydoc to work with XP Themes (.manifest file)
Martin v. Löwis <martin@v.loewis.de>
parents: 33224
diff changeset
2260 # file and the root has is not destroyed explicitly.
57a66d700c7c Patch #997284: Allow pydoc to work with XP Themes (.manifest file)
Martin v. Löwis <martin@v.loewis.de>
parents: 33224
diff changeset
2261 # If the problem is ever fixed in Tk, the explicit
57a66d700c7c Patch #997284: Allow pydoc to work with XP Themes (.manifest file)
Martin v. Löwis <martin@v.loewis.de>
parents: 33224
diff changeset
2262 # destroy can go.
57a66d700c7c Patch #997284: Allow pydoc to work with XP Themes (.manifest file)
Martin v. Löwis <martin@v.loewis.de>
parents: 33224
diff changeset
2263 try:
57a66d700c7c Patch #997284: Allow pydoc to work with XP Themes (.manifest file)
Martin v. Löwis <martin@v.loewis.de>
parents: 33224
diff changeset
2264 gui = GUI(root)
57a66d700c7c Patch #997284: Allow pydoc to work with XP Themes (.manifest file)
Martin v. Löwis <martin@v.loewis.de>
parents: 33224
diff changeset
2265 root.mainloop()
57a66d700c7c Patch #997284: Allow pydoc to work with XP Themes (.manifest file)
Martin v. Löwis <martin@v.loewis.de>
parents: 33224
diff changeset
2266 finally:
57a66d700c7c Patch #997284: Allow pydoc to work with XP Themes (.manifest file)
Martin v. Löwis <martin@v.loewis.de>
parents: 33224
diff changeset
2267 root.destroy()
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2268 except KeyboardInterrupt:
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2269 pass
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2270
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2271 # -------------------------------------------------- command-line interface
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2272
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
2273 def ispath(x):
24740
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
2274 return isinstance(x, str) and find(x, os.sep) >= 0
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
2275
16875
10b84060b7f3 Normalize case of paths in sys.path to avoid duplicates on Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 16833
diff changeset
2276 def cli():
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2277 """Command-line interface (looks at sys.argv to decide what to do)."""
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2278 import getopt
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2279 class BadUsage: pass
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2280
57282
c08423d70b9f Merged revisions 76312 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents: 54827
diff changeset
2281 # Scripts don't get the current directory in their path by default
c08423d70b9f Merged revisions 76312 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents: 54827
diff changeset
2282 # unless they are run with the '-m' switch
c08423d70b9f Merged revisions 76312 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents: 54827
diff changeset
2283 if '' not in sys.path:
c08423d70b9f Merged revisions 76312 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents: 54827
diff changeset
2284 scriptdir = os.path.dirname(sys.argv[0])
c08423d70b9f Merged revisions 76312 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents: 54827
diff changeset
2285 if scriptdir in sys.path:
c08423d70b9f Merged revisions 76312 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents: 54827
diff changeset
2286 sys.path.remove(scriptdir)
c08423d70b9f Merged revisions 76312 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents: 54827
diff changeset
2287 sys.path.insert(0, '.')
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
2288
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2289 try:
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2290 opts, args = getopt.getopt(sys.argv[1:], 'gk:p:w')
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2291 writing = 0
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2292
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2293 for opt, val in opts:
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2294 if opt == '-g':
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2295 gui()
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2296 return
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2297 if opt == '-k':
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2298 apropos(val)
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2299 return
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2300 if opt == '-p':
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2301 try:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2302 port = int(val)
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2303 except ValueError:
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2304 raise BadUsage
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2305 def ready(server):
17441
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
2306 print 'pydoc server ready at %s' % server.url
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
2307 def stopped():
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
2308 print 'pydoc server stopped'
74b9fb1c9633 Properly qualify methods inherited from classes in other modules.
Ka-Ping Yee <ping@zesty.ca>
parents: 17372
diff changeset
2309 serve(port, ready, stopped)
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2310 return
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2311 if opt == '-w':
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2312 writing = 1
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2313
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2314 if not args: raise BadUsage
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2315 for arg in args:
24740
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
2316 if ispath(arg) and not os.path.exists(arg):
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
2317 print 'file %r does not exist' % arg
10391d58d184 Extend stripid() to handle strings ending in more than one '>'.
Ka-Ping Yee <ping@zesty.ca>
parents: 24710
diff changeset
2318 break
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2319 try:
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
2320 if ispath(arg) and os.path.isfile(arg):
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2321 arg = importfile(arg)
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
2322 if writing:
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
2323 if ispath(arg) and os.path.isdir(arg):
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
2324 writedocs(arg)
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
2325 else:
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
2326 writedoc(arg)
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
2327 else:
29463
74a28f2e94cf Support keyword and topics help in cli(). Fixes #715782.
Martin v. Löwis <martin@v.loewis.de>
parents: 29409
diff changeset
2328 help.help(arg)
17181
7916d32aa081 Show inherited methods, with hyperlinks to the base class they came from.
Ka-Ping Yee <ping@zesty.ca>
parents: 17163
diff changeset
2329 except ErrorDuringImport, value:
17163
ad683f20bb14 Fixes for various issues reported and discovered since Python 9:
Ka-Ping Yee <ping@zesty.ca>
parents: 17055
diff changeset
2330 print value
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2331
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2332 except (getopt.error, BadUsage):
30821
ec1a4a29d25d Patch #785689: Use basename in usage. Backported to 2.3.
Martin v. Löwis <martin@v.loewis.de>
parents: 30698
diff changeset
2333 cmd = os.path.basename(sys.argv[0])
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2334 print """pydoc - the Python documentation tool
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2335
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2336 %s <name> ...
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2337 Show text documentation on something. <name> may be the name of a
29463
74a28f2e94cf Support keyword and topics help in cli(). Fixes #715782.
Martin v. Löwis <martin@v.loewis.de>
parents: 29409
diff changeset
2338 Python keyword, topic, function, module, or package, or a dotted
74a28f2e94cf Support keyword and topics help in cli(). Fixes #715782.
Martin v. Löwis <martin@v.loewis.de>
parents: 29409
diff changeset
2339 reference to a class or function within a module or module in a
74a28f2e94cf Support keyword and topics help in cli(). Fixes #715782.
Martin v. Löwis <martin@v.loewis.de>
parents: 29409
diff changeset
2340 package. If <name> contains a '%s', it is used as the path to a
74a28f2e94cf Support keyword and topics help in cli(). Fixes #715782.
Martin v. Löwis <martin@v.loewis.de>
parents: 29409
diff changeset
2341 Python source file to document. If name is 'keywords', 'topics',
74a28f2e94cf Support keyword and topics help in cli(). Fixes #715782.
Martin v. Löwis <martin@v.loewis.de>
parents: 29409
diff changeset
2342 or 'modules', a listing of these things is displayed.
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2343
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2344 %s -k <keyword>
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2345 Search for a keyword in the synopsis lines of all available modules.
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2346
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2347 %s -p <port>
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2348 Start an HTTP server on the given port on the local machine.
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2349
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2350 %s -g
17371
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
2351 Pop up a graphical interface for finding and serving documentation.
16791
a89f783c133a pydoc: text and HTML documentation generator for interactive use
Ka-Ping Yee <ping@zesty.ca>
parents:
diff changeset
2352
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2353 %s -w <name> ...
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2354 Write out the HTML documentation for a module to a file in the current
17371
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
2355 directory. If <name> contains a '%s', it is treated as a filename; if
e843eee7a33e Fix synopsis() so it can handle binary module files.
Ka-Ping Yee <ping@zesty.ca>
parents: 17230
diff changeset
2356 it names a directory, documentation is written for all the contents.
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2357 """ % (cmd, os.sep, cmd, cmd, cmd, cmd, os.sep)
16875
10b84060b7f3 Normalize case of paths in sys.path to avoid duplicates on Windows.
Ka-Ping Yee <ping@zesty.ca>
parents: 16833
diff changeset
2358
16897
74a9d0a4231a Docstring improvements.
Ka-Ping Yee <ping@zesty.ca>
parents: 16875
diff changeset
2359 if __name__ == '__main__': cli()