We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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') 


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pyramid/mako_templating.py`
Content:
```
1 import os
2 import posixpath
3 import re
4 import sys
5 import threading
6 
7 from zope.interface import (
8     implementer,
9     Interface,
10     )
11 
12 from pyramid.asset import (
13     resolve_asset_spec,
14     abspath_from_asset_spec,
15     )
16 
17 from pyramid.compat import (
18     is_nonstr_iter,
19     reraise,
20     )
21 
22 from pyramid.interfaces import ITemplateRenderer
23 from pyramid.settings import asbool
24 from pyramid.util import DottedNameResolver
25 
26 from mako.lookup import TemplateLookup
27 from mako import exceptions
28 
29 class IMakoLookup(Interface):
30     pass
31 
32 class PkgResourceTemplateLookup(TemplateLookup):
33     """TemplateLookup subclass that handles asset specification URIs"""
34     def adjust_uri(self, uri, relativeto):
35         """Called from within a Mako template, avoids adjusting the
36         uri if it looks like an asset specification"""
37         # Don't adjust asset spec names
38         isabs = os.path.isabs(uri)
39         if (not isabs) and (':' in uri):
40             return uri
41         if not(isabs) and ('$' in uri):
42             return uri.replace('$', ':')
43         if relativeto is not None:
44             relativeto = relativeto.replace('$', ':')
45             if not(':' in uri) and (':' in relativeto):
46                 if uri.startswith('/'):
47                     return uri
48                 pkg, relto = relativeto.split(':')
49                 _uri = posixpath.join(posixpath.dirname(relto), uri)
50                 return '{0}:{1}'.format(pkg, _uri)
51             if not(':' in uri) and not(':' in relativeto):
52                 return posixpath.join(posixpath.dirname(relativeto), uri)
53         return TemplateLookup.adjust_uri(self, uri, relativeto)
54 
55     def get_template(self, uri):
56         """Fetch a template from the cache, or check the filesystem
57         for it
58 
59         In addition to the basic filesystem lookup, this subclass will
60         use pkg_resource to load a file using the asset
61         specification syntax.
62 
63         """
64         isabs = os.path.isabs(uri)
65         if (not isabs) and (':' in uri):
66             # Windows can't cope with colons in filenames, so we replace the
67             # colon with a dollar sign in the filename mako uses to actually
68             # store the generated python code in the mako module_directory or
69             # in the temporary location of mako's modules
70             adjusted = uri.replace(':', '$')
71             try:
72                 if self.filesystem_checks:
73                     return self._check(adjusted, self._collection[adjusted])
74                 else:
75                     return self._collection[adjusted]
76             except KeyError:
77                 pname, path = resolve_asset_spec(uri)
78                 srcfile = abspath_from_asset_spec(path, pname)
79                 if os.path.isfile(srcfile):
80                     return self._load(srcfile, adjusted)
81                 raise exceptions.TopLevelLookupException(
82                     "Can not locate template for uri %r" % uri)
83         return TemplateLookup.get_template(self, uri)
84 
85 
86 registry_lock = threading.Lock()
87 
88 class MakoRendererFactoryHelper(object):
89     def __init__(self, settings_prefix=None):
90         self.settings_prefix = settings_prefix
91 
92     def __call__(self, info):
93         p = re.compile(
94                 r'(?P<asset>[\w_.:/-]+)'
95                 r'(?:\#(?P<defname>[\w_]+))?'
96                 r'(\.(?P<ext>.*))'
97                 )
98         asset, defname, ext = p.match(info.name).group(
99             'asset', 'defname', 'ext'
100             )
101         path = '%s.%s' % (asset, ext)
102         registry = info.registry
103         settings = info.settings
104         settings_prefix = self.settings_prefix
105 
106         if settings_prefix is None:
107             settings_prefix = info.type +'.'
108 
109         lookup = registry.queryUtility(IMakoLookup, name=settings_prefix)
110 
111         def sget(name, default=None):
112             return settings.get(settings_prefix + name, default)
113 
114         if lookup is None:
115             reload_templates = settings.get('pyramid.reload_templates', None)
116             if reload_templates is None:
117                 reload_templates = settings.get('reload_templates', False)
118             reload_templates = asbool(reload_templates)
119             directories = sget('directories', [])
120             module_directory = sget('module_directory', None)
121             input_encoding = sget('input_encoding', 'utf-8')
122             error_handler = sget('error_handler', None)
123             default_filters = sget('default_filters', 'h')
124             imports = sget('imports', None)
125             strict_undefined = asbool(sget('strict_undefined', False))
126             preprocessor = sget('preprocessor', None)
127             if not is_nonstr_iter(directories):
128                 directories = list(filter(None, directories.splitlines()))
129             directories = [ abspath_from_asset_spec(d) for d in directories ]
130             if module_directory is not None:
131                 module_directory = abspath_from_asset_spec(module_directory)
132             if error_handler is not None:
133                 dotted = DottedNameResolver(info.package)
134                 error_handler = dotted.maybe_resolve(error_handler)
135             if default_filters is not None:
136                 if not is_nonstr_iter(default_filters):
137                     default_filters = list(filter(
138                         None, default_filters.splitlines()))
139             if imports is not None:
140                 if not is_nonstr_iter(imports):
141                     imports = list(filter(None, imports.splitlines()))
142             if preprocessor is not None:
143                 dotted = DottedNameResolver(info.package)
144                 preprocessor = dotted.maybe_resolve(preprocessor)
145 
146 
147             lookup = PkgResourceTemplateLookup(
148                 directories=directories,
149                 module_directory=module_directory,
150                 input_encoding=input_encoding,
151                 error_handler=error_handler,
152                 default_filters=default_filters,
153                 imports=imports,
154                 filesystem_checks=reload_templates,
155                 strict_undefined=strict_undefined,
156                 preprocessor=preprocessor
157                 )
158 
159             with registry_lock:
160                 registry.registerUtility(lookup, IMakoLookup,
161                                          name=settings_prefix)
162 
163         return MakoLookupTemplateRenderer(path, defname, lookup)
164 
165 renderer_factory = MakoRendererFactoryHelper('mako.')
166 
167 class MakoRenderingException(Exception):
168     def __init__(self, text):
169         self.text = text
170 
171     def __repr__(self):
172         return self.text
173 
174     __str__ = __repr__
175 
176 @implementer(ITemplateRenderer)
177 class MakoLookupTemplateRenderer(object):
178     """ Render a :term:`Mako` template using the template
179     implied by the ``path`` argument.The ``path`` argument may be a
180     package-relative path, an absolute path, or a :term:`asset
181     specification`. If a defname is defined, in the form of
182     package:path/to/template#defname.mako, a function named ``defname``
183     inside the template will then be rendered.
184     """
185     def __init__(self, path, defname, lookup):
186         self.path = path
187         self.defname = defname
188         self.lookup = lookup
189 
190     def implementation(self):
191         return self.lookup.get_template(self.path)
192 
193     def __call__(self, value, system):
194         context = system.pop('context', None)
195         if context is not None:
196             system['_context'] = context
197         if self.defname is None:
198             if isinstance(value, tuple):
199                 self.defname, value = value
200         else:
201             if isinstance(value, tuple):
202                 _, value = value
203         try:
204             system.update(value)
205         except (TypeError, ValueError):
206             raise ValueError('renderer was passed non-dictionary as value')
207         template = self.implementation()
208         if self.defname is not None:
209             template = template.get_def(self.defname)
210         try:
211             result = template.render_unicode(**system)
212         except:
213             try:
214                 exc_info = sys.exc_info()
215                 errtext = exceptions.text_error_template().render(
216                     error=exc_info[1],
217                     traceback=exc_info[2]
218                     )
219                 reraise(MakoRenderingException(errtext), None, exc_info[2])
220             finally:
221                 del exc_info
222 
223         return result
224
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
                     "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 @@
         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

