prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  handle include tag in mako templates
  Currently templates used via include tags are not considered dependencies. It's not hard.
  
  handle include tag in mako templates
  Currently templates used via include tags are not considered dependencies. It's not hard.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `nikola/plugins/template/mako.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 
  3 # Copyright © 2012-2015 Roberto Alsina and others.
  4 
  5 # Permission is hereby granted, free of charge, to any
  6 # person obtaining a copy of this software and associated
  7 # documentation files (the "Software"), to deal in the
  8 # Software without restriction, including without limitation
  9 # the rights to use, copy, modify, merge, publish,
  10 # distribute, sublicense, and/or sell copies of the
  11 # Software, and to permit persons to whom the Software is
  12 # furnished to do so, subject to the following conditions:
  13 #
  14 # The above copyright notice and this permission notice
  15 # shall be included in all copies or substantial portions of
  16 # the Software.
  17 #
  18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  19 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  20 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  21 # PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  22 # OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  23 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  24 # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  25 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26 
  27 """Mako template handler."""
  28 
  29 from __future__ import unicode_literals, print_function, absolute_import
  30 import os
  31 import shutil
  32 import sys
  33 import tempfile
  34 
  35 from mako import util, lexer
  36 from mako.lookup import TemplateLookup
  37 from mako.template import Template
  38 from markupsafe import Markup  # It's ok, Mako requires it
  39 
  40 from nikola.plugin_categories import TemplateSystem
  41 from nikola.utils import makedirs, get_logger, STDERR_HANDLER
  42 
  43 LOGGER = get_logger('mako', STDERR_HANDLER)
  44 
  45 
  46 class MakoTemplates(TemplateSystem):
  47 
  48     """Support for Mako templates."""
  49 
  50     name = "mako"
  51 
  52     lookup = None
  53     cache = {}
  54     filters = {}
  55     directories = []
  56     cache_dir = None
  57 
  58     def get_deps(self, filename):
  59         """Get dependencies for a template (internal function)."""
  60         text = util.read_file(filename)
  61         lex = lexer.Lexer(text=text, filename=filename)
  62         lex.parse()
  63 
  64         deps = []
  65         for n in lex.template.nodes:
  66             keyword = getattr(n, 'keyword', None)
  67             if keyword in ["inherit", "namespace"]:
  68                 deps.append(n.attributes['file'])
  69             # TODO: include tags are not handled
  70         return deps
  71 
  72     def set_directories(self, directories, cache_folder):
  73         """Create a new template lookup with set directories."""
  74         cache_dir = os.path.join(cache_folder, '.mako.tmp')
  75         # Workaround for a Mako bug, Issue #825
  76         if sys.version_info[0] == 2:
  77             try:
  78                 os.path.abspath(cache_dir).decode('ascii')
  79             except UnicodeEncodeError:
  80                 cache_dir = tempfile.mkdtemp()
  81                 LOGGER.warning('Because of a Mako bug, setting cache_dir to {0}'.format(cache_dir))
  82         if os.path.exists(cache_dir):
  83             shutil.rmtree(cache_dir)
  84         self.directories = directories
  85         self.cache_dir = cache_dir
  86         self.create_lookup()
  87 
  88     def inject_directory(self, directory):
  89         """Add a directory to the lookup and recreate it if it's not there yet."""
  90         if directory not in self.directories:
  91             self.directories.append(directory)
  92             self.create_lookup()
  93 
  94     def create_lookup(self):
  95         """Create a template lookup."""
  96         self.lookup = TemplateLookup(
  97             directories=self.directories,
  98             module_directory=self.cache_dir,
  99             output_encoding='utf-8')
  100 
  101     def set_site(self, site):
  102         """Set the Nikola site."""
  103         self.site = site
  104         self.filters.update(self.site.config['TEMPLATE_FILTERS'])
  105 
  106     def render_template(self, template_name, output_name, context):
  107         """Render the template into output_name using context."""
  108         context['striphtml'] = striphtml
  109         template = self.lookup.get_template(template_name)
  110         data = template.render_unicode(**context)
  111         if output_name is not None:
  112             makedirs(os.path.dirname(output_name))
  113             with open(output_name, 'w+') as output:
  114                 output.write(data)
  115         return data
  116 
  117     def render_template_to_string(self, template, context):
  118         """Render template to a string using context."""
  119         context.update(self.filters)
  120         return Template(template).render(**context)
  121 
  122     def template_deps(self, template_name):
  123         """Generate list of dependencies for a template."""
  124         # We can cache here because dependencies should
  125         # not change between runs
  126         if self.cache.get(template_name, None) is None:
  127             template = self.lookup.get_template(template_name)
  128             dep_filenames = self.get_deps(template.filename)
  129             deps = [template.filename]
  130             for fname in dep_filenames:
  131                 deps += self.template_deps(fname)
  132             self.cache[template_name] = tuple(deps)
  133         return list(self.cache[template_name])
  134 
  135 
  136 def striphtml(text):
  137     """Strip HTML tags from text."""
  138     return Markup(text).striptags()
  139
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/nikola/plugins/template/mako.py b/nikola/plugins/template/mako.py
  --- a/nikola/plugins/template/mako.py
  +++ b/nikola/plugins/template/mako.py
  @@ -32,7 +32,7 @@
   import sys
   import tempfile
   
  -from mako import util, lexer
  +from mako import util, lexer, parsetree
   from mako.lookup import TemplateLookup
   from mako.template import Template
   from markupsafe import Markup  # It's ok, Mako requires it
  @@ -64,9 +64,8 @@
           deps = []
           for n in lex.template.nodes:
               keyword = getattr(n, 'keyword', None)
  -            if keyword in ["inherit", "namespace"]:
  +            if keyword in ["inherit", "namespace"] or isinstance(n, parsetree.IncludeTag):
                   deps.append(n.attributes['file'])
  -            # TODO: include tags are not handled
           return deps
   
       def set_directories(self, directories, cache_folder):
  
