From 4f97b61c425b620ffca190f130625c84c5754475 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 26 Mar 2012 17:58:06 -0400 Subject: speculative fix for issue #512 --- pyramid/mako_templating.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py index b2db28ba7..c4c12f02a 100644 --- a/pyramid/mako_templating.py +++ b/pyramid/mako_templating.py @@ -33,7 +33,9 @@ class PkgResourceTemplateLookup(TemplateLookup): """Called from within a Mako template, avoids adjusting the uri if it looks like an asset specification""" # Don't adjust asset spec names - if ':' in uri: + isabs = os.path.isabs(uri) + if (not isabs) and (':' in uri): + # fbo asset specs on windows: cant have colons in filename return uri return TemplateLookup.adjust_uri(self, uri, relativeto) @@ -48,16 +50,17 @@ class PkgResourceTemplateLookup(TemplateLookup): """ isabs = os.path.isabs(uri) if (not isabs) and (':' in uri): + adjusted = uri.replace(':', '_') try: if self.filesystem_checks: - return self._check(uri, self._collection[uri]) + return self._check(adjusted, self._collection[adjusted]) else: - return self._collection[uri] + return self._collection[adjusted] except KeyError: 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) -- cgit v1.2.3 From 57835f2edb1592bd3cc0d006de401ace5fc3552c Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 26 Mar 2012 23:56:31 -0400 Subject: add a test for an asset spec with a module dir --- pyramid/tests/test_mako_templating.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pyramid/tests/test_mako_templating.py b/pyramid/tests/test_mako_templating.py index 550c95312..fbb04273b 100644 --- a/pyramid/tests/test_mako_templating.py +++ b/pyramid/tests/test_mako_templating.py @@ -1,7 +1,11 @@ ## come on python gimme some of that sweet, sweet -*- coding: utf-8 -*- +import shutil +import tempfile import unittest + from pyramid import testing + from pyramid.compat import ( text_, text_type, @@ -466,6 +470,15 @@ class TestPkgResourceTemplateLookup(unittest.TestCase): result = inst.get_template('pyramid.tests:fixtures/helloworld.mak') self.assertFalse(result is None) + def test_get_template_asset_spec_with_module_dir(self): + tmpdir = tempfile.mkdtemp() + try: + inst = self._makeOne(module_directory=tmpdir) + result = inst.get_template('pyramid.tests:fixtures/helloworld.mak') + self.assertFalse(result is None) + finally: + shutil.rmtree(tmpdir, ignore_errors=True) + def test_get_template_asset_spec_missing(self): from mako.exceptions import TopLevelLookupException fixturedir = self.get_fixturedir() -- cgit v1.2.3 From 3f659fe4436958eee8fc9cd8412c5c0f2a147972 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Mon, 26 Mar 2012 23:56:44 -0400 Subject: use a dollar sign instead of an under --- pyramid/mako_templating.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py index c4c12f02a..208e54bf5 100644 --- a/pyramid/mako_templating.py +++ b/pyramid/mako_templating.py @@ -35,7 +35,6 @@ class PkgResourceTemplateLookup(TemplateLookup): # Don't adjust asset spec names isabs = os.path.isabs(uri) if (not isabs) and (':' in uri): - # fbo asset specs on windows: cant have colons in filename return uri return TemplateLookup.adjust_uri(self, uri, relativeto) @@ -50,7 +49,11 @@ class PkgResourceTemplateLookup(TemplateLookup): """ isabs = os.path.isabs(uri) if (not isabs) and (':' in uri): - adjusted = uri.replace(':', '_') + # Windows can't cope with colons in filenames, so we replace the + # colon with a dollar sign in the filename mako uses to actually + # store the generated python code in the mako module_directory or + # in the temporary location of mako's modules + adjusted = uri.replace(':', '$') try: if self.filesystem_checks: return self._check(adjusted, self._collection[adjusted]) -- cgit v1.2.3 From 077fa3a52fb3c160e33bbd7344c56534e77adc49 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 27 Mar 2012 00:01:39 -0400 Subject: add change note --- CHANGES.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 7fd8b7a64..859dc7b74 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,6 +8,16 @@ Bug Fixes the debug toolbar, which effectively requires it to be present to work properly. +- When an asset specification was used as a Mako ``renderer=`` argument and a + ``mako.modules_directory`` was specified, Pyramid would fail to render the + template and instead would raise an error when attempting to write the file + to the modules directory. Example symptom: ``WindowsError: [Error 267] The + directory name is invalid: + 'c:\\docume~1\\chrism\\locals~1\\temp\\tmp9jtjix\\pyramid.tests:fixtures'``. + We now replace the colon in the Mako module filename with a dollar sign, so + it can work on Windows. See https://github.com/Pylons/pyramid/issues/512 + for more information. + 1.3 (2012-03-21) ================ -- cgit v1.2.3