CHANGES.txt | ●●●●● patch | view | raw | blame | history | |
pyramid/mako_templating.py | ●●●●● patch | view | raw | blame | history | |
pyramid/tests/test_mako_templating.py | ●●●●● patch | view | raw | blame | history |
CHANGES.txt
@@ -8,6 +8,16 @@ 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) ================ pyramid/mako_templating.py
@@ -33,7 +33,8 @@ """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 @@ """ 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) 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 @@ 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()