当前位置: 首页>>代码示例>>Python>>正文


Python jinja2.Undefined方法代码示例

本文整理汇总了Python中jinja2.Undefined方法的典型用法代码示例。如果您正苦于以下问题:Python jinja2.Undefined方法的具体用法?Python jinja2.Undefined怎么用?Python jinja2.Undefined使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jinja2的用法示例。


在下文中一共展示了jinja2.Undefined方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Undefined [as 别名]
def __init__(self, params):
        params = params.copy()
        options = params.pop('OPTIONS').copy()
        super().__init__(params)

        self.context_processors = options.pop('context_processors', [])

        environment = options.pop('environment', 'jinja2.Environment')
        environment_cls = import_string(environment)

        if 'loader' not in options:
            options['loader'] = jinja2.FileSystemLoader(self.template_dirs)
        options.setdefault('autoescape', True)
        options.setdefault('auto_reload', settings.DEBUG)
        options.setdefault('undefined',
                           jinja2.DebugUndefined if settings.DEBUG else jinja2.Undefined)

        self.env = environment_cls(**options) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:20,代码来源:jinja2.py

示例2: xproto_fol_to_python_test

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Undefined [as 别名]
def xproto_fol_to_python_test(policy, fol, model, tag=None):
    if isinstance(fol, jinja2.Undefined):
        raise Exception("Could not find policy:", policy)

    f2p = FOL2Python()
    fol_reduced = f2p.hoist_outer(fol)

    if fol_reduced in ["True", "False"] and fol != fol_reduced:
        raise TrivialPolicy(
            "Policy %(name)s trivially reduces to %(reduced)s."
            "If this is what you want, replace its contents with %(reduced)s"
            % {"name": policy, "reduced": fol_reduced}
        )

    a = f2p.gen_test_function(fol_reduced, policy, tag="security_check")

    return astunparse.unparse(a) 
开发者ID:open-cloud,项目名称:xos,代码行数:19,代码来源:fol2.py

示例3: xproto_fol_to_python_validator

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Undefined [as 别名]
def xproto_fol_to_python_validator(policy, fol, model, message, tag=None):
    if isinstance(fol, jinja2.Undefined):
        raise Exception("Could not find policy:", policy)

    f2p = FOL2Python()
    fol_reduced = f2p.hoist_outer(fol)

    if fol_reduced in ["True", "False"] and fol != fol_reduced:
        raise TrivialPolicy(
            "Policy %(name)s trivially reduces to %(reduced)s."
            "If this is what you want, replace its contents with %(reduced)s"
            % {"name": policy, "reduced": fol_reduced}
        )

    a = f2p.gen_validation_function(fol_reduced, policy, message, tag="validator")

    return astunparse.unparse(a) 
开发者ID:open-cloud,项目名称:xos,代码行数:19,代码来源:fol2.py

示例4: __init__

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Undefined [as 别名]
def __init__(self, params):
        params = params.copy()
        options = params.pop('OPTIONS').copy()
        super(Jinja2, self).__init__(params)

        self.context_processors = options.pop('context_processors', [])

        environment = options.pop('environment', 'jinja2.Environment')
        environment_cls = import_string(environment)

        if 'loader' not in options:
            options['loader'] = jinja2.FileSystemLoader(self.template_dirs)
        options.setdefault('autoescape', True)
        options.setdefault('auto_reload', settings.DEBUG)
        options.setdefault('undefined',
                           jinja2.DebugUndefined if settings.DEBUG else jinja2.Undefined)

        self.env = environment_cls(**options) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:20,代码来源:jinja2.py

示例5: customizable

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Undefined [as 别名]
def customizable(context, val_list, call_type):
    # NOTE(mgoddard): Don't try to customise undefined values. There are cases
    # where this might happen, for example using a generic template overrides
    # file for building multiple image install types and/or distros, where
    # variables are not defined in every case.
    if isinstance(val_list, Undefined):
        return val_list
    name = context['image_name'].replace("-", "_") + "_" + call_type + "_"
    if name + "override" in context:
        return context[name + "override"]
    if name + "append" in context:
        val_list.extend(context[name + "append"])
    if name + "remove" in context:
        for removal in context[name + "remove"]:
            if removal in val_list:
                val_list.remove(removal)
    return val_list 
开发者ID:openstack,项目名称:kolla,代码行数:19,代码来源:filters.py

