##// END OF EJS Templates
fixing typo in comment
mbyt -
Show More
@@ -1,96 +1,96 b''
1 1 from IPython.core.debugger import Pdb
2 2
3 3 from IPython.core.completer import IPCompleter
4 4 from .ptutils import IPythonPTCompleter
5 5
6 6 from prompt_toolkit.token import Token
7 7 from prompt_toolkit.shortcuts import create_prompt_application
8 8 from prompt_toolkit.interface import CommandLineInterface
9 9 from prompt_toolkit.enums import EditingMode
10 10 import sys
11 11
12 12
13 13 class TerminalPdb(Pdb):
14 14 def __init__(self, *args, **kwargs):
15 15 Pdb.__init__(self, *args, **kwargs)
16 16 self._ptcomp = None
17 17 self.pt_init()
18 18
19 19 def pt_init(self):
20 20 def get_prompt_tokens(cli):
21 21 return [(Token.Prompt, self.prompt)]
22 22
23 23 if self._ptcomp is None:
24 24 compl = IPCompleter(shell=self.shell,
25 25 namespace={},
26 26 global_namespace={},
27 27 use_readline=False,
28 28 parent=self.shell,
29 29 )
30 30 self._ptcomp = IPythonPTCompleter(compl)
31 31
32 32 self._pt_app = create_prompt_application(
33 33 editing_mode=getattr(EditingMode, self.shell.editing_mode.upper()),
34 34 history=self.shell.debugger_history,
35 35 completer= self._ptcomp,
36 36 enable_history_search=True,
37 37 mouse_support=self.shell.mouse_support,
38 38 get_prompt_tokens=get_prompt_tokens
39 39 )
40 40 self.pt_cli = CommandLineInterface(self._pt_app, eventloop=self.shell._eventloop)
41 41
42 42 def cmdloop(self, intro=None):
43 43 """Repeatedly issue a prompt, accept input, parse an initial prefix
44 44 off the received input, and dispatch to action methods, passing them
45 45 the remainder of the line as argument.
46 46
47 47 override the same methods from cmd.Cmd to provide prompt toolkit replacement.
48 48 """
49 49 if not self.use_rawinput:
50 50 raise ValueError('Sorry ipdb does not support use_rawinput=False')
51 51
52 52 self.preloop()
53 53
54 54 try:
55 55 if intro is not None:
56 56 self.intro = intro
57 57 if self.intro:
58 58 self.stdout.write(str(self.intro)+"\n")
59 59 stop = None
60 60 while not stop:
61 61 if self.cmdqueue:
62 62 line = self.cmdqueue.pop(0)
63 63 else:
64 64 self._ptcomp.ipy_completer.namespace = self.curframe_locals
65 65 self._ptcomp.ipy_completer.global_namespace = self.curframe.f_globals
66 66 try:
67 67 line = self.pt_cli.run(reset_current_buffer=True).text
68 68 except EOFError:
69 69 line = 'EOF'
70 70 line = self.precmd(line)
71 71 stop = self.onecmd(line)
72 72 stop = self.postcmd(stop, line)
73 73 self.postloop()
74 74 except Exception:
75 75 raise
76 76
77 77
78 78 def set_trace(frame=None):
79 79 """
80 80 Start debugging from `frame`.
81 81
82 82 If frame is not specified, debugging starts from caller's frame.
83 83 """
84 84 TerminalPdb().set_trace(frame or sys._getframe().f_back)
85 85
86 86
87 87 if __name__ == '__main__':
88 88 import pdb
89 89 # IPython.core.debugger.Pdb.trace_dispatch shall not catch
90 # bdb.BdbQuit. When started through __main__ and an exeption
90 # bdb.BdbQuit. When started through __main__ and an exception
91 91 # happend after hitting "c", this is needed in order to
92 92 # be able to quit the debugging session (see #9950).
93 93 old_trace_dispatch = pdb.Pdb.trace_dispatch
94 94 pdb.Pdb = TerminalPdb
95 95 pdb.Pdb.trace_dispatch = old_trace_dispatch
96 96 pdb.main()
General Comments 0
You need to be logged in to leave comments. Login now