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


Python nodes.Call方法代码示例

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


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

示例1: test_is_method_call

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Call [as 别名]
def test_is_method_call(self):
        node = self.env.parse('{{ foo() }}').find(nodes.Call)
        assert is_method_call(node, 'foo') is True
        assert is_method_call(node, 'bar') is False

        node = self.env.parse('{{ foo }}').find(nodes.Name)
        assert is_method_call(node, 'foo') is False

        node = nodes.Call()
        node.node = None
        assert is_method_call(node, 'foo') is False

        node = self.env.parse('{{ foo.bar.baz() }}').find(nodes.Call)
        assert is_method_call(node, 'baz') is True
        assert is_method_call(node, 'bar') is False
        assert is_method_call(node, 'foo') is False
        assert is_method_call(node, ('foo', 'bar', 'baz')) is True

        node = self.env.parse('{{ foo["bar"]() }}').find(nodes.Call)
        assert is_method_call(node, 'bar') is True 
开发者ID:jonbretman,项目名称:jinja-to-js,代码行数:22,代码来源:test_jinja_to_js.py

示例2: call_method

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Call [as 别名]
def call_method(self, name, args=None, kwargs=None, dyn_args=None,
                    dyn_kwargs=None, lineno=None):
        """Call a method of the extension.  This is a shortcut for
        :meth:`attr` + :class:`jinja2.nodes.Call`.
        """
        if args is None:
            args = []
        if kwargs is None:
            kwargs = []
        return nodes.Call(self.attr(name, lineno=lineno), args, kwargs,
                          dyn_args, dyn_kwargs, lineno=lineno) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:13,代码来源:ext.py

示例3: parse_call_block

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Call [as 别名]
def parse_call_block(self):
        node = nodes.CallBlock(lineno=next(self.stream).lineno)
        if self.stream.current.type == 'lparen':
            self.parse_signature(node)
        else:
            node.args = []
            node.defaults = []

        node.call = self.parse_expression()
        if not isinstance(node.call, nodes.Call):
            self.fail('expected call', node.lineno)
        node.body = self.parse_statements(('name:endcall',), drop_needle=True)
        return node 
开发者ID:remg427,项目名称:misp42splunk,代码行数:15,代码来源:parser.py

示例4: _parse_trans

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Call [as 别名]
def _parse_trans(self, parser, lineno):
        string = parser.stream.expect(lexer.TOKEN_STRING)
        string = nodes.Const(string.value, lineno=string.lineno)
        is_noop = False
        context = None
        as_var = None
        for token in iter(lambda: parser.stream.next_if(lexer.TOKEN_NAME), None):
            if token.value == 'noop' and not is_noop:
                if context is not None:
                    parser.fail("noop translation can't have context", lineno=token.lineno)
                is_noop = True
            elif token.value == 'context' and context is None:
                if is_noop:
                    parser.fail("noop translation can't have context", lineno=token.lineno)
                context = parser.stream.expect(lexer.TOKEN_STRING)
                context = nodes.Const(context.value, lineno=context.lineno)
            elif token.value == 'as' and as_var is None:
                as_var = parser.stream.expect(lexer.TOKEN_NAME)
                as_var = nodes.Name(as_var.value, 'store', lineno=as_var.lineno)
            else:
                parser.fail("expected 'noop', 'context' or 'as'", lineno=token.lineno)
        if is_noop:
            output = string
        elif context is not None:
            func = nodes.Name('pgettext', 'load', lineno=lineno)
            output = nodes.Call(func, [context, string], [], None, None, lineno=lineno)
        else:
            func = nodes.Name('gettext', 'load')
            output = nodes.Call(func, [string], [], None, None, lineno=lineno)

        if as_var is None:
            return nodes.Output([output], lineno=lineno)
        else:
            return nodes.Assign(as_var, output, lineno=lineno) 
开发者ID:MoritzS,项目名称:jinja2-django-tags,代码行数:36,代码来源:extensions.py

示例5: is_method_call

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Call [as 别名]
def is_method_call(node, method_name):
    """
    Returns True if `node` is a method call for `method_name`. `method_name`
    can be either a string or an iterable of strings.
    """

    if not isinstance(node, nodes.Call):
        return False

    if isinstance(node.node, nodes.Getattr):
        # e.g. foo.bar()
        method = node.node.attr

    elif isinstance(node.node, nodes.Name):
        # e.g. bar()
        method = node.node.name

    elif isinstance(node.node, nodes.Getitem):
        # e.g. foo["bar"]()
        method = node.node.arg.value

    else:
        return False

    if isinstance(method_name, (list, tuple)):
        return method in method_name

    return method == method_name 
开发者ID:jonbretman,项目名称:jinja-to-js,代码行数:30,代码来源:__init__.py


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