def render_mako_tmpl(tmplstr, context, tmplpath=None): import mako.exceptions # pylint: disable=no-name-in-module from mako.template import Template # pylint: disable=no-name-in-module from salt.utils.mako import SaltMakoTemplateLookup saltenv = context["saltenv"] lookup = None if not saltenv: if tmplpath: # i.e., the template is from a file outside the state tree from mako.lookup import TemplateLookup # pylint: disable=no-name-in-module lookup = TemplateLookup(directories=[os.path.dirname(tmplpath)]) else: lookup = SaltMakoTemplateLookup( context["opts"], saltenv, pillar_rend=context.get("_pillar_rend", False) ) try: return Template( tmplstr, strict_undefined=True, uri=context["sls"].replace(".", "/") if "sls" in context else None, lookup=lookup, ).render(**context) except Exception: # pylint: disable=broad-except raise SaltRenderError(mako.exceptions.text_error_template().render())
def render_mako_tmpl(tmplstr, context, tmplpath=None): import mako.exceptions from mako.template import Template from salt.utils.mako import SaltMakoTemplateLookup saltenv = context['saltenv'] lookup = None if not saltenv: if tmplpath: # i.e., the template is from a file outside the state tree from mako.lookup import TemplateLookup lookup = TemplateLookup(directories=[os.path.dirname(tmplpath)]) else: lookup = SaltMakoTemplateLookup(context['opts'], saltenv, pillar_rend=context.get( '_pillar_rend', False)) try: return Template( tmplstr, strict_undefined=True, uri=context['sls'].replace('.', '/') if 'sls' in context else None, lookup=lookup).render(**context) except: raise SaltRenderError(mako.exceptions.text_error_template().render())
def render_mako_tmpl(tmplstr, context, tmplpath=None): """ Render a Mako template. :param str tmplstr: A string containing the source to be rendered. :param dict context: Any additional context data used by the renderer. :param str tmplpath: Base path from which ``tmplstr`` may load additional template files. :returns str: The string rendered by the template. """ import mako.exceptions # pylint: disable=no-name-in-module from mako.template import Template # pylint: disable=no-name-in-module from salt.utils.mako import SaltMakoTemplateLookup saltenv = context["saltenv"] lookup = None if not saltenv: if tmplpath: # i.e., the template is from a file outside the state tree from mako.lookup import TemplateLookup # pylint: disable=no-name-in-module lookup = TemplateLookup(directories=[os.path.dirname(tmplpath)]) else: lookup = SaltMakoTemplateLookup(context["opts"], saltenv, pillar_rend=context.get( "_pillar_rend", False)) try: return Template( tmplstr, strict_undefined=True, uri=context["sls"].replace(".", "/") if "sls" in context else None, lookup=lookup, ).render(**context) except Exception: # pylint: disable=broad-except raise SaltRenderError(mako.exceptions.text_error_template().render())