Show More
@@ -50,6 +50,7 b' from pdb import Pdb as OldPdb' | |||||
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: | |
@@ -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,6 +320,18 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 | |||
@@ -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) | |
@@ -449,14 +460,14 b' class Pdb(OldPdb):' | |||||
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 = "" | |
@@ -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 | |
@@ -45,10 +39,8 b' class TerminalPdb(Pdb):' | |||||
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={}, |
|
|||
51 | parent=self.shell, |
|
|||
52 | ) |
|
44 | ) | |
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_")] |
General Comments 0
You need to be logged in to leave comments.
Login now