{"golden_diff": "diff --git a/pyramid/mako_templating.py b/pyramid/mako_templating.py\n--- a/pyramid/mako_templating.py\n+++ b/pyramid/mako_templating.py\n@@ -82,7 +82,6 @@\n                     \"Can not locate template for uri %r\" % uri)\n         return TemplateLookup.get_template(self, uri)\n \n-\n registry_lock = threading.Lock()\n \n class MakoRendererFactoryHelper(object):\n@@ -90,14 +89,11 @@\n         self.settings_prefix = settings_prefix\n \n     def __call__(self, info):\n-        p = re.compile(\n-                r'(?P<asset>[\\w_.:/-]+)'\n-                r'(?:\\#(?P<defname>[\\w_]+))?'\n-                r'(\\.(?P<ext>.*))'\n-                )\n-        asset, defname, ext = p.match(info.name).group(\n-            'asset', 'defname', 'ext'\n-            )\n+        defname = None\n+        asset, ext = info.name.rsplit('.', 1)\n+        if '#' in asset:\n+            asset, defname = asset.rsplit('#', 1)\n+\n         path = '%s.%s' % (asset, ext)\n         registry = info.registry\n         settings = info.settings\n", "issue": "Spaces are no longer allowed in Mako template paths\nAs 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. \n\nFor example a renderer argument to view config such as the following would fail when looking up the template:\n@view_config(renderer='/templates/test space/mytemplate.mako') \n\n", "before_files": [{"content": "import os\nimport posixpath\nimport re\nimport sys\nimport threading\n\nfrom zope.interface import (\n    implementer,\n    Interface,\n    )\n\nfrom pyramid.asset import (\n    resolve_asset_spec,\n    abspath_from_asset_spec,\n    )\n\nfrom pyramid.compat import (\n    is_nonstr_iter,\n    reraise,\n    )\n\nfrom pyramid.interfaces import ITemplateRenderer\nfrom pyramid.settings import asbool\nfrom pyramid.util import DottedNameResolver\n\nfrom mako.lookup import TemplateLookup\nfrom mako import exceptions\n\nclass IMakoLookup(Interface):\n    pass\n\nclass PkgResourceTemplateLookup(TemplateLookup):\n    \"\"\"TemplateLookup subclass that handles asset specification URIs\"\"\"\n    def adjust_uri(self, uri, relativeto):\n        \"\"\"Called from within a Mako template, avoids adjusting the\n        uri if it looks like an asset specification\"\"\"\n        # Don't adjust asset spec names\n        isabs = os.path.isabs(uri)\n        if (not isabs) and (':' in uri):\n            return uri\n        if not(isabs) and ('$' in uri):\n            return uri.replace('$', ':')\n        if relativeto is not None:\n            relativeto = relativeto.replace('$', ':')\n            if not(':' in uri) and (':' in relativeto):\n                if uri.startswith('/'):\n                    return uri\n                pkg, relto = relativeto.split(':')\n                _uri = posixpath.join(posixpath.dirname(relto), uri)\n                return '{0}:{1}'.format(pkg, _uri)\n            if not(':' in uri) and not(':' in relativeto):\n                return posixpath.join(posixpath.dirname(relativeto), uri)\n        return TemplateLookup.adjust_uri(self, uri, relativeto)\n\n    def get_template(self, uri):\n        \"\"\"Fetch a template from the cache, or check the filesystem\n        for it\n\n        In addition to the basic filesystem lookup, this subclass will\n        use pkg_resource to load a file using the asset\n        specification syntax.\n\n        \"\"\"\n        isabs = os.path.isabs(uri)\n        if (not isabs) and (':' in uri):\n            # Windows can't cope with colons in filenames, so we replace the\n            # colon with a dollar sign in the filename mako uses to actually\n            # store the generated python code in the mako module_directory or\n            # in the temporary location of mako's modules\n            adjusted = uri.replace(':', '$')\n            try:\n                if self.filesystem_checks:\n                    return self._check(adjusted, self._collection[adjusted])\n                else:\n                    return self._collection[adjusted]\n            except KeyError:\n                pname, path = resolve_asset_spec(uri)\n                srcfile = abspath_from_asset_spec(path, pname)\n                if os.path.isfile(srcfile):\n                    return self._load(srcfile, adjusted)\n                raise exceptions.TopLevelLookupException(\n                    \"Can not locate template for uri %r\" % uri)\n        return TemplateLookup.get_template(self, uri)\n\n\nregistry_lock = threading.Lock()\n\nclass MakoRendererFactoryHelper(object):\n    def __init__(self, settings_prefix=None):\n        self.settings_prefix = settings_prefix\n\n    def __call__(self, info):\n        p = re.compile(\n                r'(?P<asset>[\\w_.:/-]+)'\n                r'(?:\\#(?P<defname>[\\w_]+))?'\n                r'(\\.(?P<ext>.*))'\n                )\n        asset, defname, ext = p.match(info.name).group(\n            'asset', 'defname', 'ext'\n            )\n        path = '%s.%s' % (asset, ext)\n        registry = info.registry\n        settings = info.settings\n        settings_prefix = self.settings_prefix\n\n        if settings_prefix is None:\n            settings_prefix = info.type +'.'\n\n        lookup = registry.queryUtility(IMakoLookup, name=settings_prefix)\n\n        def sget(name, default=None):\n            return settings.get(settings_prefix + name, default)\n\n        if lookup is None:\n            reload_templates = settings.get('pyramid.reload_templates', None)\n            if reload_templates is None:\n                reload_templates = settings.get('reload_templates', False)\n            reload_templates = asbool(reload_templates)\n            directories = sget('directories', [])\n            module_directory = sget('module_directory', None)\n            input_encoding = sget('input_encoding', 'utf-8')\n            error_handler = sget('error_handler', None)\n            default_filters = sget('default_filters', 'h')\n            imports = sget('imports', None)\n            strict_undefined = asbool(sget('strict_undefined', False))\n            preprocessor = sget('preprocessor', None)\n            if not is_nonstr_iter(directories):\n                directories = list(filter(None, directories.splitlines()))\n            directories = [ abspath_from_asset_spec(d) for d in directories ]\n            if module_directory is not None:\n                module_directory = abspath_from_asset_spec(module_directory)\n            if error_handler is not None:\n                dotted = DottedNameResolver(info.package)\n                error_handler = dotted.maybe_resolve(error_handler)\n            if default_filters is not None:\n                if not is_nonstr_iter(default_filters):\n                    default_filters = list(filter(\n                        None, default_filters.splitlines()))\n            if imports is not None:\n                if not is_nonstr_iter(imports):\n                    imports = list(filter(None, imports.splitlines()))\n            if preprocessor is not None:\n                dotted = DottedNameResolver(info.package)\n                preprocessor = dotted.maybe_resolve(preprocessor)\n\n\n            lookup = PkgResourceTemplateLookup(\n                directories=directories,\n                module_directory=module_directory,\n                input_encoding=input_encoding,\n                error_handler=error_handler,\n                default_filters=default_filters,\n                imports=imports,\n                filesystem_checks=reload_templates,\n                strict_undefined=strict_undefined,\n                preprocessor=preprocessor\n                )\n\n            with registry_lock:\n                registry.registerUtility(lookup, IMakoLookup,\n                                         name=settings_prefix)\n\n        return MakoLookupTemplateRenderer(path, defname, lookup)\n\nrenderer_factory = MakoRendererFactoryHelper('mako.')\n\nclass MakoRenderingException(Exception):\n    def __init__(self, text):\n        self.text = text\n\n    def __repr__(self):\n        return self.text\n\n    __str__ = __repr__\n\n@implementer(ITemplateRenderer)\nclass MakoLookupTemplateRenderer(object):\n    \"\"\" Render a :term:`Mako` template using the template\n    implied by the ``path`` argument.The ``path`` argument may be a\n    package-relative path, an absolute path, or a :term:`asset\n    specification`. If a defname is defined, in the form of\n    package:path/to/template#defname.mako, a function named ``defname``\n    inside the template will then be rendered.\n    \"\"\"\n    def __init__(self, path, defname, lookup):\n        self.path = path\n        self.defname = defname\n        self.lookup = lookup\n\n    def implementation(self):\n        return self.lookup.get_template(self.path)\n\n    def __call__(self, value, system):\n        context = system.pop('context', None)\n        if context is not None:\n            system['_context'] = context\n        if self.defname is None:\n            if isinstance(value, tuple):\n                self.defname, value = value\n        else:\n            if isinstance(value, tuple):\n                _, value = value\n        try:\n            system.update(value)\n        except (TypeError, ValueError):\n            raise ValueError('renderer was passed non-dictionary as value')\n        template = self.implementation()\n        if self.defname is not None:\n            template = template.get_def(self.defname)\n        try:\n            result = template.render_unicode(**system)\n        except:\n            try:\n                exc_info = sys.exc_info()\n                errtext = exceptions.text_error_template().render(\n                    error=exc_info[1],\n                    traceback=exc_info[2]\n                    )\n                reraise(MakoRenderingException(errtext), None, exc_info[2])\n            finally:\n                del exc_info\n\n        return result\n", "path": "pyramid/mako_templating.py"}], "after_files": [{"content": "import os\nimport posixpath\nimport re\nimport sys\nimport threading\n\nfrom zope.interface import (\n    implementer,\n    Interface,\n    )\n\nfrom pyramid.asset import (\n    resolve_asset_spec,\n    abspath_from_asset_spec,\n    )\n\nfrom pyramid.compat import (\n    is_nonstr_iter,\n    reraise,\n    )\n\nfrom pyramid.interfaces import ITemplateRenderer\nfrom pyramid.settings import asbool\nfrom pyramid.util import DottedNameResolver\n\nfrom mako.lookup import TemplateLookup\nfrom mako import exceptions\n\nclass IMakoLookup(Interface):\n    pass\n\nclass PkgResourceTemplateLookup(TemplateLookup):\n    \"\"\"TemplateLookup subclass that handles asset specification URIs\"\"\"\n    def adjust_uri(self, uri, relativeto):\n        \"\"\"Called from within a Mako template, avoids adjusting the\n        uri if it looks like an asset specification\"\"\"\n        # Don't adjust asset spec names\n        isabs = os.path.isabs(uri)\n        if (not isabs) and (':' in uri):\n            return uri\n        if not(isabs) and ('$' in uri):\n            return uri.replace('$', ':')\n        if relativeto is not None:\n            relativeto = relativeto.replace('$', ':')\n            if not(':' in uri) and (':' in relativeto):\n                if uri.startswith('/'):\n                    return uri\n                pkg, relto = relativeto.split(':')\n                _uri = posixpath.join(posixpath.dirname(relto), uri)\n                return '{0}:{1}'.format(pkg, _uri)\n            if not(':' in uri) and not(':' in relativeto):\n                return posixpath.join(posixpath.dirname(relativeto), uri)\n        return TemplateLookup.adjust_uri(self, uri, relativeto)\n\n    def get_template(self, uri):\n        \"\"\"Fetch a template from the cache, or check the filesystem\n        for it\n\n        In addition to the basic filesystem lookup, this subclass will\n        use pkg_resource to load a file using the asset\n        specification syntax.\n\n        \"\"\"\n        isabs = os.path.isabs(uri)\n        if (not isabs) and (':' in uri):\n            # Windows can't cope with colons in filenames, so we replace the\n            # colon with a dollar sign in the filename mako uses to actually\n            # store the generated python code in the mako module_directory or\n            # in the temporary location of mako's modules\n            adjusted = uri.replace(':', '$')\n            try:\n                if self.filesystem_checks:\n                    return self._check(adjusted, self._collection[adjusted])\n                else:\n                    return self._collection[adjusted]\n            except KeyError:\n                pname, path = resolve_asset_spec(uri)\n                srcfile = abspath_from_asset_spec(path, pname)\n                if os.path.isfile(srcfile):\n                    return self._load(srcfile, adjusted)\n                raise exceptions.TopLevelLookupException(\n                    \"Can not locate template for uri %r\" % uri)\n        return TemplateLookup.get_template(self, uri)\n\nregistry_lock = threading.Lock()\n\nclass MakoRendererFactoryHelper(object):\n    def __init__(self, settings_prefix=None):\n        self.settings_prefix = settings_prefix\n\n    def __call__(self, info):\n        defname = None\n        asset, ext = info.name.rsplit('.', 1)\n        if '#' in asset:\n            asset, defname = asset.rsplit('#', 1)\n\n        path = '%s.%s' % (asset, ext)\n        registry = info.registry\n        settings = info.settings\n        settings_prefix = self.settings_prefix\n\n        if settings_prefix is None:\n            settings_prefix = info.type +'.'\n\n        lookup = registry.queryUtility(IMakoLookup, name=settings_prefix)\n\n        def sget(name, default=None):\n            return settings.get(settings_prefix + name, default)\n\n        if lookup is None:\n            reload_templates = settings.get('pyramid.reload_templates', None)\n            if reload_templates is None:\n                reload_templates = settings.get('reload_templates', False)\n            reload_templates = asbool(reload_templates)\n            directories = sget('directories', [])\n            module_directory = sget('module_directory', None)\n            input_encoding = sget('input_encoding', 'utf-8')\n            error_handler = sget('error_handler', None)\n            default_filters = sget('default_filters', 'h')\n            imports = sget('imports', None)\n            strict_undefined = asbool(sget('strict_undefined', False))\n            preprocessor = sget('preprocessor', None)\n            if not is_nonstr_iter(directories):\n                directories = list(filter(None, directories.splitlines()))\n            directories = [ abspath_from_asset_spec(d) for d in directories ]\n            if module_directory is not None:\n                module_directory = abspath_from_asset_spec(module_directory)\n            if error_handler is not None:\n                dotted = DottedNameResolver(info.package)\n                error_handler = dotted.maybe_resolve(error_handler)\n            if default_filters is not None:\n                if not is_nonstr_iter(default_filters):\n                    default_filters = list(filter(\n                        None, default_filters.splitlines()))\n            if imports is not None:\n                if not is_nonstr_iter(imports):\n                    imports = list(filter(None, imports.splitlines()))\n            if preprocessor is not None:\n                dotted = DottedNameResolver(info.package)\n                preprocessor = dotted.maybe_resolve(preprocessor)\n\n\n            lookup = PkgResourceTemplateLookup(\n                directories=directories,\n                module_directory=module_directory,\n                input_encoding=input_encoding,\n                error_handler=error_handler,\n                default_filters=default_filters,\n                imports=imports,\n                filesystem_checks=reload_templates,\n                strict_undefined=strict_undefined,\n                preprocessor=preprocessor\n                )\n\n            with registry_lock:\n                registry.registerUtility(lookup, IMakoLookup,\n                                         name=settings_prefix)\n\n        return MakoLookupTemplateRenderer(path, defname, lookup)\n\nrenderer_factory = MakoRendererFactoryHelper('mako.')\n\nclass MakoRenderingException(Exception):\n    def __init__(self, text):\n        self.text = text\n\n    def __repr__(self):\n        return self.text\n\n    __str__ = __repr__\n\n@implementer(ITemplateRenderer)\nclass MakoLookupTemplateRenderer(object):\n    \"\"\" Render a :term:`Mako` template using the template\n    implied by the ``path`` argument.The ``path`` argument may be a\n    package-relative path, an absolute path, or a :term:`asset\n    specification`. If a defname is defined, in the form of\n    package:path/to/template#defname.mako, a function named ``defname``\n    inside the template will then be rendered.\n    \"\"\"\n    def __init__(self, path, defname, lookup):\n        self.path = path\n        self.defname = defname\n        self.lookup = lookup\n\n    def implementation(self):\n        return self.lookup.get_template(self.path)\n\n    def __call__(self, value, system):\n        context = system.pop('context', None)\n        if context is not None:\n            system['_context'] = context\n        if self.defname is None:\n            if isinstance(value, tuple):\n                self.defname, value = value\n        else:\n            if isinstance(value, tuple):\n                _, value = value\n        try:\n            system.update(value)\n        except (TypeError, ValueError):\n            raise ValueError('renderer was passed non-dictionary as value')\n        template = self.implementation()\n        if self.defname is not None:\n            template = template.get_def(self.defname)\n        try:\n            result = template.render_unicode(**system)\n        except:\n            try:\n                exc_info = sys.exc_info()\n                errtext = exceptions.text_error_template().render(\n                    error=exc_info[1],\n                    traceback=exc_info[2]\n                    )\n                reraise(MakoRenderingException(errtext), None, exc_info[2])\n            finally:\n                del exc_info\n\n        return result\n", "path": "pyramid/mako_templating.py"}]}