Removes the edges between node1 and node2. If only node1 is given, removes all edges to and from it. This does not remove node1 from the graph.
(graph, node1, node2=None)
| 1037 | # with respect for the surrounding nodes. |
| 1038 | |
| 1039 | def unlink(graph, node1, node2=None): |
| 1040 | """ Removes the edges between node1 and node2. |
| 1041 | If only node1 is given, removes all edges to and from it. |
| 1042 | This does not remove node1 from the graph. |
| 1043 | """ |
| 1044 | if not isinstance(node1, Node): |
| 1045 | node1 = graph[node1] |
| 1046 | if not isinstance(node2, Node) and node2 is not None: |
| 1047 | node2 = graph[node2] |
| 1048 | for e in list(graph.edges): |
| 1049 | if node1 in (e.node1, e.node2) and node2 in (e.node1, e.node2, None): |
| 1050 | graph.edges.remove(e) |
| 1051 | try: |
| 1052 | node1.links.remove(node2) |
| 1053 | node2.links.remove(node1) |
| 1054 | except: # 'NoneType' object has no attribute 'links' |
| 1055 | pass |
| 1056 | |
| 1057 | def redirect(graph, node1, node2): |
| 1058 | """ Connects all of node1's edges to node2 and unlinks node1. |