Mercurial > genshi > mirror
changeset 283:a86653e29c75 trunk
Fix regression introduced in [333:334]: includes no longer used the search path, because the loader was always seeing an absolute path.
author | cmlenz |
---|---|
date | Thu, 12 Oct 2006 12:23:38 +0000 |
parents | 24b3cbbc1b1b |
children | 1f5753346a75 |
files | genshi/template.py genshi/tests/template.py |
diffstat | 2 files changed, 29 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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()
--- a/genshi/tests/template.py +++ b/genshi/tests/template.py @@ -1164,6 +1164,22 @@ <div>Included</div> </html>""", tmpl.generate().render()) + def test_relative_include_from_inmemory_template(self): + file1 = open(os.path.join(self.dirname, 'tmpl1.html'), 'w') + try: + file1.write("""<div>Included</div>""") + finally: + file1.close() + + loader = TemplateLoader([self.dirname]) + tmpl2 = MarkupTemplate("""<html xmlns:xi="http://www.w3.org/2001/XInclude"> + <xi:include href="../tmpl1.html" /> + </html>""", filename='subdir/tmpl2.html', loader=loader) + + self.assertEqual("""<html> + <div>Included</div> + </html>""", tmpl2.generate().render()) + def suite(): suite = unittest.TestSuite()