Guest User

Untitled

a guest
Feb 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. Index: genshi/template.py
  2. ===================================================================
  3. --- genshi/template.py (revision 346)
  4. +++ genshi/template.py (working copy)
  5. @@ -1314,9 +1314,10 @@
  6. directly
  7. @param cls: the class of the template object to instantiate
  8. """
  9. + filepath = filename
  10. if relative_to:
  11. - filename = os.path.join(os.path.dirname(relative_to), filename)
  12. - filename = os.path.normpath(filename)
  13. + filepath = os.path.join(os.path.dirname(relative_to), filepath)
  14. + filepath = os.path.normpath(filepath)
  15.  
  16. self._lock.acquire()
  17. try:
  18. @@ -1331,23 +1332,26 @@
  19.  
  20. # Bypass the search path if the filename is absolute
  21. search_path = self.search_path
  22. + filedir = os.path.dirname(filepath)
  23. if os.path.isabs(filename):
  24. - search_path = [os.path.dirname(filename)]
  25. + search_path = [filedir]
  26. + elif filedir not in search_path:
  27. + search_path.append(filedir)
  28.  
  29. if not search_path:
  30. raise TemplateError('Search path for templates not configured')
  31.  
  32. for dirname in search_path:
  33. - filepath = os.path.join(dirname, filename)
  34. + path = os.path.join(dirname, filepath)
  35. try:
  36. - fileobj = open(filepath, 'U')
  37. + fileobj = open(path, 'U')
  38. try:
  39. tmpl = cls(fileobj, basedir=dirname, filename=filename,
  40. loader=self)
  41. finally:
  42. fileobj.close()
  43. self._cache[filename] = tmpl
  44. - self._mtime[filename] = os.path.getmtime(filepath)
  45. + self._mtime[filename] = os.path.getmtime(path)
  46. return tmpl
  47. except IOError:
  48. continue
Add Comment
Please, Sign In to add comment