当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.TemplateLookupException方法代码示例

本文整理汇总了Python中mako.exceptions.TemplateLookupException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.TemplateLookupException方法的具体用法?Python exceptions.TemplateLookupException怎么用?Python exceptions.TemplateLookupException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mako.exceptions的用法示例。


在下文中一共展示了exceptions.TemplateLookupException方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _check

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TemplateLookupException [as 别名]
def _check(self, uri, template):
        if template.filename is None:
            return template

        try:
            template_stat = os.stat(template.filename)
            if template.module._modified_time < template_stat[stat.ST_MTIME]:
                self._collection.pop(uri, None)
                return self._load(template.filename, uri)
            else:
                return template
        except OSError:
            self._collection.pop(uri, None)
            raise exceptions.TemplateLookupException(
                "Cant locate template for uri %r" % uri
            ) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:18,代码来源:lookup.py

示例2: _check

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TemplateLookupException [as 别名]
def _check(self, uri, template):
        if template.filename is None:
            return template

        try:
            template_stat = os.stat(template.filename)
            if template.module._modified_time < \
                    template_stat[stat.ST_MTIME]:
                self._collection.pop(uri, None)
                return self._load(template.filename, uri)
            else:
                return template
        except OSError:
            self._collection.pop(uri, None)
            raise exceptions.TemplateLookupException(
                "Cant locate template for uri %r" % uri) 
开发者ID:jpush,项目名称:jbox,代码行数:18,代码来源:lookup.py

示例3: test_dont_accept_relative_outside_of_root

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TemplateLookupException [as 别名]
def test_dont_accept_relative_outside_of_root(self):
        assert_raises_message(
            exceptions.TemplateLookupException,
            'Template uri "../../foo.html" is invalid - it '
            "cannot be relative outside of the root path",
            Template,
            "test",
            uri="../../foo.html",
        )

        assert_raises_message(
            exceptions.TemplateLookupException,
            'Template uri "/../../foo.html" is invalid - it '
            "cannot be relative outside of the root path",
            Template,
            "test",
            uri="/../../foo.html",
        )

        # normalizes in the root is OK
        t = Template("test", uri="foo/bar/../../foo.html")
        eq_(t.uri, "foo/bar/../../foo.html") 
开发者ID:sqlalchemy,项目名称:mako,代码行数:24,代码来源:test_template.py

示例4: test_dont_accept_relative_outside_of_root

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TemplateLookupException [as 别名]
def test_dont_accept_relative_outside_of_root(self):
        """test the mechanics of an include where
        the include goes outside of the path"""
        tl = lookup.TemplateLookup(directories=[os.path.join(template_base, "subdir")])
        index = tl.get_template("index.html")

        ctx = runtime.Context(FastEncodingBuffer())
        ctx._with_template=index

        assert_raises_message(
            exceptions.TemplateLookupException,
           "Template uri \"../index.html\" is invalid - it "
            "cannot be relative outside of the root path",
            runtime._lookup_template, ctx, "../index.html", index.uri
        )

        assert_raises_message(
            exceptions.TemplateLookupException,
           "Template uri \"../othersubdir/foo.html\" is invalid - it "
            "cannot be relative outside of the root path",
            runtime._lookup_template, ctx, "../othersubdir/foo.html", index.uri
        )

        # this is OK since the .. cancels out
        t = runtime._lookup_template(ctx, "foo/../index.html", index.uri) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:27,代码来源:test_lookup.py

示例5: test_dont_accept_relative_outside_of_root

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TemplateLookupException [as 别名]
def test_dont_accept_relative_outside_of_root(self):
        assert_raises_message(
            exceptions.TemplateLookupException,
            "Template uri \"../../foo.html\" is invalid - it "
            "cannot be relative outside of the root path",
            Template, "test", uri="../../foo.html",
        )

        assert_raises_message(
            exceptions.TemplateLookupException,
            "Template uri \"/../../foo.html\" is invalid - it "
            "cannot be relative outside of the root path",
            Template, "test", uri="/../../foo.html",
        )

        # normalizes in the root is OK
        t = Template("test", uri="foo/bar/../../foo.html")
        eq_(t.uri, "foo/bar/../../foo.html") 
开发者ID:jhpyle,项目名称:docassemble,代码行数:20,代码来源:test_template.py

