Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
pydoc._PlainTextDoc Class Reference
Inheritance diagram for pydoc._PlainTextDoc:
Inheritance graph
[legend]
Collaboration diagram for pydoc._PlainTextDoc:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def bold
def indent
def section
def formattree
def docmodule
def docclass
def formatvalue
def docroutine
def docproperty
def docdata
def docother
def document
def fail
def getdocloc

Public Attributes

 needone

Static Public Attributes

 repr = _repr_instance.repr
 docmodule = docclassdocroutinedocotherdocpropertydocdatafail
tuple PYTHONDOCS

Detailed Description

Subclass of TextDoc which overrides string styling

Definition at line 1337 of file pydoc.py.


Member Function Documentation

def pydoc._PlainTextDoc.bold (   self,
  text 
)
Format a string in bold by overstriking.

Reimplemented from pydoc.TextDoc.

Definition at line 1339 of file pydoc.py.

01339 
01340     def bold(self, text):
01341         return text
01342 
01343 # --------------------------------------------------------- user interfaces

def pydoc.TextDoc.docclass (   self,
  object,
  name = None,
  mod = None,
  ignored 
) [inherited]
Produce text documentation for a given class object.

Definition at line 1137 of file pydoc.py.

01137 
01138     def docclass(self, object, name=None, mod=None, *ignored):
01139         """Produce text documentation for a given class object."""
01140         realname = object.__name__
01141         name = name or realname
01142         bases = object.__bases__
01143 
01144         def makename(c, m=object.__module__):
01145             return classname(c, m)
01146 
01147         if name == realname:
01148             title = 'class ' + self.bold(realname)
01149         else:
01150             title = self.bold(name) + ' = class ' + realname
01151         if bases:
01152             parents = map(makename, bases)
01153             title = title + '(%s)' % ', '.join(parents)
01154 
01155         doc = getdoc(object)
01156         contents = doc and [doc + '\n'] or []
01157         push = contents.append
01158 
01159         # List the mro, if non-trivial.
01160         mro = deque(inspect.getmro(object))
01161         if len(mro) > 2:
01162             push("Method resolution order:")
01163             for base in mro:
01164                 push('    ' + makename(base))
01165             push('')
01166 
01167         # Cute little class to pump out a horizontal rule between sections.
01168         class HorizontalRule:
01169             def __init__(self):
01170                 self.needone = 0
01171             def maybe(self):
01172                 if self.needone:
01173                     push('-' * 70)
01174                 self.needone = 1
01175         hr = HorizontalRule()
01176 
01177         def spill(msg, attrs, predicate):
01178             ok, attrs = _split_list(attrs, predicate)
01179             if ok:
01180                 hr.maybe()
01181                 push(msg)
01182                 for name, kind, homecls, value in ok:
01183                     push(self.document(getattr(object, name),
01184                                        name, mod, object))
01185             return attrs
01186 
01187         def spilldescriptors(msg, attrs, predicate):
01188             ok, attrs = _split_list(attrs, predicate)
01189             if ok:
01190                 hr.maybe()
01191                 push(msg)
01192                 for name, kind, homecls, value in ok:
01193                     push(self._docdescriptor(name, value, mod))
01194             return attrs
01195 
01196         def spilldata(msg, attrs, predicate):
01197             ok, attrs = _split_list(attrs, predicate)
01198             if ok:
01199                 hr.maybe()
01200                 push(msg)
01201                 for name, kind, homecls, value in ok:
01202                     if hasattr(value, '__call__') or inspect.isdatadescriptor(value):
01203                         doc = getdoc(value)
01204                     else:
01205                         doc = None
01206                     push(self.docother(getattr(object, name),
01207                                        name, mod, maxlen=70, doc=doc) + '\n')
01208             return attrs
01209 
01210         attrs = [(name, kind, cls, value)
01211                  for name, kind, cls, value in classify_class_attrs(object)
01212                  if visiblename(name, obj=object)]
01213 
01214         while attrs:
01215             if mro:
01216                 thisclass = mro.popleft()
01217             else:
01218                 thisclass = attrs[0][2]
01219             attrs, inherited = _split_list(attrs, lambda t: t[2] is thisclass)
01220 
01221             if thisclass is builtins.object:
01222                 attrs = inherited
01223                 continue
01224             elif thisclass is object:
01225                 tag = "defined here"
01226             else:
01227                 tag = "inherited from %s" % classname(thisclass,
01228                                                       object.__module__)
01229 
01230             # Sort attrs by name.
01231             attrs.sort()
01232 
01233             # Pump out the attrs, segregated by kind.
01234             attrs = spill("Methods %s:\n" % tag, attrs,
01235                           lambda t: t[1] == 'method')
01236             attrs = spill("Class methods %s:\n" % tag, attrs,
01237                           lambda t: t[1] == 'class method')
01238             attrs = spill("Static methods %s:\n" % tag, attrs,
01239                           lambda t: t[1] == 'static method')
01240             attrs = spilldescriptors("Data descriptors %s:\n" % tag, attrs,
01241                                      lambda t: t[1] == 'data descriptor')
01242             attrs = spilldata("Data and other attributes %s:\n" % tag, attrs,
01243                               lambda t: t[1] == 'data')
01244             assert attrs == []
01245             attrs = inherited
01246 
01247         contents = '\n'.join(contents)
01248         if not contents:
01249             return title + '\n'
01250         return title + '\n' + self.indent(contents.rstrip(), ' |  ') + '\n'

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.TextDoc.docdata (   self,
  object,
  name = None,
  mod = None,
  cl = None 
) [inherited]
Produce text documentation for a data descriptor.

