summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBlaise Laflamme <blaise@laflamme.org>2012-08-10 14:20:27 -0600
committerBlaise Laflamme <blaise@laflamme.org>2012-08-10 14:20:27 -0600
commit8463c3663cf0bc1b417c8417bedc2c5d6b78adbc (patch)
tree5c095919caac2b9b75b2d72cac67042db106e949
parenta961aa646ed175089066ff1d37d57bb6546956b5 (diff)
downloadpyramid-8463c3663cf0bc1b417c8417bedc2c5d6b78adbc.tar.gz
pyramid-8463c3663cf0bc1b417c8417bedc2c5d6b78adbc.tar.bz2
pyramid-8463c3663cf0bc1b417c8417bedc2c5d6b78adbc.zip
new fix for mako adjust_uri
-rw-r--r--pyramid/mako_templating.py16
-rw-r--r--pyramid/tests/test_mako_templating.py30
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()