Python mako.exceptions.TopLevelLookupException() Examples
The following are 27
code examples of mako.exceptions.TopLevelLookupException().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
mako.exceptions
, or try the search function
.
Example #1
Source File: lookup.py From ansible-cmdb with GNU General Public License v3.0 | 6 votes |
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)
Example #2
Source File: runtime.py From mako with MIT License | 5 votes |
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()))
Example #3
Source File: runtime.py From android_universal with MIT License | 5 votes |
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()))
Example #4
Source File: lookup.py From android_universal with MIT License | 5 votes |
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)
Example #5
Source File: runtime.py From ansible-cmdb with GNU General Public License v3.0 | 5 votes |
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()))
Example #6
Source File: runtime.py From Tautulli with GNU General Public License v3.0 | 5 votes |
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()))
Example #7
Source File: lookup.py From Tautulli with GNU General Public License v3.0 | 5 votes |
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 )
Example #8
Source File: test_lookup.py From docassemble with MIT License | 5 votes |
def test_directory_lookup(self): """test that hitting an existent directory still raises LookupError.""" self.assertRaises(exceptions.TopLevelLookupException, tl.get_template, "/subdir" )
Example #9
Source File: run_wsgi.py From docassemble with MIT License | 5 votes |
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)]
Example #10
Source File: __init__.py From pdoc with GNU Affero General Public License v3.0 | 5 votes |
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
Example #11
Source File: runtime.py From SA-ctf_scoreboard with Creative Commons Zero v1.0 Universal | 5 votes |
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()))
Example #12
Source File: lookup.py From SA-ctf_scoreboard with Creative Commons Zero v1.0 Universal | 5 votes |
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)
Example #13
Source File: dev.py From ANALYSE with GNU Affero General Public License v3.0 | 5 votes |
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))
Example #14
Source File: test_lookup.py From mako with MIT License | 5 votes |
def test_directory_lookup(self): """test that hitting an existent directory still raises LookupError.""" self.assertRaises( exceptions.TopLevelLookupException, tl.get_template, "/subdir" )
Example #15
Source File: lookup.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
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 )
Example #16
Source File: lookup.py From mako with MIT License | 5 votes |
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 )
Example #17
Source File: run_wsgi.py From mako with MIT License | 5 votes |
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)]
Example #18
Source File: lookup.py From teleport with Apache License 2.0 | 5 votes |
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 )
Example #19
Source File: runtime.py From teleport with Apache License 2.0 | 5 votes |
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()))
Example #20
Source File: lookup.py From teleport with Apache License 2.0 | 5 votes |
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 )
Example #21
Source File: runtime.py From teleport with Apache License 2.0 | 5 votes |
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()))
Example #22
Source File: lookup.py From teleport with Apache License 2.0 | 5 votes |
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)
Example #23
Source File: runtime.py From jbox with MIT License | 5 votes |
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()))
Example #24
Source File: lookup.py From jbox with MIT License | 5 votes |
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)
Example #25
Source File: runtime.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
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()))
Example #26
Source File: lookup.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
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 )
Example #27
Source File: runtime.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
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()))