##// END OF EJS Templates
existence of old_all_completions checked in debugger exit
vivainio -
Show More
@@ -1,411 +1,415 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """
2 """
3 Pdb debugger class.
3 Pdb debugger class.
4
4
5 Modified from the standard pdb.Pdb class to avoid including readline, so that
5 Modified from the standard pdb.Pdb class to avoid including readline, so that
6 the command line completion of other programs which include this isn't
6 the command line completion of other programs which include this isn't
7 damaged.
7 damaged.
8
8
9 In the future, this class will be expanded with improvements over the standard
9 In the future, this class will be expanded with improvements over the standard
10 pdb.
10 pdb.
11
11
12 The code in this file is mainly lifted out of cmd.py in Python 2.2, with minor
12 The code in this file is mainly lifted out of cmd.py in Python 2.2, with minor
13 changes. Licensing should therefore be under the standard Python terms. For
13 changes. Licensing should therefore be under the standard Python terms. For
14 details on the PSF (Python Software Foundation) standard license, see:
14 details on the PSF (Python Software Foundation) standard license, see:
15
15
16 http://www.python.org/2.2.3/license.html
16 http://www.python.org/2.2.3/license.html
17
17
18 $Id: Debugger.py 1853 2006-10-30 17:00:39Z vivainio $"""
18 $Id: Debugger.py 1951 2006-11-29 07:56:47Z vivainio $"""
19
19
20 #*****************************************************************************
20 #*****************************************************************************
21 #
21 #
22 # Since this file is essentially a modified copy of the pdb module which is
22 # Since this file is essentially a modified copy of the pdb module which is
23 # part of the standard Python distribution, I assume that the proper procedure
23 # part of the standard Python distribution, I assume that the proper procedure
24 # is to maintain its copyright as belonging to the Python Software Foundation
24 # is to maintain its copyright as belonging to the Python Software Foundation
25 # (in addition to my own, for all new code).
25 # (in addition to my own, for all new code).
26 #
26 #
27 # Copyright (C) 2001 Python Software Foundation, www.python.org
27 # Copyright (C) 2001 Python Software Foundation, www.python.org
28 # Copyright (C) 2005-2006 Fernando Perez. <fperez@colorado.edu>
28 # Copyright (C) 2005-2006 Fernando Perez. <fperez@colorado.edu>
29 #
29 #
30 # Distributed under the terms of the BSD License. The full license is in
30 # Distributed under the terms of the BSD License. The full license is in
31 # the file COPYING, distributed as part of this software.
31 # the file COPYING, distributed as part of this software.
32 #
32 #
33 #*****************************************************************************
33 #*****************************************************************************
34
34
35 from IPython import Release
35 from IPython import Release
36 __author__ = '%s <%s>' % Release.authors['Fernando']
36 __author__ = '%s <%s>' % Release.authors['Fernando']
37 __license__ = 'Python'
37 __license__ = 'Python'
38
38
39 import bdb
39 import bdb
40 import cmd
40 import cmd
41 import linecache
41 import linecache
42 import os
42 import os
43 import sys
43 import sys
44
44
45 from IPython import PyColorize, ColorANSI
45 from IPython import PyColorize, ColorANSI
46 from IPython.genutils import Term
46 from IPython.genutils import Term
47 from IPython.excolors import ExceptionColors
47 from IPython.excolors import ExceptionColors
48
48
49 # See if we can use pydb.
49 # See if we can use pydb.
50 has_pydb = False
50 has_pydb = False
51 prompt = 'ipdb>'
51 prompt = 'ipdb>'
52 if sys.version[:3] >= '2.5':
52 if sys.version[:3] >= '2.5':
53 try:
53 try:
54 import pydb
54 import pydb
55 if hasattr(pydb.pydb, "runl"):
55 if hasattr(pydb.pydb, "runl"):
56 has_pydb = True
56 has_pydb = True
57 from pydb import Pdb as OldPdb
57 from pydb import Pdb as OldPdb
58 prompt = 'ipydb>'
58 prompt = 'ipydb>'
59 except ImportError:
59 except ImportError:
60 pass
60 pass
61
61
62 if has_pydb:
62 if has_pydb:
63 from pydb import Pdb as OldPdb
63 from pydb import Pdb as OldPdb
64 else:
64 else:
65 from pdb import Pdb as OldPdb
65 from pdb import Pdb as OldPdb
66
66
67 def decorate_fn_with_doc(new_fn, old_fn, additional_text=""):
67 def decorate_fn_with_doc(new_fn, old_fn, additional_text=""):
68 """Make new_fn have old_fn's doc string. This is particularly useful
68 """Make new_fn have old_fn's doc string. This is particularly useful
69 for the do_... commands that hook into the help system.
69 for the do_... commands that hook into the help system.
70 Adapted from from a comp.lang.python posting
70 Adapted from from a comp.lang.python posting
71 by Duncan Booth."""
71 by Duncan Booth."""
72 def wrapper(*args, **kw):
72 def wrapper(*args, **kw):
73 return new_fn(*args, **kw)
73 return new_fn(*args, **kw)
74 if old_fn.__doc__:
74 if old_fn.__doc__:
75 wrapper.__doc__ = old_fn.__doc__ + additional_text
75 wrapper.__doc__ = old_fn.__doc__ + additional_text
76 return wrapper
76 return wrapper
77
77
78 def _file_lines(fname):
78 def _file_lines(fname):
79 """Return the contents of a named file as a list of lines.
79 """Return the contents of a named file as a list of lines.
80
80
81 This function never raises an IOError exception: if the file can't be
81 This function never raises an IOError exception: if the file can't be
82 read, it simply returns an empty list."""
82 read, it simply returns an empty list."""
83
83
84 try:
84 try:
85 outfile = open(fname)
85 outfile = open(fname)
86 except IOError:
86 except IOError:
87 return []
87 return []
88 else:
88 else:
89 out = outfile.readlines()
89 out = outfile.readlines()
90 outfile.close()
90 outfile.close()
91 return out
91 return out
92
92
93 class Pdb(OldPdb):
93 class Pdb(OldPdb):
94 """Modified Pdb class, does not load readline."""
94 """Modified Pdb class, does not load readline."""
95
95
96 if sys.version[:3] >= '2.5':
96 if sys.version[:3] >= '2.5':
97 def __init__(self,color_scheme='NoColor',completekey=None,
97 def __init__(self,color_scheme='NoColor',completekey=None,
98 stdin=None, stdout=None):
98 stdin=None, stdout=None):
99
99
100 # Parent constructor:
100 # Parent constructor:
101 OldPdb.__init__(self,completekey,stdin,stdout)
101 OldPdb.__init__(self,completekey,stdin,stdout)
102
102
103 # IPython changes...
103 # IPython changes...
104 self.prompt = prompt # The default prompt is '(Pdb)'
104 self.prompt = prompt # The default prompt is '(Pdb)'
105 self.is_pydb = prompt == 'ipydb>'
105 self.is_pydb = prompt == 'ipydb>'
106
106
107 if self.is_pydb:
107 if self.is_pydb:
108
108
109 # iplib.py's ipalias seems to want pdb's checkline
109 # iplib.py's ipalias seems to want pdb's checkline
110 # which located in pydb.fn
110 # which located in pydb.fn
111 import pydb.fns
111 import pydb.fns
112 self.checkline = lambda filename, lineno: \
112 self.checkline = lambda filename, lineno: \
113 pydb.fns.checkline(self, filename, lineno)
113 pydb.fns.checkline(self, filename, lineno)
114
114
115 self.curframe = None
115 self.curframe = None
116 self.do_restart = self.new_do_restart
116 self.do_restart = self.new_do_restart
117
117
118 self.old_all_completions = __IPYTHON__.Completer.all_completions
118 self.old_all_completions = __IPYTHON__.Completer.all_completions
119 __IPYTHON__.Completer.all_completions=self.all_completions
119 __IPYTHON__.Completer.all_completions=self.all_completions
120
120
121 # Do we have access to pydb's list command parser?
121 # Do we have access to pydb's list command parser?
122 self.do_list = decorate_fn_with_doc(self.list_command_pydb,
122 self.do_list = decorate_fn_with_doc(self.list_command_pydb,
123 OldPdb.do_list)
123 OldPdb.do_list)
124 self.do_l = self.do_list
124 self.do_l = self.do_list
125 self.do_frame = decorate_fn_with_doc(self.new_do_frame,
125 self.do_frame = decorate_fn_with_doc(self.new_do_frame,
126 OldPdb.do_frame)
126 OldPdb.do_frame)
127
127
128 self.aliases = {}
128 self.aliases = {}
129
129
130 # Create color table: we copy the default one from the traceback
130 # Create color table: we copy the default one from the traceback
131 # module and add a few attributes needed for debugging
131 # module and add a few attributes needed for debugging
132 self.color_scheme_table = ExceptionColors.copy()
132 self.color_scheme_table = ExceptionColors.copy()
133
133
134 # shorthands
134 # shorthands
135 C = ColorANSI.TermColors
135 C = ColorANSI.TermColors
136 cst = self.color_scheme_table
136 cst = self.color_scheme_table
137
137
138 cst['NoColor'].colors.breakpoint_enabled = C.NoColor
138 cst['NoColor'].colors.breakpoint_enabled = C.NoColor
139 cst['NoColor'].colors.breakpoint_disabled = C.NoColor
139 cst['NoColor'].colors.breakpoint_disabled = C.NoColor
140
140
141 cst['Linux'].colors.breakpoint_enabled = C.LightRed
141 cst['Linux'].colors.breakpoint_enabled = C.LightRed
142 cst['Linux'].colors.breakpoint_disabled = C.Red
142 cst['Linux'].colors.breakpoint_disabled = C.Red
143
143
144 cst['LightBG'].colors.breakpoint_enabled = C.LightRed
144 cst['LightBG'].colors.breakpoint_enabled = C.LightRed
145 cst['LightBG'].colors.breakpoint_disabled = C.Red
145 cst['LightBG'].colors.breakpoint_disabled = C.Red
146
146
147 self.set_colors(color_scheme)
147 self.set_colors(color_scheme)
148
148
149 else:
149 else:
150 # Ugly hack: for Python 2.3-2.4, we can't call the parent constructor,
150 # Ugly hack: for Python 2.3-2.4, we can't call the parent constructor,
151 # because it binds readline and breaks tab-completion. This means we
151 # because it binds readline and breaks tab-completion. This means we
152 # have to COPY the constructor here.
152 # have to COPY the constructor here.
153 def __init__(self,color_scheme='NoColor'):
153 def __init__(self,color_scheme='NoColor'):
154 bdb.Bdb.__init__(self)
154 bdb.Bdb.__init__(self)
155 cmd.Cmd.__init__(self,completekey=None) # don't load readline
155 cmd.Cmd.__init__(self,completekey=None) # don't load readline
156 self.prompt = 'ipdb> ' # The default prompt is '(Pdb)'
156 self.prompt = 'ipdb> ' # The default prompt is '(Pdb)'
157 self.aliases = {}
157 self.aliases = {}
158
158
159 # These two lines are part of the py2.4 constructor, let's put them
159 # These two lines are part of the py2.4 constructor, let's put them
160 # unconditionally here as they won't cause any problems in 2.3.
160 # unconditionally here as they won't cause any problems in 2.3.
161 self.mainpyfile = ''
161 self.mainpyfile = ''
162 self._wait_for_mainpyfile = 0
162 self._wait_for_mainpyfile = 0
163
163
164 # Read $HOME/.pdbrc and ./.pdbrc
164 # Read $HOME/.pdbrc and ./.pdbrc
165 try:
165 try:
166 self.rcLines = _file_lines(os.path.join(os.environ['HOME'],
166 self.rcLines = _file_lines(os.path.join(os.environ['HOME'],
167 ".pdbrc"))
167 ".pdbrc"))
168 except KeyError:
168 except KeyError:
169 self.rcLines = []
169 self.rcLines = []
170 self.rcLines.extend(_file_lines(".pdbrc"))
170 self.rcLines.extend(_file_lines(".pdbrc"))
171
171
172 # Create color table: we copy the default one from the traceback
172 # Create color table: we copy the default one from the traceback
173 # module and add a few attributes needed for debugging
173 # module and add a few attributes needed for debugging
174 self.color_scheme_table = ExceptionColors.copy()
174 self.color_scheme_table = ExceptionColors.copy()
175
175
176 # shorthands
176 # shorthands
177 C = ColorANSI.TermColors
177 C = ColorANSI.TermColors
178 cst = self.color_scheme_table
178 cst = self.color_scheme_table
179
179
180 cst['NoColor'].colors.breakpoint_enabled = C.NoColor
180 cst['NoColor'].colors.breakpoint_enabled = C.NoColor
181 cst['NoColor'].colors.breakpoint_disabled = C.NoColor
181 cst['NoColor'].colors.breakpoint_disabled = C.NoColor
182
182
183 cst['Linux'].colors.breakpoint_enabled = C.LightRed
183 cst['Linux'].colors.breakpoint_enabled = C.LightRed
184 cst['Linux'].colors.breakpoint_disabled = C.Red
184 cst['Linux'].colors.breakpoint_disabled = C.Red
185
185
186 cst['LightBG'].colors.breakpoint_enabled = C.LightRed
186 cst['LightBG'].colors.breakpoint_enabled = C.LightRed
187 cst['LightBG'].colors.breakpoint_disabled = C.Red
187 cst['LightBG'].colors.breakpoint_disabled = C.Red
188
188
189 self.set_colors(color_scheme)
189 self.set_colors(color_scheme)
190
190
191 def set_colors(self, scheme):
191 def set_colors(self, scheme):
192 """Shorthand access to the color table scheme selector method."""
192 """Shorthand access to the color table scheme selector method."""
193 self.color_scheme_table.set_active_scheme(scheme)
193 self.color_scheme_table.set_active_scheme(scheme)
194
194
195 def interaction(self, frame, traceback):
195 def interaction(self, frame, traceback):
196 __IPYTHON__.set_completer_frame(frame)
196 __IPYTHON__.set_completer_frame(frame)
197 OldPdb.interaction(self, frame, traceback)
197 OldPdb.interaction(self, frame, traceback)
198
198
199 def new_do_up(self, arg):
199 def new_do_up(self, arg):
200 OldPdb.do_up(self, arg)
200 OldPdb.do_up(self, arg)
201 __IPYTHON__.set_completer_frame(self.curframe)
201 __IPYTHON__.set_completer_frame(self.curframe)
202 do_u = do_up = decorate_fn_with_doc(new_do_up, OldPdb.do_up)
202 do_u = do_up = decorate_fn_with_doc(new_do_up, OldPdb.do_up)
203
203
204 def new_do_down(self, arg):
204 def new_do_down(self, arg):
205 OldPdb.do_down(self, arg)
205 OldPdb.do_down(self, arg)
206 __IPYTHON__.set_completer_frame(self.curframe)
206 __IPYTHON__.set_completer_frame(self.curframe)
207
207
208 do_d = do_down = decorate_fn_with_doc(new_do_down, OldPdb.do_down)
208 do_d = do_down = decorate_fn_with_doc(new_do_down, OldPdb.do_down)
209
209
210 def new_do_frame(self, arg):
210 def new_do_frame(self, arg):
211 OldPdb.do_frame(self, arg)
211 OldPdb.do_frame(self, arg)
212 __IPYTHON__.set_completer_frame(self.curframe)
212 __IPYTHON__.set_completer_frame(self.curframe)
213
213
214 def new_do_quit(self, arg):
214 def new_do_quit(self, arg):
215 __IPYTHON__.Completer.all_completions=self.old_all_completions
215
216 if hasattr(self, 'old_all_completions'):
217 __IPYTHON__.Completer.all_completions=self.old_all_completions
218
219
216 return OldPdb.do_quit(self, arg)
220 return OldPdb.do_quit(self, arg)
217
221
218 do_q = do_quit = decorate_fn_with_doc(new_do_quit, OldPdb.do_quit)
222 do_q = do_quit = decorate_fn_with_doc(new_do_quit, OldPdb.do_quit)
219
223
220 def new_do_restart(self, arg):
224 def new_do_restart(self, arg):
221 """Restart command. In the context of ipython this is exactly the same
225 """Restart command. In the context of ipython this is exactly the same
222 thing as 'quit'."""
226 thing as 'quit'."""
223 self.msg("Restart doesn't make sense here. Using 'quit' instead.")
227 self.msg("Restart doesn't make sense here. Using 'quit' instead.")
224 return self.do_quit(arg)
228 return self.do_quit(arg)
225
229
226 def postloop(self):
230 def postloop(self):
227 __IPYTHON__.set_completer_frame(None)
231 __IPYTHON__.set_completer_frame(None)
228
232
229 def print_stack_trace(self):
233 def print_stack_trace(self):
230 try:
234 try:
231 for frame_lineno in self.stack:
235 for frame_lineno in self.stack:
232 self.print_stack_entry(frame_lineno, context = 5)
236 self.print_stack_entry(frame_lineno, context = 5)
233 except KeyboardInterrupt:
237 except KeyboardInterrupt:
234 pass
238 pass
235
239
236 def print_stack_entry(self,frame_lineno,prompt_prefix='\n-> ',
240 def print_stack_entry(self,frame_lineno,prompt_prefix='\n-> ',
237 context = 3):
241 context = 3):
238 frame, lineno = frame_lineno
242 frame, lineno = frame_lineno
239 print >>Term.cout, self.format_stack_entry(frame_lineno, '', context)
243 print >>Term.cout, self.format_stack_entry(frame_lineno, '', context)
240
244
241 def format_stack_entry(self, frame_lineno, lprefix=': ', context = 3):
245 def format_stack_entry(self, frame_lineno, lprefix=': ', context = 3):
242 import linecache, repr
246 import linecache, repr
243
247
244 ret = []
248 ret = []
245
249
246 Colors = self.color_scheme_table.active_colors
250 Colors = self.color_scheme_table.active_colors
247 ColorsNormal = Colors.Normal
251 ColorsNormal = Colors.Normal
248 tpl_link = '%s%%s%s' % (Colors.filenameEm, ColorsNormal)
252 tpl_link = '%s%%s%s' % (Colors.filenameEm, ColorsNormal)
249 tpl_call = '%s%%s%s%%s%s' % (Colors.vName, Colors.valEm, ColorsNormal)
253 tpl_call = '%s%%s%s%%s%s' % (Colors.vName, Colors.valEm, ColorsNormal)
250 tpl_line = '%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
254 tpl_line = '%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
251 tpl_line_em = '%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line,
255 tpl_line_em = '%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line,
252 ColorsNormal)
256 ColorsNormal)
253
257
254 frame, lineno = frame_lineno
258 frame, lineno = frame_lineno
255
259
256 return_value = ''
260 return_value = ''
257 if '__return__' in frame.f_locals:
261 if '__return__' in frame.f_locals:
258 rv = frame.f_locals['__return__']
262 rv = frame.f_locals['__return__']
259 #return_value += '->'
263 #return_value += '->'
260 return_value += repr.repr(rv) + '\n'
264 return_value += repr.repr(rv) + '\n'
261 ret.append(return_value)
265 ret.append(return_value)
262
266
263 #s = filename + '(' + `lineno` + ')'
267 #s = filename + '(' + `lineno` + ')'
264 filename = self.canonic(frame.f_code.co_filename)
268 filename = self.canonic(frame.f_code.co_filename)
265 link = tpl_link % filename
269 link = tpl_link % filename
266
270
267 if frame.f_code.co_name:
271 if frame.f_code.co_name:
268 func = frame.f_code.co_name
272 func = frame.f_code.co_name
269 else:
273 else:
270 func = "<lambda>"
274 func = "<lambda>"
271
275
272 call = ''
276 call = ''
273 if func != '?':
277 if func != '?':
274 if '__args__' in frame.f_locals:
278 if '__args__' in frame.f_locals:
275 args = repr.repr(frame.f_locals['__args__'])
279 args = repr.repr(frame.f_locals['__args__'])
276 else:
280 else:
277 args = '()'
281 args = '()'
278 call = tpl_call % (func, args)
282 call = tpl_call % (func, args)
279
283
280 # The level info should be generated in the same format pdb uses, to
284 # The level info should be generated in the same format pdb uses, to
281 # avoid breaking the pdbtrack functionality of python-mode in *emacs.
285 # avoid breaking the pdbtrack functionality of python-mode in *emacs.
282 ret.append('> %s(%s)%s\n' % (link,lineno,call))
286 ret.append('> %s(%s)%s\n' % (link,lineno,call))
283
287
284 start = lineno - 1 - context//2
288 start = lineno - 1 - context//2
285 lines = linecache.getlines(filename)
289 lines = linecache.getlines(filename)
286 start = max(start, 0)
290 start = max(start, 0)
287 start = min(start, len(lines) - context)
291 start = min(start, len(lines) - context)
288 lines = lines[start : start + context]
292 lines = lines[start : start + context]
289
293
290 for i,line in enumerate(lines):
294 for i,line in enumerate(lines):
291 show_arrow = (start + 1 + i == lineno)
295 show_arrow = (start + 1 + i == lineno)
292 ret.append(self.__format_line(tpl_line_em, filename,
296 ret.append(self.__format_line(tpl_line_em, filename,
293 start + 1 + i, line,
297 start + 1 + i, line,
294 arrow = show_arrow) )
298 arrow = show_arrow) )
295
299
296 return ''.join(ret)
300 return ''.join(ret)
297
301
298 def __format_line(self, tpl_line, filename, lineno, line, arrow = False):
302 def __format_line(self, tpl_line, filename, lineno, line, arrow = False):
299 bp_mark = ""
303 bp_mark = ""
300 bp_mark_color = ""
304 bp_mark_color = ""
301
305
302 bp = None
306 bp = None
303 if lineno in self.get_file_breaks(filename):
307 if lineno in self.get_file_breaks(filename):
304 bps = self.get_breaks(filename, lineno)
308 bps = self.get_breaks(filename, lineno)
305 bp = bps[-1]
309 bp = bps[-1]
306
310
307 if bp:
311 if bp:
308 Colors = self.color_scheme_table.active_colors
312 Colors = self.color_scheme_table.active_colors
309 bp_mark = str(bp.number)
313 bp_mark = str(bp.number)
310 bp_mark_color = Colors.breakpoint_enabled
314 bp_mark_color = Colors.breakpoint_enabled
311 if not bp.enabled:
315 if not bp.enabled:
312 bp_mark_color = Colors.breakpoint_disabled
316 bp_mark_color = Colors.breakpoint_disabled
313
317
314 numbers_width = 7
318 numbers_width = 7
315 if arrow:
319 if arrow:
316 # This is the line with the error
320 # This is the line with the error
317 pad = numbers_width - len(str(lineno)) - len(bp_mark)
321 pad = numbers_width - len(str(lineno)) - len(bp_mark)
318 if pad >= 3:
322 if pad >= 3:
319 marker = '-'*(pad-3) + '-> '
323 marker = '-'*(pad-3) + '-> '
320 elif pad == 2:
324 elif pad == 2:
321 marker = '> '
325 marker = '> '
322 elif pad == 1:
326 elif pad == 1:
323 marker = '>'
327 marker = '>'
324 else:
328 else:
325 marker = ''
329 marker = ''
326 num = '%s%s' % (marker, str(lineno))
330 num = '%s%s' % (marker, str(lineno))
327 line = tpl_line % (bp_mark_color + bp_mark, num, line)
331 line = tpl_line % (bp_mark_color + bp_mark, num, line)
328 else:
332 else:
329 num = '%*s' % (numbers_width - len(bp_mark), str(lineno))
333 num = '%*s' % (numbers_width - len(bp_mark), str(lineno))
330 line = tpl_line % (bp_mark_color + bp_mark, num, line)
334 line = tpl_line % (bp_mark_color + bp_mark, num, line)
331
335
332 return line
336 return line
333
337
334 def list_command_pydb(self, arg):
338 def list_command_pydb(self, arg):
335 """List command to use if we have a newer pydb installed"""
339 """List command to use if we have a newer pydb installed"""
336 filename, first, last = OldPdb.parse_list_cmd(self, arg)
340 filename, first, last = OldPdb.parse_list_cmd(self, arg)
337 if filename is not None:
341 if filename is not None:
338 self.print_list_lines(filename, first, last)
342 self.print_list_lines(filename, first, last)
339
343
340 def print_list_lines(self, filename, first, last):
344 def print_list_lines(self, filename, first, last):
341 """The printing (as opposed to the parsing part of a 'list'
345 """The printing (as opposed to the parsing part of a 'list'
342 command."""
346 command."""
343 try:
347 try:
344 Colors = self.color_scheme_table.active_colors
348 Colors = self.color_scheme_table.active_colors
345 ColorsNormal = Colors.Normal
349 ColorsNormal = Colors.Normal
346 tpl_line = '%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
350 tpl_line = '%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
347 tpl_line_em = '%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line, ColorsNormal)
351 tpl_line_em = '%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line, ColorsNormal)
348 src = []
352 src = []
349 for lineno in range(first, last+1):
353 for lineno in range(first, last+1):
350 line = linecache.getline(filename, lineno)
354 line = linecache.getline(filename, lineno)
351 if not line:
355 if not line:
352 break
356 break
353
357
354 if lineno == self.curframe.f_lineno:
358 if lineno == self.curframe.f_lineno:
355 line = self.__format_line(tpl_line_em, filename, lineno, line, arrow = True)
359 line = self.__format_line(tpl_line_em, filename, lineno, line, arrow = True)
356 else:
360 else:
357 line = self.__format_line(tpl_line, filename, lineno, line, arrow = False)
361 line = self.__format_line(tpl_line, filename, lineno, line, arrow = False)
358
362
359 src.append(line)
363 src.append(line)
360 self.lineno = lineno
364 self.lineno = lineno
361
365
362 print >>Term.cout, ''.join(src)
366 print >>Term.cout, ''.join(src)
363
367
364 except KeyboardInterrupt:
368 except KeyboardInterrupt:
365 pass
369 pass
366
370
367 def do_list(self, arg):
371 def do_list(self, arg):
368 self.lastcmd = 'list'
372 self.lastcmd = 'list'
369 last = None
373 last = None
370 if arg:
374 if arg:
371 try:
375 try:
372 x = eval(arg, {}, {})
376 x = eval(arg, {}, {})
373 if type(x) == type(()):
377 if type(x) == type(()):
374 first, last = x
378 first, last = x
375 first = int(first)
379 first = int(first)
376 last = int(last)
380 last = int(last)
377 if last < first:
381 if last < first:
378 # Assume it's a count
382 # Assume it's a count
379 last = first + last
383 last = first + last
380 else:
384 else:
381 first = max(1, int(x) - 5)
385 first = max(1, int(x) - 5)
382 except:
386 except:
383 print '*** Error in argument:', `arg`
387 print '*** Error in argument:', `arg`
384 return
388 return
385 elif self.lineno is None:
389 elif self.lineno is None:
386 first = max(1, self.curframe.f_lineno - 5)
390 first = max(1, self.curframe.f_lineno - 5)
387 else:
391 else:
388 first = self.lineno + 1
392 first = self.lineno + 1
389 if last is None:
393 if last is None:
390 last = first + 10
394 last = first + 10
391 self.print_list_lines(self.curframe.f_code.co_filename, first, last)
395 self.print_list_lines(self.curframe.f_code.co_filename, first, last)
392
396
393 do_l = do_list
397 do_l = do_list
394
398
395 def do_pdef(self, arg):
399 def do_pdef(self, arg):
396 """The debugger interface to magic_pdef"""
400 """The debugger interface to magic_pdef"""
397 namespaces = [('Locals', self.curframe.f_locals),
401 namespaces = [('Locals', self.curframe.f_locals),
398 ('Globals', self.curframe.f_globals)]
402 ('Globals', self.curframe.f_globals)]
399 __IPYTHON__.magic_pdef(arg, namespaces=namespaces)
403 __IPYTHON__.magic_pdef(arg, namespaces=namespaces)
400
404
401 def do_pdoc(self, arg):
405 def do_pdoc(self, arg):
402 """The debugger interface to magic_pdoc"""
406 """The debugger interface to magic_pdoc"""
403 namespaces = [('Locals', self.curframe.f_locals),
407 namespaces = [('Locals', self.curframe.f_locals),
404 ('Globals', self.curframe.f_globals)]
408 ('Globals', self.curframe.f_globals)]
405 __IPYTHON__.magic_pdoc(arg, namespaces=namespaces)
409 __IPYTHON__.magic_pdoc(arg, namespaces=namespaces)
406
410
407 def do_pinfo(self, arg):
411 def do_pinfo(self, arg):
408 """The debugger equivalant of ?obj"""
412 """The debugger equivalant of ?obj"""
409 namespaces = [('Locals', self.curframe.f_locals),
413 namespaces = [('Locals', self.curframe.f_locals),
410 ('Globals', self.curframe.f_globals)]
414 ('Globals', self.curframe.f_globals)]
411 __IPYTHON__.magic_pinfo("pinfo %s" % arg, namespaces=namespaces)
415 __IPYTHON__.magic_pinfo("pinfo %s" % arg, namespaces=namespaces)
General Comments 0
You need to be logged in to leave comments. Login now