Python jinja2.exceptions 模块,TemplateNotFound() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用jinja2.exceptions.TemplateNotFound()

项目:charm-plumgrid-gateway    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:charm-swift-proxy    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def get_source(self, environment, template):
        """Get the template source, filename and reload helper for a template.
        It's passed the environment and template name and has to return a
        tuple in the form ``(source, filename, uptodate)`` or raise a
        `TemplateNotFound` error if it can't locate the template.

        The source part of the returned tuple must be the source of the
        template as unicode string or a ASCII bytestring.  The filename should
        be the name of the file on the filesystem if it was loaded from there,
        otherwise `None`.  The filename is used by python for the tracebacks
        if no loader extension is used.

        The last item in the tuple is the `uptodate` function.  If auto
        reloading is enabled it's always called to check if the template
        changed.  No arguments are passed so the function must store the
        old state somewhere (for example in a closure).  If it returns `False`
        the template will be reloaded.
        """
        if not self.has_source_access:
            raise RuntimeError('%s cannot provide access to the source' %
                               self.__class__.__name__)
        raise TemplateNotFound(template)
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        for searchpath in self.searchpath:
            filename = path.join(searchpath, *pieces)
            f = open_if_exists(filename)
            if f is None:
                continue
            try:
                contents = f.read().decode(self.encoding)
            finally:
                f.close()

            mtime = path.getmtime(filename)

            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False
            return contents, filename, uptodate
        raise TemplateNotFound(template)
项目:Flask_Blog    作者:sugarguo    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        p = '/'.join((self.package_path,) + tuple(pieces))
        if not self.provider.has_resource(p):
            raise TemplateNotFound(template)

        filename = uptodate = None
        if self.filesystem_bound:
            filename = self.provider.get_resource_filename(self.manager, p)
            mtime = path.getmtime(filename)
            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False

        source = self.provider.get_resource_string(self.manager, p)
        return source.decode(self.encoding), filename, uptodate
项目:charm-heat    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:charm-keystone    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:charm-keystone    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:charm-keystone    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:charm-keystone    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def get_source(self, environment, template):
        """Get the template source, filename and reload helper for a template.
        It's passed the environment and template name and has to return a
        tuple in the form ``(source, filename, uptodate)`` or raise a
        `TemplateNotFound` error if it can't locate the template.

        The source part of the returned tuple must be the source of the
        template as unicode string or a ASCII bytestring.  The filename should
        be the name of the file on the filesystem if it was loaded from there,
        otherwise `None`.  The filename is used by python for the tracebacks
        if no loader extension is used.

        The last item in the tuple is the `uptodate` function.  If auto
        reloading is enabled it's always called to check if the template
        changed.  No arguments are passed so the function must store the
        old state somewhere (for example in a closure).  If it returns `False`
        the template will be reloaded.
        """
        if not self.has_source_access:
            raise RuntimeError('%s cannot provide access to the source' %
                               self.__class__.__name__)
        raise TemplateNotFound(template)
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        for searchpath in self.searchpath:
            filename = path.join(searchpath, *pieces)
            f = open_if_exists(filename)
            if f is None:
                continue
            try:
                contents = f.read().decode(self.encoding)
            finally:
                f.close()

            mtime = path.getmtime(filename)

            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False
            return contents, filename, uptodate
        raise TemplateNotFound(template)
项目:swjtu-pyscraper    作者:Desgard    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        p = '/'.join((self.package_path,) + tuple(pieces))
        if not self.provider.has_resource(p):
            raise TemplateNotFound(template)

        filename = uptodate = None
        if self.filesystem_bound:
            filename = self.provider.get_resource_filename(self.manager, p)
            mtime = path.getmtime(filename)
            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False

        source = self.provider.get_resource_string(self.manager, p)
        return source.decode(self.encoding), filename, uptodate
