本文整理汇总了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
)
示例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)
示例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")
示例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)
示例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")
示例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)
示例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
示例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()
示例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()))
示例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()))
示例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