##// END OF EJS Templates
Merge pull request #11127 from Carreau/clean-tb...
Matthias Bussonnier -
r24355:3bd77092 merge
parent child Browse files
Show More
@@ -375,16 +375,32 b' def _fixed_getinnerframes(etb, context=1, tb_offset=0):'
375 # (SyntaxErrors have to be treated specially because they have no traceback)
375 # (SyntaxErrors have to be treated specially because they have no traceback)
376
376
377
377
378 def _format_traceback_lines(lnum, index, lines, Colors, lvals=None, _line_format=(lambda x,_:x,None)):
378 def _format_traceback_lines(lnum, index, lines, Colors, lvals, _line_format):
379 """
380 Format tracebacks lines with pointing arrow, leading numbers...
381
382 Parameters
383 ==========
384
385 lnum: int
386 index: int
387 lines: list[string]
388 Colors:
389 ColorScheme used.
390 lvals: bytes
391 Values of local variables, already colored, to inject just after the error line.
392 _line_format: f (str) -> (str, bool)
393 return (colorized version of str, failure to do so)
394 """
379 numbers_width = INDENT_SIZE - 1
395 numbers_width = INDENT_SIZE - 1
380 res = []
396 res = []
381 i = lnum - index
382
397
383 for line in lines:
398 for i,line in enumerate(lines, lnum-index):
384 line = py3compat.cast_unicode(line)
399 line = py3compat.cast_unicode(line)
385
400
386 new_line, err = _line_format(line, 'str')
401 new_line, err = _line_format(line, 'str')
387 if not err: line = new_line
402 if not err:
403 line = new_line
388
404
389 if i == lnum:
405 if i == lnum:
390 # This is the line with the error
406 # This is the line with the error
@@ -400,7 +416,6 b' def _format_traceback_lines(lnum, index, lines, Colors, lvals=None, _line_forma'
400 res.append(line)
416 res.append(line)
401 if lvals and i == lnum:
417 if lvals and i == lnum:
402 res.append(lvals + '\n')
418 res.append(lvals + '\n')
403 i = i + 1
404 return res
419 return res
405
420
406 def is_recursion_error(etype, value, records):
421 def is_recursion_error(etype, value, records):
@@ -853,7 +868,7 b' class VerboseTB(TBTools):'
853
868
854 file = py3compat.cast_unicode(file, util_path.fs_encoding)
869 file = py3compat.cast_unicode(file, util_path.fs_encoding)
855 link = tpl_link % util_path.compress_user(file)
870 link = tpl_link % util_path.compress_user(file)
856 args, varargs, varkw, locals = inspect.getargvalues(frame)
871 args, varargs, varkw, locals_ = inspect.getargvalues(frame)
857
872
858 if func == '?':
873 if func == '?':
859 call = ''
874 call = ''
@@ -863,7 +878,7 b' class VerboseTB(TBTools):'
863 try:
878 try:
864 call = tpl_call % (func, inspect.formatargvalues(args,
879 call = tpl_call % (func, inspect.formatargvalues(args,
865 varargs, varkw,
880 varargs, varkw,
866 locals, formatvalue=var_repr))
881 locals_, formatvalue=var_repr))
867 except KeyError:
882 except KeyError:
868 # This happens in situations like errors inside generator
883 # This happens in situations like errors inside generator
869 # expressions, where local variables are listed in the
884 # expressions, where local variables are listed in the
@@ -952,14 +967,15 b' class VerboseTB(TBTools):'
952 unique_names = uniq_stable(names)
967 unique_names = uniq_stable(names)
953
968
954 # Start loop over vars
969 # Start loop over vars
955 lvals = []
970 lvals = ''
971 lvals_list = []
956 if self.include_vars:
972 if self.include_vars:
957 for name_full in unique_names:
973 for name_full in unique_names:
958 name_base = name_full.split('.', 1)[0]
974 name_base = name_full.split('.', 1)[0]
959 if name_base in frame.f_code.co_varnames:
975 if name_base in frame.f_code.co_varnames:
960 if name_base in locals:
976 if name_base in locals_:
961 try:
977 try:
962 value = repr(eval(name_full, locals))
978 value = repr(eval(name_full, locals_))
963 except:
979 except:
964 value = undefined
980 value = undefined
965 else:
981 else:
@@ -974,11 +990,9 b' class VerboseTB(TBTools):'
974 else:
990 else:
975 value = undefined
991 value = undefined
976 name = tpl_global_var % name_full
992 name = tpl_global_var % name_full
977 lvals.append(tpl_name_val % (name, value))
993 lvals_list.append(tpl_name_val % (name, value))
978 if lvals:
994 if lvals_list:
979 lvals = '%s%s' % (indent, em_normal.join(lvals))
995 lvals = '%s%s' % (indent, em_normal.join(lvals_list))
980 else:
981 lvals = ''
982
996
983 level = '%s %s\n' % (link, call)
997 level = '%s %s\n' % (link, call)
984
998
@@ -213,7 +213,7 b' class Parser(Colorable):'
213
213
214 string_output = 0
214 string_output = 0
215 if out == 'str' or self.out == 'str' or \
215 if out == 'str' or self.out == 'str' or \
216 isinstance(self.out,StringIO):
216 isinstance(self.out, StringIO):
217 # XXX - I don't really like this state handling logic, but at this
217 # XXX - I don't really like this state handling logic, but at this
218 # point I don't want to make major changes, so adding the
218 # point I don't want to make major changes, so adding the
219 # isinstance() check is the simplest I can do to ensure correct
219 # isinstance() check is the simplest I can do to ensure correct
@@ -223,6 +223,8 b' class Parser(Colorable):'
223 string_output = 1
223 string_output = 1
224 elif out is not None:
224 elif out is not None:
225 self.out = out
225 self.out = out
226 else:
227 raise ValueError('`out` or `self.out` should be file-like or the value `"str"`')
226
228
227 # Fast return of the unmodified input for NoColor scheme
229 # Fast return of the unmodified input for NoColor scheme
228 if self.style == 'NoColor':
230 if self.style == 'NoColor':
@@ -275,12 +277,13 b' class Parser(Colorable):'
275 return (output, error)
277 return (output, error)
276 return (None, error)
278 return (None, error)
277
279
278 def __call__(self, toktype, toktext, start_pos, end_pos, line):
280 def _inner_call_(self, toktype, toktext, start_pos, end_pos, line):
279 """ Token handler, with syntax highlighting."""
281 """like call but write to a temporary buffer"""
282 buff = StringIO()
280 (srow,scol) = start_pos
283 (srow,scol) = start_pos
281 (erow,ecol) = end_pos
284 (erow,ecol) = end_pos
282 colors = self.colors
285 colors = self.colors
283 owrite = self.out.write
286 owrite = buff.write
284
287
285 # line separator, so this works across platforms
288 # line separator, so this works across platforms
286 linesep = os.linesep
289 linesep = os.linesep
@@ -297,7 +300,8 b' class Parser(Colorable):'
297 # skip indenting tokens
300 # skip indenting tokens
298 if toktype in [token.INDENT, token.DEDENT]:
301 if toktype in [token.INDENT, token.DEDENT]:
299 self.pos = newpos
302 self.pos = newpos
300 return
303 buff.seek(0)
304 return buff.read()
301
305
302 # map token type to a color group
306 # map token type to a color group
303 if token.LPAR <= toktype <= token.OP:
307 if token.LPAR <= toktype <= token.OP:
@@ -316,3 +320,12 b' class Parser(Colorable):'
316
320
317 # send text
321 # send text
318 owrite('%s%s%s' % (color,toktext,colors.normal))
322 owrite('%s%s%s' % (color,toktext,colors.normal))
323 buff.seek(0)
324 return buff.read()
325
326
327 def __call__(self, toktype, toktext, start_pos, end_pos, line):
328 """ Token handler, with syntax highlighting."""
329 self.out.write(
330 self._inner_call_(toktype, toktext, start_pos, end_pos, line))
331
General Comments 0
You need to be logged in to leave comments. Login now