项目:charm-nova-cloud-controller    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:sublime-text-3-packages    作者:nickjj    | 项目源码 | 文件源码
def get_source(self, environment, template):
        """Get the template source, filename and reload helper for a template.
        It's passed the environment and template name and has to return a
        tuple in the form ``(source, filename, uptodate)`` or raise a
        `TemplateNotFound` error if it can't locate the template.

        The source part of the returned tuple must be the source of the
        template as unicode string or a ASCII bytestring.  The filename should
        be the name of the file on the filesystem if it was loaded from there,
        otherwise `None`.  The filename is used by python for the tracebacks
        if no loader extension is used.

        The last item in the tuple is the `uptodate` function.  If auto
        reloading is enabled it's always called to check if the template
        changed.  No arguments are passed so the function must store the
        old state somewhere (for example in a closure).  If it returns `False`
        the template will be reloaded.
        """
        if not self.has_source_access:
            raise RuntimeError('%s cannot provide access to the source' %
                               self.__class__.__name__)
        raise TemplateNotFound(template)
项目:sublime-text-3-packages    作者:nickjj    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        for searchpath in self.searchpath:
            filename = path.join(searchpath, *pieces)
            f = open_if_exists(filename)
            if f is None:
                continue
            try:
                contents = f.read().decode(self.encoding)
            finally:
                f.close()

            mtime = path.getmtime(filename)

            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False
            return contents, filename, uptodate
        raise TemplateNotFound(template)
项目:sublime-text-3-packages    作者:nickjj    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        p = '/'.join((self.package_path,) + tuple(pieces))
        if not self.provider.has_resource(p):
            raise TemplateNotFound(template)

        filename = uptodate = None
        if self.filesystem_bound:
            filename = self.provider.get_resource_filename(self.manager, p)
            mtime = path.getmtime(filename)
            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False

        source = self.provider.get_resource_string(self.manager, p)
        return source.decode(self.encoding), filename, uptodate
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def get_source(self, environment, template):
        """Get the template source, filename and reload helper for a template.
        It's passed the environment and template name and has to return a
        tuple in the form ``(source, filename, uptodate)`` or raise a
        `TemplateNotFound` error if it can't locate the template.

        The source part of the returned tuple must be the source of the
        template as unicode string or a ASCII bytestring.  The filename should
        be the name of the file on the filesystem if it was loaded from there,
        otherwise `None`.  The filename is used by python for the tracebacks
        if no loader extension is used.

        The last item in the tuple is the `uptodate` function.  If auto
        reloading is enabled it's always called to check if the template
        changed.  No arguments are passed so the function must store the
        old state somewhere (for example in a closure).  If it returns `False`
        the template will be reloaded.
        """
        if not self.has_source_access:
            raise RuntimeError('%s cannot provide access to the source' %
                               self.__class__.__name__)
        raise TemplateNotFound(template)
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        for searchpath in self.searchpath:
            filename = path.join(searchpath, *pieces)
            f = open_if_exists(filename)
            if f is None:
                continue
            try:
                contents = f.read().decode(self.encoding)
            finally:
                f.close()

            mtime = path.getmtime(filename)

            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False
            return contents, filename, uptodate
        raise TemplateNotFound(template)
