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 |
|
3 |
|
4 """Bytecode manipulation for coverage.py""" |
|
5 |
|
6 import types |
|
7 |
|
8 |
|
9 class CodeObjects(object): |
|
10 """Iterate over all the code objects in `code`.""" |
|
11 def __init__(self, code): |
|
12 self.stack = [code] |
|
13 |
|
14 def __iter__(self): |
|
15 while self.stack: |
|
16 # We're going to return the code object on the stack, but first |
|
17 # push its children for later returning. |
|
18 code = self.stack.pop() |
|
19 for c in code.co_consts: |
|
20 if isinstance(c, types.CodeType): |
|
21 self.stack.append(c) |
|
22 yield code |
|
23 |
|
24 # |
|
25 # eflag: FileType = Python2 |
|