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


Python jinja2.nodes方法代码示例

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


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

示例1: parse_include_block

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import nodes [as 别名]
def parse_include_block(self, parser):
        lineno = next(parser.stream).lineno

        args = [parser.parse_expression()]

        with_context = True
        if parser.stream.current.test_any('name:with', 'name:without') and parser.stream.look().test('name:context'):
            with_context = next(parser.stream).value == 'with'
            parser.stream.skip()

        if with_context:
            args.append(jinja2.nodes.ContextReference())
        else:
            # Actually we can just skip else branch because context arg default to None
            args.append(jinja2.nodes.Const(None))

        node = self.call_method('_include_block', args, lineno=lineno)
        return jinja2.nodes.Output([node], lineno=lineno) 
开发者ID:wagtail,项目名称:wagtail,代码行数:20,代码来源:jinja2tags.py

示例2: template_config_variables

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import nodes [as 别名]
def template_config_variables(template: str) -> typing.FrozenSet[str]:
    """Return the config variables used in the template."""
    unvisted_nodes = [environment.parse(template)]
    result = set()  # type: typing.Set[str]
    while unvisted_nodes:
        node = unvisted_nodes.pop()
        if not isinstance(node, jinja2.nodes.Getattr):
            unvisted_nodes.extend(node.iter_child_nodes())
            continue

        # List of attribute names in reverse order.
        # For example it's ['ab', 'c', 'd'] for 'conf.d.c.ab'.
        attrlist = []  # type: typing.List[str]
        while isinstance(node, jinja2.nodes.Getattr):
            attrlist.append(node.attr)  # type: ignore[attr-defined]
            node = node.node  # type: ignore[attr-defined]

        if isinstance(node, jinja2.nodes.Name):
            if node.name == 'conf':  # type: ignore[attr-defined]
                result.add('.'.join(reversed(attrlist)))
            # otherwise, the node is a Name node so it doesn't have any
            # child nodes
        else:
            unvisted_nodes.append(node)

    from qutebrowser.config import config
    for option in result:
        config.instance.ensure_has_opt(option)

    return frozenset(result) 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:32,代码来源:jinja.py

示例3: grok_filter_name

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import nodes [as 别名]
def grok_filter_name(element):
    """Extracts the name, which may be embedded, for a Jinja2
    filter node"""
    e_name = None
    if element.name == 'default':
        if isinstance(element.node, jinja2.nodes.Getattr):
            e_name = element.node.node.name
        else:
            e_name = element.node.name

    return e_name 
开发者ID:Autodesk,项目名称:aomi,代码行数:13,代码来源:template.py

示例4: grok_for_node

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import nodes [as 别名]
def grok_for_node(element, default_vars):
    """Properly parses a For loop element"""
    if isinstance(element.iter, jinja2.nodes.Filter):
        if element.iter.name == 'default' \
           and element.iter.node.name not in default_vars:
            default_vars.append(element.iter.node.name)

        default_vars = default_vars + grok_vars(element)

    return default_vars 
开发者ID:Autodesk,项目名称:aomi,代码行数:12,代码来源:template.py

示例5: grok_if_node

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import nodes [as 别名]
def grok_if_node(element, default_vars):
    """Properly parses a If element"""
    if isinstance(element.test, jinja2.nodes.Filter) and \
       element.test.name == 'default':
        default_vars.append(element.test.node.name)

    return default_vars + grok_vars(element) 
开发者ID:Autodesk,项目名称:aomi,代码行数:9,代码来源:template.py

示例6: grok_vars

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import nodes [as 别名]
def grok_vars(elements):
    """Returns a list of vars for which the value is being appropriately set
    This currently includes the default filter, for-based iterators,
    and the explicit use of set"""
    default_vars = []
    iterbody = None
    if hasattr(elements, 'body'):
        iterbody = elements.body
    elif hasattr(elements, 'nodes'):
        iterbody = elements.nodes

    for element in iterbody:
        if isinstance(element, jinja2.nodes.Output):
            default_vars = default_vars + grok_vars(element)
        elif isinstance(element, jinja2.nodes.Filter):
            e_name = grok_filter_name(element)
            if e_name not in default_vars:
                default_vars.append(e_name)
        elif isinstance(element, jinja2.nodes.For):
            default_vars = grok_for_node(element, default_vars)
        elif isinstance(element, jinja2.nodes.If):
            default_vars = grok_if_node(element, default_vars)
        elif isinstance(element, jinja2.nodes.Assign):
            default_vars.append(element.target.name)
        elif isinstance(element, jinja2.nodes.FromImport):
            for from_var in element.names:
                default_vars.append(from_var)

    return default_vars 
开发者ID:Autodesk,项目名称:aomi,代码行数:31,代码来源:template.py

示例7: render_jinja_node

# 需要导入模块: import jinja2 [as 别名]
# 或者: from jinja2 import nodes [as 别名]
def render_jinja_node(node, context, env):
    template_node = jinja2.nodes.Template([node])
    code = env.compile(template_node)
    template = jinja2.environment.Template.from_code(env, code, context)
    return template.render() 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:7,代码来源:compress.py


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