Guest User

Untitled

a guest
Jul 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. def adjust_uri(self, uri, relativeto):
  2. """Adjust the given uri relative to a filename.
  3.  
  4. This method is used by mako for filesystem based reasons.
  5. In dotted lookup land we don't adjust uri so we just return
  6. the value we are given without any change.
  7.  
  8. """
  9. if uri.startswith('local:'):
  10. package = tg.config['pylons.package']
  11. if relativeto:
  12. cwd = os.getcwd()
  13. assert cwd.endswith(package)
  14. path_in_common = cwd[:-len(package)]
  15. assert relativeto.startswith(path_in_common)
  16. package = relativeto[len(path_in_common):]
  17. package = package.split('/', 2)[0]
  18.  
  19. uri = uri.replace('local:', package + '.')
  20. if '.' in uri:
  21. # We are in the DottedTemplateLookup system so dots in
  22. # names should be treated as a Python path. Since this
  23. # method is called by template inheritance we must
  24. # support dotted names also in the inheritance.
  25. result = tg.config['pylons.app_globals'].\
  26. dotted_filename_finder.get_dotted_filename(template_name=uri,
  27. template_extension='.mak')
  28.  
  29. if not self.template_filenames_cache.has_key(uri):
  30. # feed our filename cache if needed.
  31. self.template_filenames_cache[uri] = result
  32.  
  33. else:
  34. # no dot detected, just return plain name
  35. result = uri
  36.  
  37. return result
Add Comment
Please, Sign In to add comment