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