]> granicus.if.org Git - python/commitdiff
Support disassembly of a variety of objects through dis.dis().
authorGuido van Rossum <guido@python.org>
Fri, 14 Mar 1997 04:15:43 +0000 (04:15 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 14 Mar 1997 04:15:43 +0000 (04:15 +0000)
Lib/dis.py

index 3957f9cf8bc801f8165d457c133c0fe23636fcb2..dc1530919cc175e3b726989cb3b7f4353694997c 100644 (file)
@@ -2,10 +2,27 @@
 
 import sys
 import string
+import types
 
 def dis(x=None):
        if not x:
                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:
                if hasattr(x, 'im_func'):
                        x = x.im_func