Repository: Pylons/pyramid

Issue:
Spaces are no longer allowed in Mako template paths
As of Pyramid 1.4 spaces are no longer accepted in the path names when rendering mako templates (changed in this commit: https://github.com/Pylons/pyramid/commit/f71ed59edb74e9a13362521918e2660e4e4263ba#L1L79). Since no one else has noticed yet I don't know if this needs a bug fix, but it should at least be documented that the file path cannot have spaces. 

For example a renderer argument to view config such as the following would fail when looking up the template:
@view_config(renderer='/templates/test space/mytemplate.mako') 



Discussion:
This is a regression, thanks for the report. If you have any interest in submitting a test case or a patch it'd be appreciated.

I can submit a patch.


Resolving patch:
diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py
--- a/pyramid/mako_templating.py
+++ b/pyramid/mako_templating.py
@@ -82,7 +82,6 @@ def get_template(self, uri):
                     "Can not locate template for uri %r" % uri)
         return TemplateLookup.get_template(self, uri)
 
-
 registry_lock = threading.Lock()
 
 class MakoRendererFactoryHelper(object):
@@ -90,14 +89,11 @@ def __init__(self, settings_prefix=None):
         self.settings_prefix = settings_prefix
 
     def __call__(self, info):
-        p = re.compile(
-                r'(?P<asset>[\w_.:/-]+)'
-                r'(?:\#(?P<defname>[\w_]+))?'
-                r'(\.(?P<ext>.*))'
-                )
-        asset, defname, ext = p.match(info.name).group(
-            'asset', 'defname', 'ext'
-            )
+        defname = None
+        asset, ext = info.name.rsplit('.', 1)
+        if '#' in asset:
+            asset, defname = asset.rsplit('#', 1)
+
         path = '%s.%s' % (asset, ext)
         registry = info.registry
         settings = info.settings


Test patch:
diff --git a/pyramid/tests/fixtures/hello .world.mako b/pyramid/tests/fixtures/hello .world.mako
new file mode 100644
--- /dev/null
+++ b/pyramid/tests/fixtures/hello .world.mako	
@@ -0,0 +1,3 @@
+## -*- coding: utf-8 -*-
+<%!from pyramid.compat import text_%><% a, b = 'foo', text_('föö', 'utf-8') %>
+Hello ${text_('föö', 'utf-8')}
\ No newline at end of file
diff --git a/pyramid/tests/test_mako_templating.py b/pyramid/tests/test_mako_templating.py
--- a/pyramid/tests/test_mako_templating.py
+++ b/pyramid/tests/test_mako_templating.py
@@ -270,6 +270,34 @@ def test_with_lookup(self):
         self.assertEqual(renderer.lookup, lookup)
         self.assertEqual(renderer.path, 'helloworld.mak')
 
+    def test_space_dot_name(self):
+        from pyramid.mako_templating import renderer_factory
+
+        info = DummyRendererInfo({
+            'name':'hello .world.mako',
+            'package':None,
+            'registry':self.config.registry,
+            'settings':{},
+        })
+
+        result = renderer_factory(info)
+        self.assertEqual(result.path, 'hello .world.mako')
+        self.assertTrue(result.defname is None)
+
+    def test_space_dot_name_def(self):
+        from pyramid.mako_templating import renderer_factory
+
+        info = DummyRendererInfo({
+            'name':'hello .world#comp.mako',
+            'package':None,
+            'registry':self.config.registry,
+            'settings':{},
+            })
+
+        result = renderer_factory(info)
+        self.assertEqual(result.path, 'hello .world.mako')
+        self.assertEqual(result.defname, 'comp')
+
 class MakoRendererFactoryHelperTests(Base, unittest.TestCase):
     def _getTargetClass(self):
         from pyramid.mako_templating import MakoRendererFactoryHelper