1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """A generic visitor abstract implementation.
19
20
21
22
23 """
24 __docformat__ = "restructuredtext en"
25
28
29
31
32 - def __init__(self, node, list_func, filter_func=None):
33 self._next = [(node, 0)]
34 if filter_func is None:
35 filter_func = no_filter
36 self._list = list_func(node, filter_func)
37
39 try:
40 return self._list.pop(0)
41 except :
42 return None
43
44 next = __next__
45
46
48
49 - def __init__(self, iterator_class, filter_func=None):
50 self._iter_class = iterator_class
51 self.filter = filter_func
52
53 - def visit(self, node, *args, **kargs):
54 """
55 launch the visit on a given node
56
57 call 'open_visit' before the beginning of the visit, with extra args
58 given
59 when all nodes have been visited, call the 'close_visit' method
60 """
61 self.open_visit(node, *args, **kargs)
62 return self.close_visit(self._visit(node))
63
65 iterator = self._get_iterator(node)
66 n = next(iterator)
67 while n:
68 result = n.accept(self)
69 n = next(iterator)
70 return result
71
73 return self._iter_class(node, self.filter)
74
76 """
77 method called at the beginning of the visit
78 """
79 pass
80
82 """
83 method called at the end of the visit
84 """
85 return result
86
87
89 """
90 Visited interface allow node visitors to use the node
91 """
93 """
94 return the visit name for the mixed class. When calling 'accept', the
95 method <'visit_' + name returned by this method> will be called on the
96 visitor
97 """
98 try:
99 return self.TYPE.replace('-', '_')
100 except:
101 return self.__class__.__name__.lower()
102
103 - def accept(self, visitor, *args, **kwargs):
106
107 - def leave(self, visitor, *args, **kwargs):
110