pylons.error
Covered: 16 lines
Missed: 16 lines
Skipped 11 lines
Percent: 50 %

     1

    """Custom EvalException support

     2

     3

    Provides template engine HTML error formatters for the Template tab of

     4

    EvalException.

     5

     6

    """

     7

    import sys

     8

     9

    try:

    10

        import mako.exceptions

    11

    except ImportError:

    12

        mako = None

    13

    14

    __all__ = ['handle_mako_error']

    15

    16

    def handle_mako_error(context, exc):

    17

        try:

    18

            exc.is_mako_exception = True

    19

        except:

    20

            pass

    21

        raise exc, None, sys.exc_info()[2]

    22

    23

    24

    def myghty_html_data(exc_value):

    25

        """Format a Myghty exception as HTML"""

    26

        if hasattr(exc_value, 'htmlformat'):

    27

            return exc_value.htmlformat()[333:-14]

    28

        if hasattr(exc_value, 'mtrace'):

    29

            return exc_value.mtrace.htmlformat()[333:-14]

    30

    31

    template_error_formatters = [myghty_html_data]

    32

    33

    34

    if mako:

    35

        def mako_html_data(exc_value):

    36

            """Format a Mako exception as HTML"""

    37

            if getattr(exc_value, 'is_mako_exception', False) or \

    38

               isinstance(exc_value, (mako.exceptions.CompileException,

    39

                                      mako.exceptions.SyntaxException)):

    40

                return mako.exceptions.html_error_template().render(full=False,

    41

                                                                    css=False)

    42

        template_error_formatters.insert(0, mako_html_data)

    43