Commits

Ned Batchelder committed cf831dc

Improvements to bytecode tools.

Comments (0)

Files changed (2)

             else:
                 srclines = None
             print("\n%s: " % bp.code)
+            upto = None
             for disline in disgen.disgen(bp.code):
                 if disline.first:
                     if srclines:
-                        print("%100s%s" % ("", srclines[disline.lineno-1]))
+                        upto = upto or disline.lineno-1
+                        while upto <= disline.lineno-1:
+                            print("%100s%s" % ("", srclines[upto]))
+                            upto += 1
                     elif disline.offset > 0:
                         print("")
                 line = disgen.format_dis_line(disline)
 
 def show_py_file(fname):
     text = open(fname).read().replace('\r\n', '\n')
+    show_py_text(text, fname=fname)
+
+def show_py_text(text, fname="<string>"):
     code = compile(text, fname, "exec")
     show_code(code)
 
         show_py_file(fname)
     else:
         print "Odd file:", fname
-        
+
 def main(args):
-    for a in args:
-        show_file(a)
-        
+    if args[0] == '-c':
+        show_py_text(" ".join(args[1:]).replace(";", "\n"))
+    else:
+        for a in args:
+            show_file(a)
+
 if __name__ == '__main__':
     main(sys.argv[1:])