Add an experimental mechanism to support extending the pprint formatting.

Partly responds to SF bug #505152.
This commit is contained in:
Fred Drake 2002-04-02 05:08:35 +00:00
parent 4993c51b94
commit aee113d368
3 changed files with 57 additions and 9 deletions

View file

@ -173,3 +173,26 @@ this returns false.
\begin{methoddesc}{isrecursive}{object}
Determine if the object requires a recursive representation.
\end{methoddesc}
This method is provided as a hook to allow subclasses to modify the
way objects are converted to strings. The default implementation uses
the internals of the \function{saferepr()} implementation.
\begin{methoddesc}{format}{object, context, maxlevels, level}
Returns three values: the formatted version of \var{object} as a
string, a flag indicating whether the result is readable, and a flag
indicating whether recursion was detected. The first argument is the
object to be presented. The second is a dictionary which contains the
\function{id()} of objects that are part of the current presentation
context (direct and indirect containers for \var{object} that are
affecting the presentation) as the keys; if an object needs to be
presented which is already represented in \var{context}, the third
return value should be true. Recursive calls to the \method{format()}
method should add additionaly entries for containers to this
dictionary. The fourth argument, \var{maxlevels}, gives the requested
limit to recursion; this will be \code{0} if there is no requested
limit. This argument should be passed unmodified to recursive calls.
The fourth argument, \var{level} gives the current level; recursive
calls should be passed a value less than that of the current call.
\versionadded{2.3}
\end{methoddesc}