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


Python exceptions.TopLevelLookupException方法代码示例

本文整理汇总了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) 
开发者ID:fboender,项目名称:ansible-cmdb,代码行数:24,代码来源:lookup.py

示例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
                ) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:29,代码来源:lookup.py

示例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())) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:14,代码来源:runtime.py

示例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) 
开发者ID:jpush,项目名称:jbox,代码行数:28,代码来源:lookup.py

示例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())) 
开发者ID:jpush,项目名称:jbox,代码行数:13,代码来源:runtime.py

示例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)] 
开发者ID:sqlalchemy,项目名称:mako,代码行数:39,代码来源:run_wsgi.py

示例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"
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:9,代码来源:test_lookup.py

示例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)) 
开发者ID:jruiperezv,项目名称:ANALYSE,代码行数:14,代码来源:dev.py

示例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 
开发者ID:pdoc3,项目名称:pdoc,代码行数:38,代码来源:__init__.py

示例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"
        ) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:9,代码来源:test_lookup.py

示例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())) 
开发者ID:fboender,项目名称:ansible-cmdb,代码行数:13,代码来源:runtime.py


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