From 8463c3663cf0bc1b417c8417bedc2c5d6b78adbc Mon Sep 17 00:00:00 2001 From: Blaise Laflamme Date: Fri, 10 Aug 2012 14:20:27 -0600 Subject: new fix for mako adjust_uri --- pyramid/mako_templating.py | 16 +++++++++++----- pyramid/tests/test_mako_templating.py | 30 ++++++++++++++++++++---------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py index d1ee68878..489c1f11a 100644 --- a/pyramid/mako_templating.py +++ b/pyramid/mako_templating.py @@ -1,4 +1,5 @@ import os +import posixpath import re import sys import threading @@ -37,6 +38,16 @@ class PkgResourceTemplateLookup(TemplateLookup): isabs = os.path.isabs(uri) if (not isabs) and (':' in uri): return uri + if not(isabs) and ('$' in uri): + return uri.replace('$', ':') + if relativeto is not None: + relativeto = relativeto.replace('$', ':') + if not(':' in uri) and (':' in relativeto): + pkg, relto = relativeto.split(':') + _uri = posixpath.join(posixpath.dirname(relto), uri) + return '{0}:{1}'.format(pkg, _uri) + if not(':' in uri) and not(':' in relativeto): + return posixpath.join(posixpath.dirname(relativeto), uri) return TemplateLookup.adjust_uri(self, uri, relativeto) def get_template(self, uri): @@ -48,11 +59,6 @@ class PkgResourceTemplateLookup(TemplateLookup): 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 diff --git a/pyramid/tests/test_mako_templating.py b/pyramid/tests/test_mako_templating.py index 46826d9dd..aced6c586 100644 --- a/pyramid/tests/test_mako_templating.py +++ b/pyramid/tests/test_mako_templating.py @@ -479,6 +479,26 @@ class TestPkgResourceTemplateLookup(unittest.TestCase): result = inst.adjust_uri('a:b', None) self.assertEqual(result, 'a:b') + def test_adjust_uri_asset_spec_with_modified_asset_spec(self): + inst = self._makeOne() + result = inst.adjust_uri('a$b', None) + self.assertEqual(result, 'a:b') + + def test_adjust_uri_not_asset_spec_with_relativeto_asset_spec(self): + inst = self._makeOne() + result = inst.adjust_uri('c', 'a:b') + self.assertEqual(result, 'a:c') + + def test_adjust_uri_not_asset_spec_with_relativeto_modified_asset_spec(self): + inst = self._makeOne() + result = inst.adjust_uri('c', 'a$b') + self.assertEqual(result, 'a:c') + + def test_adjust_uri_not_asset_spec_with_relativeto_not_asset_spec(self): + inst = self._makeOne() + result = inst.adjust_uri('b', '../a') + self.assertEqual(result, '../b') + def test_get_template_not_asset_spec(self): fixturedir = self.get_fixturedir() inst = self._makeOne(directories=[fixturedir]) @@ -499,16 +519,6 @@ class TestPkgResourceTemplateLookup(unittest.TestCase): 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() -- cgit v1.2.3