Beispiel #1
0
from mistral.expressions import base

LOG = logging.getLogger(__name__)

ANY_JINJA_REGEXP = "{{.*}}|{%.*%}"

JINJA_REGEXP = '({{(.*?)}})'
JINJA_BLOCK_REGEXP = '({%(.*?)%})'

JINJA_OPTS = {'undefined_to_none': False}

_environment = SandboxedEnvironment(undefined=jinja2.StrictUndefined,
                                    trim_blocks=True,
                                    lstrip_blocks=True)

_filters = base.get_custom_functions()

for name in _filters:
    _environment.filters[name] = _filters[name]


def get_jinja_context(data_context):
    new_ctx = {'_': data_context}

    _register_jinja_functions(new_ctx)

    if isinstance(data_context, dict):
        new_ctx['__env'] = data_context.get('__env')
        new_ctx['__execution'] = data_context.get('__execution')
        new_ctx['__task_execution'] = data_context.get('__task_execution')
Beispiel #2
0
def _register_jinja_functions(jinja_ctx):
    functions = base.get_custom_functions()

    for name in functions:
        jinja_ctx[name] = partial(functions[name], jinja_ctx['_'])
Beispiel #3
0
def _register_yaql_functions(yaql_ctx):
    functions = base.get_custom_functions()

    for name in functions:
        yaql_ctx.register_function(functions[name], name=name)