Definition at line 1321 of file pydoc.py.

01321 
01322     def docdata(self, object, name=None, mod=None, cl=None):
01323         """Produce text documentation for a data descriptor."""
01324         return self._docdescriptor(name, object, mod)

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.TextDoc.docmodule (   self,
  object,
  name = None,
  mod = None 
) [inherited]
Produce text documentation for a given module object.

Definition at line 1037 of file pydoc.py.

01037 
01038     def docmodule(self, object, name=None, mod=None):
01039         """Produce text documentation for a given module object."""
01040         name = object.__name__ # ignore the passed-in name
01041         synop, desc = splitdoc(getdoc(object))
01042         result = self.section('NAME', name + (synop and ' - ' + synop))
01043         all = getattr(object, '__all__', None)
01044         docloc = self.getdocloc(object)
01045         if docloc is not None:
01046             result = result + self.section('MODULE REFERENCE', docloc + """
01047 
01048 The following documentation is automatically generated from the Python source
01049 files.  It may be incomplete, incorrect or include features that are considered
01050 implementation detail and may vary between Python implementations.  When in
01051 doubt, consult the module reference at the location listed above.
01052 """)
01053 
01054         if desc:
01055             result = result + self.section('DESCRIPTION', desc)
01056 
01057         classes = []
01058         for key, value in inspect.getmembers(object, inspect.isclass):
01059             # if __all__ exists, believe it.  Otherwise use old heuristic.
01060             if (all is not None
01061                 or (inspect.getmodule(value) or object) is object):
01062                 if visiblename(key, all, object):
01063                     classes.append((key, value))
01064         funcs = []
01065         for key, value in inspect.getmembers(object, inspect.isroutine):
01066             # if __all__ exists, believe it.  Otherwise use old heuristic.
01067             if (all is not None or
01068                 inspect.isbuiltin(value) or inspect.getmodule(value) is object):
01069                 if visiblename(key, all, object):
01070                     funcs.append((key, value))
01071         data = []
01072         for key, value in inspect.getmembers(object, isdata):
01073             if visiblename(key, all, object):
01074                 data.append((key, value))
01075 
01076         modpkgs = []
01077         modpkgs_names = set()
01078         if hasattr(object, '__path__'):
01079             for importer, modname, ispkg in pkgutil.iter_modules(object.__path__):
01080                 modpkgs_names.add(modname)
01081                 if ispkg:
01082                     modpkgs.append(modname + ' (package)')
01083                 else:
01084                     modpkgs.append(modname)
01085 
01086             modpkgs.sort()
01087             result = result + self.section(
01088                 'PACKAGE CONTENTS', '\n'.join(modpkgs))
01089 
01090         # Detect submodules as sometimes created by C extensions
01091         submodules = []
01092         for key, value in inspect.getmembers(object, inspect.ismodule):
01093             if value.__name__.startswith(name + '.') and key not in modpkgs_names:
01094                 submodules.append(key)
01095         if submodules:
01096             submodules.sort()
01097             result = result + self.section(
01098                 'SUBMODULES', '\n'.join(submodules))
01099 
01100         if classes:
01101             classlist = [value for key, value in classes]
01102             contents = [self.formattree(
01103                 inspect.getclasstree(classlist, 1), name)]
01104             for key, value in classes:
01105                 contents.append(self.document(value, key, name))
01106             result = result + self.section('CLASSES', '\n'.join(contents))
01107 
01108         if funcs:
01109             contents = []
01110             for key, value in funcs:
01111                 contents.append(self.document(value, key, name))
01112             result = result + self.section('FUNCTIONS', '\n'.join(contents))
01113 
01114         if data:
01115             contents = []
01116             for key, value in data:
01117                 contents.append(self.docother(value, key, name, maxlen=70))
01118             result = result + self.section('DATA', '\n'.join(contents))
01119 
01120         if hasattr(object, '__version__'):
01121             version = str(object.__version__)
01122             if version[:11] == '$' + 'Revision: ' and version[-1:] == '$':
01123                 version = version[11:-1].strip()
01124             result = result + self.section('VERSION', version)
01125         if hasattr(object, '__date__'):
01126             result = result + self.section('DATE', str(object.__date__))
01127         if hasattr(object, '__author__'):
01128             result = result + self.section('AUTHOR', str(object.__author__))
01129         if hasattr(object, '__credits__'):
01130             result = result + self.section('CREDITS', str(object.__credits__))
01131         try:
01132             file = inspect.getabsfile(object)
01133         except TypeError:
01134             file = '(built-in)'
01135         result = result + self.section('FILE', file)
01136         return result

