diff options
| author | Chris McDonough <chrism@plope.com> | 2013-05-21 18:25:07 -0400 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2013-05-21 18:25:07 -0400 |
| commit | 91385e4c204532394d0cdee3ad61e0ff6cb51f0f (patch) | |
| tree | a299dd32f92304775076be3b00cfe9d0c5f6d7d8 | |
| parent | dbdfb2fea3851e31e272ebbba4297a138d74e970 (diff) | |
| parent | 0fdb540f8e432061ec09623f0275a6b6555292ef (diff) | |
| download | pyramid-91385e4c204532394d0cdee3ad61e0ff6cb51f0f.tar.gz pyramid-91385e4c204532394d0cdee3ad61e0ff6cb51f0f.tar.bz2 pyramid-91385e4c204532394d0cdee3ad61e0ff6cb51f0f.zip | |
Merge branch 'master' of github.com:Pylons/pyramid
| -rw-r--r-- | CHANGES.txt | 6 | ||||
| -rw-r--r-- | pyramid/mako_templating.py | 30 | ||||
| -rw-r--r-- | pyramid/scaffolds/__init__.py | 18 | ||||
| -rw-r--r-- | pyramid/testing.py | 4 | ||||
| -rw-r--r-- | pyramid/tests/pkgs/viewdecoratorapp/views/templates/foo.pt (renamed from pyramid/tests/pkgs/viewdecoratorapp/views/templates/foo.mak) | 0 | ||||
| -rw-r--r-- | pyramid/tests/pkgs/viewdecoratorapp/views/views.py | 4 | ||||
| -rw-r--r-- | pyramid/tests/test_integration.py | 10 | ||||
| -rw-r--r-- | pyramid/tests/test_mako_templating.py | 23 |
8 files changed, 70 insertions, 25 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index e6dd9f0cb..468fe1ed1 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -32,6 +32,12 @@ Features Bug Fixes --------- +- ``mako_templating``: added defensive workaround for non-importability of + ``mako`` due to upstream ``markupsafe`` dropping Python 3.2 support. Mako + templating will no longer work under the combination of MarkupSafe 0.17 and + Python 3.2 (although the combination of MarkupSafe 0.17 and Python 3.3 or any + supported Python 2 version will work OK). + - 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..69b48a3b5 100644 --- a/pyramid/mako_templating.py +++ b/pyramid/mako_templating.py @@ -1,6 +1,5 @@ import os import posixpath -import re import sys import threading @@ -23,8 +22,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 +98,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 +228,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] ) diff --git a/pyramid/scaffolds/__init__.py b/pyramid/scaffolds/__init__.py index dc207b540..c993ce5f9 100644 --- a/pyramid/scaffolds/__init__.py +++ b/pyramid/scaffolds/__init__.py @@ -1,5 +1,6 @@ import binascii import os +from textwrap import dedent from pyramid.compat import native_ @@ -33,7 +34,22 @@ class PyramidTemplate(Template): """ Overrides :meth:`pyramid.scaffolds.template.Template.post`, to print "Welcome to Pyramid. Sorry for the convenience." after a successful scaffolding rendering.""" - self.out('Welcome to Pyramid. Sorry for the convenience.') + + separator = "=" * 79 + msg = dedent( + """ + %(separator)s + Tutorials: http://docs.pylonsproject.org/projects/pyramid_tutorials + Documentation: http://docs.pylonsproject.org/projects/pyramid + + Twitter (tips & updates): http://twitter.com/pylons + Mailing List: http://groups.google.com/group/pylons-discuss + + Welcome to Pyramid. Sorry for the convenience. + %(separator)s + """ % {'separator': separator}) + + self.out(msg) return Template.post(self, command, output_dir, vars) def out(self, msg): # pragma: no cover (replaceable testing hook) diff --git a/pyramid/testing.py b/pyramid/testing.py index 0c701727b..06b795f9a 100644 --- a/pyramid/testing.py +++ b/pyramid/testing.py @@ -482,9 +482,9 @@ def tearDown(unhook_zca=True): If the ``unhook_zca`` argument is ``True`` (the default), call :func:`zope.component.getSiteManager.reset`. This undoes the - action of :func:`pyramid.testing.setUp` called with the + action of :func:`pyramid.testing.setUp` when called with the argument ``hook_zca=True``. If :mod:`zope.component` cannot be - imported, ignore the argument. + imported, ``unhook_zca`` is set to ``False``. """ global have_zca if unhook_zca and have_zca: diff --git a/pyramid/tests/pkgs/viewdecoratorapp/views/templates/foo.mak b/pyramid/tests/pkgs/viewdecoratorapp/views/templates/foo.pt index 6a2f701b6..6a2f701b6 100644 --- a/pyramid/tests/pkgs/viewdecoratorapp/views/templates/foo.mak +++ b/pyramid/tests/pkgs/viewdecoratorapp/views/templates/foo.pt diff --git a/pyramid/tests/pkgs/viewdecoratorapp/views/views.py b/pyramid/tests/pkgs/viewdecoratorapp/views/views.py index 6f7ff1e21..2b7d7e928 100644 --- a/pyramid/tests/pkgs/viewdecoratorapp/views/views.py +++ b/pyramid/tests/pkgs/viewdecoratorapp/views/views.py @@ -1,11 +1,11 @@ from pyramid.view import view_config -@view_config(renderer='templates/foo.mak', name='first') +@view_config(renderer='templates/foo.pt', name='first') def first(request): return {'result':'OK1'} @view_config( - renderer='pyramid.tests.pkgs.viewdecoratorapp.views:templates/foo.mak', + renderer='pyramid.tests.pkgs.viewdecoratorapp.views:templates/foo.pt', name='second') def second(request): return {'result':'OK2'} diff --git a/pyramid/tests/test_integration.py b/pyramid/tests/test_integration.py index c8418c61d..66205e618 100644 --- a/pyramid/tests/test_integration.py +++ b/pyramid/tests/test_integration.py @@ -369,22 +369,12 @@ class TestForbiddenAppHasResult(IntegrationBase, unittest.TestCase): class TestViewDecoratorApp(IntegrationBase, unittest.TestCase): package = 'pyramid.tests.pkgs.viewdecoratorapp' - def _configure_mako(self): - tmpldir = os.path.join(os.path.dirname(__file__), - 'pkgs', - 'viewdecoratorapp', - 'views') - self.config.registry.settings['mako.directories'] = tmpldir def test_first(self): - # we use mako here instead of chameleon because it works on Jython - self._configure_mako() res = self.testapp.get('/first', status=200) self.assertTrue(b'OK' in res.body) def test_second(self): - # we use mako here instead of chameleon because it works on Jython - self._configure_mako() res = self.testapp.get('/second', status=200) self.assertTrue(b'OK2' in res.body) diff --git a/pyramid/tests/test_mako_templating.py b/pyramid/tests/test_mako_templating.py index 50ef360d9..75faa771d 100644 --- a/pyramid/tests/test_mako_templating.py +++ b/pyramid/tests/test_mako_templating.py @@ -22,7 +22,20 @@ class Base(object): def tearDown(self): self.config.end() -class Test_renderer_factory(Base, unittest.TestCase): +def maybe_unittest(): + # The latest release of MarkupSafe (0.17) which is used by Mako is + # incompatible with Python 3.2, so we skip these tests if we cannot + # import a Mako module which ends up importing MarkupSafe. Note that + # this version of MarkupSafe *is* compatible with Python 2.6, 2.7, and 3.3, + # so these tests should not be skipped on those platforms. + try: + import mako.lookup + except (ImportError, SyntaxError, AttributeError): + return object + else: + return unittest.TestCase + +class Test_renderer_factory(Base, maybe_unittest()): def _callFUT(self, info): from pyramid.mako_templating import renderer_factory return renderer_factory(info) @@ -298,7 +311,7 @@ class Test_renderer_factory(Base, unittest.TestCase): self.assertEqual(result.path, 'hello .world.mako') self.assertEqual(result.defname, 'comp') -class MakoRendererFactoryHelperTests(Base, unittest.TestCase): +class MakoRendererFactoryHelperTests(Base, maybe_unittest()): def _getTargetClass(self): from pyramid.mako_templating import MakoRendererFactoryHelper return MakoRendererFactoryHelper @@ -345,7 +358,7 @@ class MakoRendererFactoryHelperTests(Base, unittest.TestCase): self.assertEqual(renderer.path, 'helloworld.mak') self.assertEqual(renderer.lookup, lookup) -class MakoLookupTemplateRendererTests(Base, unittest.TestCase): +class MakoLookupTemplateRendererTests(Base, maybe_unittest()): def _getTargetClass(self): from pyramid.mako_templating import MakoLookupTemplateRenderer return MakoLookupTemplateRenderer @@ -426,7 +439,7 @@ class MakoLookupTemplateRendererTests(Base, unittest.TestCase): self.assertTrue(isinstance(result, text_type)) self.assertEqual(result, text_('result')) -class TestIntegration(unittest.TestCase): +class TestIntegration(maybe_unittest()): def setUp(self): import pyramid.mako_templating self.config = testing.setUp() @@ -501,7 +514,7 @@ class TestIntegration(unittest.TestCase): {'name':'<b>fred</b>'}).replace('\r','') self.assertEqual(result, text_('Hello, <b>fred</b>!\n')) -class TestPkgResourceTemplateLookup(unittest.TestCase): +class TestPkgResourceTemplateLookup(maybe_unittest()): def _makeOne(self, **kw): from pyramid.mako_templating import PkgResourceTemplateLookup return PkgResourceTemplateLookup(**kw) |
