示例#1
0
def exception_colors():
    """Return a color table with fields for exception reporting.

    The table is an instance of ColorSchemeTable with schemes added for
    'Neutral', 'Linux', 'LightBG' and 'NoColor' and fields for exception handling filled
    in.

    Examples:

    >>> ec = exception_colors()
    >>> ec.active_scheme_name
    ''
    >>> print(ec.active_colors)
    None

    Now we activate a color scheme:
    >>> ec.set_active_scheme('NoColor')
    >>> ec.active_scheme_name
    'NoColor'
    >>> sorted(ec.active_colors.keys())
    ['Normal', 'caret', 'em', 'excName', 'filename', 'filenameEm', 'line',
    'lineno', 'linenoEm', 'name', 'nameEm', 'normalEm', 'topline', 'vName',
    'val', 'valEm']
    """

    ex_colors = ColorSchemeTable()

    # Populate it with color schemes
    C = TermColors  # shorthand and local lookup
    ex_colors.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
    ex_colors.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
    ex_colors.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,
        ))

    ex_colors.add_scheme(
        ColorScheme(
            'Neutral',
            # 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,
        ))

    # Hack: the 'neutral' colours are not very visible on a dark background on
    # Windows. Since Windows command prompts have a dark background by default, and
    # relatively few users are likely to alter that, we will use the 'Linux' colours,
    # designed for a dark background, as the default on Windows.
    if os.name == "nt":
        ex_colors.add_scheme(ex_colors['Linux'].copy('Neutral'))

    return ex_colors
示例#2
0
def exception_colors():
    """Return a color table with fields for exception reporting.

    The table is an instance of ColorSchemeTable with schemes added for
    'Neutral', 'Linux', 'LightBG' and 'NoColor' and fields for exception handling filled
    in.

    Examples:

    >>> ec = exception_colors()
    >>> ec.active_scheme_name
    ''
    >>> print(ec.active_colors)
    None

    Now we activate a color scheme:
    >>> ec.set_active_scheme('NoColor')
    >>> ec.active_scheme_name
    'NoColor'
    >>> sorted(ec.active_colors.keys())
    ['Normal', 'caret', 'em', 'excName', 'filename', 'filenameEm', 'line',
    'lineno', 'linenoEm', 'name', 'nameEm', 'normalEm', 'topline', 'vName',
    'val', 'valEm']
    """

    ex_colors = ColorSchemeTable()

    # Populate it with color schemes
    C = TermColors # shorthand and local lookup
    ex_colors.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
    ex_colors.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
    ex_colors.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,
        ))

    ex_colors.add_scheme(ColorScheme(
        'Neutral',
        # 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,
        ))


    return ex_colors
示例#3
0
def exception_colors():
    """Return a color table with fields for exception reporting.

    The table is an instance of ColorSchemeTable with schemes added for
    'Linux', 'LightBG' and 'NoColor' and fields for exception handling filled
    in.

    Examples:

    >>> ec = exception_colors()
    >>> ec.active_scheme_name
    ''
    >>> print(ec.active_colors)
    None

    Now we activate a color scheme:
    >>> ec.set_active_scheme('NoColor')
    >>> ec.active_scheme_name
    'NoColor'
    >>> sorted(ec.active_colors.keys())
    ['Normal', 'caret', 'em', 'excName', 'filename', 'filenameEm', 'line',
    'lineno', 'linenoEm', 'name', 'nameEm', 'normalEm', 'topline', 'vName',
    'val', 'valEm']
    """

    ex_colors = ColorSchemeTable()

    # Populate it with color schemes
    C = TermColors  # shorthand and local lookup
    ex_colors.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
    ex_colors.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
    ex_colors.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,
        ))

    return ex_colors
示例#4
0
def exception_colors():
    """Return a color table with fields for exception reporting.

    The table is an instance of ColorSchemeTable with schemes added for
    'Neutral', 'Linux', 'LightBG' and 'NoColor' and fields for exception handling filled
    in.

    Examples:

    >>> ec = exception_colors()
    >>> ec.active_scheme_name
    ''
    >>> print(ec.active_colors)
    None

    Now we activate a color scheme:
    >>> ec.set_active_scheme('NoColor')
    >>> ec.active_scheme_name
    'NoColor'
    >>> sorted(ec.active_colors.keys())
    ['Normal', 'caret', 'em', 'excName', 'filename', 'filenameEm', 'line',
    'lineno', 'linenoEm', 'name', 'nameEm', 'normalEm', 'topline', 'vName',
    'val', 'valEm']
    """

    ex_colors = ColorSchemeTable()

    # Populate it with color schemes
    C = TermColors # shorthand and local lookup
    ex_colors.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
    ex_colors.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
    ex_colors.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,
        ))

    ex_colors.add_scheme(ColorScheme(
        'Neutral',
        # 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,
        ))

    # Hack: the 'neutral' colours are not very visible on a dark background on
    # Windows. Since Windows command prompts have a dark background by default, and
    # relatively few users are likely to alter that, we will use the 'Linux' colours,
    # designed for a dark background, as the default on Windows.
    if os.name == "nt":
        ex_colors.add_scheme(ex_colors['Linux'].copy('Neutral'))

    return ex_colors
示例#5
0
    }  )

LinuxColors = ColorScheme(
    'Linux',{
    'header' : Colors.LightRed,
    'normal' : Colors.Normal  # color off (usu. Colors.Normal)
    } )

LightBGColors = ColorScheme(
    'LightBG',{
    'header' : Colors.Red,
    'normal' : Colors.Normal  # color off (usu. Colors.Normal)
    }  )

# Build table of color schemes (needed by the parser)
InspectColors = ColorSchemeTable([NoColor,LinuxColors,LightBGColors],
                                 'Linux')

#****************************************************************************
# Auxiliary functions and objects

# See the messaging spec for the definition of all these fields.  This list
# effectively defines the order of display
info_fields = ['type_name', 'base_class', 'string_form', 'namespace',
               'length', 'file', 'definition', 'docstring', 'source',
               'init_definition', 'class_docstring', 'init_docstring',
               'call_def', 'call_docstring',
               # These won't be printed but will be used to determine how to
               # format the object
               'ismagic', 'isalias', 'isclass', 'argspec', 'found', 'name'
               ]
示例#6
0
        tokenize.COMMENT: Colors.Red,
        token.NAME: Colors.Normal,
        token.ERRORTOKEN: Colors.Red,
        _KEYWORD: Colors.Green,
        _TEXT: Colors.Blue,
        'in_prompt': InputTermColors.Blue,
        'in_number': InputTermColors.LightBlue,
        'in_prompt2': InputTermColors.Blue,
        'in_normal': InputTermColors.Normal,  # color off (usu. Colors.Normal)
        'out_prompt': Colors.Red,
        'out_number': Colors.LightRed,
        'normal': Colors.Normal  # color off (usu. Colors.Normal)
    })

# Build table of color schemes (needed by the parser)
ANSICodeColors = ColorSchemeTable(
    [NoColor, LinuxColors, LightBGColors, NeutralColors], _scheme_default)

Undefined = object()


class Parser(Colorable):
    """ Format colored Python source.
    """
    def __init__(self,
                 color_table=None,
                 out=sys.stdout,
                 parent=None,
                 style=None):
        """ Create a parser with a specified color table and output channel.

        Call format() to process code.