1111import sys
1212import traceback
1313
14+
1415class Restart (Exception ):
1516 """Causes a debugger to be restarted for the debugged python program."""
1617 pass
@@ -23,11 +24,19 @@ def __init__(self, **kwargs):
2324 pdb .Pdb .__init__ (self , stdout = sys .__stdout__ , ** kwargs )
2425 self .prompt = ""
2526
26- def do_locate (self , arg ):
27- # An interface can grep the file and line number to follow along.
28- frame , lineno = self .stack [self .curindex ]
29- filename = self .canonic (frame .f_code .co_filename )
30- print >> self .stdout , "file::" , filename , "\n line::" , lineno
27+ if sys .version_info .major == 2 :
28+ def do_locate (self , arg ):
29+ # An interface can grep the file and line number to follow along.
30+ frame , lineno = self .stack [self .curindex ]
31+ filename = self .canonic (frame .f_code .co_filename )
32+ self .stdout .write ("file:: %s\n line:: %s\n " % (filename , lineno ))
33+
34+ else :
35+ def do_locate (self , arg ):
36+ # An interface can grep the file and line number to follow along.
37+ frame , lineno = self .stack [self .curindex ]
38+ filename = self .canonic (frame .f_code .co_filename )
39+ self .message ("file:: %s\n line:: %s\n " % (filename , lineno ))
3140
3241 def preloop (self ):
3342 self .do_locate (1 )
@@ -41,7 +50,7 @@ def postcmd(self, stop, line):
4150
4251def main ():
4352 if not sys .argv [1 :] or sys .argv [1 ] in ("--help" , "-h" ):
44- print >> sys .__stdout__ , "atom_pdb.py script [args...]"
53+ sys .stdout . write ( "atom_pdb.py script [args...]\n " )
4554 sys .exit (2 )
4655
4756 script = sys .argv [1 ]
@@ -55,18 +64,21 @@ def main():
5564 apdb ._runscript (script )
5665 if apdb ._user_requested_quit :
5766 break
58- print >> sys .__stdout__ , "The program finished and will be restarted"
67+ sys .stdout . write ( "The program finished and will be restarted\n " )
5968 except Restart :
60- print >> sys .__stdout__ , "Restarting" , script , " with arguments:"
61- print >> sys .__stdout__ , " " .join (sys .argv [1 :])
69+ sys .stdout . write ( "Restarting %s with arguments: " % script )
70+ sys .stdout . write ( " " .join (sys .argv [1 :]) + " \n " )
6271 except SystemExit :
63- print >> sys .__stdout__ , "The program exited via sys.exit(). Exit status: " , sys .exc_info ()[1 ]
72+ sys .stdout .write ("The program exited via sys.exit(). " )
73+ sys .stdout .write ("Exit status: %s\n " % sys .exc_info ()[1 ])
6474 except Exception as inst :
6575 traceback .print_exc ()
66- print >> sys .__stdout__ , "Uncaught exception " , type (inst ), " ... entering post-mortem debugging"
67- print >> sys .__stdout__ , "Continue or Step will restart the program"
76+ sys .stdout .write ("Uncaught exception %s " % str (type (inst )))
77+ sys .stdout .write ("... entering post-mortem debugging\n " )
78+ sys .stdout .write ("Continue or Step will restart the program\n " )
6879 apdb .interaction (None , sys .exc_info ()[2 ])
69- print >> sys .__stdout__ , "Post-mortem debugging finished. " , script , " will be restarted."
80+ sys .stdout .write ("Post-mortem debugging finished." )
81+ sys .stdout .write (" %s will be restarted.\n " % script )
7082
7183
7284if __name__ == "__main__" :
0 commit comments