Exemple #1
0
 def __init__(self,color_table,code_color_table,scheme,
              str_detail_level=0):
     self.color_table = color_table
     self.parser = PyColorize.Parser(code_color_table,out='str')
     self.format = self.parser.format
     self.str_detail_level = str_detail_level
     self.set_active_scheme(scheme)
Exemple #2
0
        def __init__(self,color_scheme='NoColor',completekey=None,
                     stdin=None, stdout=None):

            # Parent constructor:
            if has_pydb and completekey is None:
                OldPdb.__init__(self,stdin=stdin,stdout=Term.cout)
            else:
                OldPdb.__init__(self,completekey,stdin,stdout)
                
            self.prompt = prompt # The default prompt is '(Pdb)'
            
            # IPython changes...
            self.is_pydb = has_pydb

            if self.is_pydb:

                # iplib.py's ipalias seems to want pdb's checkline
                # which located in pydb.fn
                import pydb.fns
                self.checkline = lambda filename, lineno: \
                                 pydb.fns.checkline(self, filename, lineno)

                self.curframe = None
                self.do_restart = self.new_do_restart

                self.old_all_completions = __IPYTHON__.Completer.all_completions
                __IPYTHON__.Completer.all_completions=self.all_completions

                self.do_list = decorate_fn_with_doc(self.list_command_pydb,
                                                    OldPdb.do_list)
                self.do_l     = self.do_list
                self.do_frame = decorate_fn_with_doc(self.new_do_frame,
                                                     OldPdb.do_frame)

            self.aliases = {}

            # Create color table: we copy the default one from the traceback
            # module and add a few attributes needed for debugging
            self.color_scheme_table = ExceptionColors.copy()

            # shorthands 
            C = ColorANSI.TermColors
            cst = self.color_scheme_table

            cst['NoColor'].colors.breakpoint_enabled = C.NoColor
            cst['NoColor'].colors.breakpoint_disabled = C.NoColor

            cst['Linux'].colors.breakpoint_enabled = C.LightRed
            cst['Linux'].colors.breakpoint_disabled = C.Red

            cst['LightBG'].colors.breakpoint_enabled = C.LightRed
            cst['LightBG'].colors.breakpoint_disabled = C.Red

            self.set_colors(color_scheme)

            # Add a python parser so we can syntax highlight source while
            # debugging.
            self.parser = PyColorize.Parser()
Exemple #3
0
 def colorize(source, start_lineno, curlineno):
     """"""
     parser = PyColorize.Parser()
     output = StringIO()
     parser.format(source, output)
     annotated = []
     for index, line in enumerate(output.getvalue().splitlines()):
         lineno = index + start_lineno
         if lineno == curlineno:
             annotated.append('%4s\t->\t%s' % (lineno, line))
         else:
             annotated.append('%4s\t\t%s' % (lineno, line))
     return '\n'.join(annotated)
Exemple #4
0
 def colorize(source, start_lineno, curlineno):
     """colorize and annotate source with linenos
     (as in pdb's list command)
     """
     parser = PyColorize.Parser()
     output = StringIO()
     parser.format(source, output)
     annotated = []
     for index, line in enumerate(output.getvalue().splitlines()):
         lineno = index + start_lineno
         if lineno == curlineno:
             annotated.append("%4s\t->\t%s" % (lineno, line))
         else:
             annotated.append("%4s\t\t%s" % (lineno, line))
     return "\n".join(annotated)
Exemple #5
0
        def __init__(self, color_scheme='NoColor'):
            bdb.Bdb.__init__(self)
            cmd.Cmd.__init__(self, completekey=None)  # don't load readline
            self.prompt = 'ipdb> '  # The default prompt is '(Pdb)'
            self.aliases = {}

            # These two lines are part of the py2.4 constructor, let's put them
            # unconditionally here as they won't cause any problems in 2.3.
            self.mainpyfile = ''
            self._wait_for_mainpyfile = 0

            # Read $HOME/.pdbrc and ./.pdbrc
            try:
                self.rcLines = _file_lines(
                    os.path.join(os.environ['HOME'], ".pdbrc"))
            except KeyError:
                self.rcLines = []
            self.rcLines.extend(_file_lines(".pdbrc"))

            # Create color table: we copy the default one from the traceback
            # module and add a few attributes needed for debugging
            ExceptionColors.set_active_scheme(color_scheme)
            self.color_scheme_table = ExceptionColors.copy()

            # shorthands
            C = ColorANSI.TermColors
            cst = self.color_scheme_table

            cst['NoColor'].colors.breakpoint_enabled = C.NoColor
            cst['NoColor'].colors.breakpoint_disabled = C.NoColor

            cst['Linux'].colors.breakpoint_enabled = C.LightRed
            cst['Linux'].colors.breakpoint_disabled = C.Red

            cst['LightBG'].colors.breakpoint_enabled = C.LightRed
            cst['LightBG'].colors.breakpoint_disabled = C.Red

            self.set_colors(color_scheme)

            # Add a python parser so we can syntax highlight source while
            # debugging.
            self.parser = PyColorize.Parser()
Exemple #6
0
 def colorize_source(source):
     """colorize given source"""
     parser = PyColorize.Parser()
     output = StringIO()
     parser.format(source, output)
     return output.getvalue()
Exemple #7
0
        if len(lines) < context:
            lines += ['\n'] * (context - len(lines))
        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:]


# Helper function -- largely belongs to VerboseTB, but we need the same
# functionality to produce a pseudo verbose TB for SyntaxErrors, so that they
# can be recognized properly by ipython.el's py-traceback-line-re
# (SyntaxErrors have to be treated specially because they have no traceback)

_parser = PyColorize.Parser()


def _formatTracebackLines(lnum, index, lines, Colors, lvals=None, scheme=None):
    numbers_width = INDENT_SIZE - 1
    res = []
    i = lnum - index

    # This lets us get fully syntax-highlighted tracebacks.
    if scheme is None:
        ipinst = ipapi.get()
        if ipinst is not None:
            scheme = ipinst.IP.rc.colors
        else:
            scheme = DEFAULT_SCHEME
    _line_format = _parser.format2