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[ |
|
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) | |
@@ -320,13 +320,25 b' class Pdb(OldPdb):' | |||||
320 | except KeyboardInterrupt: |
|
320 | except KeyboardInterrupt: | |
321 | self.stdout.write("\n" + self.shell.get_exception_only()) |
|
321 | self.stdout.write("\n" + self.shell.get_exception_only()) | |
322 |
|
322 | |||
|
323 | def precmd(self, line): | |||
|
324 | """Perform useful escapes on the command before it is executed.""" | |||
|
325 | ||||
|
326 | if line.endswith("??"): | |||
|
327 | line = "pinfo2 " + line[:-2] | |||
|
328 | elif line.endswith("?"): | |||
|
329 | line = "pinfo " + line[:-1] | |||
|
330 | ||||
|
331 | line = super().precmd(line) | |||
|
332 | ||||
|
333 | return line | |||
|
334 | ||||
323 | def new_do_frame(self, arg): |
|
335 | def new_do_frame(self, arg): | |
324 | OldPdb.do_frame(self, arg) |
|
336 | OldPdb.do_frame(self, arg) | |
325 |
|
337 | |||
326 | def new_do_quit(self, arg): |
|
338 | def new_do_quit(self, arg): | |
327 |
|
339 | |||
328 | if hasattr(self, 'old_all_completions'): |
|
340 | if hasattr(self, 'old_all_completions'): | |
329 | self.shell.Completer.all_completions=self.old_all_completions |
|
341 | self.shell.Completer.all_completions = self.old_all_completions | |
330 |
|
342 | |||
331 | return OldPdb.do_quit(self, arg) |
|
343 | return OldPdb.do_quit(self, arg) | |
332 |
|
344 | |||
@@ -344,7 +356,7 b' class Pdb(OldPdb):' | |||||
344 | if context is None: |
|
356 | if context is None: | |
345 | context = self.context |
|
357 | context = self.context | |
346 | try: |
|
358 | try: | |
347 | context=int(context) |
|
359 | context = int(context) | |
348 | if context <= 0: |
|
360 | if context <= 0: | |
349 | raise ValueError("Context must be a positive integer") |
|
361 | raise ValueError("Context must be a positive integer") | |
350 | except (TypeError, ValueError) as e: |
|
362 | except (TypeError, ValueError) as e: | |
@@ -373,7 +385,7 b' class Pdb(OldPdb):' | |||||
373 | if context is None: |
|
385 | if context is None: | |
374 | context = self.context |
|
386 | context = self.context | |
375 | try: |
|
387 | try: | |
376 | context=int(context) |
|
388 | context = int(context) | |
377 | if context <= 0: |
|
389 | if context <= 0: | |
378 | raise ValueError("Context must be a positive integer") |
|
390 | raise ValueError("Context must be a positive integer") | |
379 | except (TypeError, ValueError) as e: |
|
391 | except (TypeError, ValueError) as e: | |
@@ -390,7 +402,7 b' class Pdb(OldPdb):' | |||||
390 | if context is None: |
|
402 | if context is None: | |
391 | context = self.context |
|
403 | context = self.context | |
392 | try: |
|
404 | try: | |
393 | context=int(context) |
|
405 | context = int(context) | |
394 | if context <= 0: |
|
406 | if context <= 0: | |
395 | print("Context must be a positive integer", file=self.stdout) |
|
407 | print("Context must be a positive integer", file=self.stdout) | |
396 | except (TypeError, ValueError): |
|
408 | except (TypeError, ValueError): | |
@@ -402,11 +414,10 b' class Pdb(OldPdb):' | |||||
402 |
|
414 | |||
403 | Colors = self.color_scheme_table.active_colors |
|
415 | Colors = self.color_scheme_table.active_colors | |
404 | ColorsNormal = Colors.Normal |
|
416 | ColorsNormal = Colors.Normal | |
405 |
tpl_link = |
|
417 | tpl_link = "%s%%s%s" % (Colors.filenameEm, ColorsNormal) | |
406 |
tpl_call = |
|
418 | tpl_call = "%s%%s%s%%s%s" % (Colors.vName, Colors.valEm, ColorsNormal) | |
407 |
tpl_line = |
|
419 | tpl_line = "%%s%s%%s %s%%s" % (Colors.lineno, ColorsNormal) | |
408 |
tpl_line_em = |
|
420 | tpl_line_em = "%%s%s%%s %s%%s%s" % (Colors.linenoEm, Colors.line, ColorsNormal) | |
409 | ColorsNormal) |
|
|||
410 |
|
421 | |||
411 | frame, lineno = frame_lineno |
|
422 | frame, lineno = frame_lineno | |
412 |
|
423 | |||
@@ -439,8 +450,8 b' class Pdb(OldPdb):' | |||||
439 | if frame is self.curframe: |
|
450 | if frame is self.curframe: | |
440 | ret.append('> ') |
|
451 | ret.append('> ') | |
441 | else: |
|
452 | else: | |
442 |
ret.append( |
|
453 | ret.append(" ") | |
443 |
ret.append( |
|
454 | ret.append("%s(%s)%s\n" % (link, lineno, call)) | |
444 |
|
455 | |||
445 | start = lineno - 1 - context//2 |
|
456 | start = lineno - 1 - context//2 | |
446 | lines = linecache.getlines(filename) |
|
457 | lines = linecache.getlines(filename) | |
@@ -448,17 +459,17 b' class Pdb(OldPdb):' | |||||
448 | start = max(start, 0) |
|
459 | start = max(start, 0) | |
449 | lines = lines[start : start + context] |
|
460 | lines = lines[start : start + context] | |
450 |
|
461 | |||
451 | for i,line in enumerate(lines): |
|
462 | for i, line in enumerate(lines): | |
452 |
show_arrow = |
|
463 | show_arrow = start + 1 + i == lineno | |
453 |
linetpl = (frame is self.curframe or show_arrow) |
|
464 | linetpl = (frame is self.curframe or show_arrow) and tpl_line_em or tpl_line | |
454 | and tpl_line_em \ |
|
465 | ret.append( | |
455 |
|
|
466 | self.__format_line( | |
456 | ret.append(self.__format_line(linetpl, filename, |
|
467 | linetpl, filename, start + 1 + i, line, arrow=show_arrow | |
457 | start + 1 + i, line, |
|
468 | ) | |
458 | arrow = show_arrow) ) |
|
469 | ) | |
459 |
return |
|
470 | return "".join(ret) | |
460 |
|
471 | |||
461 |
def __format_line(self, tpl_line, filename, lineno, line, arrow |
|
472 | def __format_line(self, tpl_line, filename, lineno, line, arrow=False): | |
462 | bp_mark = "" |
|
473 | bp_mark = "" | |
463 | bp_mark_color = "" |
|
474 | bp_mark_color = "" | |
464 |
|
475 | |||
@@ -488,7 +499,6 b' class Pdb(OldPdb):' | |||||
488 |
|
499 | |||
489 | return tpl_line % (bp_mark_color + bp_mark, num, line) |
|
500 | return tpl_line % (bp_mark_color + bp_mark, num, line) | |
490 |
|
501 | |||
491 |
|
||||
492 | def print_list_lines(self, filename, first, last): |
|
502 | def print_list_lines(self, filename, first, last): | |
493 | """The printing (as opposed to the parsing part of a 'list' |
|
503 | """The printing (as opposed to the parsing part of a 'list' | |
494 | command.""" |
|
504 | command.""" | |
@@ -507,9 +517,13 b' class Pdb(OldPdb):' | |||||
507 | break |
|
517 | break | |
508 |
|
518 | |||
509 | if lineno == self.curframe.f_lineno: |
|
519 | if lineno == self.curframe.f_lineno: | |
510 |
line = self.__format_line( |
|
520 | line = self.__format_line( | |
|
521 | tpl_line_em, filename, lineno, line, arrow=True | |||
|
522 | ) | |||
511 | else: |
|
523 | else: | |
512 |
line = self.__format_line( |
|
524 | line = self.__format_line( | |
|
525 | tpl_line, filename, lineno, line, arrow=False | |||
|
526 | ) | |||
513 |
|
527 | |||
514 | src.append(line) |
|
528 | src.append(line) | |
515 | self.lineno = lineno |
|
529 | self.lineno = lineno | |
@@ -706,7 +720,7 b' class Pdb(OldPdb):' | |||||
706 |
|
720 | |||
707 | Will skip hidden frames. |
|
721 | Will skip hidden frames. | |
708 | """ |
|
722 | """ | |
709 |
|
|
723 | # modified version of upstream that skips | |
710 | # frames with __tracebackide__ |
|
724 | # frames with __tracebackide__ | |
711 | if self.curindex == 0: |
|
725 | if self.curindex == 0: | |
712 | self.error("Oldest frame") |
|
726 | self.error("Oldest frame") | |
@@ -720,11 +734,9 b' class Pdb(OldPdb):' | |||||
720 | if count < 0: |
|
734 | if count < 0: | |
721 | _newframe = 0 |
|
735 | _newframe = 0 | |
722 | else: |
|
736 | else: | |
723 | _newindex = self.curindex |
|
|||
724 | counter = 0 |
|
737 | counter = 0 | |
725 | hidden_frames = self.hidden_frames(self.stack) |
|
738 | hidden_frames = self.hidden_frames(self.stack) | |
726 | for i in range(self.curindex - 1, -1, -1): |
|
739 | for i in range(self.curindex - 1, -1, -1): | |
727 | frame = self.stack[i][0] |
|
|||
728 | if hidden_frames[i] and self.skip_hidden: |
|
740 | if hidden_frames[i] and self.skip_hidden: | |
729 | skipped += 1 |
|
741 | skipped += 1 | |
730 | continue |
|
742 | continue | |
@@ -765,12 +777,10 b' class Pdb(OldPdb):' | |||||
765 | if count < 0: |
|
777 | if count < 0: | |
766 | _newframe = len(self.stack) - 1 |
|
778 | _newframe = len(self.stack) - 1 | |
767 | else: |
|
779 | else: | |
768 | _newindex = self.curindex |
|
|||
769 | counter = 0 |
|
780 | counter = 0 | |
770 | skipped = 0 |
|
781 | skipped = 0 | |
771 | hidden_frames = self.hidden_frames(self.stack) |
|
782 | hidden_frames = self.hidden_frames(self.stack) | |
772 | for i in range(self.curindex + 1, len(self.stack)): |
|
783 | for i in range(self.curindex + 1, len(self.stack)): | |
773 | frame = self.stack[i][0] |
|
|||
774 | if hidden_frames[i] and self.skip_hidden: |
|
784 | if hidden_frames[i] and self.skip_hidden: | |
775 | skipped += 1 |
|
785 | skipped += 1 | |
776 | continue |
|
786 | continue |
@@ -1,5 +1,4 b'' | |||||
1 | import asyncio |
|
1 | import asyncio | |
2 | import signal |
|
|||
3 | import sys |
|
2 | import sys | |
4 | import threading |
|
3 | import threading | |
5 |
|
4 | |||
@@ -7,13 +6,8 b' from IPython.core.debugger import Pdb' | |||||
7 |
|
6 | |||
8 | from IPython.core.completer import IPCompleter |
|
7 | from IPython.core.completer import IPCompleter | |
9 | from .ptutils import IPythonPTCompleter |
|
8 | from .ptutils import IPythonPTCompleter | |
10 |
from .shortcuts import create_ipython_shortcuts |
|
9 | from .shortcuts import create_ipython_shortcuts | |
11 |
|
10 | |||
12 | from prompt_toolkit.enums import DEFAULT_BUFFER |
|
|||
13 | from prompt_toolkit.filters import (Condition, has_focus, has_selection, |
|
|||
14 | vi_insert_mode, emacs_insert_mode) |
|
|||
15 | from prompt_toolkit.key_binding import KeyBindings |
|
|||
16 | from prompt_toolkit.key_binding.bindings.completion import display_completions_like_readline |
|
|||
17 | from pygments.token import Token |
|
11 | from pygments.token import Token | |
18 | from prompt_toolkit.shortcuts.prompt import PromptSession |
|
12 | from prompt_toolkit.shortcuts.prompt import PromptSession | |
19 | from prompt_toolkit.enums import EditingMode |
|
13 | from prompt_toolkit.enums import EditingMode | |
@@ -34,22 +28,20 b' class TerminalPdb(Pdb):' | |||||
34 | def pt_init(self, pt_session_options=None): |
|
28 | def pt_init(self, pt_session_options=None): | |
35 | """Initialize the prompt session and the prompt loop |
|
29 | """Initialize the prompt session and the prompt loop | |
36 | and store them in self.pt_app and self.pt_loop. |
|
30 | and store them in self.pt_app and self.pt_loop. | |
37 |
|
31 | |||
38 | Additional keyword arguments for the PromptSession class |
|
32 | Additional keyword arguments for the PromptSession class | |
39 | can be specified in pt_session_options. |
|
33 | can be specified in pt_session_options. | |
40 | """ |
|
34 | """ | |
41 | if pt_session_options is None: |
|
35 | if pt_session_options is None: | |
42 | pt_session_options = {} |
|
36 | pt_session_options = {} | |
43 |
|
37 | |||
44 | def get_prompt_tokens(): |
|
38 | def get_prompt_tokens(): | |
45 | return [(Token.Prompt, self.prompt)] |
|
39 | return [(Token.Prompt, self.prompt)] | |
46 |
|
40 | |||
47 | if self._ptcomp is None: |
|
41 | if self._ptcomp is None: | |
48 |
compl = IPCompleter( |
|
42 | compl = IPCompleter( | |
49 | namespace={}, |
|
43 | shell=self.shell, namespace={}, global_namespace={}, parent=self.shell | |
50 | global_namespace={}, |
|
44 | ) | |
51 | parent=self.shell, |
|
|||
52 | ) |
|
|||
53 | # add a completer for all the do_ methods |
|
45 | # add a completer for all the do_ methods | |
54 | methods_names = [m[3:] for m in dir(self) if m.startswith("do_")] |
|
46 | methods_names = [m[3:] for m in dir(self) if m.startswith("do_")] | |
55 |
|
47 |
General Comments 0
You need to be logged in to leave comments.
Login now