Skip to content

Commit

Permalink
Adding Mako error formatting.
Browse files Browse the repository at this point in the history
--HG--
branch : trunk
  • Loading branch information
bbangert committed Sep 19, 2008
1 parent 44690fd commit a299a30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pylons/error.py
Expand Up @@ -4,12 +4,21 @@
EvalException.
"""
import sys

try:
import mako.exceptions
except ImportError:
mako = None

__all__ = []
__all__ = ['handle_mako_error']

def handle_mako_error(context, exc):
try:
exc.is_mako_exception = True
except:
pass
raise exc, None, sys.exc_info()[2]

# Legacy support for < 0.9.7 projects
error_template = None
Expand All @@ -27,7 +36,8 @@ def myghty_html_data(exc_value):
if mako:
def mako_html_data(exc_value):
"""Format a Mako exception as HTML"""
if isinstance(exc_value, (mako.exceptions.CompileException,
if getattr(exc_value, 'is_mako_exception', False) or \
isinstance(exc_value, (mako.exceptions.CompileException,
mako.exceptions.SyntaxException)):
return mako.exceptions.html_error_template().render(full=False,
css=False)
Expand Down
Expand Up @@ -4,6 +4,7 @@ import os

{{if template_engine == 'mako'}}
from mako.lookup import TemplateLookup
from pylons.error import handle_mako_error
{{elif template_engine == 'genshi'}}
from genshi.template import TemplateLoader
{{elif template_engine == 'jinja'}}
Expand Down Expand Up @@ -43,6 +44,7 @@ def load_environment(global_conf, app_conf):
# Create the Mako TemplateLookup, with the default auto-escaping
config['pylons.app_globals'].mako_lookup = TemplateLookup(
directories=paths['templates'],
error_handler=handle_mako_error,
module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
input_encoding='utf-8', output_encoding='utf-8',
imports=['from webhelpers.html import escape'],
Expand Down

0 comments on commit a299a30

Please sign in to comment.