summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2012-03-27 00:01:58 -0400
committerChris McDonough <chrism@plope.com>2012-03-27 00:01:58 -0400
commit4321a443da2443e3097af254f285a50d81449b0f (patch)
treeb08378ba31feda0054ad50ec82bdbf5cd8b490b0
parentae5ab35c2bc9ceebbd2b52d490e1808c016bf086 (diff)
parent077fa3a52fb3c160e33bbd7344c56534e77adc49 (diff)
downloadpyramid-4321a443da2443e3097af254f285a50d81449b0f.tar.gz
pyramid-4321a443da2443e3097af254f285a50d81449b0f.tar.bz2
pyramid-4321a443da2443e3097af254f285a50d81449b0f.zip
Merge branch 'fix.512'
-rw-r--r--CHANGES.txt10
-rw-r--r--pyramid/mako_templating.py14
-rw-r--r--pyramid/tests/test_mako_templating.py13
3 files changed, 33 insertions, 4 deletions
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)
================
diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py
index b2db28ba7..208e54bf5 100644
--- a/pyramid/mako_templating.py
+++ b/pyramid/mako_templating.py
@@ -33,7 +33,8 @@ 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):
return uri
return TemplateLookup.adjust_uri(self, uri, relativeto)
@@ -48,16 +49,21 @@ class PkgResourceTemplateLookup(TemplateLookup):
"""
isabs = os.path.isabs(uri)
if (not isabs) and (':' in uri):
+ # 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(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)
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()