##// END OF EJS Templates
- Fairly significant changes to include Vivian's patches for improved pdb...
fperez -
Show More
@@ -0,0 +1,109 b''
1 # -*- coding: utf-8 -*-
2 """
3 Color schemes for exception handling code in IPython.
4
5 $Id: Prompts.py 638 2005-07-18 03:01:41Z fperez $"""
6
7 #*****************************************************************************
8 # Copyright (C) 2005 Fernando Perez <fperez@colorado.edu>
9 #
10 # Distributed under the terms of the BSD License. The full license is in
11 # the file COPYING, distributed as part of this software.
12 #*****************************************************************************
13
14 from IPython import Release
15 __author__ = '%s <%s>' % Release.authors['Fernando']
16 __license__ = Release.license
17 __version__ = Release.version
18
19 #****************************************************************************
20 # Required modules
21 from IPython.ColorANSI import ColorSchemeTable, TermColors, ColorScheme
22
23 ExceptionColors = ColorSchemeTable()
24
25 # Populate it with color schemes
26 C = TermColors # shorthand and local lookup
27 ExceptionColors.add_scheme(ColorScheme(
28 'NoColor',
29 # The color to be used for the top line
30 topline = C.NoColor,
31
32 # The colors to be used in the traceback
33 filename = C.NoColor,
34 lineno = C.NoColor,
35 name = C.NoColor,
36 vName = C.NoColor,
37 val = C.NoColor,
38 em = C.NoColor,
39
40 # Emphasized colors for the last frame of the traceback
41 normalEm = C.NoColor,
42 filenameEm = C.NoColor,
43 linenoEm = C.NoColor,
44 nameEm = C.NoColor,
45 valEm = C.NoColor,
46
47 # Colors for printing the exception
48 excName = C.NoColor,
49 line = C.NoColor,
50 caret = C.NoColor,
51 Normal = C.NoColor
52 ))
53
54 # make some schemes as instances so we can copy them for modification easily
55 ExceptionColors.add_scheme(ColorScheme(
56 'Linux',
57 # The color to be used for the top line
58 topline = C.LightRed,
59
60 # The colors to be used in the traceback
61 filename = C.Green,
62 lineno = C.Green,
63 name = C.Purple,
64 vName = C.Cyan,
65 val = C.Green,
66 em = C.LightCyan,
67
68 # Emphasized colors for the last frame of the traceback
69 normalEm = C.LightCyan,
70 filenameEm = C.LightGreen,
71 linenoEm = C.LightGreen,
72 nameEm = C.LightPurple,
73 valEm = C.LightBlue,
74
75 # Colors for printing the exception
76 excName = C.LightRed,
77 line = C.Yellow,
78 caret = C.White,
79 Normal = C.Normal
80 ))
81
82 # For light backgrounds, swap dark/light colors
83 ExceptionColors.add_scheme(ColorScheme(
84 'LightBG',
85 # The color to be used for the top line
86 topline = C.Red,
87
88 # The colors to be used in the traceback
89 filename = C.LightGreen,
90 lineno = C.LightGreen,
91 name = C.LightPurple,
92 vName = C.Cyan,
93 val = C.LightGreen,
94 em = C.Cyan,
95
96 # Emphasized colors for the last frame of the traceback
97 normalEm = C.Cyan,
98 filenameEm = C.Green,
99 linenoEm = C.Green,
100 nameEm = C.Purple,
101 valEm = C.Blue,
102
103 # Colors for printing the exception
104 excName = C.Red,
105 #line = C.Brown, # brown often is displayed as yellow
106 line = C.Red,
107 caret = C.Normal,
108 Normal = C.Normal
109 ))
@@ -1,7 +1,7 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Tools for coloring text in ANSI terminals.
3 3
4 $Id: ColorANSI.py 410 2004-11-04 07:58:17Z fperez $"""
4 $Id: ColorANSI.py 951 2005-12-25 00:57:24Z fperez $"""
5 5
6 6 #*****************************************************************************
7 7 # Copyright (C) 2002-2004 Fernando Perez. <fperez@colorado.edu>
@@ -17,7 +17,6 b' __license__ = Release.license'
17 17 __all__ = ['TermColors','InputTermColors','ColorScheme','ColorSchemeTable']
18 18
19 19 import os
20 from UserDict import UserDict
21 20
22 21 from IPython.Struct import Struct
23 22
@@ -94,8 +93,14 b' class ColorScheme:'
94 93 self.colors = Struct(**colormap)
95 94 else:
96 95 self.colors = Struct(colordict)
96
97 def copy(self,name=None):
98 """Return a full copy of the object, optionally renaming it."""
99 if name is None:
100 name = self.name
101 return ColorScheme(name,self.colors.__dict__)
97 102
98 class ColorSchemeTable(UserDict):
103 class ColorSchemeTable(dict):
99 104 """General class to handle tables of color schemes.
100 105
101 106 It's basically a dict of color schemes with a couple of shorthand
@@ -112,17 +117,21 b' class ColorSchemeTable(UserDict):'
112 117 the default active scheme.
113 118 """
114 119
115 UserDict.__init__(self)
116 if scheme_list is None:
117 self.active_scheme_name = ''
118 self.active_colors = None
119 else:
120 # create object attributes to be set later
121 self.active_scheme_name = ''
122 self.active_colors = None
123
124 if scheme_list:
120 125 if default_scheme == '':
121 126 raise ValueError,'you must specify the default color scheme'
122 127 for scheme in scheme_list:
123 128 self.add_scheme(scheme)
124 129 self.set_active_scheme(default_scheme)
125 130
131 def copy(self):
132 """Return full copy of object"""
133 return ColorSchemeTable(self.values(),self.active_scheme_name)
134
126 135 def add_scheme(self,new_scheme):
127 136 """Add a new color scheme to the table."""
128 137 if not isinstance(new_scheme,ColorScheme):
@@ -135,20 +144,20 b' class ColorSchemeTable(UserDict):'
135 144 Names are by default compared in a case-insensitive way, but this can
136 145 be changed by setting the parameter case_sensitive to true."""
137 146
138 scheme_list = self.keys()
147 scheme_names = self.keys()
139 148 if case_sensitive:
140 valid_schemes = scheme_list
149 valid_schemes = scheme_names
141 150 scheme_test = scheme
142 151 else:
143 valid_schemes = [s.lower() for s in scheme_list]
152 valid_schemes = [s.lower() for s in scheme_names]
144 153 scheme_test = scheme.lower()
145 154 try:
146 155 scheme_idx = valid_schemes.index(scheme_test)
147 156 except ValueError:
148 157 raise ValueError,'Unrecognized color scheme: ' + scheme + \
149 '\nValid schemes: '+str(scheme_list).replace("'', ",'')
158 '\nValid schemes: '+str(scheme_names).replace("'', ",'')
150 159 else:
151 active = scheme_list[scheme_idx]
160 active = scheme_names[scheme_idx]
152 161 self.active_scheme_name = active
153 162 self.active_colors = self[active].colors
154 163 # Now allow using '' as an index for the current active scheme
@@ -1,7 +1,7 b''
1 1 # -*- coding: utf-8 -*-
2 2 """sys.excepthook for IPython itself, leaves a detailed report on disk.
3 3
4 $Id: CrashHandler.py 775 2005-09-01 20:24:59Z fperez $"""
4 $Id: CrashHandler.py 951 2005-12-25 00:57:24Z fperez $"""
5 5
6 6 #*****************************************************************************
7 7 # Copyright (C) 2001-2004 Fernando Perez. <fperez@colorado.edu>
@@ -23,10 +23,10 b' import os,sys'
23 23 from pprint import pprint,pformat
24 24
25 25 # Homebrewed
26 from IPython.genutils import *
27 26 from IPython.Itpl import Itpl,itpl,printpl
27 from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names
28 28 from IPython import ultraTB
29 from IPython.ultraTB import ColorScheme,ColorSchemeTable # too long names
29 from IPython.genutils import *
30 30
31 31 #****************************************************************************
32 32 class CrashHandler:
@@ -15,39 +15,250 b' 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 590 2005-05-30 06:26:51Z fperez $"""
18 $Id: Debugger.py 951 2005-12-25 00:57:24Z fperez $"""
19 19
20 20 from IPython import Release
21 21 __author__ = '%s <%s>' % Release.authors['Fernando']
22 22 __license__ = 'Python'
23 23
24 import pdb,bdb,cmd,os,sys
24 import pdb,bdb,cmd,os,sys,linecache
25 from IPython import PyColorize, ColorANSI
26 from IPython.genutils import Term
27 from IPython.excolors import ExceptionColors
28
29 def _file_lines(fname):
30 """Return the contents of a named file as a list of lines.
31
32 This function never raises an IOError exception: if the file can't be
33 read, it simply returns an empty list."""
34
35 try:
36 outfile = open(fname)
37 except IOError:
38 return []
39 else:
40 out = outfile.readlines()
41 outfile.close()
42 return out
43
25 44
26 45 class Pdb(pdb.Pdb):
27 46 """Modified Pdb class, does not load readline."""
28 def __init__(self):
47 def __init__(self,color_scheme='NoColor'):
29 48 bdb.Bdb.__init__(self)
30 49 cmd.Cmd.__init__(self,completekey=None) # don't load readline
31 self.prompt = '(Pdb) '
50 self.prompt = 'ipdb> ' # The default prompt is '(Pdb)'
32 51 self.aliases = {}
33 52
34 53 # Read $HOME/.pdbrc and ./.pdbrc
35 self.rcLines = []
36 if os.environ.has_key('HOME'):
37 envHome = os.environ['HOME']
38 try:
39 rcFile = open(os.path.join(envHome, ".pdbrc"))
40 except IOError:
41 pass
42 else:
43 for line in rcFile.readlines():
44 self.rcLines.append(line)
45 rcFile.close()
46 54 try:
47 rcFile = open(".pdbrc")
48 except IOError:
55 self.rcLines = _file_lines(os.path.join(os.environ['HOME'],
56 ".pdbrc"))
57 except KeyError:
58 self.rcLines = []
59 self.rcLines.extend(_file_lines(".pdbrc"))
60
61 # Create color table: we copy the default one from the traceback
62 # module and add a few attributes needed for debugging
63 self.color_scheme_table = ExceptionColors.copy()
64
65 # shorthands
66 C = ColorANSI.TermColors
67 cst = self.color_scheme_table
68
69 cst['NoColor'].colors.breakpoint_enabled = C.NoColor
70 cst['NoColor'].colors.breakpoint_disabled = C.NoColor
71
72 cst['Linux'].colors.breakpoint_enabled = C.LightRed
73 cst['Linux'].colors.breakpoint_disabled = C.Red
74
75 cst['LightBG'].colors.breakpoint_enabled = C.LightRed
76 cst['LightBG'].colors.breakpoint_disabled = C.Red
77
78 self.set_colors(color_scheme)
79
80 def set_colors(self, scheme):
81 """Shorthand access to the color table scheme selector method."""
82 self.color_scheme_table.set_active_scheme(scheme)
83
84
85 def interaction(self, frame, traceback):
86 __IPYTHON__.set_completer_frame(frame)
87 pdb.Pdb.interaction(self, frame, traceback)
88
89
90 def do_up(self, arg):
91 pdb.Pdb.do_up(self, arg)
92 __IPYTHON__.set_completer_frame(self.curframe)
93 do_u = do_up
94
95
96 def do_down(self, arg):
97 pdb.Pdb.do_down(self, arg)
98 __IPYTHON__.set_completer_frame(self.curframe)
99 do_d = do_down
100
101
102 def postloop(self):
103 __IPYTHON__.set_completer_frame(None)
104
105
106 def print_stack_trace(self):
107 try:
108 for frame_lineno in self.stack:
109 self.print_stack_entry(frame_lineno, context = 5)
110 except KeyboardInterrupt:
49 111 pass
112
113
114 def print_stack_entry(self,frame_lineno,prompt_prefix='\n-> ',
115 context = 3):
116 frame, lineno = frame_lineno
117 print >>Term.cout, self.format_stack_entry(frame_lineno, '', context)
118
119
120 def format_stack_entry(self, frame_lineno, lprefix=': ', context = 3):
121 import linecache, repr
122
123 ret = ""
124
125 Colors = self.color_scheme_table.active_colors
126 ColorsNormal = Colors.Normal
127 tpl_link = '%s%%s%s' % (Colors.filenameEm, ColorsNormal)
128 tpl_call = 'in %s%%s%s%%s%s' % (Colors.vName, Colors.valEm, ColorsNormal)
129 tpl_line = '%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
130 tpl_line_em = '%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line,
131 ColorsNormal)
132
133 frame, lineno = frame_lineno
134
135 return_value = ''
136 if '__return__' in frame.f_locals:
137 rv = frame.f_locals['__return__']
138 #return_value += '->'
139 return_value += repr.repr(rv) + '\n'
140 ret += return_value
141
142 #s = filename + '(' + `lineno` + ')'
143 filename = self.canonic(frame.f_code.co_filename)
144 link = tpl_link % filename
145
146 if frame.f_code.co_name:
147 func = frame.f_code.co_name
148 else:
149 func = "<lambda>"
150
151 call = ''
152 if func != '?':
153 if '__args__' in frame.f_locals:
154 args = repr.repr(frame.f_locals['__args__'])
155 else:
156 args = '()'
157 call = tpl_call % (func, args)
158
159 level = '%s %s\n' % (link, call)
160 ret += level
161
162 start = lineno - 1 - context//2
163 lines = linecache.getlines(filename)
164 start = max(start, 0)
165 start = min(start, len(lines) - context)
166 lines = lines[start : start + context]
167
168 for i in range(len(lines)):
169 line = lines[i]
170 if start + 1 + i == lineno:
171 ret += self.__format_line(tpl_line_em, filename, start + 1 + i, line, arrow = True)
172 else:
173 ret += self.__format_line(tpl_line, filename, start + 1 + i, line, arrow = False)
174
175 return ret
176
177
178 def __format_line(self, tpl_line, filename, lineno, line, arrow = False):
179 bp_mark = ""
180 bp_mark_color = ""
181
182 bp = None
183 if lineno in self.get_file_breaks(filename):
184 bps = self.get_breaks(filename, lineno)
185 bp = bps[-1]
186
187 if bp:
188 Colors = self.color_scheme_table.active_colors
189 bp_mark = str(bp.number)
190 bp_mark_color = Colors.breakpoint_enabled
191 if not bp.enabled:
192 bp_mark_color = Colors.breakpoint_disabled
193
194 numbers_width = 7
195 if arrow:
196 # This is the line with the error
197 pad = numbers_width - len(str(lineno)) - len(bp_mark)
198 if pad >= 3:
199 marker = '-'*(pad-3) + '-> '
200 elif pad == 2:
201 marker = '> '
202 elif pad == 1:
203 marker = '>'
204 else:
205 marker = ''
206 num = '%s%s' % (marker, str(lineno))
207 line = tpl_line % (bp_mark_color + bp_mark, num, line)
208 else:
209 num = '%*s' % (numbers_width - len(bp_mark), str(lineno))
210 line = tpl_line % (bp_mark_color + bp_mark, num, line)
211
212 return line
213
214
215 def do_list(self, arg):
216 self.lastcmd = 'list'
217 last = None
218 if arg:
219 try:
220 x = eval(arg, {}, {})
221 if type(x) == type(()):
222 first, last = x
223 first = int(first)
224 last = int(last)
225 if last < first:
226 # Assume it's a count
227 last = first + last
228 else:
229 first = max(1, int(x) - 5)
230 except:
231 print '*** Error in argument:', `arg`
232 return
233 elif self.lineno is None:
234 first = max(1, self.curframe.f_lineno - 5)
50 235 else:
51 for line in rcFile.readlines():
52 self.rcLines.append(line)
53 rcFile.close()
236 first = self.lineno + 1
237 if last is None:
238 last = first + 10
239 filename = self.curframe.f_code.co_filename
240 try:
241 Colors = self.color_scheme_table.active_colors
242 ColorsNormal = Colors.Normal
243 tpl_line = '%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal)
244 tpl_line_em = '%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line, ColorsNormal)
245 src = []
246 for lineno in range(first, last+1):
247 line = linecache.getline(filename, lineno)
248 if not line:
249 break
250
251 if lineno == self.curframe.f_lineno:
252 line = self.__format_line(tpl_line_em, filename, lineno, line, arrow = True)
253 else:
254 line = self.__format_line(tpl_line, filename, lineno, line, arrow = False)
255
256 src.append(line)
257 self.lineno = lineno
258
259 print >>Term.cout, ''.join(src)
260
261 except KeyboardInterrupt:
262 pass
263
264 do_l = do_list
@@ -1,7 +1,7 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Magic functions for InteractiveShell.
3 3
4 $Id: Magic.py 923 2005-11-15 08:51:15Z fperez $"""
4 $Id: Magic.py 951 2005-12-25 00:57:24Z fperez $"""
5 5
6 6 #*****************************************************************************
7 7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -22,13 +22,16 b' __license__ = Release.license'
22 22 # Python standard modules
23 23 import __builtin__
24 24 import os,sys,inspect,pydoc,re,tempfile,pdb,bdb,time
25 import Debugger
26 from getopt import getopt
27 from pprint import pprint, pformat
28 from cStringIO import StringIO
29
30 # profile isn't bundled by default in Debian for license reasons
25 31 try:
26 32 import profile,pstats
27 33 except ImportError:
28 34 profile = pstats = None
29 from getopt import getopt
30 from pprint import pprint, pformat
31 from cStringIO import StringIO
32 35
33 36 # Homebrewed
34 37 from IPython.Struct import Struct
@@ -1371,7 +1374,7 b' Currently the magic system has the following functions:\\n"""'
1371 1374 stats = self.magic_prun('',0,opts,arg_lst,prog_ns)
1372 1375 else:
1373 1376 if opts.has_key('d'):
1374 deb = pdb.Pdb()
1377 deb = Debugger.Pdb(self.shell.rc.colors)
1375 1378 # reset Breakpoint state, which is moronically kept
1376 1379 # in a class
1377 1380 bdb.Breakpoint.next = 1
@@ -1397,8 +1400,15 b' Currently the magic system has the following functions:\\n"""'
1397 1400 deb.do_break('%s:%s' % (filename,bp))
1398 1401 # Start file run
1399 1402 print "NOTE: Enter 'c' at the",
1400 print "(Pdb) prompt to start your script."
1401 deb.run('execfile("%s")' % filename,prog_ns)
1403 print "ipdb> prompt to start your script."
1404 try:
1405 deb.run('execfile("%s")' % filename,prog_ns)
1406 except:
1407 etype, value, tb = sys.exc_info()
1408 # Skip three frames in the traceback: the %run one,
1409 # one inside bdb.py, and the command-line typed by the
1410 # user (run by exec in pdb itself).
1411 self.shell.InteractiveTB(etype,value,tb,tb_offset=3)
1402 1412 else:
1403 1413 if runner is None:
1404 1414 runner = self.shell.safe_execfile
@@ -2,7 +2,7 b''
2 2 """
3 3 Classes for handling input/output prompts.
4 4
5 $Id: Prompts.py 638 2005-07-18 03:01:41Z fperez $"""
5 $Id: Prompts.py 951 2005-12-25 00:57:24Z fperez $"""
6 6
7 7 #*****************************************************************************
8 8 # Copyright (C) 2001-2004 Fernando Perez <fperez@colorado.edu>
@@ -49,6 +49,7 b' PromptColors.add_scheme(ColorANSI.ColorScheme('
49 49
50 50 normal = Colors.NoColor # color off (usu. Colors.Normal)
51 51 ))
52
52 53 # make some schemes as instances so we can copy them for modification easily:
53 54 __PColLinux = ColorANSI.ColorScheme(
54 55 'Linux',
@@ -64,8 +65,9 b' __PColLinux = ColorANSI.ColorScheme('
64 65 )
65 66 # Don't forget to enter it into the table!
66 67 PromptColors.add_scheme(__PColLinux)
68
67 69 # Slightly modified Linux for light backgrounds
68 __PColLightBG = ColorANSI.ColorScheme('LightBG',**__PColLinux.colors.dict().copy())
70 __PColLightBG = __PColLinux.copy('LightBG')
69 71
70 72 __PColLightBG.colors.update(
71 73 in_prompt = InputColors.Blue,
@@ -1,7 +1,7 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Release data for the IPython project.
3 3
4 $Id: Release.py 775 2005-09-01 20:24:59Z fperez $"""
4 $Id: Release.py 951 2005-12-25 00:57:24Z fperez $"""
5 5
6 6 #*****************************************************************************
7 7 # Copyright (C) 2001-2005 Fernando Perez <fperez@colorado.edu>
@@ -24,7 +24,7 b" name = 'ipython'"
24 24
25 25 version = '0.6.16.svn'
26 26
27 revision = '$Revision: 775 $'
27 revision = '$Revision: 951 $'
28 28
29 29 description = "An enhanced interactive Python shell."
30 30
@@ -69,6 +69,8 b" authors = {'Fernando' : ('Fernando Perez','fperez@colorado.edu'),"
69 69
70 70 url = 'http://ipython.scipy.org'
71 71
72 download_url = 'http://ipython.scipy.org/dist'
73
72 74 platforms = ['Linux','Mac OSX','Windows XP/2000/NT','Windows 95/98/ME']
73 75
74 76 keywords = ['Interactive','Interpreter','Shell']
@@ -6,7 +6,7 b' Requires Python 2.1 or newer.'
6 6
7 7 This file contains all the classes and helper functions specific to IPython.
8 8
9 $Id: iplib.py 924 2005-11-15 20:24:31Z fperez $
9 $Id: iplib.py 951 2005-12-25 00:57:24Z fperez $
10 10 """
11 11
12 12 #*****************************************************************************
@@ -54,7 +54,7 b' from codeop import CommandCompiler'
54 54 # IPython's own modules
55 55 import IPython
56 56 from IPython import OInspect,PyColorize,ultraTB
57 from IPython.ultraTB import ColorScheme,ColorSchemeTable # too long names
57 from IPython.ColorANSI import ColorScheme,ColorSchemeTable # too long names
58 58 from IPython.Logger import Logger
59 59 from IPython.Magic import Magic,magic2python,shlex_split
60 60 from IPython.usage import cmd_line_usage,interactive_usage
@@ -969,6 +969,14 b' class InteractiveShell(code.InteractiveConsole, Logger, Magic):'
969 969 outcomps = comps.keys()
970 970 outcomps.sort()
971 971 return outcomps
972
973 def set_completer_frame(self, frame):
974 if frame:
975 ns = frame.f_globals.copy()
976 ns.update(frame.f_locals)
977 self.Completer.namespace = ns
978 else:
979 self.Completer.namespace = self.user_ns
972 980
973 981 def post_config_initialization(self):
974 982 """Post configuration init method
@@ -1441,7 +1449,7 b' want to merge them back into the new files.""" % locals()'
1441 1449 self.write(banner)
1442 1450
1443 1451 more = 0
1444
1452
1445 1453 # Mark activity in the builtins
1446 1454 __builtin__.__dict__['__IPYTHON__active'] += 1
1447 1455
@@ -60,7 +60,7 b' You can implement other color schemes easily, the syntax is fairly'
60 60 self-explanatory. Please send back new schemes you develop to the author for
61 61 possible inclusion in future releases.
62 62
63 $Id: ultraTB.py 703 2005-08-16 17:34:44Z fperez $"""
63 $Id: ultraTB.py 951 2005-12-25 00:57:24Z fperez $"""
64 64
65 65 #*****************************************************************************
66 66 # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu>
@@ -85,8 +85,8 b' from UserDict import UserDict'
85 85 from IPython import Debugger
86 86
87 87 from IPython.Struct import Struct
88 from IPython.ColorANSI import *
89 88 from IPython.genutils import Term,uniq_stable,error,info
89 from IPython.excolors import ExceptionColors
90 90
91 91 #---------------------------------------------------------------------------
92 92 # Code begins
@@ -99,131 +99,42 b' def inspect_error():'
99 99 error('Internal Python error in the inspect module.\n'
100 100 'Below is the traceback from this internal error.\n')
101 101
102 # Make a global variable out of the color scheme table used for coloring
103 # exception tracebacks. This allows user code to add new schemes at runtime.
104 ExceptionColors = ColorSchemeTable()
105
106 # Populate it with color schemes
107 C = TermColors # shorthand and local lookup
108 ExceptionColors.add_scheme(ColorScheme(
109 'NoColor',
110 # The color to be used for the top line
111 topline = C.NoColor,
112
113 # The colors to be used in the traceback
114 filename = C.NoColor,
115 lineno = C.NoColor,
116 name = C.NoColor,
117 vName = C.NoColor,
118 val = C.NoColor,
119 em = C.NoColor,
120
121 # Emphasized colors for the last frame of the traceback
122 normalEm = C.NoColor,
123 filenameEm = C.NoColor,
124 linenoEm = C.NoColor,
125 nameEm = C.NoColor,
126 valEm = C.NoColor,
127
128 # Colors for printing the exception
129 excName = C.NoColor,
130 line = C.NoColor,
131 caret = C.NoColor,
132 Normal = C.NoColor
133 ))
134
135 # make some schemes as instances so we can copy them for modification easily
136 ExceptionColors.add_scheme(ColorScheme(
137 'Linux',
138 # The color to be used for the top line
139 topline = C.LightRed,
140
141 # The colors to be used in the traceback
142 filename = C.Green,
143 lineno = C.Green,
144 name = C.Purple,
145 vName = C.Cyan,
146 val = C.Green,
147 em = C.LightCyan,
148
149 # Emphasized colors for the last frame of the traceback
150 normalEm = C.LightCyan,
151 filenameEm = C.LightGreen,
152 linenoEm = C.LightGreen,
153 nameEm = C.LightPurple,
154 valEm = C.LightBlue,
155
156 # Colors for printing the exception
157 excName = C.LightRed,
158 line = C.Yellow,
159 caret = C.White,
160 Normal = C.Normal
161 ))
162
163 # For light backgrounds, swap dark/light colors
164 ExceptionColors.add_scheme(ColorScheme(
165 'LightBG',
166 # The color to be used for the top line
167 topline = C.Red,
168
169 # The colors to be used in the traceback
170 filename = C.LightGreen,
171 lineno = C.LightGreen,
172 name = C.LightPurple,
173 vName = C.Cyan,
174 val = C.LightGreen,
175 em = C.Cyan,
176
177 # Emphasized colors for the last frame of the traceback
178 normalEm = C.Cyan,
179 filenameEm = C.Green,
180 linenoEm = C.Green,
181 nameEm = C.Purple,
182 valEm = C.Blue,
183
184 # Colors for printing the exception
185 excName = C.Red,
186 #line = C.Brown, # brown often is displayed as yellow
187 line = C.Red,
188 caret = C.Normal,
189 Normal = C.Normal
190 ))
191
192 102 class TBTools:
193 103 """Basic tools used by all traceback printer classes."""
194 104
195 def __init__(self,color_scheme = 'NoColor',call_pdb=0):
105 def __init__(self,color_scheme = 'NoColor',call_pdb=False):
196 106 # Whether to call the interactive pdb debugger after printing
197 107 # tracebacks or not
198 108 self.call_pdb = call_pdb
199 if call_pdb:
200 self.pdb = Debugger.Pdb()
201 else:
202 self.pdb = None
203 109
204 110 # Create color table
205 self.ColorSchemeTable = ExceptionColors
111 self.color_scheme_table = ExceptionColors
206 112
207 113 self.set_colors(color_scheme)
208 114 self.old_scheme = color_scheme # save initial value for toggles
209 115
116 if call_pdb:
117 self.pdb = Debugger.Pdb(self.color_scheme_table.active_scheme_name)
118 else:
119 self.pdb = None
120
210 121 def set_colors(self,*args,**kw):
211 122 """Shorthand access to the color table scheme selector method."""
212 123
213 self.ColorSchemeTable.set_active_scheme(*args,**kw)
124 self.color_scheme_table.set_active_scheme(*args,**kw)
214 125 # for convenience, set Colors to the active scheme
215 self.Colors = self.ColorSchemeTable.active_colors
126 self.Colors = self.color_scheme_table.active_colors
216 127
217 128 def color_toggle(self):
218 129 """Toggle between the currently active color scheme and NoColor."""
219 130
220 if self.ColorSchemeTable.active_scheme_name == 'NoColor':
221 self.ColorSchemeTable.set_active_scheme(self.old_scheme)
222 self.Colors = self.ColorSchemeTable.active_colors
131 if self.color_scheme_table.active_scheme_name == 'NoColor':
132 self.color_scheme_table.set_active_scheme(self.old_scheme)
133 self.Colors = self.color_scheme_table.active_colors
223 134 else:
224 self.old_scheme = self.ColorSchemeTable.active_scheme_name
225 self.ColorSchemeTable.set_active_scheme('NoColor')
226 self.Colors = self.ColorSchemeTable.active_colors
135 self.old_scheme = self.color_scheme_table.active_scheme_name
136 self.color_scheme_table.set_active_scheme('NoColor')
137 self.Colors = self.color_scheme_table.active_colors
227 138
228 139 #---------------------------------------------------------------------------
229 140 class ListTB(TBTools):
@@ -660,14 +571,21 b' class VerboseTB(TBTools):'
660 571
661 572 if self.call_pdb:
662 573 if self.pdb is None:
663 self.pdb = Debugger.Pdb()
664 # the system displayhook may have changed, restore the original for pdb
574 self.pdb = Debugger.Pdb(
575 self.color_scheme_table.active_scheme_name)
576 # the system displayhook may have changed, restore the original
577 # for pdb
665 578 dhook = sys.displayhook
666 579 sys.displayhook = sys.__displayhook__
667 580 self.pdb.reset()
581 # Find the right frame so we don't pop up inside ipython itself
582 etb = self.tb
668 583 while self.tb.tb_next is not None:
669 584 self.tb = self.tb.tb_next
670 585 try:
586 if etb and etb.tb_next:
587 etb = etb.tb_next
588 self.pdb.botframe = etb.tb_frame
671 589 self.pdb.interaction(self.tb.tb_frame, self.tb)
672 590 except:
673 591 print '*** ERROR ***'
@@ -801,7 +719,7 b' class AutoFormattedTB(FormattedTB):'
801 719 print >> out, self.text(etype, evalue, etb)
802 720 self.tb_offset = tb_offset
803 721 else:
804 print >> out, self.text()
722 print >> out, self.text(etype, evalue, etb)
805 723 self.debugger()
806 724
807 725 def text(self,etype=None,value=None,tb=None,context=5,mode=None):
@@ -1,3 +1,19 b''
1 2005-12-24 Fernando Perez <Fernando.Perez@colorado.edu>
2
3 * setup.py: added download_url to setup(). This registers the
4 download address at PyPI, which is not only useful to humans
5 browsing the site, but is also picked up by setuptools (the Eggs
6 machinery). Thanks to Ville and R. Kern for the info/discussion
7 on this.
8
9 2005-12-23 Fernando Perez <Fernando.Perez@colorado.edu>
10
11 * IPython/Debugger.py (Pdb.__init__): Major pdb mode enhancements.
12 This brings a lot of nice functionality to the pdb mode, which now
13 has tab-completion, syntax highlighting, and better stack handling
14 than before. Many thanks to Vivian De Smedt
15 <vivian-AT-vdesmedt.com> for the original patches.
16
1 17 2005-12-08 Fernando Perez <Fernando.Perez@colorado.edu>
2 18
3 19 * IPython/Shell.py (IPShellGTK.mainloop): fix mainloop() calling
@@ -11,7 +27,7 b''
11 27 Fix bug where a naked 'alias' call in the ipythonrc file would
12 28 cause a crash. Bug reported by Jorgen Stenarson.
13 29
14 2005-11-15 <Fernando.Perez@colorado.edu>
30 2005-11-15 Fernando Perez <Fernando.Perez@colorado.edu>
15 31
16 32 * IPython/ipmaker.py (make_IPython): cleanups which should improve
17 33 startup time.
@@ -26,13 +42,13 b''
26 42 searches. Users can still select either mode at runtime on a
27 43 per-search basis.
28 44
29 2005-11-13 <Fernando.Perez@colorado.edu>
45 2005-11-13 Fernando Perez <Fernando.Perez@colorado.edu>
30 46
31 47 * IPython/wildcard.py (NameSpace.__init__): fix resolution of
32 48 attributes in wildcard searches for subclasses. Modified version
33 49 of a patch by Jorgen.
34 50
35 2005-11-12 <Fernando.Perez@colorado.edu>
51 2005-11-12 Fernando Perez <Fernando.Perez@colorado.edu>
36 52
37 53 * IPython/iplib.py (embed_mainloop): Fix handling of globals for
38 54 embedded instances. I added a user_global_ns attribute to the
@@ -133,6 +133,7 b' setup(name = name,'
133 133 author = authors['Fernando'][0],
134 134 author_email = authors['Fernando'][1],
135 135 url = url,
136 download_url = download_url,
136 137 license = license,
137 138 platforms = platforms,
138 139 keywords = keywords,
General Comments 0
You need to be logged in to leave comments. Login now