Here is the call graph for this function:

def pydoc.TextDoc.docother (   self,
  object,
  name = None,
  mod = None,
  parent = None,
  maxlen = None,
  doc = None 
) [inherited]
Produce text documentation for a data object.

Definition at line 1325 of file pydoc.py.

01325 
01326     def docother(self, object, name=None, mod=None, parent=None, maxlen=None, doc=None):
01327         """Produce text documentation for a data object."""
01328         repr = self.repr(object)
01329         if maxlen:
01330             line = (name and name + ' = ' or '') + repr
01331             chop = maxlen - len(line)
01332             if chop < 0: repr = repr[:chop] + '...'
01333         line = (name and self.bold(name) + ' = ' or '') + repr
01334         if doc is not None:
01335             line += '\n' + self.indent(str(doc))
01336         return line

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.TextDoc.docproperty (   self,
  object,
  name = None,
  mod = None,
  cl = None 
) [inherited]
Produce text documentation for a property.

Definition at line 1317 of file pydoc.py.

01317 
01318     def docproperty(self, object, name=None, mod=None, cl=None):
01319         """Produce text documentation for a property."""
01320         return self._docdescriptor(name, object, mod)

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.TextDoc.docroutine (   self,
  object,
  name = None,
  mod = None,
  cl = None 
) [inherited]
Produce text documentation for a function or method object.

Definition at line 1255 of file pydoc.py.

01255 
01256     def docroutine(self, object, name=None, mod=None, cl=None):
01257         """Produce text documentation for a function or method object."""
01258         realname = object.__name__
01259         name = name or realname
01260         note = ''
01261         skipdocs = 0
01262         if inspect.ismethod(object):
01263             imclass = object.__self__.__class__
01264             if cl:
01265                 if imclass is not cl:
01266                     note = ' from ' + classname(imclass, mod)
01267             else:
01268                 if object.__self__ is not None:
01269                     note = ' method of %s instance' % classname(
01270                         object.__self__.__class__, mod)
01271                 else:
01272                     note = ' unbound %s method' % classname(imclass,mod)
01273             object = object.__func__
01274 
01275         if name == realname:
01276             title = self.bold(realname)
01277         else:
01278             if (cl and realname in cl.__dict__ and
01279                 cl.__dict__[realname] is object):
01280                 skipdocs = 1
01281             title = self.bold(name) + ' = ' + realname
01282         if inspect.isfunction(object):
01283             args, varargs, varkw, defaults, kwonlyargs, kwdefaults, ann = \
01284               inspect.getfullargspec(object)
01285             argspec = inspect.formatargspec(
01286                 args, varargs, varkw, defaults, kwonlyargs, kwdefaults, ann,
01287                 formatvalue=self.formatvalue,
01288                 formatannotation=inspect.formatannotationrelativeto(object))
01289             if realname == '<lambda>':
01290                 title = self.bold(name) + ' lambda '
01291                 # XXX lambda's won't usually have func_annotations['return']
01292                 # since the syntax doesn't support but it is possible.
01293                 # So removing parentheses isn't truly safe.
01294                 argspec = argspec[1:-1] # remove parentheses
01295         else:
01296             argspec = '(...)'
01297         decl = title + argspec + note
01298 
01299         if skipdocs:
01300             return decl + '\n'
01301         else:
01302             doc = getdoc(object) or ''
01303             return decl + '\n' + (doc and self.indent(doc).rstrip() + '\n')

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.Doc.document (   self,
  object,
  name = None,
  args 
) [inherited]
Generate documentation for an object.

Definition at line 328 of file pydoc.py.

00328 
00329     def document(self, object, name=None, *args):
00330         """Generate documentation for an object."""
00331         args = (object, name) + args
00332         # 'try' clause is to attempt to handle the possibility that inspect
00333         # identifies something in a way that pydoc itself has issues handling;
00334         # think 'super' and how it is a descriptor (which raises the exception
00335         # by lacking a __name__ attribute) and an instance.
00336         if inspect.isgetsetdescriptor(object): return self.docdata(*args)
00337         if inspect.ismemberdescriptor(object): return self.docdata(*args)
00338         try:
00339             if inspect.ismodule(object): return self.docmodule(*args)
00340             if inspect.isclass(object): return self.docclass(*args)
00341             if inspect.isroutine(object): return self.docroutine(*args)
00342         except AttributeError:
00343             pass
00344         if isinstance(object, property): return self.docproperty(*args)
00345         return self.docother(*args)

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.Doc.fail (   self,
  object,
  name = None,
  args 
) [inherited]
Raise an exception for unimplemented types.

