The karbor.services.protection.graph Module

exception karbor.services.protection.graph.FoundLoopError

Bases: exceptions.RuntimeError

class karbor.services.protection.graph.GraphNode(value, child_nodes)

Bases: tuple

child_nodes

Alias for field number 1

value

Alias for field number 0

class karbor.services.protection.graph.GraphWalker

Bases: object

register_listener(graph_walker_listener)
unregister_listener(graph_walker_listener)
walk_graph(source_nodes)
class karbor.services.protection.graph.GraphWalkerListener

Bases: object

Interface for listening to GraphWaler events

Classes that want to be able to use the graph walker to iterate over a graph should implement this interface.

on_node_enter(node, already_visited)
on_node_exit(node)
class karbor.services.protection.graph.PackGraphWalker(adjacency_list, nodes_dict)

Bases: karbor.services.protection.graph.GraphWalkerListener

Pack a list of GraphNode

Allocate a serialized id (sid) for every node and build an adjacency list, suitable for graph unpacking.

on_node_enter(node, already_visited)
on_node_exit(node)
class karbor.services.protection.graph.PackedGraph(nodes, adjacency)

Bases: tuple

adjacency

Alias for field number 1

nodes

Alias for field number 0

karbor.services.protection.graph.build_graph(start_nodes, get_child_nodes_func)
karbor.services.protection.graph.deserialize_resource_graph(serialized_resource_graph)
karbor.services.protection.graph.pack_graph(start_nodes)

Return a PackedGraph from a list of GraphNodes

Packs a graph into a flat PackedGraph (nodes dictionary, adjacency list).

karbor.services.protection.graph.serialize_resource_graph(resource_graph)
karbor.services.protection.graph.unpack_graph(packed_graph)

Return a list of GraphNodes from a PackedGraph

Unpacks a PackedGraph, which must have the property: each parent node in the adjacency list appears after its children.