项目:zanph    作者:zanph    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        p = '/'.join((self.package_path,) + tuple(pieces))
        if not self.provider.has_resource(p):
            raise TemplateNotFound(template)

        filename = uptodate = None
        if self.filesystem_bound:
            filename = self.provider.get_resource_filename(self.manager, p)
            mtime = path.getmtime(filename)
            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False

        source = self.provider.get_resource_string(self.manager, p)
        return source.decode(self.encoding), filename, uptodate
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def get_source(self, environment, template):
        """Get the template source, filename and reload helper for a template.
        It's passed the environment and template name and has to return a
        tuple in the form ``(source, filename, uptodate)`` or raise a
        `TemplateNotFound` error if it can't locate the template.

        The source part of the returned tuple must be the source of the
        template as unicode string or a ASCII bytestring.  The filename should
        be the name of the file on the filesystem if it was loaded from there,
        otherwise `None`.  The filename is used by python for the tracebacks
        if no loader extension is used.

        The last item in the tuple is the `uptodate` function.  If auto
        reloading is enabled it's always called to check if the template
        changed.  No arguments are passed so the function must store the
        old state somewhere (for example in a closure).  If it returns `False`
        the template will be reloaded.
        """
        if not self.has_source_access:
            raise RuntimeError('%s cannot provide access to the source' %
                               self.__class__.__name__)
        raise TemplateNotFound(template)
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        for searchpath in self.searchpath:
            filename = path.join(searchpath, *pieces)
            f = open_if_exists(filename)
            if f is None:
                continue
            try:
                contents = f.read().decode(self.encoding)
            finally:
                f.close()

            mtime = path.getmtime(filename)

            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False
            return contents, filename, uptodate
        raise TemplateNotFound(template)
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        p = '/'.join((self.package_path,) + tuple(pieces))
        if not self.provider.has_resource(p):
            raise TemplateNotFound(template)

        filename = uptodate = None
        if self.filesystem_bound:
            filename = self.provider.get_resource_filename(self.manager, p)
            mtime = path.getmtime(filename)
            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False

        source = self.provider.get_resource_string(self.manager, p)
        return source.decode(self.encoding), filename, uptodate
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def get_source(self, environment, template):
        """Get the template source, filename and reload helper for a template.
        It's passed the environment and template name and has to return a
        tuple in the form ``(source, filename, uptodate)`` or raise a
        `TemplateNotFound` error if it can't locate the template.

        The source part of the returned tuple must be the source of the
        template as unicode string or a ASCII bytestring.  The filename should
        be the name of the file on the filesystem if it was loaded from there,
        otherwise `None`.  The filename is used by python for the tracebacks
        if no loader extension is used.

        The last item in the tuple is the `uptodate` function.  If auto
        reloading is enabled it's always called to check if the template
        changed.  No arguments are passed so the function must store the
        old state somewhere (for example in a closure).  If it returns `False`
        the template will be reloaded.
        """
        if not self.has_source_access:
            raise RuntimeError('%s cannot provide access to the source' %
                               self.__class__.__name__)
        raise TemplateNotFound(template)
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        for searchpath in self.searchpath:
            filename = path.join(searchpath, *pieces)
            f = open_if_exists(filename)
            if f is None:
                continue
            try:
                contents = f.read().decode(self.encoding)
            finally:
                f.close()

            mtime = path.getmtime(filename)

            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False
            return contents, filename, uptodate
        raise TemplateNotFound(template)
项目:Sci-Finder    作者:snverse    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        p = '/'.join((self.package_path,) + tuple(pieces))
        if not self.provider.has_resource(p):
            raise TemplateNotFound(template)

        filename = uptodate = None
        if self.filesystem_bound:
            filename = self.provider.get_resource_filename(self.manager, p)
            mtime = path.getmtime(filename)
            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False

        source = self.provider.get_resource_string(self.manager, p)
        return source.decode(self.encoding), filename, uptodate
项目:Texty    作者:sarthfrey    | 项目源码 | 文件源码
def get_source(self, environment, template):
        """Get the template source, filename and reload helper for a template.
        It's passed the environment and template name and has to return a
        tuple in the form ``(source, filename, uptodate)`` or raise a
        `TemplateNotFound` error if it can't locate the template.

        The source part of the returned tuple must be the source of the
        template as unicode string or a ASCII bytestring.  The filename should
        be the name of the file on the filesystem if it was loaded from there,
        otherwise `None`.  The filename is used by python for the tracebacks
        if no loader extension is used.

        The last item in the tuple is the `uptodate` function.  If auto
        reloading is enabled it's always called to check if the template
        changed.  No arguments are passed so the function must store the
        old state somewhere (for example in a closure).  If it returns `False`
        the template will be reloaded.
        """
        if not self.has_source_access:
            raise RuntimeError('%s cannot provide access to the source' %
                               self.__class__.__name__)
        raise TemplateNotFound(template)
项目:Texty    作者:sarthfrey    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        for searchpath in self.searchpath:
            filename = path.join(searchpath, *pieces)
            f = open_if_exists(filename)
            if f is None:
                continue
            try:
                contents = f.read().decode(self.encoding)
            finally:
                f.close()

            mtime = path.getmtime(filename)

            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False
            return contents, filename, uptodate
        raise TemplateNotFound(template)
项目:Texty    作者:sarthfrey    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        p = '/'.join((self.package_path,) + tuple(pieces))
        if not self.provider.has_resource(p):
            raise TemplateNotFound(template)

        filename = uptodate = None
        if self.filesystem_bound:
            filename = self.provider.get_resource_filename(self.manager, p)
            mtime = path.getmtime(filename)
            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False

        source = self.provider.get_resource_string(self.manager, p)
        return source.decode(self.encoding), filename, uptodate