verification_info: {"golden_diff": "diff --git a/nikola/plugins/template/mako.py b/nikola/plugins/template/mako.py\n--- a/nikola/plugins/template/mako.py\n+++ b/nikola/plugins/template/mako.py\n@@ -32,7 +32,7 @@\n import sys\n import tempfile\n \n-from mako import util, lexer\n+from mako import util, lexer, parsetree\n from mako.lookup import TemplateLookup\n from mako.template import Template\n from markupsafe import Markup  # It's ok, Mako requires it\n@@ -64,9 +64,8 @@\n         deps = []\n         for n in lex.template.nodes:\n             keyword = getattr(n, 'keyword', None)\n-            if keyword in [\"inherit\", \"namespace\"]:\n+            if keyword in [\"inherit\", \"namespace\"] or isinstance(n, parsetree.IncludeTag):\n                 deps.append(n.attributes['file'])\n-            # TODO: include tags are not handled\n         return deps\n \n     def set_directories(self, directories, cache_folder):\n", "issue": "handle include tag in mako templates\nCurrently templates used via include tags are not considered dependencies. It's not hard.\n\nhandle include tag in mako templates\nCurrently templates used via include tags are not considered dependencies. It's not hard.\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Copyright \u00a9 2012-2015 Roberto Alsina and others.\n\n# Permission is hereby granted, free of charge, to any\n# person obtaining a copy of this software and associated\n# documentation files (the \"Software\"), to deal in the\n# Software without restriction, including without limitation\n# the rights to use, copy, modify, merge, publish,\n# distribute, sublicense, and/or sell copies of the\n# Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice\n# shall be included in all copies or substantial portions of\n# the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY\n# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR\n# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS\n# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR\n# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\"\"\"Mako template handler.\"\"\"\n\nfrom __future__ import unicode_literals, print_function, absolute_import\nimport os\nimport shutil\nimport sys\nimport tempfile\n\nfrom mako import util, lexer\nfrom mako.lookup import TemplateLookup\nfrom mako.template import Template\nfrom markupsafe import Markup  # It's ok, Mako requires it\n\nfrom nikola.plugin_categories import TemplateSystem\nfrom nikola.utils import makedirs, get_logger, STDERR_HANDLER\n\nLOGGER = get_logger('mako', STDERR_HANDLER)\n\n\nclass MakoTemplates(TemplateSystem):\n\n    \"\"\"Support for Mako templates.\"\"\"\n\n    name = \"mako\"\n\n    lookup = None\n    cache = {}\n    filters = {}\n    directories = []\n    cache_dir = None\n\n    def get_deps(self, filename):\n        \"\"\"Get dependencies for a template (internal function).\"\"\"\n        text = util.read_file(filename)\n        lex = lexer.Lexer(text=text, filename=filename)\n        lex.parse()\n\n        deps = []\n        for n in lex.template.nodes:\n            keyword = getattr(n, 'keyword', None)\n            if keyword in [\"inherit\", \"namespace\"]:\n                deps.append(n.attributes['file'])\n            # TODO: include tags are not handled\n        return deps\n\n    def set_directories(self, directories, cache_folder):\n        \"\"\"Create a new template lookup with set directories.\"\"\"\n        cache_dir = os.path.join(cache_folder, '.mako.tmp')\n        # Workaround for a Mako bug, Issue #825\n        if sys.version_info[0] == 2:\n            try:\n                os.path.abspath(cache_dir).decode('ascii')\n            except UnicodeEncodeError:\n                cache_dir = tempfile.mkdtemp()\n                LOGGER.warning('Because of a Mako bug, setting cache_dir to {0}'.format(cache_dir))\n        if os.path.exists(cache_dir):\n            shutil.rmtree(cache_dir)\n        self.directories = directories\n        self.cache_dir = cache_dir\n        self.create_lookup()\n\n    def inject_directory(self, directory):\n        \"\"\"Add a directory to the lookup and recreate it if it's not there yet.\"\"\"\n        if directory not in self.directories:\n            self.directories.append(directory)\n            self.create_lookup()\n\n    def create_lookup(self):\n        \"\"\"Create a template lookup.\"\"\"\n        self.lookup = TemplateLookup(\n            directories=self.directories,\n            module_directory=self.cache_dir,\n            output_encoding='utf-8')\n\n    def set_site(self, site):\n        \"\"\"Set the Nikola site.\"\"\"\n        self.site = site\n        self.filters.update(self.site.config['TEMPLATE_FILTERS'])\n\n    def render_template(self, template_name, output_name, context):\n        \"\"\"Render the template into output_name using context.\"\"\"\n        context['striphtml'] = striphtml\n        template = self.lookup.get_template(template_name)\n        data = template.render_unicode(**context)\n        if output_name is not None:\n            makedirs(os.path.dirname(output_name))\n            with open(output_name, 'w+') as output:\n                output.write(data)\n        return data\n\n    def render_template_to_string(self, template, context):\n        \"\"\"Render template to a string using context.\"\"\"\n        context.update(self.filters)\n        return Template(template).render(**context)\n\n    def template_deps(self, template_name):\n        \"\"\"Generate list of dependencies for a template.\"\"\"\n        # We can cache here because dependencies should\n        # not change between runs\n        if self.cache.get(template_name, None) is None:\n            template = self.lookup.get_template(template_name)\n            dep_filenames = self.get_deps(template.filename)\n            deps = [template.filename]\n            for fname in dep_filenames:\n                deps += self.template_deps(fname)\n            self.cache[template_name] = tuple(deps)\n        return list(self.cache[template_name])\n\n\ndef striphtml(text):\n    \"\"\"Strip HTML tags from text.\"\"\"\n    return Markup(text).striptags()\n", "path": "nikola/plugins/template/mako.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\n# Copyright \u00a9 2012-2015 Roberto Alsina and others.\n\n# Permission is hereby granted, free of charge, to any\n# person obtaining a copy of this software and associated\n# documentation files (the \"Software\"), to deal in the\n# Software without restriction, including without limitation\n# the rights to use, copy, modify, merge, publish,\n# distribute, sublicense, and/or sell copies of the\n# Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice\n# shall be included in all copies or substantial portions of\n# the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY\n# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR\n# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS\n# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR\n# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\"\"\"Mako template handler.\"\"\"\n\nfrom __future__ import unicode_literals, print_function, absolute_import\nimport os\nimport shutil\nimport sys\nimport tempfile\n\nfrom mako import util, lexer, parsetree\nfrom mako.lookup import TemplateLookup\nfrom mako.template import Template\nfrom markupsafe import Markup  # It's ok, Mako requires it\n\nfrom nikola.plugin_categories import TemplateSystem\nfrom nikola.utils import makedirs, get_logger, STDERR_HANDLER\n\nLOGGER = get_logger('mako', STDERR_HANDLER)\n\n\nclass MakoTemplates(TemplateSystem):\n\n    \"\"\"Support for Mako templates.\"\"\"\n\n    name = \"mako\"\n\n    lookup = None\n    cache = {}\n    filters = {}\n    directories = []\n    cache_dir = None\n\n    def get_deps(self, filename):\n        \"\"\"Get dependencies for a template (internal function).\"\"\"\n        text = util.read_file(filename)\n        lex = lexer.Lexer(text=text, filename=filename)\n        lex.parse()\n\n        deps = []\n        for n in lex.template.nodes:\n            keyword = getattr(n, 'keyword', None)\n            if keyword in [\"inherit\", \"namespace\"] or isinstance(n, parsetree.IncludeTag):\n                deps.append(n.attributes['file'])\n        return deps\n\n    def set_directories(self, directories, cache_folder):\n        \"\"\"Create a new template lookup with set directories.\"\"\"\n        cache_dir = os.path.join(cache_folder, '.mako.tmp')\n        # Workaround for a Mako bug, Issue #825\n        if sys.version_info[0] == 2:\n            try:\n                os.path.abspath(cache_dir).decode('ascii')\n            except UnicodeEncodeError:\n                cache_dir = tempfile.mkdtemp()\n                LOGGER.warning('Because of a Mako bug, setting cache_dir to {0}'.format(cache_dir))\n        if os.path.exists(cache_dir):\n            shutil.rmtree(cache_dir)\n        self.directories = directories\n        self.cache_dir = cache_dir\n        self.create_lookup()\n\n    def inject_directory(self, directory):\n        \"\"\"Add a directory to the lookup and recreate it if it's not there yet.\"\"\"\n        if directory not in self.directories:\n            self.directories.append(directory)\n            self.create_lookup()\n\n    def create_lookup(self):\n        \"\"\"Create a template lookup.\"\"\"\n        self.lookup = TemplateLookup(\n            directories=self.directories,\n            module_directory=self.cache_dir,\n            output_encoding='utf-8')\n\n    def set_site(self, site):\n        \"\"\"Set the Nikola site.\"\"\"\n        self.site = site\n        self.filters.update(self.site.config['TEMPLATE_FILTERS'])\n\n    def render_template(self, template_name, output_name, context):\n        \"\"\"Render the template into output_name using context.\"\"\"\n        context['striphtml'] = striphtml\n        template = self.lookup.get_template(template_name)\n        data = template.render_unicode(**context)\n        if output_name is not None:\n            makedirs(os.path.dirname(output_name))\n            with open(output_name, 'w+') as output:\n                output.write(data)\n        return data\n\n    def render_template_to_string(self, template, context):\n        \"\"\"Render template to a string using context.\"\"\"\n        context.update(self.filters)\n        return Template(template).render(**context)\n\n    def template_deps(self, template_name):\n        \"\"\"Generate list of dependencies for a template.\"\"\"\n        # We can cache here because dependencies should\n        # not change between runs\n        if self.cache.get(template_name, None) is None:\n            template = self.lookup.get_template(template_name)\n            dep_filenames = self.get_deps(template.filename)\n            deps = [template.filename]\n            for fname in dep_filenames:\n                deps += self.template_deps(fname)\n            self.cache[template_name] = tuple(deps)\n        return list(self.cache[template_name])\n\n\ndef striphtml(text):\n    \"\"\"Strip HTML tags from text.\"\"\"\n    return Markup(text).striptags()\n", "path": "nikola/plugins/template/mako.py"}]}