##// END OF EJS Templates
ipdb: fix formatting in core.debugger
Blazej Michalik -
Show More
@@ -43,13 +43,14 b' from IPython.testing.skipdoctest import skip_doctest'
43
43
44 prompt = 'ipdb> '
44 prompt = 'ipdb> '
45
45
46 #We have to check this directly from sys.argv, config struct not yet available
46 # We have to check this directly from sys.argv, config struct not yet available
47 from pdb import Pdb as OldPdb
47 from pdb import Pdb as OldPdb
48
48
49 # Allow the set_trace code to operate outside of an ipython instance, even if
49 # Allow the set_trace code to operate outside of an ipython instance, even if
50 # it does so with some limitations. The rest of this support is implemented in
50 # it does so with some limitations. The rest of this support is implemented in
51 # the Tracer constructor.
51 # the Tracer constructor.
52
52
53
53 def make_arrow(pad):
54 def make_arrow(pad):
54 """generate the leading arrow in front of traceback or debugger"""
55 """generate the leading arrow in front of traceback or debugger"""
55 if pad >= 2:
56 if pad >= 2:
@@ -67,16 +68,16 b' def BdbQuit_excepthook(et, ev, tb, excepthook=None):'
67 """
68 """
68 warnings.warn("`BdbQuit_excepthook` is deprecated since version 5.1",
69 warnings.warn("`BdbQuit_excepthook` is deprecated since version 5.1",
69 DeprecationWarning, stacklevel=2)
70 DeprecationWarning, stacklevel=2)
70 if et==bdb.BdbQuit:
71 if et == bdb.BdbQuit:
71 print('Exiting Debugger.')
72 print('Exiting Debugger.')
72 elif excepthook is not None:
73 elif excepthook is not None:
73 excepthook(et, ev, tb)
74 excepthook(et, ev, tb)
74 else:
75 else:
75 # Backwards compatibility. Raise deprecation warning?
76 # Backwards compatibility. Raise deprecation warning?
76 BdbQuit_excepthook.excepthook_ori(et,ev,tb)
77 BdbQuit_excepthook.excepthook_ori(et, ev, tb)
77
78
78
79
79 def BdbQuit_IPython_excepthook(self,et,ev,tb,tb_offset=None):
80 def BdbQuit_IPython_excepthook(self, et, ev, tb, tb_offset=None):
80 warnings.warn(
81 warnings.warn(
81 "`BdbQuit_IPython_excepthook` is deprecated since version 5.1",
82 "`BdbQuit_IPython_excepthook` is deprecated since version 5.1",
82 DeprecationWarning, stacklevel=2)
83 DeprecationWarning, stacklevel=2)
@@ -203,7 +204,7 b' class Pdb(OldPdb):'
203 def __init__(self, color_scheme=None, completekey=None,
204 def __init__(self, color_scheme=None, completekey=None,
204 stdin=None, stdout=None, context=5, **kwargs):
205 stdin=None, stdout=None, context=5, **kwargs):
205 """Create a new IPython debugger.
206 """Create a new IPython debugger.
206
207
207 :param color_scheme: Deprecated, do not use.
208 :param color_scheme: Deprecated, do not use.
208 :param completekey: Passed to pdb.Pdb.
209 :param completekey: Passed to pdb.Pdb.
209 :param stdin: Passed to pdb.Pdb.
210 :param stdin: Passed to pdb.Pdb.
@@ -237,7 +238,7 b' class Pdb(OldPdb):'
237 self.shell = TerminalInteractiveShell.instance()
238 self.shell = TerminalInteractiveShell.instance()
238 # needed by any code which calls __import__("__main__") after
239 # needed by any code which calls __import__("__main__") after
239 # the debugger was entered. See also #9941.
240 # the debugger was entered. See also #9941.
240 sys.modules['__main__'] = save_main
241 sys.modules['__main__'] = save_main
241
242
242 if color_scheme is not None:
243 if color_scheme is not None:
243 warnings.warn(
244 warnings.warn(
@@ -272,7 +273,6 b' class Pdb(OldPdb):'
272 cst['Neutral'].colors.breakpoint_enabled = C.LightRed
273 cst['Neutral'].colors.breakpoint_enabled = C.LightRed
273 cst['Neutral'].colors.breakpoint_disabled = C.Red
274 cst['Neutral'].colors.breakpoint_disabled = C.Red
274
275
275
276 # Add a python parser so we can syntax highlight source while
276 # Add a python parser so we can syntax highlight source while
277 # debugging.
277 # debugging.
278 self.parser = PyColorize.Parser(style=color_scheme)
278 self.parser = PyColorize.Parser(style=color_scheme)
@@ -326,7 +326,7 b' class Pdb(OldPdb):'
326 def new_do_quit(self, arg):
326 def new_do_quit(self, arg):
327
327
328 if hasattr(self, 'old_all_completions'):
328 if hasattr(self, 'old_all_completions'):
329 self.shell.Completer.all_completions=self.old_all_completions
329 self.shell.Completer.all_completions = self.old_all_completions
330
330
331 return OldPdb.do_quit(self, arg)
331 return OldPdb.do_quit(self, arg)
332
332
@@ -344,7 +344,7 b' class Pdb(OldPdb):'
344 if context is None:
344 if context is None:
345 context = self.context
345 context = self.context
346 try:
346 try:
347 context=int(context)
347 context = int(context)
348 if context <= 0:
348 if context <= 0:
349 raise ValueError("Context must be a positive integer")
349 raise ValueError("Context must be a positive integer")
350 except (TypeError, ValueError) as e:
350 except (TypeError, ValueError) as e:
@@ -373,7 +373,7 b' class Pdb(OldPdb):'
373 if context is None:
373 if context is None:
374 context = self.context
374 context = self.context
375 try:
375 try:
376 context=int(context)
376 context = int(context)
377 if context <= 0:
377 if context <= 0:
378 raise ValueError("Context must be a positive integer")
378 raise ValueError("Context must be a positive integer")
379 except (TypeError, ValueError) as e:
379 except (TypeError, ValueError) as e:
@@ -390,7 +390,7 b' class Pdb(OldPdb):'
390 if context is None:
390 if context is None:
391 context = self.context
391 context = self.context
392 try:
392 try:
393 context=int(context)
393 context = int(context)
394 if context <= 0:
394 if context <= 0:
395 print("Context must be a positive integer", file=self.stdout)
395 print("Context must be a positive integer", file=self.stdout)
396 except (TypeError, ValueError):
396 except (TypeError, ValueError):
@@ -406,7 +406,7 b' class Pdb(OldPdb):'
406 tpl_call = u'%s%%s%s%%s%s' % (Colors.vName, Colors.valEm, ColorsNormal)
406 tpl_call = u'%s%%s%s%%s%s' % (Colors.vName, Colors.valEm, ColorsNormal)
407 tpl_line = u'%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
407 tpl_line = u'%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
408 tpl_line_em = u'%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line,
408 tpl_line_em = u'%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line,
409 ColorsNormal)
409 ColorsNormal)
410
410
411 frame, lineno = frame_lineno
411 frame, lineno = frame_lineno
412
412
@@ -440,7 +440,7 b' class Pdb(OldPdb):'
440 ret.append('> ')
440 ret.append('> ')
441 else:
441 else:
442 ret.append(' ')
442 ret.append(' ')
443 ret.append(u'%s(%s)%s\n' % (link,lineno,call))
443 ret.append(u'%s(%s)%s\n' % (link, lineno, call))
444
444
445 start = lineno - 1 - context//2
445 start = lineno - 1 - context//2
446 lines = linecache.getlines(filename)
446 lines = linecache.getlines(filename)
@@ -448,17 +448,17 b' class Pdb(OldPdb):'
448 start = max(start, 0)
448 start = max(start, 0)
449 lines = lines[start : start + context]
449 lines = lines[start : start + context]
450
450
451 for i,line in enumerate(lines):
451 for i, line in enumerate(lines):
452 show_arrow = (start + 1 + i == lineno)
452 show_arrow = (start + 1 + i == lineno)
453 linetpl = (frame is self.curframe or show_arrow) \
453 linetpl = (frame is self.curframe or show_arrow) \
454 and tpl_line_em \
454 and tpl_line_em \
455 or tpl_line
455 or tpl_line
456 ret.append(self.__format_line(linetpl, filename,
456 ret.append(self.__format_line(linetpl, filename,
457 start + 1 + i, line,
457 start + 1 + i, line,
458 arrow = show_arrow) )
458 arrow=show_arrow))
459 return ''.join(ret)
459 return ''.join(ret)
460
460
461 def __format_line(self, tpl_line, filename, lineno, line, arrow = False):
461 def __format_line(self, tpl_line, filename, lineno, line, arrow=False):
462 bp_mark = ""
462 bp_mark = ""
463 bp_mark_color = ""
463 bp_mark_color = ""
464
464
@@ -488,7 +488,6 b' class Pdb(OldPdb):'
488
488
489 return tpl_line % (bp_mark_color + bp_mark, num, line)
489 return tpl_line % (bp_mark_color + bp_mark, num, line)
490
490
491
492 def print_list_lines(self, filename, first, last):
491 def print_list_lines(self, filename, first, last):
493 """The printing (as opposed to the parsing part of a 'list'
492 """The printing (as opposed to the parsing part of a 'list'
494 command."""
493 command."""
@@ -507,9 +506,9 b' class Pdb(OldPdb):'
507 break
506 break
508
507
509 if lineno == self.curframe.f_lineno:
508 if lineno == self.curframe.f_lineno:
510 line = self.__format_line(tpl_line_em, filename, lineno, line, arrow = True)
509 line = self.__format_line(tpl_line_em, filename, lineno, line, arrow=True)
511 else:
510 else:
512 line = self.__format_line(tpl_line, filename, lineno, line, arrow = False)
511 line = self.__format_line(tpl_line, filename, lineno, line, arrow=False)
513
512
514 src.append(line)
513 src.append(line)
515 self.lineno = lineno
514 self.lineno = lineno
@@ -706,7 +705,7 b' class Pdb(OldPdb):'
706
705
707 Will skip hidden frames.
706 Will skip hidden frames.
708 """
707 """
709 ## modified version of upstream that skips
708 # modified version of upstream that skips
710 # frames with __tracebackide__
709 # frames with __tracebackide__
711 if self.curindex == 0:
710 if self.curindex == 0:
712 self.error("Oldest frame")
711 self.error("Oldest frame")
General Comments 0
You need to be logged in to leave comments. Login now