项目:charm-nova-compute    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:RPoint    作者:george17-meet    | 项目源码 | 文件源码
def get_source(self, environment, template):
        """Get the template source, filename and reload helper for a template.
        It's passed the environment and template name and has to return a
        tuple in the form ``(source, filename, uptodate)`` or raise a
        `TemplateNotFound` error if it can't locate the template.

        The source part of the returned tuple must be the source of the
        template as unicode string or a ASCII bytestring.  The filename should
        be the name of the file on the filesystem if it was loaded from there,
        otherwise `None`.  The filename is used by python for the tracebacks
        if no loader extension is used.

        The last item in the tuple is the `uptodate` function.  If auto
        reloading is enabled it's always called to check if the template
        changed.  No arguments are passed so the function must store the
        old state somewhere (for example in a closure).  If it returns `False`
        the template will be reloaded.
        """
        if not self.has_source_access:
            raise RuntimeError('%s cannot provide access to the source' %
                               self.__class__.__name__)
        raise TemplateNotFound(template)
项目:RPoint    作者:george17-meet    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        for searchpath in self.searchpath:
            filename = path.join(searchpath, *pieces)
            f = open_if_exists(filename)
            if f is None:
                continue
            try:
                contents = f.read().decode(self.encoding)
            finally:
                f.close()

            mtime = path.getmtime(filename)

            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False
            return contents, filename, uptodate
        raise TemplateNotFound(template)
项目:RPoint    作者:george17-meet    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        p = '/'.join((self.package_path,) + tuple(pieces))
        if not self.provider.has_resource(p):
            raise TemplateNotFound(template)

        filename = uptodate = None
        if self.filesystem_bound:
            filename = self.provider.get_resource_filename(self.manager, p)
            mtime = path.getmtime(filename)
            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False

        source = self.provider.get_resource_string(self.manager, p)
        return source.decode(self.encoding), filename, uptodate
项目:isni-reconcile    作者:cmh2166    | 项目源码 | 文件源码
def get_source(self, environment, template):
        """Get the template source, filename and reload helper for a template.
        It's passed the environment and template name and has to return a
        tuple in the form ``(source, filename, uptodate)`` or raise a
        `TemplateNotFound` error if it can't locate the template.

        The source part of the returned tuple must be the source of the
        template as unicode string or a ASCII bytestring.  The filename should
        be the name of the file on the filesystem if it was loaded from there,
        otherwise `None`.  The filename is used by python for the tracebacks
        if no loader extension is used.

        The last item in the tuple is the `uptodate` function.  If auto
        reloading is enabled it's always called to check if the template
        changed.  No arguments are passed so the function must store the
        old state somewhere (for example in a closure).  If it returns `False`
        the template will be reloaded.
        """
        if not self.has_source_access:
            raise RuntimeError('%s cannot provide access to the source' %
                               self.__class__.__name__)
        raise TemplateNotFound(template)
项目:isni-reconcile    作者:cmh2166    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        for searchpath in self.searchpath:
            filename = path.join(searchpath, *pieces)
            f = open_if_exists(filename)
            if f is None:
                continue
            try:
                contents = f.read().decode(self.encoding)
            finally:
                f.close()

            mtime = path.getmtime(filename)

            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False
            return contents, filename, uptodate
        raise TemplateNotFound(template)
项目:isni-reconcile    作者:cmh2166    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        p = '/'.join((self.package_path,) + tuple(pieces))
        if not self.provider.has_resource(p):
            raise TemplateNotFound(template)

        filename = uptodate = None
        if self.filesystem_bound:
            filename = self.provider.get_resource_filename(self.manager, p)
            mtime = path.getmtime(filename)
            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False

        source = self.provider.get_resource_string(self.manager, p)
        return source.decode(self.encoding), filename, uptodate
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        for searchpath in self.searchpath:
            filename = path.join(searchpath, *pieces)
            f = open_if_exists(filename)
            if f is None:
                continue
            try:
                contents = f.read().decode(self.encoding)
            finally:
                f.close()

            mtime = path.getmtime(filename)
            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False
            return contents, filename, uptodate
        raise TemplateNotFound(template)
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        p = '/'.join((self.package_path,) + tuple(pieces))
        if not self.provider.has_resource(p):
            raise TemplateNotFound(template)

        filename = uptodate = None
        if self.filesystem_bound:
            filename = self.provider.get_resource_filename(self.manager, p)
            mtime = path.getmtime(filename)
            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False

        source = self.provider.get_resource_string(self.manager, p)
        return source.decode(self.encoding), filename, uptodate
