[Python-checkins] python/dist/src/Lib pydoc.py,1.79,1.80
ping@users.sourceforge.net
ping@users.sourceforge.net
Fri, 28 Mar 2003 08:35:58 -0800
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv14702
Modified Files:
pydoc.py
Log Message:
Hide private names beginning with _ (but don't hide __special__ names).
Clean up section headings; make the bars on the left less fat.
Adjust the display of properties slightly.
Don't show stuff inherited from the base 'object' type.
Index: pydoc.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/pydoc.py,v
retrieving revision 1.79
retrieving revision 1.80
diff -C2 -d -r1.79 -r1.80
*** pydoc.py 1 Mar 2003 15:22:41 -0000 1.79
--- pydoc.py 28 Mar 2003 16:35:51 -0000 1.80
***************
*** 45,49 ****
# path will be displayed.
! import sys, imp, os, re, types, inspect
from repr import Repr
from string import expandtabs, find, join, lower, split, strip, rfind, rstrip
--- 45,49 ----
# path will be displayed.
! import sys, imp, os, re, types, inspect, __builtin__
from repr import Repr
from string import expandtabs, find, join, lower, split, strip, rfind, rstrip
***************
*** 143,146 ****
--- 143,155 ----
return yes, no
+ def visiblename(name):
+ """Decide whether to show documentation on a variable."""
+ # Certain special names are redundant.
+ if name in ['__builtins__', '__doc__', '__file__', '__path__',
+ '__module__', '__name__']: return 0
+ # Private names are hidden, but special names are displayed.
+ if name.startswith('__') and name.endswith('__'): return 1
+ return not name.startswith('_')
+
# ----------------------------------------------------- module manipulation
***************
*** 338,344 ****
<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: %s</title>
! <style type="text/css"><!--
! TT { font-family: lucidatypewriter, lucida console, courier }
! --></style></head><body bgcolor="#f0f0f8">
%s
</body></html>''' % (title, contents)
--- 347,351 ----
<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: %s</title>
! </head><body bgcolor="#f0f0f8">
%s
</body></html>''' % (title, contents)
***************
*** 355,364 ****
''' % (bgcol, fgcol, title, fgcol, extras or ' ')
! def section(self, title, fgcol, bgcol, contents, width=10,
! prelude='', marginalia=None, gap=' '):
"""Format a section with a heading."""
if marginalia is None:
marginalia = '<tt>' + ' ' * width + '</tt>'
! result = '''
<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="%s">
--- 362,371 ----
''' % (bgcol, fgcol, title, fgcol, extras or ' ')
! def section(self, title, fgcol, bgcol, contents, width=6,
! prelude='', marginalia=None, gap=' '):
"""Format a section with a heading."""
if marginalia is None:
marginalia = '<tt>' + ' ' * width + '</tt>'
! result = '''<p>
<table width="100%%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="%s">
***************
*** 530,535 ****
for key, value in inspect.getmembers(object, inspect.isclass):
if (inspect.getmodule(value) or object) is object:
! classes.append((key, value))
! cdict[key] = cdict[value] = '#' + key
for key, value in classes:
for base in value.__bases__:
--- 537,543 ----
for key, value in inspect.getmembers(object, inspect.isclass):
if (inspect.getmodule(value) or object) is object:
! if visiblename(key):
! classes.append((key, value))
! cdict[key] = cdict[value] = '#' + key
for key, value in classes:
for base in value.__bases__:
***************
*** 543,552 ****
for key, value in inspect.getmembers(object, inspect.isroutine):
if inspect.isbuiltin(value) or inspect.getmodule(value) is object:
! funcs.append((key, value))
! fdict[key] = '#-' + key
! if inspect.isfunction(value): fdict[value] = fdict[key]
data = []
for key, value in inspect.getmembers(object, isdata):
! if key not in ['__builtins__', '__doc__']:
data.append((key, value))
--- 551,561 ----
for key, value in inspect.getmembers(object, inspect.isroutine):
if inspect.isbuiltin(value) or inspect.getmodule(value) is object:
! if visiblename(key):
! funcs.append((key, value))
! fdict[key] = '#-' + key
! if inspect.isfunction(value): fdict[value] = fdict[key]
data = []
for key, value in inspect.getmembers(object, isdata):
! if visiblename(key):
data.append((key, value))
***************
*** 561,569 ****
path = os.path.join(object.__path__[0], file)
modname = inspect.getmodulename(file)
! if modname and modname not in modnames:
! modpkgs.append((modname, name, 0, 0))
! modnames.append(modname)
! elif ispackage(path):
! modpkgs.append((file, name, 1, 0))
modpkgs.sort()
contents = self.multicolumn(modpkgs, self.modpkglink)
--- 570,579 ----
path = os.path.join(object.__path__[0], file)
modname = inspect.getmodulename(file)
! if modname != '__init__':
! if modname and modname not in modnames:
! modpkgs.append((modname, name, 0, 0))
! modnames.append(modname)
! elif ispackage(path):
! modpkgs.append((file, name, 1, 0))
modpkgs.sort()
contents = self.multicolumn(modpkgs, self.modpkglink)
***************
*** 659,668 ****
funcs, classes, mdict)
push('<dd><tt>%s</tt></dd>\n' % doc)
! for attr, tag in [("fget", " getter"),
! ("fset", " setter"),
! ("fdel", " deleter")]:
func = getattr(value, attr)
if func is not None:
! base = self.document(func, name + tag, mod,
funcs, classes, mdict, object)
push('<dd>%s</dd>\n' % base)
--- 669,678 ----
funcs, classes, mdict)
push('<dd><tt>%s</tt></dd>\n' % doc)
! for attr, tag in [('fget', '<em>get</em>'),
! ('fset', '<em>set</em>'),
! ('fdel', '<em>delete</em>')]:
func = getattr(value, attr)
if func is not None:
! base = self.document(func, tag, mod,
funcs, classes, mdict, object)
push('<dd>%s</dd>\n' % base)
***************
*** 691,695 ****
return attrs
! attrs = inspect.classify_class_attrs(object)
mdict = {}
for key, kind, homecls, value in attrs:
--- 701,706 ----
return attrs
! attrs = filter(lambda (name, kind, cls, value): visiblename(name),
! inspect.classify_class_attrs(object))
mdict = {}
for key, kind, homecls, value in attrs:
***************
*** 710,718 ****
attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass)
! if thisclass is object:
! tag = "defined here"
else:
! tag = "inherited from %s" % self.classlink(thisclass,
! object.__module__)
tag += ':<br>\n'
--- 721,732 ----
attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass)
! if thisclass is __builtin__.object:
! attrs = inherited
! continue
! elif thisclass is object:
! tag = 'defined here'
else:
! tag = 'inherited from %s' % self.classlink(thisclass,
! object.__module__)
tag += ':<br>\n'
***************
*** 721,733 ****
# Pump out the attrs, segregated by kind.
! attrs = spill("Methods %s" % tag, attrs,
lambda t: t[1] == 'method')
! attrs = spill("Class methods %s" % tag, attrs,
lambda t: t[1] == 'class method')
! attrs = spill("Static methods %s" % tag, attrs,
lambda t: t[1] == 'static method')
! attrs = spillproperties("Properties %s" % tag, attrs,
lambda t: t[1] == 'property')
! attrs = spilldata("Data and non-method functions %s" % tag, attrs,
lambda t: t[1] == 'data')
assert attrs == []
--- 735,747 ----
# Pump out the attrs, segregated by kind.
! attrs = spill('Methods %s' % tag, attrs,
lambda t: t[1] == 'method')
! attrs = spill('Class methods %s' % tag, attrs,
lambda t: t[1] == 'class method')
! attrs = spill('Static methods %s' % tag, attrs,
lambda t: t[1] == 'static method')
! attrs = spillproperties('Properties %s' % tag, attrs,
lambda t: t[1] == 'property')
! attrs = spilldata('Data and other attributes %s' % tag, attrs,
lambda t: t[1] == 'data')
assert attrs == []
***************
*** 748,754 ****
title = title + '(%s)' % join(parents, ', ')
doc = self.markup(getdoc(object), self.preformat, funcs, classes, mdict)
! doc = doc and '<tt>%s<br> </tt>' % doc or ' '
! return self.section(title, '#000000', '#ffc8d8', contents, 5, doc)
def formatvalue(self, object):
--- 762,768 ----
title = title + '(%s)' % join(parents, ', ')
doc = self.markup(getdoc(object), self.preformat, funcs, classes, mdict)
! doc = doc and '<tt>%s<br> </tt>' % doc
! return self.section(title, '#000000', '#ffc8d8', contents, 3, doc)
def formatvalue(self, object):
***************
*** 936,947 ****
for key, value in inspect.getmembers(object, inspect.isclass):
if (inspect.getmodule(value) or object) is object:
! classes.append((key, value))
funcs = []
for key, value in inspect.getmembers(object, inspect.isroutine):
if inspect.isbuiltin(value) or inspect.getmodule(value) is object:
! funcs.append((key, value))
data = []
for key, value in inspect.getmembers(object, isdata):
! if key not in ['__builtins__', '__doc__']:
data.append((key, value))
--- 950,963 ----
for key, value in inspect.getmembers(object, inspect.isclass):
if (inspect.getmodule(value) or object) is object:
! if visiblename(key):
! classes.append((key, value))
funcs = []
for key, value in inspect.getmembers(object, inspect.isroutine):
if inspect.isbuiltin(value) or inspect.getmodule(value) is object:
! if visiblename(key):
! funcs.append((key, value))
data = []
for key, value in inspect.getmembers(object, isdata):
! if visiblename(key):
data.append((key, value))
***************
*** 951,958 ****
path = os.path.join(object.__path__[0], file)
modname = inspect.getmodulename(file)
! if modname and modname not in modpkgs:
! modpkgs.append(modname)
! elif ispackage(path):
! modpkgs.append(file + ' (package)')
modpkgs.sort()
result = result + self.section(
--- 967,975 ----
path = os.path.join(object.__path__[0], file)
modname = inspect.getmodulename(file)
! if modname != '__init__':
! if modname and modname not in modpkgs:
! modpkgs.append(modname)
! elif ispackage(path):
! modpkgs.append(file + ' (package)')
modpkgs.sort()
result = result + self.section(
***************
*** 1053,1059 ****
push(self.indent(doc))
need_blank_after_doc = 1
! for attr, tag in [("fget", " getter"),
! ("fset", " setter"),
! ("fdel", " deleter")]:
func = getattr(value, attr)
if func is not None:
--- 1070,1076 ----
push(self.indent(doc))
need_blank_after_doc = 1
! for attr, tag in [('fget', '<get>'),
! ('fset', '<set>'),
! ('fdel', '<delete>')]:
func = getattr(value, attr)
if func is not None:
***************
*** 1061,1067 ****
push('')
need_blank_after_doc = 0
! base = self.docother(func, name + tag, mod, 70)
push(self.indent(base))
- push('')
return attrs
--- 1078,1083 ----
push('')
need_blank_after_doc = 0
! base = self.document(func, tag, mod)
push(self.indent(base))
return attrs
***************
*** 1080,1084 ****
return attrs
! attrs = inspect.classify_class_attrs(object)
while attrs:
if mro:
--- 1096,1101 ----
return attrs
! attrs = filter(lambda (name, kind, cls, value): visiblename(name),
! inspect.classify_class_attrs(object))
while attrs:
if mro:
***************
*** 1088,1099 ****
attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass)
! if thisclass is object:
tag = "defined here"
else:
tag = "inherited from %s" % classname(thisclass,
object.__module__)
# Sort attrs by name.
! attrs.sort(lambda t1, t2: cmp(t1[0], t2[0]))
# Pump out the attrs, segregated by kind.
--- 1105,1120 ----
attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass)
! if thisclass is __builtin__.object:
! attrs = inherited
! continue
! elif thisclass is object:
tag = "defined here"
else:
tag = "inherited from %s" % classname(thisclass,
object.__module__)
+ filter(lambda t: not t[0].startswith('_'), attrs)
# Sort attrs by name.
! attrs.sort()
# Pump out the attrs, segregated by kind.
***************
*** 1106,1111 ****
attrs = spillproperties("Properties %s:\n" % tag, attrs,
lambda t: t[1] == 'property')
! attrs = spilldata("Data and non-method functions %s:\n" % tag,
! attrs, lambda t: t[1] == 'data')
assert attrs == []
attrs = inherited
--- 1127,1132 ----
attrs = spillproperties("Properties %s:\n" % tag, attrs,
lambda t: t[1] == 'property')
! attrs = spilldata("Data and other attributes %s:\n" % tag, attrs,
! lambda t: t[1] == 'data')
assert attrs == []
attrs = inherited
***************
*** 1317,1321 ****
return object
else:
- import __builtin__
if hasattr(__builtin__, path):
return getattr(__builtin__, path)
--- 1338,1341 ----
***************
*** 1372,1377 ****
modname = inspect.getmodulename(path)
if modname:
! modname = pkgpath + modname
! if not modname in done:
done[modname] = 1
writedoc(modname)
--- 1392,1400 ----
modname = inspect.getmodulename(path)
if modname:
! if modname == '__init__':
! modname = pkgpath[:-1] # remove trailing period
! else:
! modname = pkgpath + modname
! if modname not in done:
done[modname] = 1
writedoc(modname)