Definition at line 346 of file pydoc.py.

00346 
00347     def fail(self, object, name=None, *args):
00348         """Raise an exception for unimplemented types."""
00349         message = "don't know how to document object%s of type %s" % (
00350             name and ' ' + repr(name), type(object).__name__)
00351         raise TypeError(message)

def pydoc.TextDoc.formattree (   self,
  tree,
  modname,
  parent = None,
  prefix = '' 
) [inherited]
Render in text a class tree as returned by inspect.getclasstree().

Definition at line 1021 of file pydoc.py.

01021 
01022     def formattree(self, tree, modname, parent=None, prefix=''):
01023         """Render in text a class tree as returned by inspect.getclasstree()."""
01024         result = ''
01025         for entry in tree:
01026             if type(entry) is type(()):
01027                 c, bases = entry
01028                 result = result + prefix + classname(c, modname)
01029                 if bases and bases != (parent,):
01030                     parents = (classname(c, modname) for c in bases)
01031                     result = result + '(%s)' % ', '.join(parents)
01032                 result = result + '\n'
01033             elif type(entry) is type([]):
01034                 result = result + self.formattree(
01035                     entry, modname, c, prefix + '    ')
01036         return result

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.TextDoc.formatvalue (   self,
  object 
) [inherited]
Format an argument default value as text.

Definition at line 1251 of file pydoc.py.

01251 
01252     def formatvalue(self, object):
01253         """Format an argument default value as text."""
01254         return '=' + self.repr(object)

Here is the caller graph for this function:

def pydoc.Doc.getdocloc (   self,
  object 
) [inherited]
Return the location of module docs or None

Definition at line 354 of file pydoc.py.

00354 
00355     def getdocloc(self, object):
00356         """Return the location of module docs or None"""
00357 
00358         try:
00359             file = inspect.getabsfile(object)
00360         except TypeError:
00361             file = '(built-in)'
00362 
00363         docloc = os.environ.get("PYTHONDOCS", self.PYTHONDOCS)
00364 
00365         basedir = os.path.join(sys.exec_prefix, "lib",
00366                                "python%d.%d" %  sys.version_info[:2])
00367         if (isinstance(object, type(os)) and
00368             (object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
00369                                  'marshal', 'posix', 'signal', 'sys',
00370                                  '_thread', 'zipimport') or
00371              (file.startswith(basedir) and
00372               not file.startswith(os.path.join(basedir, 'site-packages')))) and
00373             object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
00374             if docloc.startswith("http://"):
00375                 docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__)
00376             else:
00377                 docloc = os.path.join(docloc, object.__name__ + ".html")
00378         else:
00379             docloc = None
00380         return docloc
00381 
00382 # -------------------------------------------- HTML documentation generator

Here is the call graph for this function:

Here is the caller graph for this function:

def pydoc.TextDoc.indent (   self,
  text,
  prefix = '    ' 
) [inherited]
Indent text by prepending a given prefix to each line.

Definition at line 1007 of file pydoc.py.

01007 
01008     def indent(self, text, prefix='    '):
01009         """Indent text by prepending a given prefix to each line."""
01010         if not text: return ''
01011         lines = [prefix + line for line in text.split('\n')]
01012         if lines: lines[-1] = lines[-1].rstrip()
01013         return '\n'.join(lines)

Here is the caller graph for this function:

def pydoc.TextDoc.section (   self,
  title,
  contents 
) [inherited]
Format a section with a given heading.

Definition at line 1014 of file pydoc.py.

01014 
01015     def section(self, title, contents):
01016         """Format a section with a given heading."""
01017         clean_contents = self.indent(contents).rstrip()
01018         return self.bold(title) + '\n' + clean_contents + '\n\n'

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

pydoc.Doc.docmodule = docclassdocroutinedocotherdocpropertydocdatafail [static, inherited]

Definition at line 352 of file pydoc.py.

pydoc.TextDoc.needone [inherited]

Definition at line 1169 of file pydoc.py.

tuple pydoc.Doc.PYTHONDOCS [static, inherited]
Initial value:
os.environ.get("PYTHONDOCS",
                                "http://docs.python.org/%d.%d/library"
                                % sys.version_info[:2])

Definition at line 324 of file pydoc.py.

pydoc.TextDoc.repr = _repr_instance.repr [static, inherited]

Definition at line 1001 of file pydoc.py.


The documentation for this class was generated from the following file: