summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt3
-rw-r--r--pyramid/mako_templating.py29
2 files changed, 28 insertions, 4 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index e6dd9f0cb..2c4f4e31c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -32,6 +32,9 @@ Features
Bug Fixes
---------
+- ``mako_templating``: added defensive workaround for non-importability
+ of ``mako`` (due to upstream ``markupsafe`` dropping Python 3.2 support).
+
- View lookup will now search for valid views based on the inheritance
hierarchy of the context. It tries to find views based on the most
specific context first, and upon predicate failure, will move up the
diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py
index 061bcb717..5fbdd002e 100644
--- a/pyramid/mako_templating.py
+++ b/pyramid/mako_templating.py
@@ -23,8 +23,29 @@ from pyramid.interfaces import ITemplateRenderer
from pyramid.settings import asbool
from pyramid.util import DottedNameResolver
-from mako.lookup import TemplateLookup
-from mako import exceptions
+try:
+ from mako.lookup import TemplateLookup
+except (ImportError, SyntaxError, AttributeError): #pragma NO COVER
+ class TemplateLookup(object):
+ def __init__(self, **kw):
+ pass
+ def no_mako(self, *args, **kw):
+ raise NotImplementedError("'mako' not importable")
+ adjust_uri = get_template = filename_to_uri = no_mako
+ put_string = put_template = no_mako
+
+try:
+ from mako.exceptions import TopLevelLookupException
+except (ImportError, SyntaxError, AttributeError): #pragma NO COVER
+ class TopLevelLookupException(Exception):
+ pass
+
+try:
+ from mako.exceptions import text_error_template
+except (ImportError, SyntaxError, AttributeError): #pragma NO COVER
+ def text_error_template(lookup=None):
+ raise NotImplementedError("'mako' not importable")
+
class IMakoLookup(Interface):
pass
@@ -78,7 +99,7 @@ class PkgResourceTemplateLookup(TemplateLookup):
srcfile = abspath_from_asset_spec(path, pname)
if os.path.isfile(srcfile):
return self._load(srcfile, adjusted)
- raise exceptions.TopLevelLookupException(
+ raise TopLevelLookupException(
"Can not locate template for uri %r" % uri)
return TemplateLookup.get_template(self, uri)
@@ -208,7 +229,7 @@ class MakoLookupTemplateRenderer(object):
except:
try:
exc_info = sys.exc_info()
- errtext = exceptions.text_error_template().render(
+ errtext = text_error_template().render(
error=exc_info[1],
traceback=exc_info[2]
)