本文整理汇总了Python中mako.exceptions.TopLevelLookupException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.TopLevelLookupException方法的具体用法?Python exceptions.TopLevelLookupException怎么用?Python exceptions.TopLevelLookupException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mako.exceptions
的用法示例。
在下文中一共展示了exceptions.TopLevelLookupException方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_template
# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TopLevelLookupException [as 别名]
def get_template(self, uri):
"""Return a :class:`.Template` object corresponding to the given
``uri``.
.. note:: The ``relativeto`` argument is not supported here at the moment.
"""
try:
if self.filesystem_checks:
return self._check(uri, self._collection[uri])
else:
return self._collection[uri]
except KeyError:
u = re.sub(r'^\/+', '', uri)
for dir in self.directories:
srcfile = posixpath.normpath(posixpath.join(dir, u))
if os.path.isfile(srcfile):
return self._load(srcfile, uri)
else:
raise exceptions.TopLevelLookupException(
"Cant locate template for uri %r" % uri)
示例2: get_template
# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TopLevelLookupException [as 别名]
def get_template(self, uri):
"""Return a :class:`.Template` object corresponding to the given
``uri``.
.. note:: The ``relativeto`` argument is not supported here at
the moment.
"""
try:
if self.filesystem_checks:
return self._check(uri, self._collection[uri])
else:
return self._collection[uri]
except KeyError:
u = re.sub(r"^\/+", "", uri)
for dir_ in self.directories:
# make sure the path seperators are posix - os.altsep is empty
# on POSIX and cannot be used.
dir_ = dir_.replace(os.path.sep, posixpath.sep)
srcfile = posixpath.normpath(posixpath.join(dir_, u))
if os.path.isfile(srcfile):
return self._load(srcfile, uri)
else:
raise exceptions.TopLevelLookupException(
"Cant locate template for uri %r" % uri
)
示例3: _lookup_template
# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TopLevelLookupException [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()))
示例4: get_template
# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TopLevelLookupException [as 别名]
def get_template(self, uri):
"""Return a :class:`.Template` object corresponding to the given
``uri``.
.. note:: The ``relativeto`` argument is not supported here at
the moment.
"""
try:
if self.filesystem_checks:
return self._check(uri, self._collection[uri])
else:
return self._collection[uri]
except KeyError:
u = re.sub(r'^\/+', '', uri)
for dir in self.directories:
# make sure the path seperators are posix - os.altsep is empty
# on POSIX and cannot be used.
dir = dir.replace(os.path.sep, posixpath.sep)
srcfile = posixpath.normpath(posixpath.join(dir, u))
if os.path.isfile(srcfile):
return self._load(srcfile, uri)
else:
raise exceptions.TopLevelLookupException(
"Cant locate template for uri %r" % uri)
示例5: _lookup_template
# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TopLevelLookupException [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()))
示例6: serve
# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TopLevelLookupException [as 别名]
def serve(environ, start_response):
"""serves requests using the WSGI callable interface."""
fieldstorage = cgi.FieldStorage(
fp = environ['wsgi.input'],
environ = environ,
keep_blank_values = True
)
d = dict([(k, getfield(fieldstorage[k])) for k in fieldstorage])
uri = environ.get('PATH_INFO', '/')
if not uri:
uri = '/index.html'
else:
uri = re.sub(r'^/$', '/index.html', uri)
if re.match(r'.*\.html$', uri):
try:
template = lookup.get_template(uri)
except exceptions.TopLevelLookupException:
start_response("404 Not Found", [])
return [str.encode("Cant find template '%s'" % uri)]
start_response("200 OK", [('Content-type','text/html')])
try:
return [template.render(**d)]
except:
return [exceptions.html_error_template().render()]
else:
u = re.sub(r'^\/+', '', uri)
filename = os.path.join(root, u)
if os.path.isfile(filename):
start_response("200 OK", [('Content-type',guess_type(uri))])
return [open(filename, 'rb').read()]
else:
start_response("404 Not Found", [])
return [str.encode("File not found: '%s'" % filename)]
示例7: test_directory_lookup
# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TopLevelLookupException [as 别名]
def test_directory_lookup(self):
"""test that hitting an existent directory still raises
LookupError."""
self.assertRaises(
exceptions.TopLevelLookupException, tl.get_template, "/subdir"
)
示例8: dev_show_template
# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TopLevelLookupException [as 别名]
def dev_show_template(request, template):
"""
Shows the specified template as an HTML page.
e.g. /template/ux/reference/container.html shows the template under ux/reference/container.html
Note: dynamic parameters can also be passed to the page.
e.g. /template/ux/reference/container.html?name=Foo
"""
try:
return render_to_response(template, request.GET.dict())
except TopLevelLookupException:
return HttpResponseNotFound("Couldn't find template {tpl}".format(tpl=template))
示例9: _render_template
# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TopLevelLookupException [as 别名]
def _render_template(template_name, **kwargs):
"""
Returns the Mako template with the given name. If the template
cannot be found, a nicer error message is displayed.
"""
# Apply config.mako configuration
MAKO_INTERNALS = Template('').module.__dict__.keys()
DEFAULT_CONFIG = path.join(path.dirname(__file__), 'templates', 'config.mako')
config = {}
for config_module in (Template(filename=DEFAULT_CONFIG).module,
tpl_lookup.get_template('/config.mako').module):
config.update((var, getattr(config_module, var, None))
for var in config_module.__dict__
if var not in MAKO_INTERNALS)
known_keys = (set(config)
| {'docformat'} # Feature. https://github.com/pdoc3/pdoc/issues/169
| {'module', 'modules', 'http_server', 'external_links'}) # deprecated
invalid_keys = {k: v for k, v in kwargs.items() if k not in known_keys}
if invalid_keys:
warn('Unknown configuration variables (not in config.mako): {}'.format(invalid_keys))
config.update(kwargs)
try:
t = tpl_lookup.get_template(template_name)
except TopLevelLookupException:
raise OSError(
"No template found at any of: {}".format(
', '.join(path.join(p, template_name.lstrip("/"))
for p in tpl_lookup.directories)))
try:
return t.render(**config).strip()
except Exception:
from mako import exceptions
print(exceptions.text_error_template().render(),
file=sys.stderr)
raise
示例10: test_directory_lookup
# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TopLevelLookupException [as 别名]
def test_directory_lookup(self):
"""test that hitting an existent directory still raises
LookupError."""
self.assertRaises(exceptions.TopLevelLookupException,
tl.get_template, "/subdir"
)
示例11: _lookup_template
# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import TopLevelLookupException [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()))