#NEWLINE# def _apply_node_name( self , node , name ) : #NEWLINE# #INDENT# 'Assign the given name to the node and make sure the\n        name is unique within the current set of nodes.\n\n        If there is another node with the same name, the nodes index will\n        be set accordingly.\n\n        :param node: the node\n        :param name: the new name\n        ' #NEWLINE# name = ( name if name else 'tool' ) #NEWLINE# old_name = node . _name #NEWLINE# node . _name = name #NEWLINE# node . _index = ( - 1 ) #NEWLINE# nodes_with_same_name = [ nn for i in self . nodes ( ) if ( i . _name == name ) ] #NEWLINE# if ( len ( nodes_with_same_name ) > 1 ) : #NEWLINE# #INDENT# nodes_with_same_name = sorted ( nodes_with_same_name , key = ( lambda x : x . _node_index ) ) #NEWLINE# for ( i , nn ) in enumerate ( nodes_with_same_name ) : #NEWLINE# #INDENT# nn . _index = i #NEWLINE# #UNINDENT# #UNINDENT# if ( old_name and ( old_name != name ) ) : #NEWLINE# #INDENT# old_nodes = [ i for i in self . nodes ( ) if ( i . _name == old_name ) ] #NEWLINE# if ( len ( old_nodes ) == 1 ) : #NEWLINE# #INDENT# old_nodes [ 0 ] . _index = ( - 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( old_nodes ) > 1 ) : #NEWLINE# #INDENT# old_nodes = sorted ( old_nodes , key = ( lambda x : x . _node_index ) ) #NEWLINE# for ( i , nn ) in enumerate ( old_nodes ) : #NEWLINE# #INDENT# nn . _index = i