1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 '''
31 Support for classes that monitor the execution process (for example, managing
32 resources and tracing program flow).
33
34 See `trampoline()`.
35 '''
36
37
39 '''
40 An interface expected by `trampoline()`, called to track data flow.
41 '''
42
44 '''
45 Called at the start of each iteration.
46 '''
47 pass
48
50 '''
51 Called before invoking ``next`` on a generator.
52 '''
53 pass
54
56 '''
57 Called after invoking ``next`` on a generator.
58 '''
59 pass
60
62 '''
63 Called before invoking ``throw`` on a generator.
64 '''
65 pass
66
68 '''
69 Called after invoking ``throw`` on a generator.
70 '''
71 pass
72
74 '''
75 Called before invoking ``send`` on a generator.
76 '''
77 pass
78
80 '''
81 Called after invoking ``send`` on a generator.
82 '''
83 pass
84
86 '''
87 Called when an exception is caught (instead of any 'after' method).
88 '''
89 pass
90
92 '''
93 Called before raising an exception to the caller.
94 '''
95 pass
96
98 '''
99 Called before yielding a value to the caller.
100 '''
101 pass
102
103
105 '''
106 An interface expected by `trampoline()`, called to track stack growth.
107 '''
108
109 - def push(self, generator):
110 '''
111 Called before adding a generator to the stack.
112 '''
113 pass
114
115 - def pop(self, generator):
116 '''
117 Called after removing a generator from the stack.
118 '''
119 pass
120
121
123 '''
124 A `StackMonitor` implementation that allows matchers that implement the
125 interface on_push/on_pop to be called.
126
127 Generators can interact with active monitors if:
128
129 1. The monitor extends this class
130
131 2. The matcher has a monitor_class attribute whose value is equal to (or a
132 subclass of) the monitor class it will interact with
133 '''
134
135 - def push(self, generator):
142
143 - def pop(self, generator):
150
151
153 '''
154 Combine several value monitors into one.
155 '''
156
160
162 '''
163 Add another monitor to the chain.
164 '''
165 self._monitors.append(monitor)
166
168 return len(self._monitors)
169
176
183
185 '''
186 Called after invoking ``next`` on a generator.
187 '''
188 for monitor in self._monitors:
189 monitor.after_next(value)
190
197
199 '''
200 Called after invoking ``throw`` on a generator.
201 '''
202 for monitor in self._monitors:
203 monitor.after_throw(value)
204
211
213 '''
214 Called after invoking ``send`` on a generator.
215 '''
216 for monitor in self._monitors:
217 monitor.after_send(value)
218
220 '''
221 Called when an exception is caught (instead of any 'after' method).
222 '''
223 for monitor in self._monitors:
224 monitor.exception(value)
225
227 '''
228 Called before raising an exception to the caller.
229 '''
230 for monitor in self._monitors:
231 monitor.raise_(value)
232
234 '''
235 Called before yielding a value to the caller.
236 '''
237 for monitor in self._monitors:
238 monitor.yield_(value)
239
240
242 '''
243 Combine several stack monitors into one.
244 '''
245
249
251 '''
252 Add another monitor to the chain.
253 '''
254 self._monitors.append(monitor)
255
257 return len(self._monitors)
258
259 - def push(self, value):
260 '''
261 Called before adding a generator to the stack.
262 '''
263 for monitor in self._monitors:
264 monitor.push(value)
265
266 - def pop(self, value):
267 '''
268 Called after removing a generator from the stack.
269 '''
270 for monitor in self._monitors:
271 monitor.pop(value)
272
273
288