Show More
@@ -15,7 +15,7 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 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 | 179 | # Parent constructor: |
|
180 | 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 | 182 | else: |
|
183 | 183 | OldPdb.__init__(self,completekey,stdin,stdout) |
|
184 | 184 | |
@@ -228,6 +228,11 b' class Pdb(OldPdb):' | |||
|
228 | 228 | |
|
229 | 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 | 236 | else: |
|
232 | 237 | # Ugly hack: for Python 2.3-2.4, we can't call the parent constructor, |
|
233 | 238 | # because it binds readline and breaks tab-completion. This means we |
@@ -271,6 +276,10 b' class Pdb(OldPdb):' | |||
|
271 | 276 | |
|
272 | 277 | self.set_colors(color_scheme) |
|
273 | 278 | |
|
279 | # Add a python parser so we can syntax highlight source while | |
|
280 | # debugging. | |
|
281 | self.parser = PyColorize.Parser() | |
|
282 | ||
|
274 | 283 | def set_colors(self, scheme): |
|
275 | 284 | """Shorthand access to the color table scheme selector method.""" |
|
276 | 285 | self.color_scheme_table.set_active_scheme(scheme) |
@@ -393,6 +402,10 b' class Pdb(OldPdb):' | |||
|
393 | 402 | bp_mark = "" |
|
394 | 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 | 409 | bp = None |
|
397 | 410 | if lineno in self.get_file_breaks(filename): |
|
398 | 411 | bps = self.get_breaks(filename, lineno) |
@@ -28,7 +28,7 b'' | |||
|
28 | 28 | scan Python source code and re-emit it with no changes to its original |
|
29 | 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 | 33 | __all__ = ['ANSICodeColors','Parser'] |
|
34 | 34 | |
@@ -120,6 +120,9 b' class Parser:' | |||
|
120 | 120 | self.out = out |
|
121 | 121 | |
|
122 | 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 | 126 | """ Parse and send the colored source. |
|
124 | 127 | |
|
125 | 128 | If out and scheme are not specified, the defaults (given to |
@@ -153,6 +156,8 b' class Parser:' | |||
|
153 | 156 | self.pos = 0 |
|
154 | 157 | text = cStringIO.StringIO(self.raw) |
|
155 | 158 | #self.out.write('<pre><font face="Courier New">') |
|
159 | ||
|
160 | error = False | |
|
156 | 161 | try: |
|
157 | 162 | tokenize.tokenize(text.readline, self) |
|
158 | 163 | except tokenize.TokenError, ex: |
@@ -163,11 +168,13 b' class Parser:' | |||
|
163 | 168 | msg, self.raw[self.lines[line]:], |
|
164 | 169 | colors.normal) |
|
165 | 170 | ) |
|
171 | error = True | |
|
166 | 172 | self.out.write(colors.normal+'\n') |
|
167 | 173 | if string_output: |
|
168 | 174 | output = self.out.getvalue() |
|
169 | 175 | self.out = out_old |
|
170 | return output | |
|
176 | return (output, error) | |
|
177 | return (None, error) | |
|
171 | 178 | |
|
172 | 179 | def __call__(self, toktype, toktext, (srow,scol), (erow,ecol), line): |
|
173 | 180 | """ Token handler, with syntax highlighting.""" |
@@ -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 2 |
|
|
63 | $Id: ultraTB.py 2155 2007-03-19 00:45:51Z fperez $""" | |
|
64 | 64 | |
|
65 | 65 | #***************************************************************************** |
|
66 | 66 | # Copyright (C) 2001 Nathaniel Gray <n8gray@caltech.edu> |
@@ -90,7 +90,7 b' import types' | |||
|
90 | 90 | |
|
91 | 91 | # IPython's own modules |
|
92 | 92 | # Modified pdb which doesn't damage IPython's readline handling |
|
93 | from IPython import Debugger | |
|
93 | from IPython import Debugger, PyColorize | |
|
94 | 94 | from IPython.ipstruct import Struct |
|
95 | 95 | from IPython.excolors import ExceptionColors |
|
96 | 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 | 99 | # amount of space to put line numbers before verbose tracebacks |
|
100 | 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 | 109 | # Code begins |
|
104 | 110 | |
@@ -151,11 +157,25 b' def _fixed_getinnerframes(etb, context=1,tb_offset=0):' | |||
|
151 | 157 | # functionality to produce a pseudo verbose TB for SyntaxErrors, so that they |
|
152 | 158 | # can be recognized properly by ipython.el's py-traceback-line-re |
|
153 | 159 | # (SyntaxErrors have to be treated specially because they have no traceback) |
|
160 | ||
|
161 | _parser = PyColorize.Parser() | |
|
162 | ||
|
154 | 163 | def _formatTracebackLines(lnum, index, lines, Colors, lvals=None): |
|
155 | 164 | numbers_width = INDENT_SIZE - 1 |
|
156 | 165 | res = [] |
|
157 | 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 | 175 | for line in lines: |
|
176 | new_line, err = _line_format(line,'str',scheme) | |
|
177 | if not err: line = new_line | |
|
178 | ||
|
159 | 179 | if i == lnum: |
|
160 | 180 | # This is the line with the error |
|
161 | 181 | pad = numbers_width - len(str(i)) |
@@ -181,6 +201,7 b' def _formatTracebackLines(lnum, index, lines, Colors, lvals=None):' | |||
|
181 | 201 | i = i + 1 |
|
182 | 202 | return res |
|
183 | 203 | |
|
204 | ||
|
184 | 205 | #--------------------------------------------------------------------------- |
|
185 | 206 | # Module classes |
|
186 | 207 | class TBTools: |
@@ -1,5 +1,13 b'' | |||
|
1 | 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 | 11 | * IPython/genutils.py (IOStream.close): small patch by |
|
4 | 12 | R. Bernstein for improved pydb support. |
|
5 | 13 |
General Comments 0
You need to be logged in to leave comments.
Login now