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