def get_jinja_environment(allow_undefined=False, trim_blocks=True, lstrip_blocks=True):
    """
    jinja2.Environment object that is setup with right behaviors and custom filters.

    :param strict_undefined: If should allow undefined variables in templates
    :type strict_undefined: ``bool``

    """
    # Late import to avoid very expensive in-direct import (~1 second) when this function
    # is not called / used
    import jinja2
    import jinja2.sandbox

    undefined = jinja2.Undefined if allow_undefined else jinja2.StrictUndefined
    env = jinja2.sandbox.SandboxedEnvironment(  # nosec
        undefined=undefined, trim_blocks=trim_blocks, lstrip_blocks=lstrip_blocks
    )
    env.filters.update(get_filters())
    env.tests["in"] = lambda item, list: item in list
    return env

    jinja2.Environment object that is setup with right behaviors and custom filters.

    :param strict_undefined: If should allow undefined variables in templates
    :type strict_undefined: ``bool``

    
st2common/st2common/util/jinja.py