| ' % (100/cols))
for i in range(rows*col, rows*col+rows):
if i < len(list):
results.append(format(list[i]) + ' ') results.append(' | ')
results.append('
%s | %s | ||
%s | ||
| %s | %s | |
| %s | %s | """ % (bgcol, marginalia, gap)) # Alas, this horrible hack seems to be the only way to force Netscape # to expand the main cell consistently to the maximum available width. results.append('' + ' '*100 + '') results.append(contents) results.append(' |
| generated with htmldoc by Ka-Ping Yee |
' + doc + '\n\n' else: doc = '
no doc string\n'
results.append(doc)
if hasattr(object, '__path__'):
modpkgs = []
modnames = []
for file in os.listdir(object.__path__[0]):
if file[:1] != '_':
path = os.path.join(object.__path__[0], file)
if file[-3:] == '.py' and file[:-3] not in modnames:
modpkgs.append((file[:-3], 0, name, 0))
modnames.append(file[:-3])
elif file[-4:] == '.pyc' and file[:-4] not in modnames:
modpkgs.append((file[:-4], 0, name, 0))
modnames.append(file[:-4])
elif os.path.isdir(path):
init = os.path.join(path, '__init__.py')
initc = os.path.join(path, '__init__.pyc')
if os.path.isfile(init) or os.path.isfile(initc):
modpkgs.append((file, 1, name, 0))
modpkgs.sort()
contents = multicolumn(modpkgs, modpkglink)
results.append(section('Package Contents',
'#ffffff', '#aa55cc', contents))
elif modules:
contents = multicolumn(modules, modulelink)
results.append(section('Modules',
'#fffff', '#aa55cc', contents))
if classes:
contents = document_tree(inspect.getclasstree(classes, 1), name, cdict)
for item in classes:
contents.append(document_class(item, fdict, cdict))
results.append(section('Classes',
'#ffffff', '#ee77aa', contents))
if functions:
contents = []
for item in functions:
contents.append(document_function(item, fdict, cdict))
results.append(section('Functions',
'#ffffff', '#eeaa77', contents))
if constants:
contents = []
for key, value in constants:
contents.append('
%s = %s' %
(key, htmlrepr(value)))
results.append(section('Constants',
'#ffffff', '#55aa55', contents))
return results
def document_class(object, functions={}, classes={}):
"""Produce HTML documentation for a given class object."""
name = object.__name__
bases = object.__bases__
results = []
methods, mdict = [], {}
for key, value in inspect.getmembers(object, inspect.ismethod):
methods.append(value)
mdict[key] = mdict[value] = '#' + name + '-' + key
if methods:
for item in methods:
results.append(document_method(
item, functions, classes, mdict, name))
title = 'class %s' % (name, name)
if bases:
parents = []
for base in bases:
parents.append(classlink(base, object.__module__, classes))
title = title + '(%s)' % join(parents, ', ')
doc = markup(getdoc(object), functions, classes, mdict, escape=preformat)
if doc: doc = '' + doc + '
'
else: doc = 'no doc string'
return section(title, '#000000', '#ffc8d8', results, 10, doc)
def document_method(object, functions={}, classes={}, methods={}, clname=''):
"""Produce HTML documentation for a given method object."""
return document_function(
object.im_func, functions, classes, methods, clname)
def defaultformat(object):
return '=' + \
htmlrepr(object) + ''
def document_function(object, functions={}, classes={}, methods={}, clname=''):
"""Produce HTML documentation for a given function object."""
try:
args, varargs, varkw, defaults = inspect.getargspec(object)
argspec = inspect.formatargspec(
args, varargs, varkw, defaults, defaultformat=defaultformat)
except TypeError:
argspec = '(...)'
if object.__name__ == '
\n', '
']
def document_builtin(object):
"""Produce HTML documentation for a given built-in function."""
return ('%s' % object.__name__ +
'(...)')
# --------------------------------------------------- main dispatch routine
def document(object):
"""Generate documentation for a given object."""
if inspect.ismodule(object): results = document_module(object)
elif inspect.isclass(object): results = document_class(object)
elif inspect.ismethod(object): results = document_method(object)
elif inspect.isfunction(object): results = document_function(object)
elif inspect.isbuiltin(object): results = document_builtin(object)
else: raise TypeError, 'don\'t know how to document this kind of object'
return serialize(results)
def index(dir, shadowed=None):
modpkgs = []
if shadowed is None: shadowed = {}
seen = {}
files = os.listdir(dir)
def found(name, ispackage, modpkgs=modpkgs, shadowed=shadowed, seen=seen):
if not seen.has_key(name):
modpkgs.append((name, '', ispackage, shadowed.has_key(name)))
seen[name] = 1
shadowed[name] = 1
# Package spam/__init__.py takes precedence over module spam.py.
for file in files:
path = os.path.join(dir, file)
if os.path.isdir(path):
init = os.path.join(path, '__init__.py')
initc = os.path.join(path, '__init__.pyc')
if os.path.isfile(init) or os.path.isfile(initc):
found(file, 1)
for file in files:
path = os.path.join(dir, file)
if file[:1] != '_' and os.path.isfile(path):
if file[-3:] == '.py':
found(file[:-3], 0)
elif file[-4:] == '.pyc':
found(file[:-4], 0)
elif file[-11:] == 'module.so':
found(file[:-11], 0)
elif file[-13:] == 'module.so.1':
found(file[:-13], 0)
modpkgs.sort()
contents = multicolumn(modpkgs, modpkglink)
results = section('%s' % dir,
'#ffffff', '#ee77aa', contents)
return serialize(results)
if __name__ == '__main__':
import os
modnames = []
for arg in sys.argv[1:]:
if os.path.isdir(arg):
for file in os.listdir(arg):
if file[-3:] == '.py' and file[:-3] not in modnames:
modnames.append(file[:-3])
elif file[-4:] == '.pyc' and file[:-4] not in modnames:
modnames.append(file[:-4])
elif file[-9:] == 'module.so':
modnames.append(file[:-9])
else:
if arg[-3:] == '.py' and arg[:-3] not in modnames:
modnames.append(arg[:-3])
elif arg[-4:] == '.pyc' and arg[:-4] not in modnames:
modnames.append(arg[:-4])
else:
modnames.append(arg)
for modname in modnames:
try:
module = __import__(modname)
except:
print 'failed to import %s' % modname
else:
file = open(modname + '.html', 'w')
file.write(
"""