# HG changeset patch # User cmlenz # Date 1160655818 0 # Node ID 5cbeeb72c5d49a5cc36dd98221a2096b00768de1 # Parent db5bdeca9192f6d231b5c0ab9c05a731c825a3b3 Fix regression introduced in [333:334]: includes no longer used the search path, because the loader was always seeing an absolute path. diff --git a/genshi/template.py b/genshi/template.py --- a/genshi/template.py +++ b/genshi/template.py @@ -1314,7 +1314,7 @@ directly @param cls: the class of the template object to instantiate """ - if relative_to: + if relative_to and not os.path.isabs(relative_to): filename = os.path.join(os.path.dirname(relative_to), filename) filename = os.path.normpath(filename) @@ -1329,12 +1329,21 @@ except KeyError: pass - # Bypass the search path if the filename is absolute search_path = self.search_path + if os.path.isabs(filename): + # Bypass the search path if the requested filename is absolute search_path = [os.path.dirname(filename)] - if not search_path: + 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] + + elif not search_path: + # Uh oh, don't know where to look for the template raise TemplateError('Search path for templates not configured') for dirname in search_path: @@ -1352,7 +1361,7 @@ except IOError: continue - raise TemplateNotFound(filename, self.search_path) + raise TemplateNotFound(filename, search_path) finally: self._lock.release() diff --git a/genshi/tests/template.py b/genshi/tests/template.py --- a/genshi/tests/template.py +++ b/genshi/tests/template.py @@ -1164,6 +1164,22 @@
Included
""", tmpl.generate().render()) + def test_relative_include_from_inmemory_template(self): + file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') + try: + file1.write("""
Included
""") + finally: + file1.close() + + loader = TemplateLoader([self.dirname]) + tmpl2 = MarkupTemplate(""" + + """, filename='subdir/tmpl2.html', loader=loader) + + self.assertEqual(""" +
Included
+ """, tmpl2.generate().render()) + def suite(): suite = unittest.TestSuite()