Ejemplo n.º 1
0
    def debugger(self):
        """Call up the pdb debugger if desired, always clean up the tb reference.

        If the call_pdb flag is set, the pdb interactive debugger is
        invoked. In all cases, the self.tb reference to the current traceback
        is deleted to prevent lingering references which hamper memory
        management.

        Note that each call to pdb() does an 'import readline', so if your app
        requires a special setup for the readline completers, you'll have to
        fix that by hand after invoking the exception handler."""

        if self.call_pdb:
            if self.pdb is None:
                self.pdb = Debugger.Pdb()
            # the system displayhook may have changed, restore the original for pdb
            dhook = sys.displayhook
            sys.displayhook = sys.__displayhook__
            self.pdb.reset()
            while self.tb.tb_next is not None:
                self.tb = self.tb.tb_next
            try:
                self.pdb.interaction(self.tb.tb_frame, self.tb)
            except:
                print '*** ERROR ***'
                print 'This version of pdb has a bug and crashed.'
                print 'Returning to IPython...'
            sys.displayhook = dhook
        del self.tb
Ejemplo n.º 2
0
    def prompt(self, frame, file, line):
        if file:
            file = file[file.rfind("\\")+1:]
        while 1:
            try:
                choice = raw_input('>> ').strip()
                if dynreload_all: dynreload_all()
            except EOFError:
                raise QuitTests()
            
            if choice == 'd' and frame != None:
                if ipyDebugger:
                    debugger = ipyDebugger.Pdb()
                    debugger.reset()
                    debugger.interaction(frame, None)
                    print self.topgroup.__module__ + ": " + self.currentTestName()
                else:
                    print "IPython debugger not available"

            elif choice == 'de':
                postmortem(self.traceback)
            
            elif choice == 'q':
                raise QuitTests()
            elif choice == 'e':
                emacsto(file, line)
            elif choice == 'c':
                break
            elif choice == 'r':
                self.redo = True
                self.testCount -= 1
                break
            elif choice != '':
                print "Unknown command"
Ejemplo n.º 3
0
def ipy_set_trace():
    try:
        from IPython import Debugger
        Debugger.Pdb().set_trace()
    except ImportError:
        # IPython 0.10.2+
        from IPython.core.debugger import Pdb
        Pdb().set_trace()
Ejemplo n.º 4
0
    def __init__(self, color_scheme='NoColor', call_pdb=0):
        # Whether to call the interactive pdb debugger after printing
        # tracebacks or not
        self.call_pdb = call_pdb
        if call_pdb:
            self.pdb = Debugger.Pdb()
        else:
            self.pdb = None

        # Create color table
        self.ColorSchemeTable = ExceptionColors

        self.set_colors(color_scheme)
        self.old_scheme = color_scheme  # save initial value for toggles
Ejemplo n.º 5
0
    def __init__(self, color_scheme='NoColor', call_pdb=False):
        # Whether to call the interactive pdb debugger after printing
        # tracebacks or not
        self.call_pdb = call_pdb

        # Create color table
        self.color_scheme_table = exception_colors()

        self.set_colors(color_scheme)
        self.old_scheme = color_scheme  # save initial value for toggles

        if call_pdb:
            self.pdb = Debugger.Pdb(self.color_scheme_table.active_scheme_name)
        else:
            self.pdb = None
Ejemplo n.º 6
0
    def debugger(self, force=False):
        """Call up the pdb debugger if desired, always clean up the tb
        reference.

        Keywords:

          - force(False): by default, this routine checks the instance call_pdb
          flag and does not actually invoke the debugger if the flag is false.
          The 'force' option forces the debugger to activate even if the flag
          is false.

        If the call_pdb flag is set, the pdb interactive debugger is
        invoked. In all cases, the self.tb reference to the current traceback
        is deleted to prevent lingering references which hamper memory
        management.

        Note that each call to pdb() does an 'import readline', so if your app
        requires a special setup for the readline completers, you'll have to
        fix that by hand after invoking the exception handler."""

        if force or self.call_pdb:
            if self.pdb is None:
                self.pdb = Debugger.Pdb(
                    self.color_scheme_table.active_scheme_name)
            # the system displayhook may have changed, restore the original
            # for pdb
            dhook = sys.displayhook
            sys.displayhook = sys.__displayhook__
            self.pdb.reset()
            # Find the right frame so we don't pop up inside ipython itself
            if hasattr(self, 'tb'):
                etb = self.tb
            else:
                etb = self.tb = sys.last_traceback
            while self.tb.tb_next is not None:
                self.tb = self.tb.tb_next
            try:
                if etb and etb.tb_next:
                    etb = etb.tb_next
                self.pdb.botframe = etb.tb_frame
                self.pdb.interaction(self.tb.tb_frame, self.tb)
            finally:
                sys.displayhook = dhook

        if hasattr(self, 'tb'):
            del self.tb
Ejemplo n.º 7
0
def call_pydb(self, args):
    """Invoke pydb with the supplied parameters."""
    try:
        import pydb
    except ImportError:
        raise ImportError("pydb doesn't seem to be installed.")

    if not hasattr(pydb.pydb, "runv"):
        raise ImportError("You need pydb version 1.19 or later installed.")

    argl = arg_split(args)
    # print argl # dbg
    if len(inspect.getargspec(pydb.runv)[0]) == 2:
        pdb = Debugger.Pdb()
        ip.IP.history_saving_wrapper( lambda : pydb.runv(argl, pdb) )()
    else:
        ip.IP.history_saving_wrapper( lambda : pydb.runv(argl) )()
Ejemplo n.º 8
0
    def __init__(self, color_scheme='NoColor', call_pdb=0):
        # Whether to call the interactive pdb debugger after printing
        # tracebacks or not
        self.call_pdb = call_pdb
        if call_pdb:
            self.pdb = Debugger.Pdb()
        else:
            self.pdb = None

        # Create color table
        self.ColorSchemeTable = ColorSchemeTable()

        # Populate it with color schemes
        C = TermColors  # shorthand and local lookup
        self.ColorSchemeTable.add_scheme(
            ColorScheme(
                'NoColor',
                # The color to be used for the top line
                topline=C.NoColor,

                # The colors to be used in the traceback
                filename=C.NoColor,
                lineno=C.NoColor,
                name=C.NoColor,
                vName=C.NoColor,
                val=C.NoColor,
                em=C.NoColor,

                # Emphasized colors for the last frame of the traceback
                normalEm=C.NoColor,
                filenameEm=C.NoColor,
                linenoEm=C.NoColor,
                nameEm=C.NoColor,
                valEm=C.NoColor,

                # Colors for printing the exception
                excName=C.NoColor,
                line=C.NoColor,
                caret=C.NoColor,
                Normal=C.NoColor))

        # make some schemes as instances so we can copy them for modification easily:
        self.ColorSchemeTable.add_scheme(
            ColorScheme(
                'Linux',
                # The color to be used for the top line
                topline=C.LightRed,

                # The colors to be used in the traceback
                filename=C.Green,
                lineno=C.Green,
                name=C.Purple,
                vName=C.Cyan,
                val=C.Green,
                em=C.LightCyan,

                # Emphasized colors for the last frame of the traceback
                normalEm=C.LightCyan,
                filenameEm=C.LightGreen,
                linenoEm=C.LightGreen,
                nameEm=C.LightPurple,
                valEm=C.LightBlue,

                # Colors for printing the exception
                excName=C.LightRed,
                line=C.Yellow,
                caret=C.White,
                Normal=C.Normal))

        # For light backgrounds, swap dark/light colors
        self.ColorSchemeTable.add_scheme(
            ColorScheme(
                'LightBG',
                # The color to be used for the top line
                topline=C.Red,

                # The colors to be used in the traceback
                filename=C.LightGreen,
                lineno=C.LightGreen,
                name=C.LightPurple,
                vName=C.Cyan,
                val=C.LightGreen,
                em=C.Cyan,

                # Emphasized colors for the last frame of the traceback
                normalEm=C.Cyan,
                filenameEm=C.Green,
                linenoEm=C.Green,
                nameEm=C.Purple,
                valEm=C.Blue,

                # Colors for printing the exception
                excName=C.Red,
                #line = C.Brown,  # brown often is displayed as yellow
                line=C.Red,
                caret=C.Normal,
                Normal=C.Normal))

        self.set_colors(color_scheme)
        self.old_scheme = color_scheme  # save initial value for toggles