Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
This paste will be private.
Index: genshi/template.py =================================================================== --- genshi/template.py (revision 346) +++ genshi/template.py (working copy) @@ -1314,9 +1314,10 @@ directly @param cls: the class of the template object to instantiate """ + filepath = filename if relative_to: - filename = os.path.join(os.path.dirname(relative_to), filename) - filename = os.path.normpath(filename) + filepath = os.path.join(os.path.dirname(relative_to), filepath) + filepath = os.path.normpath(filepath) self._lock.acquire() try: @@ -1329,25 +1330,32 @@ except KeyError: pass - # Bypass the search path if the filename is absolute search_path = self.search_path + if os.path.isabs(filename): - search_path = [os.path.dirname(filename)] + # Bypass the search path if the requested filename is absolute + search_path = [os.path.dirname(filepath)] - if not search_path: + elif relative_to and os.path.isabs(relative_to): + # Otherwise, make sure that the directory containing the + # template is on the search path + search_path.append(os.path.dirname(relative_to)) + + 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: - filepath = os.path.join(dirname, filename) + path = os.path.join(dirname, filepath) try: - fileobj = open(filepath, 'U') + fileobj = open(path, 'U') try: tmpl = cls(fileobj, basedir=dirname, filename=filename, loader=self) finally: fileobj.close() self._cache[filename] = tmpl - self._mtime[filename] = os.path.getmtime(filepath) + self._mtime[filename] = os.path.getmtime(path) return tmpl except IOError: continue
From the Design Piracy series on my blog: