diff options
| author | Chris McDonough <chrism@plope.com> | 2012-08-10 23:22:01 -0600 |
|---|---|---|
| committer | Chris McDonough <chrism@plope.com> | 2012-08-10 23:22:01 -0600 |
| commit | 6e01fe9fdd5f39641855507bf3367427e9ea4c15 (patch) | |
| tree | 5c095919caac2b9b75b2d72cac67042db106e949 | |
| parent | 351d75f83127bd3b0ae9dc9f34be840cf8ce70bc (diff) | |
| parent | 8463c3663cf0bc1b417c8417bedc2c5d6b78adbc (diff) | |
| download | pyramid-6e01fe9fdd5f39641855507bf3367427e9ea4c15.tar.gz pyramid-6e01fe9fdd5f39641855507bf3367427e9ea4c15.tar.bz2 pyramid-6e01fe9fdd5f39641855507bf3367427e9ea4c15.zip | |
Merge branch 'master' of github.com:Pylons/pyramid
| -rw-r--r-- | pyramid/mako_templating.py | 18 | ||||
| -rw-r--r-- | pyramid/tests/test_mako_templating.py | 30 |
2 files changed, 32 insertions, 16 deletions
diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py index 16170aa0f..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 @@ -69,7 +75,7 @@ class PkgResourceTemplateLookup(TemplateLookup): pname, path = resolve_asset_spec(uri) srcfile = abspath_from_asset_spec(path, pname) if os.path.isfile(srcfile): - return self._load(srcfile, uri) + return self._load(srcfile, adjusted) raise exceptions.TopLevelLookupException( "Can not locate template for uri %r" % uri) return TemplateLookup.get_template(self, uri) 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() |
