def format_stack_entry(self, frame_lineno, lprefix=": ", context=3): try: import reprlib # Py 3 except ImportError: import repr as reprlib # Py 2 ret = [] Colors = self.color_scheme_table.active_colors ColorsNormal = Colors.Normal tpl_link = u"%s%%s%s" % (Colors.filenameEm, ColorsNormal) tpl_call = u"%s%%s%s%%s%s" % (Colors.vName, Colors.valEm, ColorsNormal) tpl_line = u"%%s%s%%s %s%%s" % (Colors.lineno, ColorsNormal) tpl_line_em = u"%%s%s%%s %s%%s%s" % (Colors.linenoEm, Colors.line, ColorsNormal) frame, lineno = frame_lineno return_value = "" if "__return__" in frame.f_locals: rv = frame.f_locals["__return__"] # return_value += '->' return_value += reprlib.repr(rv) + "\n" ret.append(return_value) # s = filename + '(' + `lineno` + ')' filename = self.canonic(frame.f_code.co_filename) link = tpl_link % py3compat.cast_unicode(filename) if frame.f_code.co_name: func = frame.f_code.co_name else: func = "<lambda>" call = "" if func != "?": if "__args__" in frame.f_locals: args = reprlib.repr(frame.f_locals["__args__"]) else: args = "()" call = tpl_call % (func, args) # The level info should be generated in the same format pdb uses, to # avoid breaking the pdbtrack functionality of python-mode in *emacs. if frame is self.curframe: ret.append("> ") else: ret.append(" ") ret.append(u"%s(%s)%s\n" % (link, lineno, call)) start = lineno - 1 - context // 2 lines = ulinecache.getlines(filename) start = min(start, len(lines) - context) start = max(start, 0) lines = lines[start : start + context] for i, line in enumerate(lines): show_arrow = start + 1 + i == lineno linetpl = (frame is self.curframe or show_arrow) and tpl_line_em or tpl_line ret.append(self.__format_line(linetpl, filename, start + 1 + i, line, arrow=show_arrow)) return "".join(ret)
def _fixed_getinnerframes(etb, context=1,tb_offset=0): LNUM_POS, LINES_POS, INDEX_POS = 2, 4, 5 records = fix_frame_records_filenames(inspect.getinnerframes(etb, context)) # If the error is at the console, don't build any context, since it would # otherwise produce 5 blank lines printed out (there is no file at the # console) rec_check = records[tb_offset:] try: rname = rec_check[0][1] if rname == '<ipython console>' or rname.endswith('<string>'): return rec_check except IndexError: pass aux = traceback.extract_tb(etb) assert len(records) == len(aux) for i, (file, lnum, _, _) in zip(range(len(records)), aux): maybeStart = lnum-1 - context//2 start = max(maybeStart, 0) end = start + context lines = ulinecache.getlines(file)[start:end] buf = list(records[i]) buf[LNUM_POS] = lnum buf[INDEX_POS] = lnum - 1 - start buf[LINES_POS] = lines records[i] = tuple(buf) return records[tb_offset:]
def format_stack_entry(self, frame_lineno, lprefix=': ', context=None): if context is None: context = self.context try: context = int(context) if context <= 0: print("Context must be a positive integer") except (TypeError, ValueError): print("Context must be a positive integer") try: import reprlib # Py 3 except ImportError: import repr as reprlib # Py 2 ret = [] Colors = self.color_scheme_table.active_colors ColorsNormal = Colors.Normal tpl_link = u'%s%%s%s' % (Colors.filenameEm, ColorsNormal) tpl_call = u'%s%%s%s%%s%s' % (Colors.vName, Colors.valEm, ColorsNormal) tpl_line = u'%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal) tpl_line_em = u'%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line, ColorsNormal) frame, lineno = frame_lineno return_value = '' if '__return__' in frame.f_locals: rv = frame.f_locals['__return__'] #return_value += '->' return_value += reprlib.repr(rv) + '\n' ret.append(return_value) #s = filename + '(' + `lineno` + ')' filename = self.canonic(frame.f_code.co_filename) link = tpl_link % py3compat.cast_unicode(filename) if frame.f_code.co_name: func = frame.f_code.co_name else: func = "<lambda>" call = '' if func != '?': if '__args__' in frame.f_locals: args = reprlib.repr(frame.f_locals['__args__']) else: args = '()' call = tpl_call % (func, args) # The level info should be generated in the same format pdb uses, to # avoid breaking the pdbtrack functionality of python-mode in *emacs. if frame is self.curframe: ret.append('> ') else: ret.append(' ') ret.append(u'%s(%s)%s\n' % (link, lineno, call)) start = lineno - 1 - context // 2 lines = ulinecache.getlines(filename) start = min(start, len(lines) - context) start = max(start, 0) lines = lines[start:start + context] for i, line in enumerate(lines): show_arrow = (start + 1 + i == lineno) linetpl = (frame is self.curframe or show_arrow) \ and tpl_line_em \ or tpl_line ret.append( self.__format_line(linetpl, filename, start + 1 + i, line, arrow=show_arrow)) return ''.join(ret)
def format_stack_entry(self, frame_lineno, lprefix=': ', context=None): if context is None: context = self.context try: context=int(context) if context <= 0: print("Context must be a positive integer") except (TypeError, ValueError): print("Context must be a positive integer") try: import reprlib # Py 3 except ImportError: import repr as reprlib # Py 2 ret = [] Colors = self.color_scheme_table.active_colors ColorsNormal = Colors.Normal tpl_link = u'%s%%s%s' % (Colors.filenameEm, ColorsNormal) tpl_call = u'%s%%s%s%%s%s' % (Colors.vName, Colors.valEm, ColorsNormal) tpl_line = u'%%s%s%%s %s%%s' % (Colors.lineno, ColorsNormal) tpl_line_em = u'%%s%s%%s %s%%s%s' % (Colors.linenoEm, Colors.line, ColorsNormal) frame, lineno = frame_lineno return_value = '' if '__return__' in frame.f_locals: rv = frame.f_locals['__return__'] #return_value += '->' return_value += reprlib.repr(rv) + '\n' ret.append(return_value) #s = filename + '(' + `lineno` + ')' filename = self.canonic(frame.f_code.co_filename) link = tpl_link % py3compat.cast_unicode(filename) if frame.f_code.co_name: func = frame.f_code.co_name else: func = "<lambda>" call = '' if func != '?': if '__args__' in frame.f_locals: args = reprlib.repr(frame.f_locals['__args__']) else: args = '()' call = tpl_call % (func, args) # The level info should be generated in the same format pdb uses, to # avoid breaking the pdbtrack functionality of python-mode in *emacs. if frame is self.curframe: ret.append('> ') else: ret.append(' ') ret.append(u'%s(%s)%s\n' % (link,lineno,call)) start = lineno - 1 - context//2 lines = ulinecache.getlines(filename) start = min(start, len(lines) - context) start = max(start, 0) lines = lines[start : start + context] for i,line in enumerate(lines): show_arrow = (start + 1 + i == lineno) linetpl = (frame is self.curframe or show_arrow) \ and tpl_line_em \ or tpl_line ret.append(self.__format_line(linetpl, filename, start + 1 + i, line, arrow = show_arrow) ) return ''.join(ret)