We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Pyramid app frozen with py2exe fails because of Chameleon imports
If I freeze a Pyramid application with py2exe and try to run it, it fails during the startup, with the following traceback:

```
Traceback (most recent call last):
  File "web_server.py", line 2, in <module>
  File "pyramid\config\__init__.pyc", line 66, in <module>
  File "pyramid\config\rendering.pyc", line 11, in <module>
  File "pyramid\chameleon_text.pyc", line 3, in <module>
  File "chameleon\__init__.pyc", line 1, in <module>
  File "chameleon\zpt\template.pyc", line 10, in <module>
  File "chameleon\tales.pyc", line 19, in <module>
  File "chameleon\compiler.pyc", line 145, in <module>
  File "chameleon\codegen.pyc", line 93, in template
  File "inspect.pyc", line 701, in getsource
  File "inspect.pyc", line 690, in getsourcelines
  File "inspect.pyc", line 538, in findsource
IOError: could not get source code
```

My application doesn't use Chameleon, but the Pyramid modules still import it, which ultimately causes the .exe to fail to run.


--- 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/chameleon_zpt.py`
Content:
```
1 from zope.interface import implementer
2 
3 from chameleon.zpt.template import PageTemplateFile
4 
5 from pyramid.interfaces import ITemplateRenderer
6 from pyramid.decorator import reify
7 from pyramid import renderers
8 
9 def renderer_factory(info):
10     return renderers.template_renderer_factory(info, ZPTTemplateRenderer)
11 
12 @implementer(ITemplateRenderer)
13 class ZPTTemplateRenderer(object):
14     def __init__(self, path, lookup, macro=None):
15         self.path = path
16         self.lookup = lookup
17         self.macro = macro
18 
19     @reify # avoid looking up reload_templates before manager pushed
20     def template(self):
21         tf = PageTemplateFile(
22             self.path,
23             auto_reload=self.lookup.auto_reload,
24             debug=self.lookup.debug,
25             translate=self.lookup.translate
26             )
27         if self.macro:
28             # render only the portion of the template included in a
29             # define-macro named the value of self.macro
30             macro_renderer = tf.macros[self.macro].include
31             tf._render = macro_renderer
32         return tf
33 
34     def implementation(self):
35         return self.template
36     
37     def __call__(self, value, system):
38         try:
39             system.update(value)
40         except (TypeError, ValueError):
41             raise ValueError('renderer was passed non-dictionary as value')
42         result = self.template(**system)
43         return result
44 
45
```

Path: `pyramid/chameleon_text.py`
Content:
```
1 from zope.interface import implementer
2 
3 from chameleon.zpt.template import PageTextTemplateFile
4 
5 from pyramid.interfaces import ITemplateRenderer
6 
7 from pyramid.decorator import reify
8 from pyramid import renderers
9 
10 def renderer_factory(info):
11     return renderers.template_renderer_factory(info, TextTemplateRenderer)
12 
13 @implementer(ITemplateRenderer)
14 class TextTemplateRenderer(object):
15     def __init__(self, path, lookup, macro=None):
16         self.path = path
17         self.lookup = lookup
18         # text template renderers have no macros, so we ignore the
19         # macro arg
20 
21     @reify # avoid looking up reload_templates before manager pushed
22     def template(self):
23         return PageTextTemplateFile(self.path,
24                                     auto_reload=self.lookup.auto_reload,
25                                     debug=self.lookup.debug,
26                                     translate=self.lookup.translate)
27 
28     def implementation(self):
29         return self.template
30     
31     def __call__(self, value, system):
32         try:
33             system.update(value)
34         except (TypeError, ValueError):
35             raise ValueError('renderer was passed non-dictionary as value')
36         result = self.template(**system)
37         return result
38 
39
```
--- 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/chameleon_text.py b/pyramid/chameleon_text.py
--- a/pyramid/chameleon_text.py
+++ b/pyramid/chameleon_text.py
@@ -1,7 +1,5 @@
 from zope.interface import implementer
 
-from chameleon.zpt.template import PageTextTemplateFile
-
 from pyramid.interfaces import ITemplateRenderer
 
 from pyramid.decorator import reify
@@ -20,6 +18,7 @@
 
     @reify # avoid looking up reload_templates before manager pushed
     def template(self):
+        from chameleon.zpt.template import PageTextTemplateFile
         return PageTextTemplateFile(self.path,
                                     auto_reload=self.lookup.auto_reload,
                                     debug=self.lookup.debug,
diff --git a/pyramid/chameleon_zpt.py b/pyramid/chameleon_zpt.py
--- a/pyramid/chameleon_zpt.py
+++ b/pyramid/chameleon_zpt.py
@@ -1,7 +1,5 @@
 from zope.interface import implementer
 
-from chameleon.zpt.template import PageTemplateFile
-
 from pyramid.interfaces import ITemplateRenderer
 from pyramid.decorator import reify
 from pyramid import renderers
@@ -18,6 +16,7 @@
 
     @reify # avoid looking up reload_templates before manager pushed
     def template(self):
+        from chameleon.zpt.template import PageTemplateFile
         tf = PageTemplateFile(
             self.path,
             auto_reload=self.lookup.auto_reload,

{"golden_diff": "diff --git a/pyramid/chameleon_text.py b/pyramid/chameleon_text.py\n--- a/pyramid/chameleon_text.py\n+++ b/pyramid/chameleon_text.py\n@@ -1,7 +1,5 @@\n from zope.interface import implementer\n \n-from chameleon.zpt.template import PageTextTemplateFile\n-\n from pyramid.interfaces import ITemplateRenderer\n \n from pyramid.decorator import reify\n@@ -20,6 +18,7 @@\n \n     @reify # avoid looking up reload_templates before manager pushed\n     def template(self):\n+        from chameleon.zpt.template import PageTextTemplateFile\n         return PageTextTemplateFile(self.path,\n                                     auto_reload=self.lookup.auto_reload,\n                                     debug=self.lookup.debug,\ndiff --git a/pyramid/chameleon_zpt.py b/pyramid/chameleon_zpt.py\n--- a/pyramid/chameleon_zpt.py\n+++ b/pyramid/chameleon_zpt.py\n@@ -1,7 +1,5 @@\n from zope.interface import implementer\n \n-from chameleon.zpt.template import PageTemplateFile\n-\n from pyramid.interfaces import ITemplateRenderer\n from pyramid.decorator import reify\n from pyramid import renderers\n@@ -18,6 +16,7 @@\n \n     @reify # avoid looking up reload_templates before manager pushed\n     def template(self):\n+        from chameleon.zpt.template import PageTemplateFile\n         tf = PageTemplateFile(\n             self.path,\n             auto_reload=self.lookup.auto_reload,\n", "issue": "Pyramid app frozen with py2exe fails because of Chameleon imports\nIf I freeze a Pyramid application with py2exe and try to run it, it fails during the startup, with the following traceback:\n\n```\nTraceback (most recent call last):\n  File \"web_server.py\", line 2, in <module>\n  File \"pyramid\\config\\__init__.pyc\", line 66, in <module>\n  File \"pyramid\\config\\rendering.pyc\", line 11, in <module>\n  File \"pyramid\\chameleon_text.pyc\", line 3, in <module>\n  File \"chameleon\\__init__.pyc\", line 1, in <module>\n  File \"chameleon\\zpt\\template.pyc\", line 10, in <module>\n  File \"chameleon\\tales.pyc\", line 19, in <module>\n  File \"chameleon\\compiler.pyc\", line 145, in <module>\n  File \"chameleon\\codegen.pyc\", line 93, in template\n  File \"inspect.pyc\", line 701, in getsource\n  File \"inspect.pyc\", line 690, in getsourcelines\n  File \"inspect.pyc\", line 538, in findsource\nIOError: could not get source code\n```\n\nMy application doesn't use Chameleon, but the Pyramid modules still import it, which ultimately causes the .exe to fail to run.\n\n", "before_files": [{"content": "from zope.interface import implementer\n\nfrom chameleon.zpt.template import PageTemplateFile\n\nfrom pyramid.interfaces import ITemplateRenderer\nfrom pyramid.decorator import reify\nfrom pyramid import renderers\n\ndef renderer_factory(info):\n    return renderers.template_renderer_factory(info, ZPTTemplateRenderer)\n\n@implementer(ITemplateRenderer)\nclass ZPTTemplateRenderer(object):\n    def __init__(self, path, lookup, macro=None):\n        self.path = path\n        self.lookup = lookup\n        self.macro = macro\n\n    @reify # avoid looking up reload_templates before manager pushed\n    def template(self):\n        tf = PageTemplateFile(\n            self.path,\n            auto_reload=self.lookup.auto_reload,\n            debug=self.lookup.debug,\n            translate=self.lookup.translate\n            )\n        if self.macro:\n            # render only the portion of the template included in a\n            # define-macro named the value of self.macro\n            macro_renderer = tf.macros[self.macro].include\n            tf._render = macro_renderer\n        return tf\n\n    def implementation(self):\n        return self.template\n    \n    def __call__(self, value, system):\n        try:\n            system.update(value)\n        except (TypeError, ValueError):\n            raise ValueError('renderer was passed non-dictionary as value')\n        result = self.template(**system)\n        return result\n\n", "path": "pyramid/chameleon_zpt.py"}, {"content": "from zope.interface import implementer\n\nfrom chameleon.zpt.template import PageTextTemplateFile\n\nfrom pyramid.interfaces import ITemplateRenderer\n\nfrom pyramid.decorator import reify\nfrom pyramid import renderers\n\ndef renderer_factory(info):\n    return renderers.template_renderer_factory(info, TextTemplateRenderer)\n\n@implementer(ITemplateRenderer)\nclass TextTemplateRenderer(object):\n    def __init__(self, path, lookup, macro=None):\n        self.path = path\n        self.lookup = lookup\n        # text template renderers have no macros, so we ignore the\n        # macro arg\n\n    @reify # avoid looking up reload_templates before manager pushed\n    def template(self):\n        return PageTextTemplateFile(self.path,\n                                    auto_reload=self.lookup.auto_reload,\n                                    debug=self.lookup.debug,\n                                    translate=self.lookup.translate)\n\n    def implementation(self):\n        return self.template\n    \n    def __call__(self, value, system):\n        try:\n            system.update(value)\n        except (TypeError, ValueError):\n            raise ValueError('renderer was passed non-dictionary as value')\n        result = self.template(**system)\n        return result\n\n", "path": "pyramid/chameleon_text.py"}], "after_files": [{"content": "from zope.interface import implementer\n\nfrom pyramid.interfaces import ITemplateRenderer\nfrom pyramid.decorator import reify\nfrom pyramid import renderers\n\ndef renderer_factory(info):\n    return renderers.template_renderer_factory(info, ZPTTemplateRenderer)\n\n@implementer(ITemplateRenderer)\nclass ZPTTemplateRenderer(object):\n    def __init__(self, path, lookup, macro=None):\n        self.path = path\n        self.lookup = lookup\n        self.macro = macro\n\n    @reify # avoid looking up reload_templates before manager pushed\n    def template(self):\n        from chameleon.zpt.template import PageTemplateFile\n        tf = PageTemplateFile(\n            self.path,\n            auto_reload=self.lookup.auto_reload,\n            debug=self.lookup.debug,\n            translate=self.lookup.translate\n            )\n        if self.macro:\n            # render only the portion of the template included in a\n            # define-macro named the value of self.macro\n            macro_renderer = tf.macros[self.macro].include\n            tf._render = macro_renderer\n        return tf\n\n    def implementation(self):\n        return self.template\n    \n    def __call__(self, value, system):\n        try:\n            system.update(value)\n        except (TypeError, ValueError):\n            raise ValueError('renderer was passed non-dictionary as value')\n        result = self.template(**system)\n        return result\n\n", "path": "pyramid/chameleon_zpt.py"}, {"content": "from zope.interface import implementer\n\nfrom pyramid.interfaces import ITemplateRenderer\n\nfrom pyramid.decorator import reify\nfrom pyramid import renderers\n\ndef renderer_factory(info):\n    return renderers.template_renderer_factory(info, TextTemplateRenderer)\n\n@implementer(ITemplateRenderer)\nclass TextTemplateRenderer(object):\n    def __init__(self, path, lookup, macro=None):\n        self.path = path\n        self.lookup = lookup\n        # text template renderers have no macros, so we ignore the\n        # macro arg\n\n    @reify # avoid looking up reload_templates before manager pushed\n    def template(self):\n        from chameleon.zpt.template import PageTextTemplateFile\n        return PageTextTemplateFile(self.path,\n                                    auto_reload=self.lookup.auto_reload,\n                                    debug=self.lookup.debug,\n                                    translate=self.lookup.translate)\n\n    def implementation(self):\n        return self.template\n    \n    def __call__(self, value, system):\n        try:\n            system.update(value)\n        except (TypeError, ValueError):\n            raise ValueError('renderer was passed non-dictionary as value')\n        result = self.template(**system)\n        return result\n\n", "path": "pyramid/chameleon_text.py"}]}