#NEWLINE# def pformat( self , stringify_node = None , linesep = LINE_SEP , vertical_conn = VERTICAL_CONN , horizontal_conn = HORIZONTAL_CONN , empty_space = EMPTY_SPACE_SEP , starting_prefix = STARTING_PREFIX ) : #NEWLINE# #INDENT# 'Formats this node + children into a nice string representation.\n\n        **Example**::\n\n            >>> from taskflow.types import tree\n            >>> yahoo = tree.Node("CEO")\n            >>> yahoo.add(tree.Node("Infra"))\n            >>> yahoo[0].add(tree.Node("Boss"))\n            >>> yahoo[0][0].add(tree.Node("Me"))\n            >>> yahoo.add(tree.Node("Mobile"))\n            >>> yahoo.add(tree.Node("Mail"))\n            >>> print(yahoo.pformat())\n            CEO\n            |__Infra\n            |  |__Boss\n            |     |__Me\n            |__Mobile\n            |__Mail\n        ' #NEWLINE# if ( stringify_node is None ) : #NEWLINE# #INDENT# stringify_node = ( lambda node : six . text_type ( node . item ) ) #NEWLINE# #UNINDENT# expected_lines = ( self . child_count ( only_direct = False ) + 1 ) #NEWLINE# buff = six . StringIO ( ) #NEWLINE# conn = ( vertical_conn + horizontal_conn ) #NEWLINE# stop_at_parent = self #NEWLINE# for ( i , node ) in enumerate ( self . dfs_iter ( include_self = True ) , 1 ) : #NEWLINE# #INDENT# prefix = [ ] #NEWLINE# connected_to_parent = False #NEWLINE# last_node = node #NEWLINE# parent_node_it = iter_utils . while_is_not ( node . path_iter ( include_self = True ) , stop_at_parent ) #NEWLINE# for ( j , parent_node ) in enumerate ( parent_node_it ) : #NEWLINE# #INDENT# if ( parent_node is stop_at_parent ) : #NEWLINE# #INDENT# if ( j > 0 ) : #NEWLINE# #INDENT# if ( not connected_to_parent ) : #NEWLINE# #INDENT# prefix . append ( conn ) #NEWLINE# connected_to_parent = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# last_node = self . _children [ ( - 1 ) ] #NEWLINE# m = last_node . find_first_match ( ( lambda n : ( n is node ) ) , include_self = False , only_direct = False ) #NEWLINE# if ( m is not None ) : #NEWLINE# #INDENT# prefix . append ( empty_space ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# prefix . append ( vertical_conn ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( parent_node is node ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not connected_to_parent ) : #NEWLINE# #INDENT# prefix . append ( conn ) #NEWLINE# spaces = len ( horizontal_conn ) #NEWLINE# connected_to_parent = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( parent_node [ ( - 1 ) ] is not last_node ) : #NEWLINE# #INDENT# prefix . append ( vertical_conn ) #NEWLINE# spaces = len ( horizontal_conn ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# spaces = len ( conn ) #NEWLINE# #UNINDENT# #UNINDENT# prefix . append ( ( empty_space * spaces ) ) #NEWLINE# #UNINDENT# #UNINDENT# last_node = parent_node #NEWLINE# #UNINDENT# prefix . append ( starting_prefix ) #NEWLINE# for prefix_piece in reversed ( prefix ) : #NEWLINE# #INDENT# buff . write ( prefix_piece ) #NEWLINE# #UNINDENT# buff . write ( stringify_node ( node ) ) #NEWLINE# if ( i != expected_lines ) : #NEWLINE# #INDENT# buff . write ( linesep ) #NEWLINE# #UNINDENT# #UNINDENT# return buff . getvalue ( )