def dumpDocumentTree( self, document: ValueTreeNode, tree_traversal_options: Optional[TreeTraversalOptions] = None, generator_options: Optional[GeneratorOptions] = None, ) -> str: """Dump the document tree as a string""" generator_options = generator_options or GeneratorOptions() anytree_tree = DocumentExplorer.generateAnytreeTree( document=document, tree_traversal_options=tree_traversal_options, generator_options=generator_options, ) self.sink.reset() # Non-ascii styles cause problems with encoding on Windows system if os.name == "nt": style = anytree.AsciiStyle() else: style = anytree.ContStyle() for pre, _, node in anytree.RenderTree(anytree_tree, style=style): if hasattr(node, "value_tree_value"): node_representation = prettyPrintValue( node.value_tree_value, display_values=self.display_values, name_alias=node.name, ) elif hasattr(node, "value_tree_node"): node_representation = prettyPrintNode( node.value_tree_node, display_values=self.display_values, name_alias=node.name, ) else: node_representation = node.name self.sink.output(f"{pre}{node_representation}") return self.sink.flush()
def test_contstyle(): style = anytree.ContStyle() eq_(style.vertical, u'\u2502 ') eq_(style.cont, u'\u251c\u2500\u2500 ') eq_(style.end, u'\u2514\u2500\u2500 ')
def render_tree(self, root): return str(at.RenderTree(root, style=at.ContStyle()))