當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。