Package concurrent_tree_crawler :: Module abstract_tree_accessor
[hide private]
[frames] | no frames]

Source Code for Module concurrent_tree_crawler.abstract_tree_accessor

 1  from concurrent_tree_crawler.abstract_node import AbstractNode, NodeState 
2 3 -class NodeAction:
4 """Enumeration describing actions that can be taken by a crawler when 5 entering a new node""" 6 7 TO_PROCESS = 0 8 TO_VISIT = 1 9 10 @staticmethod
11 - def to_str(action):
12 """@type action: L{NodeAction} enum""" 13 if action == NodeAction.TO_PROCESS: 14 return "TO_PROCESS" 15 elif action == NodeAction.TO_VISIT: 16 return "TO_VISIT"
17
18 -class AbstractTreeAccessor:
19 """ 20 An interface for the tree made of L{AbstractNode}s. 21 """ 22
23 - def get_sentinel(self):
24 """ 25 @return: sentinel node 26 @rtype: L{AbstractNode} 27 """ 28 raise NotImplementedError
29
30 - def get_root(self):
31 """ 32 @return: root node 33 @rtype: L{AbstractNode} 34 """ 35 raise NotImplementedError
36
37 - def get_path(self, node):
38 """ 39 A convenience method. Returns tree path to the given node. 40 41 @type node: L{AbstractNode} 42 @return: subsequent node names from the tree root to the current node 43 @rtype: list of strings 44 """ 45 path = [] 46 while node != self.get_sentinel(): 47 path.append(node.get_name()) 48 node = node.get_parent() 49 path.reverse() 50 return path
51
52 - def update_and_get_child(self, node, possible_children_names):
53 """ 54 Append new children to the node and return a child that can be 55 entered by the crawler. 56 57 @param node: node considered 58 @type node: L{AbstractNode} 59 @param possible_children_names: list of children names 60 @type possible_children_names: list of strings 61 @return: children node along with information what the crawler should 62 do with it. C{None} instead is returned if all children have 63 state C{NodeState.CLOSED} or C{NodeState.ERROR} or the node 64 has no children. 65 @rtype: (L{AbstractNode}, L{NodeAction}) pair or C{None} 66 """ 67 raise NotImplementedError
68
69 - def set_node_type(self, node, is_leaf):
70 """ 71 Set the leaf state of the node 72 73 @param is_leaf: C{True} iff the node is a leaf 74 """ 75 raise NotImplementedError
76
77 - def set_error(self, node):
78 """Set the node state as C{NodeState.ERROR}""" 79 raise NotImplementedError
80