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


Python nodes.If方法代码示例

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


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

示例1: parse_if

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import If [as 别名]
def parse_if(self):
        """Parse an if construct."""
        node = result = nodes.If(lineno=self.stream.expect('name:if').lineno)
        while 1:
            node.test = self.parse_tuple(with_condexpr=False)
            node.body = self.parse_statements(('name:elif', 'name:else',
                                               'name:endif'))
            node.elif_ = []
            node.else_ = []
            token = next(self.stream)
            if token.test('name:elif'):
                node = nodes.If(lineno=self.stream.current.lineno)
                result.elif_.append(node)
                continue
            elif token.test('name:else'):
                result.else_ = self.parse_statements(('name:endif',),
                                                     drop_needle=True)
            break
        return result 
开发者ID:remg427,项目名称:misp42splunk,代码行数:21,代码来源:parser.py

示例2: parse_if

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import If [as 别名]
def parse_if(self):
        """Parse an if construct."""
        node = result = nodes.If(lineno=self.stream.expect('name:if').lineno)
        while 1:
            node.test = self.parse_tuple(with_condexpr=False)
            node.body = self.parse_statements(('name:elif', 'name:else',
                                               'name:endif'))
            token = next(self.stream)
            if token.test('name:elif'):
                new_node = nodes.If(lineno=self.stream.current.lineno)
                node.else_ = [new_node]
                node = new_node
                continue
            elif token.test('name:else'):
                node.else_ = self.parse_statements(('name:endif',),
                                                   drop_needle=True)
            else:
                node.else_ = []
            break
        return result 
开发者ID:jpush,项目名称:jbox,代码行数:22,代码来源:parser.py

示例3: parse_assign_target

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import If [as 别名]
def parse_assign_target(self, with_tuple=True, name_only=False,
                            extra_end_rules=None):
        """Parse an assignment target.  As Jinja2 allows assignments to
        tuples, this function can parse all allowed assignment targets.  Per
        default assignments to tuples are parsed, that can be disable however
        by setting `with_tuple` to `False`.  If only assignments to names are
        wanted `name_only` can be set to `True`.  The `extra_end_rules`
        parameter is forwarded to the tuple parsing function.
        """
        if name_only:
            token = self.stream.expect('name')
            target = nodes.Name(token.value, 'store', lineno=token.lineno)
        else:
            if with_tuple:
                target = self.parse_tuple(simplified=True,
                                          extra_end_rules=extra_end_rules)
            else:
                target = self.parse_primary()
            target.set_ctx('store')
        if not target.can_assign():
            self.fail('can\'t assign to %r' % target.__class__.
                      __name__.lower(), target.lineno)
        return target 
开发者ID:jpush,项目名称:jbox,代码行数:25,代码来源:parser.py

示例4: parse_statements

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import If [as 别名]
def parse_statements(self, end_tokens, drop_needle=False):
        """Parse multiple statements into a list until one of the end tokens
        is reached.  This is used to parse the body of statements as it also
        parses template data if appropriate.  The parser checks first if the
        current token is a colon and skips it if there is one.  Then it checks
        for the block end and parses until if one of the `end_tokens` is
        reached.  Per default the active token in the stream at the end of
        the call is the matched end token.  If this is not wanted `drop_needle`
        can be set to `True` and the end token is removed.
        """
        # the first token may be a colon for python compatibility
        self.stream.skip_if('colon')

        # in the future it would be possible to add whole code sections
        # by adding some sort of end of statement token and parsing those here.
        self.stream.expect('block_end')
        result = self.subparse(end_tokens)

        # we reached the end of the template too early, the subparser
        # does not check for this, so we do that now
        if self.stream.current.type == 'eof':
            self.fail_eof(end_tokens)

        if drop_needle:
            next(self.stream)
        return result 
开发者ID:remg427,项目名称:misp42splunk,代码行数:28,代码来源:parser.py

示例5: parse_assign_target

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import If [as 别名]
def parse_assign_target(self, with_tuple=True, name_only=False,
                            extra_end_rules=None, with_namespace=False):
        """Parse an assignment target.  As Jinja2 allows assignments to
        tuples, this function can parse all allowed assignment targets.  Per
        default assignments to tuples are parsed, that can be disable however
        by setting `with_tuple` to `False`.  If only assignments to names are
        wanted `name_only` can be set to `True`.  The `extra_end_rules`
        parameter is forwarded to the tuple parsing function.  If
        `with_namespace` is enabled, a namespace assignment may be parsed.
        """
        if with_namespace and self.stream.look().type == 'dot':
            token = self.stream.expect('name')
            next(self.stream)  # dot
            attr = self.stream.expect('name')
            target = nodes.NSRef(token.value, attr.value, lineno=token.lineno)
        elif name_only:
            token = self.stream.expect('name')
            target = nodes.Name(token.value, 'store', lineno=token.lineno)
        else:
            if with_tuple:
                target = self.parse_tuple(simplified=True,
                                          extra_end_rules=extra_end_rules)
            else:
                target = self.parse_primary()
            target.set_ctx('store')
        if not target.can_assign():
            self.fail('can\'t assign to %r' % target.__class__.
                      __name__.lower(), target.lineno)
        return target 
开发者ID:remg427,项目名称:misp42splunk,代码行数:31,代码来源:parser.py


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