Example #1
0
 def deep_eq(self, other):
     '''
     Recursive equality; used only for testing.
     '''
     for ((a, b), (c, d)) in zip(edge_iterator(self), edge_iterator(other)):
         if not a._node_eq(c) or not b._node_eq(d):
             return False
     return True
Example #2
0
 def deep_eq(self, other):
     '''
     Recursive equality; used only for testing.
     '''
     for ((a, b), (c, d)) in zip(edge_iterator(self), edge_iterator(other)):
         if not a._node_eq(c) or not b._node_eq(d):
             return False
     return True
Example #3
0
    def __repr__(self):
        '''
        Generate a description of this node and accessible children which can
        be used to plot the graph in GraphViz.
        '''
        indices = {}
        reverse = {}

        def index(node):
            '''Map from node to index, adding nodes as needed.'''
            if node not in indices:
                n = len(indices)
                indices[node] = n
                reverse[n] = node
            return str(indices[node])

        def escape(node):
            '''Escape text for Graphviz.'''
            text = str(node)
            text = text.replace('\n', '\\n')
            return text.replace('\\', '\\\\')

        edge_indices = [(index(start), index(end))
                        for (start, end) in edge_iterator(self)]
        edges = [' ' + start + ' -> ' + end for (start, end) in edge_indices]
        nodes = [
            ' ' + str(index) +
            ' [label="{0!s}"]'.format(escape(reverse[index]))
            for index in sorted(reverse)
        ]
        return 'digraph {{\n{0!s}\n{1!s}\n}}'.format('\n'.join(nodes),
                                                     '\n'.join(edges))
Example #4
0
 def __repr__(self):
     '''
     Generate a description of this node and accessible children which can
     be used to plot the graph in GraphViz.
     '''
     indices = {}
     reverse = {}
     def index(node):
         '''Map from node to index, adding nodes as needed.'''
         if node not in indices:
             n = len(indices)
             indices[node] = n
             reverse[n] = node
         return str(indices[node])
     def escape(node):
         '''Escape text for Graphviz.'''
         text = str(node)
         text = text.replace('\n','\\n')
         return text.replace('\\', '\\\\')
     edge_indices = [(index(start), index(end))
                     for (start, end) in edge_iterator(self)]
     edges = [' ' + start + ' -> ' + end for (start, end) in edge_indices]
     nodes = [' ' + str(index) + ' [label="{0!s}"]'.format(escape(reverse[index]))
              for index in sorted(reverse)]
     return 'digraph {{\n{0!s}\n{1!s}\n}}'.format(
                     '\n'.join(nodes), '\n'.join(edges))