Show More
@@ -43,13 +43,14 b' from IPython.testing.skipdoctest import skip_doctest' | |||
|
43 | 43 | |
|
44 | 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 | 47 | from pdb import Pdb as OldPdb |
|
48 | 48 | |
|
49 | 49 | # Allow the set_trace code to operate outside of an ipython instance, even if |
|
50 | 50 | # it does so with some limitations. The rest of this support is implemented in |
|
51 | 51 | # the Tracer constructor. |
|
52 | 52 | |
|
53 | ||
|
53 | 54 | def make_arrow(pad): |
|
54 | 55 | """generate the leading arrow in front of traceback or debugger""" |
|
55 | 56 | if pad >= 2: |
@@ -67,16 +68,16 b' def BdbQuit_excepthook(et, ev, tb, excepthook=None):' | |||
|
67 | 68 | """ |
|
68 | 69 | warnings.warn("`BdbQuit_excepthook` is deprecated since version 5.1", |
|
69 | 70 | DeprecationWarning, stacklevel=2) |
|
70 | if et==bdb.BdbQuit: | |
|
71 | if et == bdb.BdbQuit: | |
|
71 | 72 | print('Exiting Debugger.') |
|
72 | 73 | elif excepthook is not None: |
|
73 | 74 | excepthook(et, ev, tb) |
|
74 | 75 | else: |
|
75 | 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 | 81 | warnings.warn( |
|
81 | 82 | "`BdbQuit_IPython_excepthook` is deprecated since version 5.1", |
|
82 | 83 | DeprecationWarning, stacklevel=2) |
@@ -203,7 +204,7 b' class Pdb(OldPdb):' | |||
|
203 | 204 | def __init__(self, color_scheme=None, completekey=None, |
|
204 | 205 | stdin=None, stdout=None, context=5, **kwargs): |
|
205 | 206 | """Create a new IPython debugger. |
|
206 | ||
|
207 | ||
|
207 | 208 | :param color_scheme: Deprecated, do not use. |
|
208 | 209 | :param completekey: Passed to pdb.Pdb. |
|
209 | 210 | :param stdin: Passed to pdb.Pdb. |
@@ -237,7 +238,7 b' class Pdb(OldPdb):' | |||
|
237 | 238 | self.shell = TerminalInteractiveShell.instance() |
|
238 | 239 | # needed by any code which calls __import__("__main__") after |
|
239 | 240 | # the debugger was entered. See also #9941. |
|
240 |
sys.modules[ |
|
|
241 | sys.modules["__main__"] = save_main | |
|
241 | 242 | |
|
242 | 243 | if color_scheme is not None: |
|
243 | 244 | warnings.warn( |
@@ -272,7 +273,6 b' class Pdb(OldPdb):' | |||
|
272 | 273 | cst['Neutral'].colors.breakpoint_enabled = C.LightRed |
|
273 | 274 | cst['Neutral'].colors.breakpoint_disabled = C.Red |
|
274 | 275 | |
|
275 | ||
|
276 | 276 | # Add a python parser so we can syntax highlight source while |
|
277 | 277 | # debugging. |
|
278 | 278 | self.parser = PyColorize.Parser(style=color_scheme) |
@@ -320,13 +320,25 b' class Pdb(OldPdb):' | |||
|
320 | 320 | except KeyboardInterrupt: |
|
321 | 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 | 335 | def new_do_frame(self, arg): |
|
324 | 336 | OldPdb.do_frame(self, arg) |
|
325 | 337 | |
|
326 | 338 | def new_do_quit(self, arg): |
|
327 | 339 | |
|
328 | 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 | 343 | return OldPdb.do_quit(self, arg) |
|
332 | 344 | |
@@ -344,7 +356,7 b' class Pdb(OldPdb):' | |||
|
344 | 356 | if context is None: |
|
345 | 357 | context = self.context |
|
346 | 358 | try: |
|
347 | context=int(context) | |
|
359 | context = int(context) | |
|
348 | 360 | if context <= 0: |
|
349 | 361 | raise ValueError("Context must be a positive integer") |
|
350 | 362 | except (TypeError, ValueError) as e: |
@@ -373,7 +385,7 b' class Pdb(OldPdb):' | |||
|
373 | 385 | if context is None: |
|
374 | 386 | context = self.context |
|
375 | 387 | try: |
|
376 | context=int(context) | |
|
388 | context = int(context) | |
|
377 | 389 | if context <= 0: |
|
378 | 390 | raise ValueError("Context must be a positive integer") |
|
379 | 391 | except (TypeError, ValueError) as e: |
@@ -390,7 +402,7 b' class Pdb(OldPdb):' | |||
|
390 | 402 | if context is None: |
|
391 | 403 | context = self.context |
|
392 | 404 | try: |
|
393 | context=int(context) | |
|
405 | context = int(context) | |
|
394 | 406 | if context <= 0: |
|
395 | 407 | print("Context must be a positive integer", file=self.stdout) |
|
396 | 408 | except (TypeError, ValueError): |
@@ -402,11 +414,10 b' class Pdb(OldPdb):' | |||
|
402 | 414 | |
|
403 | 415 | Colors = self.color_scheme_table.active_colors |
|
404 | 416 | ColorsNormal = Colors.Normal |
|
405 |
tpl_link = |
|
|
406 |
tpl_call = |
|
|
407 |
tpl_line = |
|
|
408 |
tpl_line_em = |
|
|
409 | ColorsNormal) | |
|
417 | tpl_link = "%s%%s%s" % (Colors.filenameEm, ColorsNormal) | |
|
418 | tpl_call = "%s%%s%s%%s%s" % (Colors.vName, Colors.valEm, ColorsNormal) | |
|
419 | tpl_line = "%%s%s%%s %s%%s" % (Colors.lineno, ColorsNormal) | |
|
420 | tpl_line_em = "%%s%s%%s %s%%s%s" % (Colors.linenoEm, Colors.line, ColorsNormal) | |
|
410 | 421 | |
|
411 | 422 | frame, lineno = frame_lineno |
|
412 | 423 | |
@@ -439,8 +450,8 b' class Pdb(OldPdb):' | |||
|
439 | 450 | if frame is self.curframe: |
|
440 | 451 | ret.append('> ') |
|
441 | 452 | else: |
|
442 |
ret.append( |
|
|
443 |
ret.append( |
|
|
453 | ret.append(" ") | |
|
454 | ret.append("%s(%s)%s\n" % (link, lineno, call)) | |
|
444 | 455 | |
|
445 | 456 | start = lineno - 1 - context//2 |
|
446 | 457 | lines = linecache.getlines(filename) |
@@ -448,17 +459,17 b' class Pdb(OldPdb):' | |||
|
448 | 459 | start = max(start, 0) |
|
449 | 460 | lines = lines[start : start + context] |
|
450 | 461 | |
|
451 | for i,line in enumerate(lines): | |
|
452 |
show_arrow = |
|
|
453 |
linetpl = (frame is self.curframe or show_arrow) |
|
|
454 | and tpl_line_em \ | |
|
455 |
|
|
|
456 | ret.append(self.__format_line(linetpl, filename, | |
|
457 | start + 1 + i, line, | |
|
458 | arrow = show_arrow) ) | |
|
459 |
return |
|
|
460 | ||
|
461 |
def __format_line(self, tpl_line, filename, lineno, line, arrow |
|
|
462 | for i, line in enumerate(lines): | |
|
463 | show_arrow = start + 1 + i == lineno | |
|
464 | linetpl = (frame is self.curframe or show_arrow) and tpl_line_em or tpl_line | |
|
465 | ret.append( | |
|
466 | self.__format_line( | |
|
467 | linetpl, filename, start + 1 + i, line, arrow=show_arrow | |
|
468 | ) | |
|
469 | ) | |
|
470 | return "".join(ret) | |
|
471 | ||
|
472 | def __format_line(self, tpl_line, filename, lineno, line, arrow=False): | |
|
462 | 473 | bp_mark = "" |
|
463 | 474 | bp_mark_color = "" |
|
464 | 475 | |
@@ -488,7 +499,6 b' class Pdb(OldPdb):' | |||
|
488 | 499 | |
|
489 | 500 | return tpl_line % (bp_mark_color + bp_mark, num, line) |
|
490 | 501 | |
|
491 | ||
|
492 | 502 | def print_list_lines(self, filename, first, last): |
|
493 | 503 | """The printing (as opposed to the parsing part of a 'list' |
|
494 | 504 | command.""" |
@@ -507,9 +517,13 b' class Pdb(OldPdb):' | |||
|
507 | 517 | break |
|
508 | 518 | |
|
509 | 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 | 523 | else: |
|
512 |
line = self.__format_line( |
|
|
524 | line = self.__format_line( | |
|
525 | tpl_line, filename, lineno, line, arrow=False | |
|
526 | ) | |
|
513 | 527 | |
|
514 | 528 | src.append(line) |
|
515 | 529 | self.lineno = lineno |
@@ -706,7 +720,7 b' class Pdb(OldPdb):' | |||
|
706 | 720 | |
|
707 | 721 | Will skip hidden frames. |
|
708 | 722 | """ |
|
709 |
|
|
|
723 | # modified version of upstream that skips | |
|
710 | 724 | # frames with __tracebackide__ |
|
711 | 725 | if self.curindex == 0: |
|
712 | 726 | self.error("Oldest frame") |
@@ -720,11 +734,9 b' class Pdb(OldPdb):' | |||
|
720 | 734 | if count < 0: |
|
721 | 735 | _newframe = 0 |
|
722 | 736 | else: |
|
723 | _newindex = self.curindex | |
|
724 | 737 | counter = 0 |
|
725 | 738 | hidden_frames = self.hidden_frames(self.stack) |
|
726 | 739 | for i in range(self.curindex - 1, -1, -1): |
|
727 | frame = self.stack[i][0] | |
|
728 | 740 | if hidden_frames[i] and self.skip_hidden: |
|
729 | 741 | skipped += 1 |
|
730 | 742 | continue |
@@ -765,12 +777,10 b' class Pdb(OldPdb):' | |||
|
765 | 777 | if count < 0: |
|
766 | 778 | _newframe = len(self.stack) - 1 |
|
767 | 779 | else: |
|
768 | _newindex = self.curindex | |
|
769 | 780 | counter = 0 |
|
770 | 781 | skipped = 0 |
|
771 | 782 | hidden_frames = self.hidden_frames(self.stack) |
|
772 | 783 | for i in range(self.curindex + 1, len(self.stack)): |
|
773 | frame = self.stack[i][0] | |
|
774 | 784 | if hidden_frames[i] and self.skip_hidden: |
|
775 | 785 | skipped += 1 |
|
776 | 786 | continue |
@@ -1,5 +1,4 b'' | |||
|
1 | 1 | import asyncio |
|
2 | import signal | |
|
3 | 2 | import sys |
|
4 | 3 | import threading |
|
5 | 4 | |
@@ -7,13 +6,8 b' from IPython.core.debugger import Pdb' | |||
|
7 | 6 | |
|
8 | 7 | from IPython.core.completer import IPCompleter |
|
9 | 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 | 11 | from pygments.token import Token |
|
18 | 12 | from prompt_toolkit.shortcuts.prompt import PromptSession |
|
19 | 13 | from prompt_toolkit.enums import EditingMode |
@@ -34,22 +28,20 b' class TerminalPdb(Pdb):' | |||
|
34 | 28 | def pt_init(self, pt_session_options=None): |
|
35 | 29 | """Initialize the prompt session and the prompt loop |
|
36 | 30 | and store them in self.pt_app and self.pt_loop. |
|
37 | ||
|
31 | ||
|
38 | 32 | Additional keyword arguments for the PromptSession class |
|
39 | 33 | can be specified in pt_session_options. |
|
40 | 34 | """ |
|
41 | 35 | if pt_session_options is None: |
|
42 | 36 | pt_session_options = {} |
|
43 | ||
|
37 | ||
|
44 | 38 | def get_prompt_tokens(): |
|
45 | 39 | return [(Token.Prompt, self.prompt)] |
|
46 | 40 | |
|
47 | 41 | if self._ptcomp is None: |
|
48 |
compl = IPCompleter( |
|
|
49 | namespace={}, | |
|
50 | global_namespace={}, | |
|
51 | parent=self.shell, | |
|
52 | ) | |
|
42 | compl = IPCompleter( | |
|
43 | shell=self.shell, namespace={}, global_namespace={}, parent=self.shell | |
|
44 | ) | |
|
53 | 45 | # add a completer for all the do_ methods |
|
54 | 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