Helper to handle methods, compiled or raw code objects, and strings.
(x)
| 190 | UNKNOWN = _Unknown() |
| 191 | |
| 192 | def _get_code_object(x): |
| 193 | """Helper to handle methods, compiled or raw code objects, and strings.""" |
| 194 | # Extract functions from methods. |
| 195 | if hasattr(x, '__func__'): |
| 196 | x = x.__func__ |
| 197 | # Extract compiled code objects from... |
| 198 | if hasattr(x, '__code__'): # ...a function, or |
| 199 | x = x.__code__ |
| 200 | elif hasattr(x, 'gi_code'): #...a generator object, or |
| 201 | x = x.gi_code |
| 202 | elif hasattr(x, 'ag_code'): #...an asynchronous generator object, or |
| 203 | x = x.ag_code |
| 204 | elif hasattr(x, 'cr_code'): #...a coroutine. |
| 205 | x = x.cr_code |
| 206 | # Handle source code. |
| 207 | if isinstance(x, str): |
| 208 | x = _try_compile(x, "<disassembly>") |
| 209 | # By now, if we don't have a code object, we can't disassemble x. |
| 210 | if hasattr(x, 'co_code'): |
| 211 | return x |
| 212 | raise TypeError("don't know how to disassemble %s objects" % |
| 213 | type(x).__name__) |
| 214 | |
| 215 | def _deoptop(op): |
| 216 | name = _all_opname[op] |
no test coverage detected
searching dependent graphs…