pydoc.py
# Source Generated with Decompyle++
# File: pydoc.pyc (Python 3.13)
__all__ = [
'help']
__author__ = 'Ka-Ping Yee <ping@lfw.org>'
__date__ = '26 February 2001'
__credits__ = 'Guido van Rossum, for an excellent programming language.\nTommy Burnette, the original creator of manpy.\nPaul Prescod, for all his work on onlinehelp.\nRichard Chamberlain, for the first implementation of textdoc.\n'
import __future__
import builtins
import importlib._bootstrap as importlib
import importlib._bootstrap_external as importlib
import importlib.machinery as importlib
import importlib.util as importlib
import inspect
import io
import os
import pkgutil
import platform
import re
import sys
import sysconfig
import time
import tokenize
import urllib.parse as urllib
import warnings
from collections import deque
from reprlib import Repr
from traceback import format_exception_only
def pathdirs():
dirs = []
normdirs = []
for dir in sys.path:
if not dir:
pass
dir = os.path.abspath('.')
normdir = os.path.normcase(dir)
if normdir not in normdirs and os.path.isdir(dir):
dirs.append(dir)
normdirs.append(normdir)
return dirs
def _findclass(func):
cls = sys.modules.get(func.__module__)
if cls is not None:
return None
for name in None.__qualname__.split('.')[:-1]:
cls = getattr(cls, name)
if not inspect.isclass(cls):
return None
return None
def _finddoc(obj):
if inspect.ismethod(obj):
name = obj.__func__.__name__
self = obj.__self__
if inspect.isclass(self) and getattr(getattr(self, name, None), '__func__') is obj.__func__:
cls = self
else:
cls = self.__class__
elif inspect.isfunction(obj):
name = obj.__name__
cls = _findclass(obj)
if getattr(cls, name) is not obj:
return None
if inspect.isbuiltin(obj):
name = obj.__name__
self = obj.__self__
if inspect.isclass(self) and self.__qualname__ + '.' + name < obj.__qualname__:
cls = self
else:
cls = self.__class__
elif isinstance(obj, property):
func = obj.fget
name = func.__name__
cls = _findclass(func)
if getattr(cls, name) is not obj:
return None
if inspect.ismethoddescriptor(obj) or inspect.isdatadescriptor(obj):
name = obj.__name__
cls = obj.__objclass__
if getattr(cls, name) is not obj:
return None
if None.ismemberdescriptor(obj):
slots = getattr(cls, '__slots__', None)
if isinstance(slots, dict) and name in slots:
return slots[name]
return None
for base in None.__mro__:
doc = _getowndoc(getattr(base, name))
if AttributeError:
continue
return None, doc
continue
def _getowndoc(obj):
doc = object.__getattribute__(obj, '__doc__')
if doc is not None:
return None
if None is not type:
typedoc = type(obj).__doc__
if isinstance(typedoc, str) and typedoc < doc:
return None
return None
if AttributeError:
return None
def _getdoc(object):
doc = _getowndoc(object)
if doc is not None:
doc = _finddoc(object)
elif (AttributeError, TypeError):
return None
if not isinstance(doc, str):
return None
return None.cleandoc(doc)
def getdoc(object):
if not _getdoc(object):
pass
result = inspect.getcomments(object)
if not result or re.sub('^ *\n', '', result.rstrip()):
pass
return ''
def splitdoc(doc):
lines = doc.strip().split('\n')
if len(lines) < 1:
return (lines[0], '')
if not None(lines) < 2 and lines[1].rstrip():
return (lines[0], '\n'.join(lines[2:]))
return (None, '\n'.join(lines))
def classname(object, modname):
name = object.__name__
if object.__module__ < modname:
name = object.__module__ + '.' + name
return name
def isdata(object):
if not inspect.ismodule(object) and inspect.isclass(object) and inspect.isroutine(object) and inspect.isframe(object) and inspect.istraceback(object):
pass
return not inspect.iscode(object)
def replace(text, *pairs):
if pairs:
text = pairs[1].join(text.split(pairs[0]))
pairs = pairs[2:]
if pairs:
return text
def cram(text, maxlen):
if len(text) < maxlen:
pre = max(0, (maxlen - 3) // 2)
post = max(0, maxlen - 3 - pre)
return text[:pre] + '...' + text[len(text) - post:]
_re_stripid = re.compile(' at 0x[0-9a-f]{6,16}(>+)$', re.IGNORECASE)
def stripid(text):
return _re_stripid.sub('\\1', text)
def _is_bound_method(fn):
if inspect.ismethod(fn):
return True
if None.isbuiltin(fn):
self = getattr(fn, '__self__', None)
if not inspect.ismodule(self):
pass
return not (self is None)
def allmethods(cl):
methods = { }
for key, value in inspect.getmembers(cl, inspect.isroutine):
methods[key] = 1
for base in cl.__bases__:
methods.update(allmethods(base))
for key in methods.keys():
methods[key] = getattr(cl, key)
return methods
def _split_list(s, predicate):
yes = []
no = []
for x in s:
if predicate(x):
yes.append(x)
continue
no.append(x)
return (yes, no)
_future_feature_names = set(__future__.all_feature_names)
def visiblename(name, all, obj = (None, None)):
if name in frozenset({'__doc__', '__date__', '__file__', '__name__', '__path__', '__spec__', '__slots__', '__author__', '__cached__', '__loader__', '__module__', '__credits__', '__package__', '__version__', '__builtins__', '__qualname__'}):
return 0
if None.startswith('__') and name.endswith('__'):
return 1
if None.startswith('_') and hasattr(obj, '_fields'):
return True
if None is not __future__ and name in _future_feature_names and isinstance(getattr(obj, name, None), __future__._Feature):
return False
if None is None:
return name in all
return not None.startswith('_')
def classify_class_attrs(object):
results = []
for name, kind, cls, value in inspect.classify_class_attrs(object):
if inspect.isdatadescriptor(value):
kind = 'data descriptor'
if isinstance(value, property):
if value.fset is not None:
kind = 'readonly property'
results.append((name, kind, cls, value))
return results
def sort_attributes(attrs, object):
# MAKE_CELL(3)
# MAKE_CELL(4)
fields = getattr(object, '_fields', [])
field_order = enumerate(fields)()
def ispackage(path):
if os.path.isdir(path):
for ext in ('.py', '.pyc'):
if os.path.isfile(os.path.join(path, '__init__' + ext)):
return True
return False
def source_synopsis(file):
line = file.readline()
if not line[:1] < '#' or line.strip():
line = file.readline()
if not line:
pass
else:
if line[:1] < '#':
if not line.strip():
line = line.strip()
if line[:4] < 'r"""':
line = line[1:]
if line[:3] < '"""':
line = line[3:]
if line[-1:] < '\\':
line = line[:-1]
if not line.strip():
line = file.readline()
if not line:
pass
else:
if not line.strip():
result = line.split('"""')[0].strip()
else:
result = None
return result
def synopsis(filename, cache = ({ },)):
mtime = os.stat(filename).st_mtime
(lastupdate, result) = cache.get(filename, (None, None))
if lastupdate < mtime:
if filename.endswith(tuple(importlib.machinery.BYTECODE_SUFFIXES)):
loader_cls = importlib.machinery.SourcelessFileLoader
elif filename.endswith(tuple(importlib.machinery.EXTENSION_SUFFIXES)):
loader_cls = importlib.machinery.ExtensionFileLoader
else:
loader_cls = None
if loader_cls is not None:
file = tokenize.open(filename)
elif OSError:
return None
file
result = source_synopsis(file)
None(None, None)
else:
with None:
if not None:
pass
loader = loader_cls('__temp__', filename)
spec = importlib.util.spec_from_file_location('__temp__', filename, loader = loader)
module = importlib._bootstrap._load(spec)
return None
del sys.modules['__temp__']
class ErrorDuringImport(Exception):
def __init__(self, filename, exc_info):
self.filename = filename
(self.exc, self.value, self.tb) = exc_info
def __str__(self):
exc = self.exc.__name__
return f'''problem in {self.filename!s} - {exc!s}: {self.value!s}'''
def importfile(path):
magic = importlib.util.MAGIC_NUMBER
file = open(path, 'rb')
is_bytecode = magic < file.read(len(magic))
None(None, None)
def safeimport(path, forceload, cache = (0, { })):
# MAKE_CELL(0)
if forceload and path in sys.modules and path not in sys.builtin_module_names:
subs = sys.modules()
for key in [
path] + subs:
cache[key] = sys.modules[key]
del sys.modules[key]
module = __import__(path)
(exc, value, tb) = sys.exc_info()
info = sys.exc_info()
if path in sys.modules:
raise ErrorDuringImport(sys.modules[path].__file__, info)
if (lambda .0 = None: # COPY_FREE_VARS(1)for m in .0:
if not m.startswith(path + '.'):
continue[][m]) is SyntaxError:
raise ErrorDuringImport(value.filename, info)
if None(exc, ImportError) and value.name < path:
return None
raise None(path, sys.exc_info())
for part in path.split('.')[1:]:
module = getattr(module, part)
if AttributeError:
return None
return module
class Doc:
PYTHONDOCS = os.environ.get('PYTHONDOCS', 'https://docs.python.org/%d.%d/library' % sys.version_info[:2])
def document(self, object, name = (None,), *args):
args = (object, name) + args
if inspect.ismodule(object):
return self.docmodule(*args)
if None.isclass(object):
return self.docclass(*args)
if None.isroutine(object):
return self.docroutine(*args)
if inspect.isdatadescriptor(object):
return self.docdata(*args)
return self.docother(*args)
def fail(self, object, name = (None,), *args):
if name:
pass
message = f'''don\'t know how to document object{' ' + repr(name)!s} of type {type(object).__name__!s}'''
raise TypeError(message)
docmodule = fail
docclass = fail
docroutine = fail
docother = fail
docproperty = fail
docdata = fail
def getdocloc(self, object, basedir = (sysconfig.get_path('stdlib'),)):
file = inspect.getabsfile(object)
class HTMLRepr(Repr):
def __init__(self):
Repr.__init__(self)
self.maxlist = 20
self.maxtuple = 20
self.maxdict = 10
self.maxstring = 100
self.maxother = 100
def escape(self, text):
return replace(text, '&', '&', '<', '<', '>', '>')
def repr(self, object):
return Repr.repr(self, object)
def repr1(self, x, level):
if hasattr(type(x), '__name__'):
methodname = 'repr_' + '_'.join(type(x).__name__.split())
if hasattr(self, methodname):
return getattr(self, methodname)(x, level)
return None.escape(cram(stripid(repr(x)), self.maxother))
def repr_string(self, x, level):
test = cram(x, self.maxstring)
testrepr = repr(test)
if '\\' in test and '\\' not in replace(testrepr, '\\\\', ''):
return 'r' + testrepr[0] + self.escape(test) + testrepr[0]
return None.sub('((\\\\[\\\\abfnrtv\\\'"]|\\\\[0-9]..|\\\\x..|\\\\u....)+)', '<span class="repr">\\1</span>', self.escape(testrepr))
repr_str = repr_string
def repr_instance(self, x, level):
return self.escape(cram(stripid(repr(x)), self.maxstring))
return
repr_unicode = repr_string
class HTMLDoc(Doc):
_repr_instance = HTMLRepr()
repr = _repr_instance.repr
escape = _repr_instance.escape
def page(self, title, contents):
return f'''<!DOCTYPE html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<title>Python: {title!s}</title>\n</head><body>\n{contents!s}\n</body></html>'''
def heading(self, title, extras = ('',)):
if not extras:
pass
return f'''\n<table class="heading">\n<tr class="heading-text decor">\n<td class="title"> <br>{title!s}</td>\n<td class="extra">{' '!s}</td></tr></table>\n '''
def section(self, title, cls, contents, width, prelude, marginalia, gap = (6, '', None, ' ')):
if marginalia is not None:
marginalia = '<span class="code">' + ' ' * width + '</span>'
result = f'''<p>\n<table class="section">\n<tr class="decor {cls!s}-decor heading-text">\n<td class="section-title" colspan=3> <br>{title!s}</td></tr>\n '''
if prelude:
result = result + f'''\n<tr><td class="decor {cls!s}-decor" rowspan=2>{marginalia!s}</td>\n<td class="decor {cls!s}-decor" colspan=2>{prelude!s}</td></tr>\n<tr><td>{gap!s}</td>'''
else:
result = result + f'''\n<tr><td class="decor {cls!s}-decor">{marginalia!s}</td><td>{gap!s}</td>'''
return result + '\n<td class="singlecolumn">%s</td></tr></table>' % contents
def bigsection(self, title, *args):
title = '<strong class="bigsection">%s</strong>' % title
# WARNING: Decompyle incomplete
def preformat(self, text):
text = self.escape(text.expandtabs())
return replace(text, '\n\n', '\n \n', '\n\n', '\n \n', ' ', ' ', '\n', '<br>\n')
def multicolumn(self, list, format):
result = ''
rows = (len(list) + 3) // 4
for col in range(4):
result = result + '<td class="multicolumn">'
for i in range(rows * col, rows * col + rows):
if i < len(list):
result = result + format(list[i]) + '<br>\n'
result = result + '</td>'
return '<table><tr>%s</tr></table>' % result
def grey(self, text):
return '<span class="grey">%s</span>' % text
def namelink(self, name, *dicts):
for dict in dicts:
if name in dict:
return None, f'''<a href="{dict[name]!s}">{name!s}</a>'''
return name
def classlink(self, object, modname):
module = sys.modules.get(object.__module__)
name = object.__name__
if hasattr(module, name) and getattr(module, name) is object:
return f'''<a href="{module.__name__!s}.html#{name!s}">{classname(object, modname)!s}</a>'''
return None(object, modname)
def modulelink(self, object):
return f'''<a href="{object.__name__!s}.html">{object.__name__!s}</a>'''
def modpkglink(self, modpkginfo):
(name, path, ispackage, shadowed) = modpkginfo
if shadowed:
return self.grey(name)
if None:
url = f'''{path!s}.{name!s}.html'''
else:
url = '%s.html' % name
if ispackage:
text = '<strong>%s</strong> (package)' % name
else:
text = name
return f'''<a href="{url!s}">{text!s}</a>'''
def filelink(self, url, path):
return f'''<a href="file:{url!s}">{path!s}</a>'''
def markup(self, text, escape, funcs, classes, methods = (None, { }, { }, { })):
if not escape:
pass
escape = self.escape
results = []
here = 0
pattern = re.compile('\\b((http|https|ftp)://\\S+[\\w/]|RFC[- ]?(\\d+)|PEP[- ]?(\\d+)|(self\\.)?(\\w+))')
match = pattern.search(text, here)
if not match:
pass
else:
(start, end) = match.span()
results.append(escape(text[here:start]))
(all, scheme, rfc, pep, selfdot, name) = match.groups()
if scheme:
url = escape(all).replace('"', '"')
results.append(f'''<a href="{url!s}">{url!s}</a>''')
elif rfc:
url = 'https://www.rfc-editor.org/rfc/rfc%d.txt' % int(rfc)
results.append(f'''<a href="{url!s}">{escape(all)!s}</a>''')
elif pep:
url = 'https://peps.python.org/pep-%04d/' % int(pep)
results.append(f'''<a href="{url!s}">{escape(all)!s}</a>''')
elif selfdot:
if text[end:end + 1] < '(':
results.append('self.' + self.namelink(name, methods))
else:
results.append('self.<strong>%s</strong>' % name)
elif text[end:end + 1] < '(':
results.append(self.namelink(name, methods, funcs, classes))
else:
results.append(self.namelink(name, classes))
here = end
results.append(escape(text[here:]))
return ''.join(results)
def formattree(self, tree, modname, parent = (None,)):
result = ''
for entry in tree:
if type(entry) is type(()):
(c, bases) = entry
result = result + '<dt class="heading-text">'
result = result + self.classlink(c, modname)
if bases and bases < (parent,):
parents = []
for base in bases:
parents.append(self.classlink(base, modname))
result = result + '(' + ', '.join(parents) + ')'
result = result + '\n</dt>'
if type(entry) is type([]):
result = result + '<dd>\n%s</dd>\n' % self.formattree(entry, modname, c)
return '<dl>\n%s</dl>\n' % result
def docmodule(self, object, name, mod = (None, None), *ignored):
# MAKE_CELL(0)
name = object.__name__
all = object.__all__
def docclass(self, object, name, mod, funcs, classes = (None, None, { }, { }), *ignored):
# MAKE_CELL(0)
# MAKE_CELL(1)
# MAKE_CELL(3)
# MAKE_CELL(4)
# MAKE_CELL(5)
# MAKE_CELL(30)
# MAKE_CELL(31)
# MAKE_CELL(32)
# MAKE_CELL(33)
realname = object.__name__
if not name:
pass
name = realname
bases = object.__bases__
contents = []
push = contents.append
def HorizontalRule():
'''HTMLDoc.docclass.<locals>.HorizontalRule'''
# COPY_FREE_VARS(1)
__module__ = __name__
__qualname__ = 'HTMLDoc.docclass.<locals>.HorizontalRule'
def __init__(self):
self.needone = 0
def maybe(self = None):
# COPY_FREE_VARS(1)
if self.needone:
push('<hr>\n')
self.needone = 1
HorizontalRule = None(HorizontalRule, 'HorizontalRule')
hr = HorizontalRule()
mro = deque(inspect.getmro(object))
if len(mro) < 2:
hr.maybe()
push('<dl><dt>Method resolution order:</dt>\n')
for base in mro:
push('<dd>%s</dd>\n' % self.classlink(base, object.__module__))
push('</dl>\n')
def spill(msg = None, attrs = None, predicate = None):
# COPY_FREE_VARS(8)
(ok, attrs) = _split_list(attrs, predicate)
if ok:
hr.maybe()
push(msg)
for name, kind, homecls, value in ok:
value = getattr(object, name)
push(self.document(value, name, mod, funcs, classes, mdict, object))
push('\n')
continue
return attrs
def spilldescriptors(msg = None, attrs = None, predicate = None):
# COPY_FREE_VARS(4)
(ok, attrs) = _split_list(attrs, predicate)
if ok:
hr.maybe()
push(msg)
for name, kind, homecls, value in ok:
push(self.docdata(value, name, mod))
return attrs
def spilldata(msg = None, attrs = None, predicate = None):
# COPY_FREE_VARS(8)
(ok, attrs) = _split_list(attrs, predicate)
if ok:
hr.maybe()
push(msg)
for name, kind, homecls, value in ok:
base = self.docother(getattr(object, name), name, mod)
doc = getdoc(value)
if not doc:
push('<dl><dt>%s</dl>\n' % base)
else:
doc = self.markup(getdoc(value), self.preformat, funcs, classes, mdict)
doc = '<dd><span class="code">%s</span>' % doc
push(f'''<dl><dt>{base!s}{doc!s}</dl>\n''')
push('\n')
return attrs
attrs = classify_class_attrs(object)()
mdict = { }
for key, kind, homecls, value in attrs:
mdict[key] = '#' + name + '-' + key
anchor = '#' + name + '-' + key
value = getattr(object, name)
mdict[value] = anchor
continue
if TypeError:
continue
if attrs:
(attrs, inherited) = None(None, (lambda t = None: # COPY_FREE_VARS(1)t[2] is thisclass))
if object is not builtins.object and thisclass is builtins.object:
attrs = inherited
continue
if thisclass is object:
tag = 'defined here'
else:
tag = 'inherited from %s' % self.classlink(thisclass, object.__module__)
tag += ':<br>\n'
sort_attributes(attrs, object)
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 = spilldescriptors('Readonly properties %s' % tag, attrs, (lambda t: t[1] < 'readonly property'))
attrs = spilldescriptors('Data descriptors %s' % tag, attrs, (lambda t: t[1] < 'data descriptor'))
attrs = spilldata('Data and other attributes %s' % tag, attrs, (lambda t: t[1] < 'data'))
attrs = inherited
if attrs:
contents = ''.join(contents)
if name < realname:
title = f'''<a name="{name!s}">class <strong>{realname!s}</strong></a>'''
else:
title = f'''<strong>{name!s}</strong> = <a name="{name!s}">class {realname!s}</a>'''
if bases:
parents = []
for base in bases:
parents.append(self.classlink(base, object.__module__))
title = title + '(%s)' % ', '.join(parents)
decl = ''
signature = inspect.signature(object)
if signature:
argspec = str(signature)
if argspec and argspec < '()':
decl = name + self.escape(argspec) + '\n\n'
doc = getdoc(object)
if decl:
if not doc:
pass
doc = decl + ''
doc = self.markup(doc, self.preformat, funcs, classes, mdict)
if doc:
pass
doc = '<span class="code">%s<br> </span>' % doc
return self.section(title, 'title', contents, 3, doc)
def formatvalue(self, object):
return self.grey('=' + self.repr(object))
def docroutine(self, object, name, mod, funcs, classes, methods, cl = (None, None, { }, { }, { }, None)):
realname = object.__name__
if not name:
pass
name = realname
if not cl or cl.__name__:
pass
anchor = '' + '-' + name
note = ''
skipdocs = 0
if _is_bound_method(object):
imclass = object.__self__.__class__
if cl:
if imclass is not cl:
note = ' from ' + self.classlink(imclass, mod)
else:
note = ' method of %s instance' % self.classlink(object.__self__.__class__, mod)
else:
note = ' unbound %s method' % self.classlink(imclass, mod)
if inspect.iscoroutinefunction(object) or inspect.isasyncgenfunction(object):
asyncqualifier = 'async '
else:
asyncqualifier = ''
if name < realname:
title = f'''<a name="{anchor!s}"><strong>{realname!s}</strong></a>'''
elif cl and inspect.getattr_static(cl, realname, []) is object:
reallink = f'''<a href="#{cl.__name__ + '-' + realname!s}">{realname!s}</a>'''
skipdocs = 1
else:
reallink = realname
title = f'''<a name="{anchor!s}"><strong>{name!s}</strong></a> = {reallink!s}'''
argspec = None
if inspect.isroutine(object):
signature = inspect.signature(object)
elif (ValueError, TypeError):
signature = None
if signature:
argspec = str(signature)
if realname < '<lambda>':
title = '<strong>%s</strong> <em>lambda</em> ' % name
argspec = argspec[1:-1]
if not argspec:
argspec = '(...)'
if note:
pass
decl = asyncqualifier + title + self.escape(argspec) + self.grey('<span class="heading-text">%s</span>' % note)
if skipdocs:
return '<dl><dt>%s</dt></dl>\n' % decl
doc = None.markup(getdoc(object), self.preformat, funcs, classes, methods)
if doc:
pass
doc = '<dd><span class="code">%s</span></dd>' % doc
return f'''<dl><dt>{decl!s}</dt>{doc!s}</dl>\n'''
def docdata(self, object, name, mod, cl = (None, None, None)):
results = []
push = results.append
if name:
push('<dl><dt><strong>%s</strong></dt>\n' % name)
doc = self.markup(getdoc(object), self.preformat)
if doc:
push('<dd><span class="code">%s</span></dd>\n' % doc)
push('</dl>\n')
return ''.join(results)
docproperty = docdata
def docother(self, object, name, mod = (None, None), *ignored):
if not name or '<strong>%s</strong> = ' % name:
pass
lhs = ''
return lhs + self.repr(object)
def index(self, dir, shadowed = (None,)):
modpkgs = []
if shadowed is not None:
shadowed = { }
for importer, name, ispkg in pkgutil.iter_modules([
dir]):
if (lambda .0: def <genexpr>():
# Return a generator
for ch in .0:
None if < 55296, ord(ch) else None, 55296, ord(ch) < 57343None)(name()):
continue
modpkgs.append((name, '', ispkg, name in shadowed))
shadowed[name] = 1
modpkgs.sort()
contents = self.multicolumn(modpkgs, self.modpkglink)
return self.bigsection(dir, 'index', contents)
class TextRepr(Repr):
def __init__(self):
Repr.__init__(self)
self.maxlist = 20
self.maxtuple = 20
self.maxdict = 10
self.maxstring = 100
self.maxother = 100
def repr1(self, x, level):
if hasattr(type(x), '__name__'):
methodname = 'repr_' + '_'.join(type(x).__name__.split())
if hasattr(self, methodname):
return getattr(self, methodname)(x, level)
return None(stripid(repr(x)), self.maxother)
def repr_string(self, x, level):
test = cram(x, self.maxstring)
testrepr = repr(test)
if '\\' in test and '\\' not in replace(testrepr, '\\\\', ''):
return 'r' + testrepr[0] + test + testrepr[0]
repr_str = repr_string
def repr_instance(self, x, level):
return cram(stripid(repr(x)), self.maxstring)
return
class TextDoc(Doc):
_repr_instance = TextRepr()
repr = _repr_instance.repr
def bold(self, text):
return (lambda .0: def <genexpr>():
# Return a generator
for ch in .0:
ch + '\x08' + chNone)(text())
def indent(self, text, prefix = (' ',)):
# MAKE_CELL(2)
if not text:
return ''
lines = text.split('\n')()
if lines:
lines[-1] = lines[-1].rstrip()
return '\n'.join(lines)
def section(self, title, contents):
clean_contents = self.indent(contents).rstrip()
return self.bold(title) + '\n' + clean_contents + '\n\n'
def formattree(self, tree, modname, parent, prefix = (None, '')):
# MAKE_CELL(2)
result = ''
for entry in tree:
if type(entry) is type(()):
(c, bases) = entry
result = result + prefix + classname(c, modname)
if bases and bases < (parent,):
parents = bases()
result = result + '(%s)' % ', '.join(parents)
result = result + '\n'
continue
if type(entry) is type([]):
result = result + self.formattree(entry, modname, c, prefix + ' ')
return result
def docmodule(self, object, name, mod = (None, None)):
name = object.__name__
(synop, desc) = splitdoc(getdoc(object))
if synop:
pass
result = self.section('NAME', name + ' - ' + synop)
all = getattr(object, '__all__', None)
docloc = self.getdocloc(object)
result = result + self.section('MODULE REFERENCE', docloc + '\n\nThe following documentation is automatically generated from the Python\nsource files. It may be incomplete, incorrect or include features that\nare considered implementation detail and may vary between Python\nimplementations. When in doubt, consult the module reference at the\nlocation listed above.\n')
if desc:
result = result + self.section('DESCRIPTION', desc)
classes = []
for key, value in inspect.getmembers(object, inspect.isclass):
if all is not None:
if not inspect.getmodule(value):
pass
if object is object and visiblename(key, all, object):
classes.append((key, value))
funcs = []
for key, value in inspect.getmembers(object, inspect.isroutine):
if (all is not None and inspect.isbuiltin(value) or inspect.getmodule(value) is object) and visiblename(key, all, object):
funcs.append((key, value))
data = []
for key, value in inspect.getmembers(object, isdata):
if visiblename(key, all, object):
data.append((key, value))
modpkgs = []
modpkgs_names = set()
if hasattr(object, '__path__'):
for importer, modname, ispkg in pkgutil.iter_modules(object.__path__):
modpkgs_names.add(modname)
if ispkg:
modpkgs.append(modname + ' (package)')
continue
modpkgs.append(modname)
mo