mirror of
https://github.com/python/cpython.git
synced 2025-11-24 20:30:18 +00:00
Support disassembly of a variety of objects through dis.dis().
This commit is contained in:
parent
7b7c578616
commit
18aef3c102
1 changed files with 17 additions and 0 deletions
17
Lib/dis.py
17
Lib/dis.py
|
|
@ -2,10 +2,27 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import string
|
import string
|
||||||
|
import types
|
||||||
|
|
||||||
def dis(x=None):
|
def dis(x=None):
|
||||||
if not x:
|
if not x:
|
||||||
distb()
|
distb()
|
||||||
|
return
|
||||||
|
if type(x) is types.InstanceType:
|
||||||
|
x = x.__class__
|
||||||
|
if hasattr(x, '__dict__'):
|
||||||
|
items = x.__dict__.items()
|
||||||
|
items.sort()
|
||||||
|
for name, x1 in items:
|
||||||
|
if type(x1) in (types.MethodType,
|
||||||
|
types.FunctionType,
|
||||||
|
types.CodeType):
|
||||||
|
print "Disassembly of %s:" % name
|
||||||
|
try:
|
||||||
|
dis(x1)
|
||||||
|
except TypeError, msg:
|
||||||
|
print "Sorry:", msg
|
||||||
|
print
|
||||||
else:
|
else:
|
||||||
if hasattr(x, 'im_func'):
|
if hasattr(x, 'im_func'):
|
||||||
x = x.im_func
|
x = x.im_func
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue