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