##// END OF EJS Templates
Merge pull request #9097 from JamshedVesuna/master...
Matthias Bussonnier -
r21884:74860b86 merge
parent child Browse files
Show More
@@ -29,7 +29,6 b' from __future__ import print_function'
29 import bdb
29 import bdb
30 import functools
30 import functools
31 import inspect
31 import inspect
32 import linecache
33 import sys
32 import sys
34
33
35 from IPython import get_ipython
34 from IPython import get_ipython
@@ -54,7 +53,6 b" if '--pydb' in sys.argv:"
54
53
55 if has_pydb:
54 if has_pydb:
56 from pydb import Pdb as OldPdb
55 from pydb import Pdb as OldPdb
57 #print "Using pydb for %run -d and post-mortem" #dbg
58 prompt = 'ipydb> '
56 prompt = 'ipydb> '
59 else:
57 else:
60 from pdb import Pdb as OldPdb
58 from pdb import Pdb as OldPdb
@@ -94,7 +92,7 b' class Tracer(object):'
94 """
92 """
95
93
96 @skip_doctest
94 @skip_doctest
97 def __init__(self,colors=None):
95 def __init__(self, colors=None):
98 """Create a local debugger instance.
96 """Create a local debugger instance.
99
97
100 Parameters
98 Parameters
@@ -202,9 +200,16 b' class Pdb(OldPdb):'
202 """Modified Pdb class, does not load readline."""
200 """Modified Pdb class, does not load readline."""
203
201
204 def __init__(self,color_scheme='NoColor',completekey=None,
202 def __init__(self,color_scheme='NoColor',completekey=None,
205 stdin=None, stdout=None):
203 stdin=None, stdout=None, context=5):
206
204
207 # Parent constructor:
205 # Parent constructor:
206 try:
207 self.context=int(context)
208 if self.context <= 0:
209 raise ValueError("Context must be a positive integer")
210 except (TypeError, ValueError):
211 raise ValueError("Context must be a positive integer")
212
208 if has_pydb and completekey is None:
213 if has_pydb and completekey is None:
209 OldPdb.__init__(self,stdin=stdin,stdout=io.stdout)
214 OldPdb.__init__(self,stdin=stdin,stdout=io.stdout)
210 else:
215 else:
@@ -324,16 +329,31 b' class Pdb(OldPdb):'
324 def postloop(self):
329 def postloop(self):
325 self.shell.set_completer_frame(None)
330 self.shell.set_completer_frame(None)
326
331
327 def print_stack_trace(self):
332 def print_stack_trace(self, context=None):
333 if context is None:
334 context = self.context
335 try:
336 context=int(context)
337 if context <= 0:
338 raise ValueError("Context must be a positive integer")
339 except (TypeError, ValueError):
340 raise ValueError("Context must be a positive integer")
328 try:
341 try:
329 for frame_lineno in self.stack:
342 for frame_lineno in self.stack:
330 self.print_stack_entry(frame_lineno, context = 5)
343 self.print_stack_entry(frame_lineno, context=context)
331 except KeyboardInterrupt:
344 except KeyboardInterrupt:
332 pass
345 pass
333
346
334 def print_stack_entry(self,frame_lineno,prompt_prefix='\n-> ',
347 def print_stack_entry(self,frame_lineno,prompt_prefix='\n-> ',
335 context = 3):
348 context=None):
336 #frame, lineno = frame_lineno
349 if context is None:
350 context = self.context
351 try:
352 context=int(context)
353 if context <= 0:
354 raise ValueError("Context must be a positive integer")
355 except (TypeError, ValueError):
356 raise ValueError("Context must be a positive integer")
337 print(self.format_stack_entry(frame_lineno, '', context), file=io.stdout)
357 print(self.format_stack_entry(frame_lineno, '', context), file=io.stdout)
338
358
339 # vds: >>
359 # vds: >>
@@ -342,7 +362,15 b' class Pdb(OldPdb):'
342 self.shell.hooks.synchronize_with_editor(filename, lineno, 0)
362 self.shell.hooks.synchronize_with_editor(filename, lineno, 0)
343 # vds: <<
363 # vds: <<
344
364
345 def format_stack_entry(self, frame_lineno, lprefix=': ', context = 3):
365 def format_stack_entry(self, frame_lineno, lprefix=': ', context=None):
366 if context is None:
367 context = self.context
368 try:
369 context=int(context)
370 if context <= 0:
371 print("Context must be a positive integer")
372 except (TypeError, ValueError):
373 print("Context must be a positive integer")
346 try:
374 try:
347 import reprlib # Py 3
375 import reprlib # Py 3
348 except ImportError:
376 except ImportError:
@@ -530,7 +558,6 b' class Pdb(OldPdb):'
530 def do_longlist(self, arg):
558 def do_longlist(self, arg):
531 self.lastcmd = 'longlist'
559 self.lastcmd = 'longlist'
532 filename = self.curframe.f_code.co_filename
560 filename = self.curframe.f_code.co_filename
533 breaklist = self.get_file_breaks(filename)
534 try:
561 try:
535 lines, lineno = self.getsourcelines(self.curframe)
562 lines, lineno = self.getsourcelines(self.curframe)
536 except OSError as err:
563 except OSError as err:
@@ -586,3 +613,20 b' class Pdb(OldPdb):'
586 namespaces = [('Locals', self.curframe.f_locals),
613 namespaces = [('Locals', self.curframe.f_locals),
587 ('Globals', self.curframe.f_globals)]
614 ('Globals', self.curframe.f_globals)]
588 self.shell.find_line_magic('psource')(arg, namespaces=namespaces)
615 self.shell.find_line_magic('psource')(arg, namespaces=namespaces)
616
617 if sys.version_info > (3, ):
618 def do_where(self, arg):
619 """w(here)
620 Print a stack trace, with the most recent frame at the bottom.
621 An arrow indicates the "current frame", which determines the
622 context of most commands. 'bt' is an alias for this command.
623
624 Take a number as argument as an (optional) number of context line to
625 print"""
626 if arg:
627 context = int(arg)
628 self.print_stack_trace(context)
629 else:
630 self.print_stack_trace()
631
632 do_w = do_where
General Comments 0
You need to be logged in to leave comments. Login now