示例6: get_jinja_environment

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Undefined [as 别名]
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

    undefined = jinja2.Undefined if allow_undefined else jinja2.StrictUndefined
    env = jinja2.Environment(  # 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 
开发者ID:StackStorm,项目名称:st2,代码行数:23,代码来源:jinja.py

示例7: load_jinja

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Undefined [as 别名]
def load_jinja(
        path, tests, filters, classes, mode,
        trim_blocks, lstrip_blocks, keep_trailing_newline):
    from jinja2.defaults import BLOCK_START_STRING, BLOCK_END_STRING, \
        VARIABLE_START_STRING, VARIABLE_END_STRING, \
        COMMENT_START_STRING, COMMENT_END_STRING, \
        LINE_STATEMENT_PREFIX, LINE_COMMENT_PREFIX, \
        NEWLINE_SEQUENCE

    undefined = {
        'pedantic': jinja.StrictUndefined,
        'debug': jinja.DebugUndefined,
        None: jinja.Undefined,
    }

    env = jinja.Environment(
        block_start_string=BLOCK_START_STRING,
        block_end_string=BLOCK_END_STRING,
        variable_start_string=VARIABLE_START_STRING,
        variable_end_string=VARIABLE_END_STRING,
        comment_start_string=COMMENT_START_STRING,
        comment_end_string=COMMENT_END_STRING,
        line_statement_prefix=LINE_STATEMENT_PREFIX,
        line_comment_prefix=LINE_COMMENT_PREFIX,
        trim_blocks=trim_blocks,
        lstrip_blocks=lstrip_blocks,
        newline_sequence=NEWLINE_SEQUENCE,
        keep_trailing_newline=keep_trailing_newline,
        extensions=classes,
        undefined=undefined[mode],
        loader=jinja.FileSystemLoader(path)
    )
    env.tests.update(tests)
    env.filters.update(filters)
    return env 
开发者ID:kblomqvist,项目名称:yasha,代码行数:37,代码来源:yasha.py

示例8: __init__

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Undefined [as 别名]
def __init__(self, params):
        params = params.copy()
        options = params.pop('OPTIONS').copy()
        super(Jinja2, self).__init__(params)

        environment = options.pop('environment', 'jinja2.Environment')
        environment_cls = import_string(environment)

        options.setdefault('autoescape', True)
        options.setdefault('loader', jinja2.FileSystemLoader(self.template_dirs))
        options.setdefault('auto_reload', settings.DEBUG)
        options.setdefault('undefined',
                           jinja2.DebugUndefined if settings.DEBUG else jinja2.Undefined)

        self.env = environment_cls(**options) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:17,代码来源:jinja2.py

示例9: _j_getenv

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Undefined [as 别名]
def _j_getenv(x):
    if isinstance(x, Undefined):
        x = x._undefined_name
    return os.getenv(x, '') 
开发者ID:intake,项目名称:intake,代码行数:6,代码来源:utils.py

示例10: _j_getshell

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Undefined [as 别名]
def _j_getshell(x):
    if isinstance(x, Undefined):
        x = x._undefined_name
    try:
        return subprocess.check_output(x).decode()
    except (IOError, OSError):
        return "" 
开发者ID:intake,项目名称:intake,代码行数:9,代码来源:utils.py

示例11: _j_passthrough

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Undefined [as 别名]
def _j_passthrough(x, funcname):
    if isinstance(x, Undefined):
        x = x._undefined_name
    return "{{%s(%s)}}" % (funcname, x) 
开发者ID:intake,项目名称:intake,代码行数:6,代码来源:utils.py

示例12: js_filter

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Undefined [as 别名]
def js_filter(val):
    """Jinja2 filter function 'js' produces JSONified string of the value, without surrounding quotes"""
    if val is None or isinstance(val, jinja2.Undefined):
        return "null"
    js = json_filter(val)
    return js[1:-1] 
开发者ID:ibmresilient,项目名称:resilient-python-api,代码行数:8,代码来源:template_functions.py

示例13: json_filter

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Undefined [as 别名]
def json_filter(val, indent=0):
    """Jinja2 filter function 'json' produces JSONified string of the value"""
    if val is None or isinstance(val, jinja2.Undefined):
        return "null"
    return json.dumps(val, indent=indent, sort_keys=True) 
开发者ID:ibmresilient,项目名称:resilient-python-api,代码行数:7,代码来源:template_functions.py

示例14: html_filter

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Undefined [as 别名]
def html_filter(val):
    """Jinja2 filter function 'html' produces HTML-encoded string of the value"""
    if isinstance(val, jinja2.Undefined):
        return "[undefined]"
    return html_escape(val) 
开发者ID:ibmresilient,项目名称:resilient-python-api,代码行数:7,代码来源:template_functions.py

示例15: url_filter

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import Undefined [as 别名]
def url_filter(val):
    """Jinja2 filter function 'url' produces URL-encoded string of the value"""
    if isinstance(val, jinja2.Undefined):
        return "[undefined]"
    return urllib.quote(str(val)) 
开发者ID:ibmresilient,项目名称:resilient-python-api,代码行数:7,代码来源:template_functions.py


注:本文中的jinja2.Undefined方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。