Code Duplication    Length = 15-16 lines in 2 locations

main.py 2 locations

@@ 40-55 (lines=16) @@
37
        """
38
        filtered_paths = []
39
40
        if desired:
41
            for link_id in desired:
42
                try:
43
                    endpoint_a = self._topology.links[link_id].endpoint_a.id
44
                    endpoint_b = self._topology.links[link_id].endpoint_b.id
45
                except KeyError:
46
                    return []
47
48
                for path in paths:
49
                    head = path['hops'][:-1]
50
                    tail = path['hops'][1:]
51
                    if (((endpoint_a, endpoint_b) in zip(head, tail)) or
52
                            ((endpoint_b, endpoint_a) in zip(head, tail))):
53
                        filtered_paths.append(path)
54
        else:
55
            filtered_paths = paths
56
57
        if undesired:
58
            for link_id in undesired:
@@ 57-71 (lines=15) @@
54
        else:
55
            filtered_paths = paths
56
57
        if undesired:
58
            for link_id in undesired:
59
                try:
60
                    endpoint_a = self._topology.links[link_id].endpoint_a.id
61
                    endpoint_b = self._topology.links[link_id].endpoint_b.id
62
                except KeyError:
63
                    continue
64
65
                for path in paths:
66
                    head = path['hops'][:-1]
67
                    tail = path['hops'][1:]
68
                    if (((endpoint_a, endpoint_b) in zip(head, tail)) or
69
                            ((endpoint_b, endpoint_a) in zip(head, tail))):
70
71
                        filtered_paths.remove(path)
72
73
        return filtered_paths
74