當前位置: 首頁>>代碼示例>>Python>>正文


Python nodes.Name方法代碼示例

本文整理匯總了Python中jinja2.nodes.Name方法的典型用法代碼示例。如果您正苦於以下問題:Python nodes.Name方法的具體用法?Python nodes.Name怎麽用?Python nodes.Name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在jinja2.nodes的用法示例。


在下文中一共展示了nodes.Name方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: parse_assign_target

# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Name [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

示例2: _process_name

# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Name [as 別名]
def _process_name(self, node, **kwargs):
        """
        Processes a `Name` node. Some examples of `Name` nodes:
            {{ foo }} -> 'foo' is a Name
            {% if foo }} -> 'foo' is a Name
        """

        with self._interpolation():
            with self._python_bool_wrapper(**kwargs):

                if node.name not in self.stored_names and node.ctx != 'store':
                    self.output.write(self.context_name)
                    self.output.write('.')

                if node.ctx == 'store':
                    self.stored_names.add(node.name)

                self.output.write(node.name) 
開發者ID:jonbretman,項目名稱:jinja-to-js,代碼行數:20,代碼來源:__init__.py

示例3: test_is_method_call

# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Name [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

示例4: parse_assign_target

# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Name [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

示例5: parse_primary

# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Name [as 別名]
def parse_primary(self):
        token = self.stream.current
        if token.type == 'name':
            if token.value in ('true', 'false', 'True', 'False'):
                node = nodes.Const(token.value in ('true', 'True'),
                                   lineno=token.lineno)
            elif token.value in ('none', 'None'):
                node = nodes.Const(None, lineno=token.lineno)
            else:
                node = nodes.Name(token.value, 'load', lineno=token.lineno)
            next(self.stream)
        elif token.type == 'string':
            next(self.stream)
            buf = [token.value]
            lineno = token.lineno
            while self.stream.current.type == 'string':
                buf.append(self.stream.current.value)
                next(self.stream)
            node = nodes.Const(''.join(buf), lineno=lineno)
        elif token.type in ('integer', 'float'):
            next(self.stream)
            node = nodes.Const(token.value, lineno=token.lineno)
        elif token.type == 'lparen':
            next(self.stream)
            node = self.parse_tuple(explicit_parentheses=True)
            self.stream.expect('rparen')
        elif token.type == 'lbracket':
            node = self.parse_list()
        elif token.type == 'lbrace':
            node = self.parse_dict()
        else:
            self.fail("unexpected '%s'" % describe_token(token), token.lineno)
        return node 
開發者ID:remg427,項目名稱:misp42splunk,代碼行數:35,代碼來源:parser.py

示例6: make_assignment_frame

# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Name [as 別名]
def make_assignment_frame(self, frame):
        # toplevel assignments however go into the local namespace and
        # the current template's context.  We create a copy of the frame
        # here and add a set so that the Name visitor can add the assigned
        # names here.
        if not frame.toplevel:
            return frame
        assignment_frame = frame.copy()
        assignment_frame.toplevel_assignments = set()
        return assignment_frame 
開發者ID:jpush,項目名稱:jbox,代碼行數:12,代碼來源:compiler.py

示例7: parse

# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Name [as 別名]
def parse(self, parser):
        lineno = parser.stream.expect('name:csrf_token').lineno
        call = self.call_method(
            '_csrf_token',
            [nodes.Name('csrf_token', 'load', lineno=lineno)],
            lineno=lineno
        )
        return nodes.Output([nodes.MarkSafe(call)]) 
開發者ID:MoritzS,項目名稱:jinja2-django-tags,代碼行數:10,代碼來源:extensions.py

示例8: _parse_trans

# 需要導入模塊: from jinja2 import nodes [as 別名]
# 或者: from jinja2.nodes import Name [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


注:本文中的jinja2.nodes.Name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。