def get_ancestor_source(self, environment, template, tried): """ Given a template identifier of format `<loader>_parent:foo.html` find the template by going through the loaders above it sequentially until it is found. Args: * `environment` - the jinja environment object * `template` - the template name to look up * `tried` - ref to iterable of tried paths Raises `TemplateNotFound` Returns an instantiated template """ try: prefix, template_name = template.split(self.delimiter, 1) except ValueError: raise TemplateNotFound(template) try: child = prefix.split("_parent", 1)[0] except ValueError: raise TemplateNotFound(template) # Work out a flat list of the loader's ancestry to iterate through loader_ancestry = self.get_ancestor_loader_names(child) # For each loader in the ancestry, try to get the template and return it for loader_name in loader_ancestry: loader = self.hierarchy[loader_name] try: return loader.get_source(environment, template_name) except TemplateNotFound: loader_path = "%s/%s" % (loader.searchpath[0], template) origin = JinjaOrigin(loader, loader_path) tried.append([origin, "Source does not exist"]) continue raise TemplateNotFound(template)
def get_source(self, environment, template): if not template.startswith(self.prefix): raise TemplateNotFound(template) template = template[len(self.prefix):] if not template in self.files: raise TemplateNotFound(template) return FileSystemLoader.get_source(self, environment, template)
def get_source(self, environment, template): template = template[8:] try: themename, templatename = template.split('/', 1) theme = _fleem.themes[themename] except (ValueError, KeyError): raise TemplateNotFound(template) try: return theme.jinja_loader.get_source(environment, templatename) except TemplateNotFound: raise TemplateNotFound(template)
def get_source(self, environment, template): if self.as_blueprint and template.startswith("_themes/"): template = template[8:] try: themename, templatename = template.split('/', 1) ctx = _request_ctx_stack.top theme = ctx.app.theme_manager.themes[themename] except (ValueError, KeyError): raise TemplateNotFound(template) try: return theme.jinja_loader.get_source(environment, templatename) except TemplateNotFound: raise TemplateNotFound(template)
def get_source(self, environment, template): pieces = split_template_path(template) for searchpath in self.searchpath: globbed_filename = os.path.join(searchpath, *pieces) filenames = glob.glob(globbed_filename) # Filter out files if they match any of the ignore patterns for ig in self.ignores: filenames = [ f for f in filenames if not fnmatch.fnmatch(os.path.basename(f), ig) ] if len(filenames) > 1: raise AmbiguousTemplate(template) elif len(filenames) < 1: continue filename = filenames[0] with open(filename) as f: contents = f.read().decode(self.encoding) mtime = os.path.getmtime(filename) def uptodate(): try: return os.path.getmtime(filename) == mtime except OSError: return False return contents, filename, uptodate else: raise TemplateNotFound(template)
def get_source(self, environment, template): if callable(self.path_filter): pieces = split_template_path(template) if not self._combined_filter(os.path.join(*pieces)): raise TemplateNotFound(template) return FileSystemLoader.get_source(self, environment, template)
def get_source(self, environment, template): for prefix in sorted(self.loader.mapping.keys()): try: return self.loader.mapping[prefix].get_source(environment, template) except TemplateNotFound: pass raise TemplateNotFound(template)
def get_source(self, environment, template): try: path = self.registry.verify_path(template) except FileNotFoundError: raise TemplateNotFound(template) with codecs.open(path, encoding='utf-8') as f: source = f.read() return source, path, uptodate_checker(path)
def get_ancestor_loader_names(self, child): """ Get a list of ancestor loaders to try, in order of closest relative to most distant. """ # Get a list of loader keys all_loaders = list(self.hierarchy) try: child_index = all_loaders.index(child) except ValueError: raise TemplateNotFound() return all_loaders[child_index+1:]
def get_source(self, environment, template): if not template in self.files: raise TemplateNotFound(template) from jinja2.loaders import open_if_exists path = self.files[template] f = open_if_exists(path) if f is None: raise TemplateNotFound(template) try: contents = f.read().decode(self.encoding) finally: f.close() mtime = os.path.getmtime(path) def uptodate(): try: return os.path.getmtime(path) == mtime except OSError: return False return contents, path, uptodate
def get_namespace_source(self, environment, template, tried): """ Given a template identifier of format `<loader>:foo.html` find the template by looking up the specified loader in the loader hierarchy and retrieving it from there. Args: * `environment` - the jinja environment object * `template` - the template name to look up * `tried` - ref to iterable of tried paths Raises `TemplateNotFound` Returns an instantiated template """ try: loader_name, template_name = template.split(self.delimiter, 1) except ValueError: raise TemplateNotFound(template) try: loader = self.hierarchy[loader_name] except (KeyError): raise TemplateNotFound(template) return loader.get_source(environment, template_name)
def get_source(self, environment, template): pieces = split_template_path(template) filename = posixpath.join(self.template_folder, *pieces) if filename in current_app.blohg.changectx.files: filectx = current_app.blohg.changectx.get_filectx(filename) def up2date(): if current_app.blohg.changectx is None: return False return not \ current_app.blohg.changectx.filectx_needs_reload(filectx) return filectx.content, \ os.path.join(self.template_folder, *pieces), up2date raise TemplateNotFound(template)
def get_source(self, environment, template): pieces = split_template_path(template) for searchpath in self.searchpath: globbed_filename = os.path.join(searchpath, *pieces) filenames = glob.glob(globbed_filename) if len(filenames) > 1: raise AmbiguousTemplate(template) elif len(filenames) < 1: continue filename = filenames[0] with open(filename) as f: contents = f.read().decode(self.encoding) mtime = os.path.getmtime(filename) def uptodate(): try: return os.path.getmtime(filename) == mtime except OSError: return False return contents, filename, uptodate else: raise TemplateNotFound(template)
def get_source(self, environment, template): if template == self.base_ref: fn = self.base_fn else: fn = os.path.join(self.disttemp_path, template + self.template_postfix) f = open_if_exists(fn) if not f: return TemplateNotFound(template) try: contents = f.read().decode(self.encoding) finally: f.close() mtime = os.path.getmtime(self.base_fn) def uptodate(): try: return os.path.getmtime(self.base_fn) == mtime except OSError: return False return contents, fn, uptodate