# HG changeset patch # User cmlenz # Date 1160986307 0 # Node ID b11569429cf5a0b8aecc05b545be14c558b1a150 # Parent cd8e7129479d57d3177d9dd96ad5a5ff2c603868 Ported [370] to 0.3.x branch. diff --git a/genshi/template.py b/genshi/template.py --- a/genshi/template.py +++ b/genshi/template.py @@ -1340,17 +1340,20 @@ pass search_path = self.search_path + isabs = False if os.path.isabs(filename): # Bypass the search path if the requested filename is absolute search_path = [os.path.dirname(filename)] + isabs = True elif relative_to and os.path.isabs(relative_to): # Make sure that the directory containing the including # template is on the search path dirname = os.path.dirname(relative_to) if dirname not in search_path: - search_path = search_path[:] + [dirname] + search_path = search_path + [dirname] + isabs = True elif not search_path: # Uh oh, don't know where to look for the template @@ -1361,6 +1364,14 @@ try: fileobj = open(filepath, 'U') try: + if isabs: + # If the filename of either the included or the + # including template is absolute, make sure the + # included template gets an absolute path, too, + # so that nested include work properly without a + # search path + filename = os.path.join(dirname, filename) + dirname = '' tmpl = cls(fileobj, basedir=dirname, filename=filename, loader=self) finally: diff --git a/genshi/tests/template.py b/genshi/tests/template.py --- a/genshi/tests/template.py +++ b/genshi/tests/template.py @@ -1174,6 +1174,37 @@
Included
""", tmpl.generate().render()) + def test_relative_include_without_search_path_nested(self): + file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') + try: + file1.write("""
Included
""") + finally: + file1.close() + + file2 = open(os.path.join(self.dirname, 'tmpl2.html'), 'w') + try: + file2.write("""
+ +
""") + finally: + file2.close() + + file3 = open(os.path.join(self.dirname, 'tmpl3.html'), 'w') + try: + file3.write(""" + + """) + finally: + file3.close() + + loader = TemplateLoader() + tmpl = loader.load(os.path.join(self.dirname, 'tmpl3.html')) + self.assertEqual(""" +
+
Included
+
+ """, tmpl.generate().render()) + def test_relative_include_from_inmemory_template(self): file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') try: