MCPcopy Create free account
hub / github.com/ipython/ipython / VerboseTB

Class VerboseTB

IPython/core/ultratb.py:849–1291  ·  view source on GitHub ↗

A port of Ka-Ping Yee's cgitb.py module that outputs color text instead of HTML. Requires inspect and pydoc. Crazy, man. Modified version which optionally strips the topmost entries from the traceback, to be used with alternate interpreters (because their own code would appear in

Source from the content-addressed store, hash-verified

847
848#----------------------------------------------------------------------------
849class VerboseTB(TBTools):
850 """A port of Ka-Ping Yee's cgitb.py module that outputs color text instead
851 of HTML. Requires inspect and pydoc. Crazy, man.
852
853 Modified version which optionally strips the topmost entries from the
854 traceback, to be used with alternate interpreters (because their own code
855 would appear in the traceback)."""
856
857 def __init__(self, color_scheme='Linux', call_pdb=False, ostream=None,
858 tb_offset=0, long_header=False, include_vars=True,
859 check_cache=None, debugger_cls = None,
860 parent=None, config=None):
861 """Specify traceback offset, headers and color scheme.
862
863 Define how many frames to drop from the tracebacks. Calling it with
864 tb_offset=1 allows use of this handler in interpreters which will have
865 their own code at the top of the traceback (VerboseTB will first
866 remove that frame before printing the traceback info)."""
867 TBTools.__init__(self, color_scheme=color_scheme, call_pdb=call_pdb,
868 ostream=ostream, parent=parent, config=config)
869 self.tb_offset = tb_offset
870 self.long_header = long_header
871 self.include_vars = include_vars
872 # By default we use linecache.checkcache, but the user can provide a
873 # different check_cache implementation. This is used by the IPython
874 # kernel to provide tracebacks for interactive code that is cached,
875 # by a compiler instance that flushes the linecache but preserves its
876 # own code cache.
877 if check_cache is None:
878 check_cache = linecache.checkcache
879 self.check_cache = check_cache
880
881 self.debugger_cls = debugger_cls or debugger.Pdb
882 self.skip_hidden = True
883
884 def format_records(self, records, last_unique, recursion_repeat):
885 """Format the stack frames of the traceback"""
886 frames = []
887
888 skipped = 0
889 for r in records[:last_unique+recursion_repeat+1]:
890 if self.skip_hidden:
891 if r[0].f_locals.get("__tracebackhide__", 0):
892 skipped += 1
893 continue
894 if skipped:
895 Colors = self.Colors # just a shorthand + quicker name lookup
896 ColorsNormal = Colors.Normal # used a lot
897 frames.append(
898 " %s[... skipping hidden %s frame]%s\n"
899 % (Colors.excName, skipped, ColorsNormal)
900 )
901 skipped = 0
902
903 frames.append(self.format_record(*r))
904
905 if skipped:
906 Colors = self.Colors # just a shorthand + quicker name lookup

Callers 1

test_handlersFunction · 0.90

Calls

no outgoing calls

Tested by 1

test_handlersFunction · 0.72