项目:flasky    作者:RoseOu    | 项目源码 | 文件源码
def load(self, environment, name, globals=None):
        key = self.get_template_key(name)
        module = '%s.%s' % (self.package_name, key)
        mod = getattr(self.module, module, None)
        if mod is None:
            try:
                mod = __import__(module, None, None, ['root'])
            except ImportError:
                raise TemplateNotFound(name)

            # remove the entry from sys.modules, we only want the attribute
            # on the module object we have stored on the loader.
            sys.modules.pop(module, None)

        return environment.template_class.from_module_dict(
            environment, mod.__dict__, globals)
项目:macos-st-packages    作者:zce    | 项目源码 | 文件源码
def get_source(self, environment, template):
        """Get the template source, filename and reload helper for a template.
        It's passed the environment and template name and has to return a
        tuple in the form ``(source, filename, uptodate)`` or raise a
        `TemplateNotFound` error if it can't locate the template.

        The source part of the returned tuple must be the source of the
        template as unicode string or a ASCII bytestring.  The filename should
        be the name of the file on the filesystem if it was loaded from there,
        otherwise `None`.  The filename is used by python for the tracebacks
        if no loader extension is used.

        The last item in the tuple is the `uptodate` function.  If auto
        reloading is enabled it's always called to check if the template
        changed.  No arguments are passed so the function must store the
        old state somewhere (for example in a closure).  If it returns `False`
        the template will be reloaded.
        """
        if not self.has_source_access:
            raise RuntimeError('%s cannot provide access to the source' %
                               self.__class__.__name__)
        raise TemplateNotFound(template)
项目:macos-st-packages    作者:zce    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        for searchpath in self.searchpath:
            filename = path.join(searchpath, *pieces)
            f = open_if_exists(filename)
            if f is None:
                continue
            try:
                contents = f.read().decode(self.encoding)
            finally:
                f.close()

            mtime = path.getmtime(filename)

            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False
            return contents, filename, uptodate
        raise TemplateNotFound(template)
项目:macos-st-packages    作者:zce    | 项目源码 | 文件源码
def get_source(self, environment, template):
        pieces = split_template_path(template)
        p = '/'.join((self.package_path,) + tuple(pieces))
        if not self.provider.has_resource(p):
            raise TemplateNotFound(template)

        filename = uptodate = None
        if self.filesystem_bound:
            filename = self.provider.get_resource_filename(self.manager, p)
            mtime = path.getmtime(filename)
            def uptodate():
                try:
                    return path.getmtime(filename) == mtime
                except OSError:
                    return False

        source = self.provider.get_resource_string(self.manager, p)
        return source.decode(self.encoding), filename, uptodate
项目:charm-glance    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:charm-glance    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:charm-glance    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:charm-glance    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:charm-neutron-api    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:charm-ceph-mon    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:charm-openstack-dashboard    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)
项目:charm-ceilometer    作者:openstack    | 项目源码 | 文件源码
def render(self, config_file):
        if config_file not in self.templates:
            log('Config not registered: %s' % config_file, level=ERROR)
            raise OSConfigException
        ctxt = self.templates[config_file].context()

        _tmpl = os.path.basename(config_file)
        try:
            template = self._get_template(_tmpl)
        except exceptions.TemplateNotFound:
            # if no template is found with basename, try looking for it
            # using a munged full path, eg:
            #   /etc/apache2/apache2.conf -> etc_apache2_apache2.conf
            _tmpl = '_'.join(config_file.split('/')[1:])
            try:
                template = self._get_template(_tmpl)
            except exceptions.TemplateNotFound as e:
                log('Could not load template from %s by %s or %s.' %
                    (self.templates_dir, os.path.basename(config_file), _tmpl),
                    level=ERROR)
                raise e

        log('Rendering from template: %s' % _tmpl, level=INFO)
        return template.render(ctxt)