# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/03_capture_trace.ipynb.

# %% auto 0
__all__ = ['SaveTraceback']

# %% ../nbs/03_capture_trace.ipynb 2
import re
from IPython import get_ipython
from .utils import nict

# %% ../nbs/03_capture_trace.ipynb 3
class SaveTraceback:
    def __init__(self, saved):
        self._saved_showtraceback = saved
        self.tracebacks = []

    def _showtraceback(self, etype, value, stb):
        self.tracebacks.append( nict(
            ename=etype,
            evalue=", ".join(value.args),
            traceback= stb # ["\n".join([ strip_junk(s) for s in stb]) if isinstance(stb, list) else stb]
        ))
        self._saved_showtraceback(etype, value, stb)

    def register(self):
        get_ipython()._showtraceback = self._showtraceback

    def unregister(self):
        get_ipython()._showtraceback = self._saved_showtraceback

