How to use the mako.exceptions function in Mako

To help you get started, we’ve selected a few Mako examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github grpc / grpc / tools / run_tests / report_utils.py View on Github external
'http2_cases': sorted_http2_cases,
          'resultset': resultset,
          'num_failures': num_failures,
          'cloud_to_prod': cloud_to_prod,
          'prod_servers': sorted_prod_servers,
          'http2_interop': http2_interop}

  html_report_out_dir = 'reports' 
  if not os.path.exists(html_report_out_dir):
    os.mkdir(html_report_out_dir) 
  html_file_path = os.path.join(html_report_out_dir, 'index.html')
  try:
    with open(html_file_path, 'w') as output_file:
      mytemplate.render_context(Context(output_file, **args))
  except:
    print(exceptions.text_error_template().render())
    raise
github sqlalchemy / mako / test / __init__.py View on Github external
def go(*arg, **kw):
        from mako import exceptions

        exceptions._install_fallback()
        try:
            return fn(*arg, **kw)
        finally:
            exceptions._install_highlighting()
github tiadobatima / gpwm / src / gpwm / renderers.py View on Github external
# troubleshoot pesky templates
    mako_template = mako.template.Template(
        template_body,
        strict_undefined=False
    )
    parameters["utils"] = gpwm.utils
#    parameters["get_stack_output"] = get_stack_output
#    parameters["get_stack_resource"] = get_stack_resource
#    parameters["call_aws"] = call_aws
    try:
        rendered_mako_template = mako_template.render(**parameters)
    # Weird Mako exception handling:
    # http://docs.makotemplates.org/en/latest/usage.html#handling-exceptions
    except Exception:
        raise SystemExit(
            mako.exceptions.text_error_template().render()
        )

    # Ignoring yaml tags unknown to this script, because one might want to use
    # the providers tags like !Ref, !Sub, etc in their templates
    try:
        template = yaml.load(rendered_mako_template)
    except yaml.constructor.ConstructorError as exc:
        if "could not determine a constructor for the tag" not in exc.problem:
            raise exc
    # Automatically adds and merges outputs for every resource in the
    # template - outputs are automatically exported.
    # An existing output in the template will not be overriden by an
    # automatic output.
    outputs = {
        k: {
            "Value": {"Ref": k},
github openkratio / proyecto-colibri / application.py View on Github external
def render_template(filename):
    if os.path.isdir(os.path.join(template_root, filename)):
        filename = os.path.join(filename, 'index.html')
    else:
        filename = '%s.html' % filename
    if any(filename.lstrip('/').startswith(p) for p in blacklist_templates):
        raise httpclient.HTTPError(404)
    try:
        return template_lookup.get_template(filename).render()
    except exceptions.TopLevelLookupException:
        raise httpclient.HTTPError(404)
github rembo10 / headphones / lib / mako / runtime.py View on Github external
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()))
github sqlalchemy / sqlalchemy / doc / build / genhtml.py View on Github external
outfile = file(outname, 'w')
    print infile, '->', outname
    t = lookup.get_template(infile)
    outfile.write(t.render(attributes={}))

for filename in files:
    try:
        genfile(filename, os.path.join(os.getcwd(), '../', filename + ".html"))
    except:
        print exceptions.text_error_template().render()

for filename in doc_files:
    try:
        genfile(filename, os.path.join(os.getcwd(), '../', os.path.basename(filename) + ".html"))
    except:
        print exceptions.text_error_template().render()
github kakwa / ldapcherry / ldapcherry / __init__.py View on Github external
roles=self.roles.flatten,
                graph=self.roles.graph,
                graph_js=graph_js,
                roles_js=roles_js,
                current_roles=None,
                )
            return self.temp['adduser.tmpl'].render(
                form=form,
                roles=roles,
                is_admin=is_admin,
                custom_js=self.custom_js,
                notifications=self._empty_notification(),
                )
        except NameError:
            raise TemplateRenderError(
                    exceptions.text_error_template().render()
                    )
github EzoxSystems / gae-skeleton / skel / mako / lexer.py View on Github external
if self.match_control_line():
                continue
            if self.match_comment():
                continue
            if self.match_tag_start(): 
                continue
            if self.match_tag_end():
                continue
            if self.match_python_block():
                continue
            if self.match_text(): 
                continue
 
            if self.match_position > self.textlength: 
                break
            raise exceptions.CompileException("assertion failed")
 
        if len(self.tag):
            raise exceptions.SyntaxException("Unclosed tag: <%%%s>" % 
                                                self.tag[-1].keyword, 
                                                **self.exception_kwargs)
        if len(self.control_line):
            raise exceptions.SyntaxException(
                                      "Unterminated control keyword: '%s'" %
                                      self.control_line[-1].keyword, 
                                      self.text, 
                                      self.control_line[-1].lineno,
                                      self.control_line[-1].pos, self.filename)
        return self.template
github WhiteMagic / JoystickGremlin / mako / lookup.py View on Github external
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