def structured_traceback(self, etype, evalue, etb, tb_offset=None,<EOL>context=<NUM_LIT:5>):
tb_offset = self.tb_offset if tb_offset is None else tb_offset<EOL>try:<EOL><INDENT>etype = etype.__name__<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>Colors        = self.Colors   <EOL>ColorsNormal  = Colors.Normal  <EOL>col_scheme    = self.color_scheme_table.active_scheme_name<EOL>indent        = '<STR_LIT:U+0020>'*INDENT_SIZE<EOL>em_normal     = '<STR_LIT>' % (Colors.valEm, indent,ColorsNormal)<EOL>undefined     = '<STR_LIT>' % (Colors.em, ColorsNormal)<EOL>exc = '<STR_LIT>' % (Colors.excName,etype,ColorsNormal)<EOL>def text_repr(value):<EOL><INDENT>"""<STR_LIT>"""<EOL>try:<EOL><INDENT>return pydoc.text.repr(value)<EOL><DEDENT>except KeyboardInterrupt:<EOL><INDENT>raise<EOL><DEDENT>except:<EOL><INDENT>try:<EOL><INDENT>return repr(value)<EOL><DEDENT>except KeyboardInterrupt:<EOL><INDENT>raise<EOL><DEDENT>except:<EOL><INDENT>try:<EOL><INDENT>name = getattr(value, '<STR_LIT>', None)<EOL>if name:<EOL><INDENT>return text_repr(name)<EOL><DEDENT>klass = getattr(value, '<STR_LIT>', None)<EOL>if klass:<EOL><INDENT>return '<STR_LIT>' % text_repr(klass)<EOL><DEDENT><DEDENT>except KeyboardInterrupt:<EOL><INDENT>raise<EOL><DEDENT>except:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT><DEDENT><DEDENT><DEDENT>def eqrepr(value, repr=text_repr): return '<STR_LIT>' % repr(value)<EOL>def nullrepr(value, repr=text_repr): return '<STR_LIT>'<EOL>try:<EOL><INDENT>etype = etype.__name__<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT>if self.long_header:<EOL><INDENT>pyver = '<STR_LIT>' + sys.version.split()[<NUM_LIT:0>] + '<STR_LIT>' + sys.executable<EOL>date = time.ctime(time.time())<EOL>head = '<STR_LIT>' % (Colors.topline, '<STR_LIT:->'*<NUM_LIT>, ColorsNormal,<EOL>exc, '<STR_LIT:U+0020>'*(<NUM_LIT>-len(str(etype))-len(pyver)),<EOL>pyver, date.rjust(<NUM_LIT>) )<EOL>head += "<STR_LIT>""<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>head = '<STR_LIT>' % (Colors.topline, '<STR_LIT:->'*<NUM_LIT>, ColorsNormal,exc,<EOL>'<STR_LIT>'.rjust(<NUM_LIT> - len(str(etype)) ) )<EOL><DEDENT>frames = []<EOL>try:<EOL><INDENT>records = _fixed_getinnerframes(etb, context, tb_offset)<EOL><DEDENT>except:<EOL><INDENT>inspect_error()<EOL>traceback.print_exc(file=self.ostream)<EOL>info('<STR_LIT>')<EOL>return '<STR_LIT>'<EOL><DEDENT>tpl_link       = '<STR_LIT>' % (Colors.filenameEm,ColorsNormal)<EOL>tpl_call       = '<STR_LIT>' % (Colors.vName, Colors.valEm,<EOL>ColorsNormal)<EOL>tpl_call_fail  = '<STR_LIT>' %(Colors.vName, Colors.valEm, ColorsNormal)<EOL>tpl_local_var  = '<STR_LIT>' % (Colors.vName, ColorsNormal)<EOL>tpl_global_var = '<STR_LIT>' % (Colors.em, ColorsNormal,<EOL>Colors.vName, ColorsNormal)<EOL>tpl_name_val   = '<STR_LIT>' % (Colors.valEm, ColorsNormal)<EOL>tpl_line       = '<STR_LIT>' % (Colors.lineno, ColorsNormal)<EOL>tpl_line_em    = '<STR_LIT>' % (Colors.linenoEm,Colors.line,<EOL>ColorsNormal)<EOL>abspath = os.path.abspath<EOL>for frame, file, lnum, func, lines, index in records:<EOL><INDENT>if not file:<EOL><INDENT>file = '<STR_LIT:?>'<EOL><DEDENT>elif not(file.startswith("<STR_LIT:<>") and file.endswith("<STR_LIT:>>")):<EOL><INDENT>try:<EOL><INDENT>file = abspath(file)<EOL><DEDENT>except OSError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>link = tpl_link % file<EOL>args, varargs, varkw, locals = inspect.getargvalues(frame)<EOL>if func == '<STR_LIT:?>':<EOL><INDENT>call = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>var_repr = self.include_vars and eqrepr or nullrepr<EOL>try:<EOL><INDENT>call = tpl_call % (func,inspect.formatargvalues(args,<EOL>varargs, varkw,<EOL>locals,formatvalue=var_repr))<EOL><DEDENT>except KeyError:<EOL><INDENT>call = tpl_call_fail % func<EOL><DEDENT><DEDENT>if file.endswith(('<STR_LIT>', '<STR_LIT>', '<STR_LIT>')):<EOL><INDENT>frames.append('<STR_LIT>' % (link,call))<EOL>continue<EOL><DEDENT>elif file.endswith(('<STR_LIT>','<STR_LIT>')):<EOL><INDENT>file = pyfile.source_from_cache(file)<EOL><DEDENT>def linereader(file=file, lnum=[lnum], getline=linecache.getline):<EOL><INDENT>line = getline(file, lnum[<NUM_LIT:0>])<EOL>lnum[<NUM_LIT:0>] += <NUM_LIT:1><EOL>return line<EOL><DEDENT>try:<EOL><INDENT>names = []<EOL>name_cont = False<EOL>for token_type, token, start, end, line in generate_tokens(linereader):<EOL><INDENT>if token_type == tokenize.NAME and token not in keyword.kwlist:<EOL><INDENT>if name_cont:<EOL><INDENT>try:<EOL><INDENT>names[-<NUM_LIT:1>].append(token)<EOL><DEDENT>except IndexError:<EOL><INDENT>names.append([token])<EOL><DEDENT>name_cont = False<EOL><DEDENT>else:<EOL><INDENT>names.append([token])<EOL><DEDENT><DEDENT>elif token == '<STR_LIT:.>':<EOL><INDENT>name_cont = True<EOL><DEDENT>elif token_type == tokenize.NEWLINE:<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>except (IndexError, UnicodeDecodeError):<EOL><INDENT>pass<EOL><DEDENT>except tokenize.TokenError as msg:<EOL><INDENT>_m = ("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % msg)<EOL>error(_m)<EOL><DEDENT>names = ['<STR_LIT:.>'.join(n) for n in names]<EOL>unique_names = uniq_stable(names)<EOL>lvals = []<EOL>if self.include_vars:<EOL><INDENT>for name_full in unique_names:<EOL><INDENT>name_base = name_full.split('<STR_LIT:.>',<NUM_LIT:1>)[<NUM_LIT:0>]<EOL>if name_base in frame.f_code.co_varnames:<EOL><INDENT>if name_base in locals:<EOL><INDENT>try:<EOL><INDENT>value = repr(eval(name_full,locals))<EOL><DEDENT>except:<EOL><INDENT>value = undefined<EOL><DEDENT><DEDENT>else:<EOL><INDENT>value = undefined<EOL><DEDENT>name = tpl_local_var % name_full<EOL><DEDENT>else:<EOL><INDENT>if name_base in frame.f_globals:<EOL><INDENT>try:<EOL><INDENT>value = repr(eval(name_full,frame.f_globals))<EOL><DEDENT>except:<EOL><INDENT>value = undefined<EOL><DEDENT><DEDENT>else:<EOL><INDENT>value = undefined<EOL><DEDENT>name = tpl_global_var % name_full<EOL><DEDENT>lvals.append(tpl_name_val % (name,value))<EOL><DEDENT><DEDENT>if lvals:<EOL><INDENT>lvals = '<STR_LIT>' % (indent,em_normal.join(lvals))<EOL><DEDENT>else:<EOL><INDENT>lvals = '<STR_LIT>'<EOL><DEDENT>level = '<STR_LIT>' % (link,call)<EOL>if index is None:<EOL><INDENT>frames.append(level)<EOL><DEDENT>else:<EOL><INDENT>frames.append('<STR_LIT>' % (level,'<STR_LIT>'.join(<EOL>_format_traceback_lines(lnum,index,lines,Colors,lvals,<EOL>col_scheme))))<EOL><DEDENT><DEDENT>try:<EOL><INDENT>etype_str,evalue_str = list(map(str,(etype,evalue)))<EOL><DEDENT>except:<EOL><INDENT>etype,evalue = str,sys.exc_info()[:<NUM_LIT:2>]<EOL>etype_str,evalue_str = list(map(str,(etype,evalue)))<EOL><DEDENT>exception = ['<STR_LIT>' % (Colors.excName, etype_str,<EOL>ColorsNormal, evalue_str)]<EOL>if (not py3compat.PY3) and type(evalue) is types.InstanceType:<EOL><INDENT>try:<EOL><INDENT>names = [w for w in dir(evalue) if isinstance(w, str)]<EOL><DEDENT>except:<EOL><INDENT>_m = '<STR_LIT>'<EOL>exception.append(_m % (Colors.excName,ColorsNormal))<EOL>etype_str,evalue_str = list(map(str,sys.exc_info()[:<NUM_LIT:2>]))<EOL>exception.append('<STR_LIT>' % (Colors.excName,etype_str,<EOL>ColorsNormal, evalue_str))<EOL>names = []<EOL><DEDENT>for name in names:<EOL><INDENT>value = text_repr(getattr(evalue, name))<EOL>exception.append('<STR_LIT>' % (indent, name, value))<EOL><DEDENT><DEDENT>if records:<EOL><INDENT>filepath, lnum = records[-<NUM_LIT:1>][<NUM_LIT:1>:<NUM_LIT:3>]<EOL>filepath = os.path.abspath(filepath)<EOL>ipinst = ipapi.get()<EOL>if ipinst is not None:<EOL><INDENT>ipinst.hooks.synchronize_with_editor(filepath, lnum, <NUM_LIT:0>)<EOL><DEDENT><DEDENT>return [head] + frames + ['<STR_LIT>'.join(exception[<NUM_LIT:0>])]<EOL>
Return a nice text document describing the traceback.