1 # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 |
1 # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 |
2 # For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt |
2 # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt |
3 |
3 |
4 """Bytecode manipulation for coverage.py""" |
4 """Bytecode manipulation for coverage.py""" |
5 |
5 |
6 import types |
6 import types |
7 |
7 |
8 |
8 |
9 class CodeObjects(object): |
9 def code_objects(code): |
10 """Iterate over all the code objects in `code`.""" |
10 """Iterate over all the code objects in `code`.""" |
11 def __init__(self, code): |
11 stack = [code] |
12 self.stack = [code] |
12 while stack: |
13 |
13 # We're going to return the code object on the stack, but first |
14 def __iter__(self): |
14 # push its children for later returning. |
15 while self.stack: |
15 code = stack.pop() |
16 # We're going to return the code object on the stack, but first |
16 for c in code.co_consts: |
17 # push its children for later returning. |
17 if isinstance(c, types.CodeType): |
18 code = self.stack.pop() |
18 stack.append(c) |
19 for c in code.co_consts: |
19 yield code |
20 if isinstance(c, types.CodeType): |
|
21 self.stack.append(c) |
|
22 yield code |
|