Guest User

Untitled

a guest
Feb 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. Index: template.py
  2. ===================================================================
  3. --- template.py (revision 348)
  4. +++ template.py (working copy)
  5. @@ -1314,9 +1314,8 @@
  6. directly
  7. @param cls: the class of the template object to instantiate
  8. """
  9. - if relative_to:
  10. - filename = os.path.join(os.path.dirname(relative_to), filename)
  11. - filename = os.path.normpath(filename)
  12. + filepath = filename
  13. + filepath = os.path.normpath(filepath)
  14.  
  15. self._lock.acquire()
  16. try:
  17. @@ -1329,25 +1328,37 @@
  18. except KeyError:
  19. pass
  20.  
  21. - # Bypass the search path if the filename is absolute
  22. search_path = self.search_path
  23. +
  24. if os.path.isabs(filename):
  25. + # Bypass the normal search path if the requested filename is absolute
  26. search_path = [os.path.dirname(filename)]
  27.  
  28. + elif relative_to:
  29. + if os.path.isabs(relative_to):
  30. + # then make sure that the directory containing the
  31. + # template is on the search path
  32. + search_path.append(os.path.dirname(relative_to))
  33. + else:
  34. + filepath = os.path.join(os.path.dirname(relative_to), filepath)
  35. +
  36. + print filename, relative_to, filepath, repr(search_path)
  37. +
  38. if not search_path:
  39. + # Uh, oh, don't know where to look for the template
  40. raise TemplateError('Search path for templates not configured')
  41.  
  42. for dirname in search_path:
  43. - filepath = os.path.join(dirname, filename)
  44. + path = os.path.join(dirname, filepath)
  45. try:
  46. - fileobj = open(filepath, 'U')
  47. + fileobj = open(path, 'U')
  48. try:
  49. - tmpl = cls(fileobj, basedir=dirname, filename=filename,
  50. + tmpl = cls(fileobj, basedir=dirname, filename=filepath,
  51. loader=self)
  52. finally:
  53. fileobj.close()
  54. self._cache[filename] = tmpl
  55. - self._mtime[filename] = os.path.getmtime(filepath)
  56. + self._mtime[filename] = os.path.getmtime(path)
  57. return tmpl
  58. except IOError:
  59. continue
Add Comment
Please, Sign In to add comment