Printing Protocol¶
The protocol for delegating how a graphtage.TreeNode
or graphtage.Edit
is printed in
graphtage.GraphtageFormatter.print()
is as follows:
- Determine the actual object to be printed:
- If
node_or_edit
is angraphtage.Edit
: If
with_edits
, then choose the editOtherwise, choose
node_or_edit.from_node
- If
- If
node_or_edit
is agraphtage.TreeNode
: - If
with_edits
and the node is edited and has a non-zero cost, then choose
node_or_edit.edit
:node_or_edit.edit is not None and node_or_edit.edit.bounds().lower_bound > 0
- If
Otherwise choose
node_or_edit
- If
- If the chosen object is an edit:
See if there is a specialized formatter for this edit by calling
graphtage.formatter.Formatter.get_formatter()
If so, delegate to that formatter and return.
If not, try calling the edit’s
graphtage.Edit.print()
method. IfNotImplementedError
is not raised, return.
- If the chosen object is a node, or if we failed to find a printer for the edit:
See if there is a specialized formatter for this node by calling
graphtage.formatter.Formatter.get_formatter()
If so, delegate to that formatter and return.
If not, print a debug warning and delegate to the node’s internal print implementation
graphtage.TreeNode.print()
.
This is implemented in graphtage.GraphtageFormatter.print()
. See the Formatting Protocol for how formatters
are chosen.