summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2012-08-03 04:10:55 -0400
committerChris McDonough <chrism@plope.com>2012-08-03 04:10:55 -0400
commit43ea7a73af370dea4eed4d09c594305d3b333ab6 (patch)
tree69d6729f85f827e164f100a1d06726c79800ff0f
parent1bbe668972a6ac3b116f44e50825c66ae5813326 (diff)
parent8b26752c4e54b1c9a6f8b14b14c0236be9c239b7 (diff)
downloadpyramid-43ea7a73af370dea4eed4d09c594305d3b333ab6.tar.gz
pyramid-43ea7a73af370dea4eed4d09c594305d3b333ab6.tar.bz2
pyramid-43ea7a73af370dea4eed4d09c594305d3b333ab6.zip
Merge branch 'master' of github.com:Pylons/pyramid
-rw-r--r--CHANGES.txt12
-rw-r--r--pyramid/mako_templating.py19
-rw-r--r--pyramid/tests/test_mako_templating.py32
3 files changed, 42 insertions, 21 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index ecb2bf659..94553955c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -17,6 +17,12 @@ Bug Fixes
during iteration`` exception. It no longer does. See
https://github.com/Pylons/pyramid/issues/635 for more information.
+- In Mako Templates lookup, check if the uri is already adjusted and bring
+ it back to an asset spec. Normally occurs with inherited templates or
+ included components.
+ https://github.com/Pylons/pyramid/issues/606
+ https://github.com/Pylons/pyramid/issues/607
+
Features
--------
@@ -50,9 +56,9 @@ Features
and ``HTTPMovedPermanently`` exceptions, so these can be caught by the
NotFound view (and other exception views).
-- The mako renderer now accepts a def name and returns the template def
- result for the view being called. The uri format using an asset spec is
- package:path/to/template#defname.mako. The old way of returning a tuple
+- The mako renderer now accepts a def name and returns the template def
+ result for the view being called. The uri format using an asset spec is
+ package:path/to/template#defname.mako. The old way of returning a tuple
from the view is supported for backward compatibility, ('defname', {}).
- When there is a predicate mismatch exception (seen when no view matches for
diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py
index bb4ccb2f0..d1ee68878 100644
--- a/pyramid/mako_templating.py
+++ b/pyramid/mako_templating.py
@@ -42,12 +42,17 @@ class PkgResourceTemplateLookup(TemplateLookup):
def get_template(self, uri):
"""Fetch a template from the cache, or check the filesystem
for it
-
+
In addition to the basic filesystem lookup, this subclass will
use pkg_resource to load a file using the asset
specification syntax.
-
+
"""
+ if '$' in uri:
+ # Checks if the uri is already adjusted and brings it back to
+ # an asset spec. Normally occurs with inherited templates or
+ # included components.
+ uri = uri.replace('$', ':')
isabs = os.path.isabs(uri)
if (not isabs) and (':' in uri):
# Windows can't cope with colons in filenames, so we replace the
@@ -70,7 +75,7 @@ class PkgResourceTemplateLookup(TemplateLookup):
return TemplateLookup.get_template(self, uri)
-registry_lock = threading.Lock()
+registry_lock = threading.Lock()
class MakoRendererFactoryHelper(object):
def __init__(self, settings_prefix=None):
@@ -143,7 +148,7 @@ class MakoRendererFactoryHelper(object):
registry_lock.acquire()
try:
- registry.registerUtility(lookup, IMakoLookup,
+ registry.registerUtility(lookup, IMakoLookup,
name=settings_prefix)
finally:
registry_lock.release()
@@ -166,15 +171,15 @@ class MakoLookupTemplateRenderer(object):
""" Render a :term:`Mako` template using the template
implied by the ``path`` argument.The ``path`` argument may be a
package-relative path, an absolute path, or a :term:`asset
- specification`. If a defname is defined, in the form of
- package:path/to/template#defname.mako, a function named ``defname``
+ specification`. If a defname is defined, in the form of
+ package:path/to/template#defname.mako, a function named ``defname``
inside the template will then be rendered.
"""
def __init__(self, path, defname, lookup):
self.path = path
self.defname = defname
self.lookup = lookup
-
+
def implementation(self):
return self.lookup.get_template(self.path)
diff --git a/pyramid/tests/test_mako_templating.py b/pyramid/tests/test_mako_templating.py
index 41fa9bdc4..46826d9dd 100644
--- a/pyramid/tests/test_mako_templating.py
+++ b/pyramid/tests/test_mako_templating.py
@@ -135,7 +135,7 @@ class Test_renderer_factory(Base, unittest.TestCase):
self._callFUT(info)
lookup = self._getLookup()
self.assertEqual(lookup.template_args['input_encoding'], 'utf-16')
-
+
def test_with_error_handler(self):
settings = {'mako.directories':self.templates_dir,
'mako.error_handler':'pyramid.tests'}
@@ -383,7 +383,7 @@ class MakoLookupTemplateRendererTests(Base, unittest.TestCase):
result = instance.implementation().render_unicode()
self.assertTrue(isinstance(result, text_type))
self.assertEqual(result, text_('result'))
-
+
class TestIntegration(unittest.TestCase):
def setUp(self):
import pyramid.mako_templating
@@ -406,7 +406,7 @@ class TestIntegration(unittest.TestCase):
self.config.add_settings({'reload_templates': True})
result = render('helloworld.mak', {'a':1}).replace('\r','')
self.assertEqual(result, text_('\nHello föö\n', 'utf-8'))
-
+
def test_render_inheritance(self):
from pyramid.renderers import render
result = render('helloinherit.mak', {}).replace('\r','')
@@ -434,7 +434,7 @@ class TestIntegration(unittest.TestCase):
{'a':1})
self.assertEqual(result.ubody.replace('\r', ''),
text_('\nHello föö\n', 'utf-8'))
-
+
def test_render_with_abs_path(self):
from pyramid.renderers import render
result = render('/helloworld.mak', {'a':1}).replace('\r','')
@@ -446,7 +446,7 @@ class TestIntegration(unittest.TestCase):
self.assertEqual(
result.implementation().render_unicode().replace('\r',''),
text_('\nHello föö\n', 'utf-8'))
-
+
def test_template_not_found(self):
from pyramid.renderers import render
from mako.exceptions import TemplateLookupException
@@ -484,7 +484,7 @@ class TestPkgResourceTemplateLookup(unittest.TestCase):
inst = self._makeOne(directories=[fixturedir])
result = inst.get_template('helloworld.mak')
self.assertFalse(result is None)
-
+
def test_get_template_asset_spec_with_filesystem_checks(self):
inst = self._makeOne(filesystem_checks=True)
result = inst.get_template('pyramid.tests:fixtures/helloworld.mak')
@@ -498,7 +498,17 @@ class TestPkgResourceTemplateLookup(unittest.TestCase):
self.assertFalse(result is None)
finally:
shutil.rmtree(tmpdir, ignore_errors=True)
-
+
+ def test_get_template_asset_spec_with_uri_adjusted(self):
+ inst = self._makeOne(filesystem_checks=True)
+ result = inst.get_template('pyramid.tests$fixtures/helloworld.mak')
+ self.assertFalse(result is None)
+
+ def test_get_template_asset_spec_with_uri_not_adjusted(self):
+ inst = self._makeOne(filesystem_checks=True)
+ result = inst.get_template('pyramid.tests:fixtures/helloworld.mak')
+ self.assertFalse(result is None)
+
def test_get_template_asset_spec_missing(self):
from mako.exceptions import TopLevelLookupException
fixturedir = self.get_fixturedir()
@@ -510,7 +520,7 @@ class TestMakoRenderingException(unittest.TestCase):
def _makeOne(self, text):
from pyramid.mako_templating import MakoRenderingException
return MakoRenderingException(text)
-
+
def test_repr_and_str(self):
exc = self._makeOne('text')
self.assertEqual(str(exc), 'text')
@@ -519,7 +529,7 @@ class TestMakoRenderingException(unittest.TestCase):
class DummyLookup(object):
def __init__(self, exc=None):
self.exc = exc
-
+
def get_template(self, path):
self.path = path
return self
@@ -533,8 +543,8 @@ class DummyLookup(object):
raise self.exc
self.values = values
return text_('result')
-
+
class DummyRendererInfo(object):
def __init__(self, kw):
self.__dict__.update(kw)
-
+