diff options
| author | Chris McDonough <chrism@plope.com> | 2013-05-21 13:05:31 -0700 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2013-05-21 13:05:31 -0700 |
| commit | da8bcf5bd8920c21c8f4691a31c73eb72b7e3eab (patch) | |
| tree | a6e440a79c767af099308294e6c9d66d89d20623 | |
| parent | d037a9d47b6dd8fe6da88c6a6e26ceefcfe00fc9 (diff) | |
| parent | 45ef9a69e51189051c03b3fdeac4458ee94d7529 (diff) | |
| download | pyramid-da8bcf5bd8920c21c8f4691a31c73eb72b7e3eab.tar.gz pyramid-da8bcf5bd8920c21c8f4691a31c73eb72b7e3eab.tar.bz2 pyramid-da8bcf5bd8920c21c8f4691a31c73eb72b7e3eab.zip | |
Merge pull request #1023 from Pylons/defend_against_mako_unimportable
Prevent non-3.2-compatible MarkupSafe 0.16 from breaking us.
| -rw-r--r-- | CHANGES.txt | 3 | ||||
| -rw-r--r-- | pyramid/mako_templating.py | 29 |
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] ) |