示例6: _check

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TemplateLookupException [as 别名]
def _check(self, uri, template):
        if template.filename is None:
            return template

        try:
            template_stat = os.stat(template.filename)
            if template.module._modified_time < \
                        template_stat[stat.ST_MTIME]:
                self._collection.pop(uri, None)
                return self._load(template.filename, uri)
            else:
                return template
        except OSError:
            self._collection.pop(uri, None)
            raise exceptions.TemplateLookupException(
                                "Cant locate template for uri %r" % uri) 
开发者ID:fboender,项目名称:ansible-cmdb,代码行数:18,代码来源:lookup.py

示例7: has_template

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TemplateLookupException [as 别名]
def has_template(self, uri):
        """Return ``True`` if this :class:`.TemplateLookup` is
        capable of returning a :class:`.Template` object for the
        given ``uri``.

        :param uri: String URI of the template to be resolved.

        """
        try:
            self.get_template(uri)
            return True
        except exceptions.TemplateLookupException:
            return False 
开发者ID:remg427,项目名称:misp42splunk,代码行数:15,代码来源:lookup.py

示例8: get_template

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TemplateLookupException [as 别名]
def get_template(self, uri, relativeto=None):
        """Return a :class:`.Template` object corresponding to the given
        ``uri``.

        The default implementation raises
        :class:`.NotImplementedError`. Implementations should
        raise :class:`.TemplateLookupException` if the given ``uri``
        cannot be resolved.

        :param uri: String URI of the template to be resolved.
        :param relativeto: if present, the given ``uri`` is assumed to
         be relative to this URI.

        """
        raise NotImplementedError() 
开发者ID:remg427,项目名称:misp42splunk,代码行数:17,代码来源:lookup.py

示例9: _lookup_template

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TemplateLookupException [as 别名]
def _lookup_template(context, uri, relativeto):
    lookup = context._with_template.lookup
    if lookup is None:
        raise exceptions.TemplateLookupException(
            "Template '%s' has no TemplateLookup associated"
            % context._with_template.uri
        )
    uri = lookup.adjust_uri(uri, relativeto)
    try:
        return lookup.get_template(uri)
    except exceptions.TopLevelLookupException:
        raise exceptions.TemplateLookupException(str(compat.exception_as())) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:14,代码来源:runtime.py

示例10: _lookup_template

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TemplateLookupException [as 别名]
def _lookup_template(context, uri, relativeto):
    lookup = context._with_template.lookup
    if lookup is None:
        raise exceptions.TemplateLookupException(
            "Template '%s' has no TemplateLookup associated" %
            context._with_template.uri)
    uri = lookup.adjust_uri(uri, relativeto)
    try:
        return lookup.get_template(uri)
    except exceptions.TopLevelLookupException:
        raise exceptions.TemplateLookupException(str(compat.exception_as())) 
开发者ID:jpush,项目名称:jbox,代码行数:13,代码来源:runtime.py

示例11: render_string

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TemplateLookupException [as 别名]
def render_string(template_name, request, context, *, app_key):
    lookup = request.app.get(app_key)

    if lookup is None:
        raise web.HTTPInternalServerError(
            text=("Template engine is not initialized, "
                  "call aiohttp_mako.setup(app_key={}) first"
                  "".format(app_key)))
    try:
        template = lookup.get_template(template_name)
    except TemplateLookupException as e:
        raise web.HTTPInternalServerError(
            text="Template '{}' not found".format(template_name)) from e
    if not isinstance(context, Mapping):
        raise web.HTTPInternalServerError(
            text="context should be mapping, not {}".format(type(context)))
    if request.get(REQUEST_CONTEXT_KEY):
        context = dict(request[REQUEST_CONTEXT_KEY], **context)
    try:
        text = template.render_unicode(**context)
    except Exception:  # pragma: no cover
        exc_info = sys.exc_info()
        errtext = text_error_template().render(
            error=exc_info[1],
            traceback=exc_info[2])
        exc = MakoRenderingException(errtext).with_traceback(exc_info[2])
        raise exc

    return text 
开发者ID:aio-libs,项目名称:aiohttp-mako,代码行数:31,代码来源:__init__.py


注:本文中的mako.exceptions.TemplateLookupException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。