Show More
@@ -15,7 +15,7 b' 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 215 |
|
18 | $Id: Debugger.py 2155 2007-03-19 00:45:51Z fperez $""" | |
19 |
|
19 | |||
20 | #***************************************************************************** |
|
20 | #***************************************************************************** | |
21 | # |
|
21 | # | |
@@ -178,7 +178,7 b' class Pdb(OldPdb):' | |||||
178 |
|
178 | |||
179 | # Parent constructor: |
|
179 | # Parent constructor: | |
180 | if has_pydb and completekey is None: |
|
180 | if has_pydb and completekey is None: | |
181 |
OldPdb.__init__(self,stdin=stdin,stdout=Term.cout) |
|
181 | OldPdb.__init__(self,stdin=stdin,stdout=Term.cout) | |
182 | else: |
|
182 | else: | |
183 | OldPdb.__init__(self,completekey,stdin,stdout) |
|
183 | OldPdb.__init__(self,completekey,stdin,stdout) | |
184 |
|
184 | |||
@@ -228,6 +228,11 b' class Pdb(OldPdb):' | |||||
228 |
|
228 | |||
229 | self.set_colors(color_scheme) |
|
229 | self.set_colors(color_scheme) | |
230 |
|
230 | |||
|
231 | # Add a python parser so we can syntax highlight source while | |||
|
232 | # debugging. | |||
|
233 | self.parser = PyColorize.Parser() | |||
|
234 | ||||
|
235 | ||||
231 | else: |
|
236 | else: | |
232 | # Ugly hack: for Python 2.3-2.4, we can't call the parent constructor, |
|
237 | # Ugly hack: for Python 2.3-2.4, we can't call the parent constructor, | |
233 | # because it binds readline and breaks tab-completion. This means we |
|
238 | # because it binds readline and breaks tab-completion. This means we | |
@@ -270,6 +275,10 b' class Pdb(OldPdb):' | |||||
270 | cst['LightBG'].colors.breakpoint_disabled = C.Red |
|
275 | cst['LightBG'].colors.breakpoint_disabled = C.Red | |
271 |
|
276 | |||
272 | self.set_colors(color_scheme) |
|
277 | self.set_colors(color_scheme) | |
|
278 | ||||
|
279 | # Add a python parser so we can syntax highlight source while | |||
|
280 | # debugging. | |||
|
281 | self.parser = PyColorize.Parser() | |||
273 |
|
282 | |||
274 | def set_colors(self, scheme): |
|
283 | def set_colors(self, scheme): | |
275 | """Shorthand access to the color table scheme selector method.""" |
|
284 | """Shorthand access to the color table scheme selector method.""" | |
@@ -393,6 +402,10 b' class Pdb(OldPdb):' | |||||
393 | bp_mark = "" |
|
402 | bp_mark = "" | |
394 | bp_mark_color = "" |
|
403 | bp_mark_color = "" | |
395 |
|
404 | |||
|
405 | scheme = self.color_scheme_table.active_scheme_name | |||
|
406 | new_line, err = self.parser.format2(line, 'str', scheme) | |||
|
407 | if not err: line = new_line | |||
|
408 | ||||
396 | bp = None |
|
409 | bp = None | |
397 | if lineno in self.get_file_breaks(filename): |
|
410 | if lineno in self.get_file_breaks(filename): | |
398 | bps = self.get_breaks(filename, lineno) |
|
411 | bps = self.get_breaks(filename, lineno) |
@@ -28,7 +28,7 b'' | |||||
28 | scan Python source code and re-emit it with no changes to its original |
|
28 | scan Python source code and re-emit it with no changes to its original | |
29 | formatting (which is the hard part). |
|
29 | formatting (which is the hard part). | |
30 |
|
30 | |||
31 |
$Id: PyColorize.py |
|
31 | $Id: PyColorize.py 2155 2007-03-19 00:45:51Z fperez $""" | |
32 |
|
32 | |||
33 | __all__ = ['ANSICodeColors','Parser'] |
|
33 | __all__ = ['ANSICodeColors','Parser'] | |
34 |
|
34 | |||
@@ -120,6 +120,9 b' class Parser:' | |||||
120 | self.out = out |
|
120 | self.out = out | |
121 |
|
121 | |||
122 | def format(self, raw, out = None, scheme = ''): |
|
122 | def format(self, raw, out = None, scheme = ''): | |
|
123 | return self.format2(raw, out, scheme)[0] | |||
|
124 | ||||
|
125 | def format2(self, raw, out = None, scheme = ''): | |||
123 | """ Parse and send the colored source. |
|
126 | """ Parse and send the colored source. | |
124 |
|
127 | |||
125 | If out and scheme are not specified, the defaults (given to |
|
128 | If out and scheme are not specified, the defaults (given to | |
@@ -153,6 +156,8 b' class Parser:' | |||||
153 | self.pos = 0 |
|
156 | self.pos = 0 | |
154 | text = cStringIO.StringIO(self.raw) |
|
157 | text = cStringIO.StringIO(self.raw) | |
155 | #self.out.write('<pre><font face="Courier New">') |
|
158 | #self.out.write('<pre><font face="Courier New">') | |
|
159 | ||||
|
160 | error = False | |||
156 | try: |
|
161 | try: | |
157 | tokenize.tokenize(text.readline, self) |
|
162 | tokenize.tokenize(text.readline, self) | |
158 | except tokenize.TokenError, ex: |
|
163 | except tokenize.TokenError, ex: | |
@@ -163,11 +168,13 b' class Parser:' | |||||
163 | msg, self.raw[self.lines[line]:], |
|
168 | msg, self.raw[self.lines[line]:], | |
164 | colors.normal) |
|
169 | colors.normal) | |
165 | ) |
|
170 | ) | |
|
171 | error = True | |||
166 | self.out.write(colors.normal+'\n') |
|
172 | self.out.write(colors.normal+'\n') | |
167 | if string_output: |
|
173 | if string_output: | |
168 | output = self.out.getvalue() |
|
174 | output = self.out.getvalue() | |
169 | self.out = out_old |
|
175 | self.out = out_old | |
170 | return output |
|
176 | return (output, error) | |
|
177 | return (None, error) | |||
171 |
|
178 | |||
172 | def __call__(self, toktype, toktext, (srow,scol), (erow,ecol), line): |
|
179 | def __call__(self, toktype, toktext, (srow,scol), (erow,ecol), line): | |
173 | """ Token handler, with syntax highlighting.""" |
|
180 | """ Token handler, with syntax highlighting.""" |
@@ -60,7 +60,7 b' You can implement other color schemes easily, the syntax is fairly' | |||||
60 | self-explanatory. Please send back new schemes you develop to the author for |
|
60 | self-explanatory. Please send back new schemes you develop to the author for | |
61 | possible inclusion in future releases. |
|
61 | possible inclusion in future releases. | |
62 |
|
62 | |||
63 |
$Id: ultraTB.py 2 |
|
63 | $Id: ultraTB.py 2155 2007-03-19 00:45:51Z fperez $""" | |
64 |
|
64 | |||
65 | #***************************************************************************** |
|
65 | #***************************************************************************** | |
66 | # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu> |
|
66 | # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu> | |
@@ -90,7 +90,7 b' import types' | |||||
90 |
|
90 | |||
91 | # IPython's own modules |
|
91 | # IPython's own modules | |
92 | # Modified pdb which doesn't damage IPython's readline handling |
|
92 | # Modified pdb which doesn't damage IPython's readline handling | |
93 | from IPython import Debugger |
|
93 | from IPython import Debugger, PyColorize | |
94 | from IPython.ipstruct import Struct |
|
94 | from IPython.ipstruct import Struct | |
95 | from IPython.excolors import ExceptionColors |
|
95 | from IPython.excolors import ExceptionColors | |
96 | from IPython.genutils import Term,uniq_stable,error,info |
|
96 | from IPython.genutils import Term,uniq_stable,error,info | |
@@ -99,6 +99,12 b' from IPython.genutils import Term,uniq_stable,error,info' | |||||
99 | # amount of space to put line numbers before verbose tracebacks |
|
99 | # amount of space to put line numbers before verbose tracebacks | |
100 | INDENT_SIZE = 8 |
|
100 | INDENT_SIZE = 8 | |
101 |
|
101 | |||
|
102 | # Default color scheme. This is used, for example, by the traceback | |||
|
103 | # formatter. When running in an actual IPython instance, the user's rc.colors | |||
|
104 | # value is used, but havinga module global makes this functionality available | |||
|
105 | # to users of ultraTB who are NOT running inside ipython. | |||
|
106 | DEFAULT_SCHEME = 'NoColors' | |||
|
107 | ||||
102 | #--------------------------------------------------------------------------- |
|
108 | #--------------------------------------------------------------------------- | |
103 | # Code begins |
|
109 | # Code begins | |
104 |
|
110 | |||
@@ -151,11 +157,25 b' def _fixed_getinnerframes(etb, context=1,tb_offset=0):' | |||||
151 | # functionality to produce a pseudo verbose TB for SyntaxErrors, so that they |
|
157 | # functionality to produce a pseudo verbose TB for SyntaxErrors, so that they | |
152 | # can be recognized properly by ipython.el's py-traceback-line-re |
|
158 | # can be recognized properly by ipython.el's py-traceback-line-re | |
153 | # (SyntaxErrors have to be treated specially because they have no traceback) |
|
159 | # (SyntaxErrors have to be treated specially because they have no traceback) | |
|
160 | ||||
|
161 | _parser = PyColorize.Parser() | |||
|
162 | ||||
154 | def _formatTracebackLines(lnum, index, lines, Colors, lvals=None): |
|
163 | def _formatTracebackLines(lnum, index, lines, Colors, lvals=None): | |
155 | numbers_width = INDENT_SIZE - 1 |
|
164 | numbers_width = INDENT_SIZE - 1 | |
156 | res = [] |
|
165 | res = [] | |
157 | i = lnum - index |
|
166 | i = lnum - index | |
|
167 | ||||
|
168 | # This lets us get fully syntax-highlighted tracebacks. | |||
|
169 | try: | |||
|
170 | scheme = __IPYTHON__.rc.colors | |||
|
171 | except: | |||
|
172 | scheme = DEFAULT_SCHEME | |||
|
173 | _line_format = _parser.format2 | |||
|
174 | ||||
158 | for line in lines: |
|
175 | for line in lines: | |
|
176 | new_line, err = _line_format(line,'str',scheme) | |||
|
177 | if not err: line = new_line | |||
|
178 | ||||
159 | if i == lnum: |
|
179 | if i == lnum: | |
160 | # This is the line with the error |
|
180 | # This is the line with the error | |
161 | pad = numbers_width - len(str(i)) |
|
181 | pad = numbers_width - len(str(i)) | |
@@ -181,6 +201,7 b' def _formatTracebackLines(lnum, index, lines, Colors, lvals=None):' | |||||
181 | i = i + 1 |
|
201 | i = i + 1 | |
182 | return res |
|
202 | return res | |
183 |
|
203 | |||
|
204 | ||||
184 | #--------------------------------------------------------------------------- |
|
205 | #--------------------------------------------------------------------------- | |
185 | # Module classes |
|
206 | # Module classes | |
186 | class TBTools: |
|
207 | class TBTools: |
@@ -1,5 +1,13 b'' | |||||
1 | 2007-03-18 Fernando Perez <Fernando.Perez@colorado.edu> |
|
1 | 2007-03-18 Fernando Perez <Fernando.Perez@colorado.edu> | |
2 |
|
2 | |||
|
3 | * IPython/ultraTB.py (_formatTracebackLines): Added (slightly | |||
|
4 | modified) R. Bernstein's patch for fully syntax highlighted | |||
|
5 | tracebacks. The functionality is also available under ultraTB for | |||
|
6 | non-ipython users (someone using ultraTB but outside an ipython | |||
|
7 | session). They can select the color scheme by setting the | |||
|
8 | module-level global DEFAULT_SCHEME. The highlight functionality | |||
|
9 | also works when debugging. | |||
|
10 | ||||
3 | * IPython/genutils.py (IOStream.close): small patch by |
|
11 | * IPython/genutils.py (IOStream.close): small patch by | |
4 | R. Bernstein for improved pydb support. |
|
12 | R. Bernstein for improved pydb support. | |
5 |
|
13 |
General Comments 0
You need to be logged in to leave comments.
Login now