How to use the mako.exceptions.html_error_template function in Mako

To help you get started, we’ve selected a few Mako examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zzzeek / mako / test / test_exceptions.py View on Github external
code = """# -*- coding: utf-8 -*-
% if 2 == 2: /an error
${'привет'}
% endif
"""
        else:
            code = """# -*- coding: utf-8 -*-
% if 2 == 2: /an error
${u'привет'}
% endif
"""
        try:
            template = Template(code)
            template.render_unicode()
        except exceptions.CompileException:
            html_error = exceptions.html_error_template().render()
            if compat.py3k:
                assert (
                    (
                        "CompileException: Fragment 'if 2 == 2: /an "
                        "error' is not a partial control statement "
                        "at line: 2 char: 1"
                    ).encode(sys.getdefaultencoding(), "htmlentityreplace")
                    in html_error
                )
            else:
                assert (
                    "CompileException: Fragment 'if 2 == 2: /an "
                    "error' is not a partial control statement "
                    "at line: 2 char: 1"
                ) in html_error
github sqlalchemy / mako / mako / runtime.py View on Github external
def _render_error(template, context, error):
    if template.error_handler:
        result = template.error_handler(context, error)
        if not result:
            compat.reraise(*sys.exc_info())
    else:
        error_template = exceptions.html_error_template()
        if context._outputting_as_unicode:
            context._buffer_stack[:] = [
                util.FastEncodingBuffer(as_unicode=True)
            ]
        else:
            context._buffer_stack[:] = [
                util.FastEncodingBuffer(
                    error_template.output_encoding,
                    error_template.encoding_errors,
                )
            ]

        context._set_with_template(error_template)
        error_template.render_context(context, error=error)
github hubbcaps / gazee / gazee / gazee.py View on Github external
def serve_template(templatename, **kwargs):
    html_dir = 'public/html/'
    _hplookup = TemplateLookup(directories=[html_dir])
    try:
        template = _hplookup.get_template(templatename)
        return template.render(**kwargs)
    except:
        return exceptions.html_error_template().render()
github Workiva / gae-financials / gae_skeleton / main.py View on Github external
def get(self):

        from appname import person
        # we check and create a Person if you login to this app
        person.initilize_person(self.request.headers)

        try:
            import settings
            template = Template(filename='templates/base.mako')
            out = template.render(CLOUD_API_KEY=settings.CLOUD_API_KEY)
        except:
            out = exceptions.html_error_template().render()
            logging.exception('Oh NO! Rendering error.')

        self.response.out.write(out)
github galaxyproject / galaxy / lib / galaxy / web / buildapp.py View on Github external
def mako_html_data( exc_value ):
        if isinstance( exc_value, ( mako.exceptions.CompileException, mako.exceptions.SyntaxException ) ):
            return mako.exceptions.html_error_template().render( full=False, css=False )
        if isinstance( exc_value, AttributeError ) and exc_value.args[0].startswith( "'Undefined' object has no attribute" ):
            return mako.exceptions.html_error_template().render( full=False, css=False )
    formatters.append( mako_html_data )
github SEI-TAS / pycloud / server / pycloud / pycloud / pylons / lib / tm.py View on Github external
def get(self, name, style='html'):
        key = "%s.%s" % (name.lower(), style)
        template = self.templates.get(key)
        if not template:
            try:
                template = config['pylons.g'].mako_lookup.get_template(key)
                if template:
                    self.templates[key] = template
            except TemplateLookupException:
                print exceptions.html_error_template().render()
        if not template:
            raise AttributeError('template for %s not found' % name)
        return template
github rembo10 / headphones / lib / mako / runtime.py View on Github external
def _render_error(template, context, error):
    if template.error_handler:
        result = template.error_handler(context, error)
        if not result:
            compat.reraise(*sys.exc_info())
    else:
        error_template = exceptions.html_error_template()
        if context._outputting_as_unicode:
            context._buffer_stack[:] = [
                                    util.FastEncodingBuffer(as_unicode=True)]
        else:
            context._buffer_stack[:] = [util.FastEncodingBuffer(
                                            error_template.output_encoding,
                                            error_template.encoding_errors)]

        context._set_with_template(error_template)
        error_template.render_context(context, error=error)
github rembo10 / headphones / headphones / webserve.py View on Github external
def serve_template(templatename, **kwargs):
    interface_dir = os.path.join(str(headphones.PROG_DIR), 'data/interfaces/')
    template_dir = os.path.join(str(interface_dir), headphones.CONFIG.INTERFACE)

    _hplookup = TemplateLookup(directories=[template_dir])

    try:
        template = _hplookup.get_template(templatename)
        return template.render(**kwargs)
    except:
        return exceptions.html_error_template().render()
github tp4a / teleport / server / www / packages / packages-linux / x64 / mako / runtime.py View on Github external
def _render_error(template, context, error):
    if template.error_handler:
        result = template.error_handler(context, error)
        if not result:
            compat.reraise(*sys.exc_info())
    else:
        error_template = exceptions.html_error_template()
        if context._outputting_as_unicode:
            context._buffer_stack[:] = [
                util.FastEncodingBuffer(as_unicode=True)]
        else:
            context._buffer_stack[:] = [util.FastEncodingBuffer(
                error_template.output_encoding,
                error_template.encoding_errors)]

        context._set_with_template(error_template)
        error_template.render_context(context, error=error)