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


Python nodes.Assign方法代码示例

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


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

示例1: parse_set

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Assign [as 别名]
def parse_set(self):
        """Parse an assign statement."""
        lineno = next(self.stream).lineno
        target = self.parse_assign_target(with_namespace=True)
        if self.stream.skip_if('assign'):
            expr = self.parse_tuple()
            return nodes.Assign(target, expr, lineno=lineno)
        filter_node = self.parse_filter(None)
        body = self.parse_statements(('name:endset',),
                                     drop_needle=True)
        return nodes.AssignBlock(target, filter_node, body, lineno=lineno) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:13,代码来源:parser.py

示例2: parse

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Assign [as 别名]
def parse(self, parser):
        node = nodes.Scope(lineno=next(parser.stream).lineno)
        assignments = []
        while parser.stream.current.type != 'block_end':
            lineno = parser.stream.current.lineno
            if assignments:
                parser.stream.expect('comma')
            target = parser.parse_assign_target()
            parser.stream.expect('assign')
            expr = parser.parse_expression()
            assignments.append(nodes.Assign(target, expr, lineno=lineno))
        node.body = assignments + \
            list(parser.parse_statements(('name:endwith',),
                                         drop_needle=True))
        return node 
开发者ID:jpush,项目名称:jbox,代码行数:17,代码来源:ext.py

示例3: parse_set

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Assign [as 别名]
def parse_set(self):
        """Parse an assign statement."""
        lineno = next(self.stream).lineno
        target = self.parse_assign_target()
        if self.stream.skip_if('assign'):
            expr = self.parse_tuple()
            return nodes.Assign(target, expr, lineno=lineno)
        body = self.parse_statements(('name:endset',),
                                     drop_needle=True)
        return nodes.AssignBlock(target, body, lineno=lineno) 
开发者ID:jpush,项目名称:jbox,代码行数:12,代码来源:parser.py

示例4: _parse_trans

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Assign [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: parse

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Assign [as 别名]
def parse(self, parser):
        lineno = next(parser.stream).lineno
        token = parser.stream.expect(lexer.TOKEN_STRING)
        path = nodes.Const(token.value)
        call = self.call_method('_static', [path], lineno=lineno)

        token = parser.stream.current
        if token.test('name:as'):
            next(parser.stream)
            as_var = parser.stream.expect(lexer.TOKEN_NAME)
            as_var = nodes.Name(as_var.value, 'store', lineno=as_var.lineno)
            return nodes.Assign(as_var, call, lineno=lineno)
        else:
            return nodes.Output([call], lineno=lineno) 
开发者ID:MoritzS,项目名称:jinja2-django-tags,代码行数:16,代码来源:extensions.py

示例6: _process_with

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Assign [as 别名]
def _process_with(self, node, **kwargs):

        # keep a copy of the stored names before the scope
        previous_stored_names = self.stored_names.copy()

        # assigns in the with tag
        # e.g. {% with var = "something %}
        assigns_in_tag = [nodes.Assign(t, v) for t, v in zip(node.targets, node.values)]

        # assigns in the with body
        # e.g. {% set name = 'John' %}
        assigns_in_body = [x for x in node.body if isinstance(x, nodes.Assign)]

        # remove assigns from the body
        node.body = [x for x in node.body if not isinstance(x, nodes.Assign)]

        # get a list of all the assigns in this with block
        # both on the tag, and within the body of the block
        all_assigns = assigns_in_tag + assigns_in_body

        with self._execution():
            self.output.write('(function () {')

        with self._scoped_variables(all_assigns, **kwargs):
            for node in node.body:
                self._process_node(node, **kwargs)

        with self._execution():
            self.output.write('})();')

        # restore previous stored names
        self.stored_names = previous_stored_names 
开发者ID:jonbretman,项目名称:jinja-to-js,代码行数:34,代码来源:__init__.py

示例7: _scoped_variables

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Assign [as 别名]
def _scoped_variables(self, nodes_list, **kwargs):
        """
        Context manager for creating scoped variables defined by the nodes in `nodes_list`.
        These variables will be added to the context, and when the context manager exits the
        context object will be restored to it's previous state.
        """

        tmp_vars = []
        for node in nodes_list:

            is_assign_node = isinstance(node, nodes.Assign)
            name = node.target.name if is_assign_node else node.name

            # create a temp variable name
            tmp_var = next(self.temp_var_names)

            # save previous context value
            with self._execution():

                # save the current value of this name
                self.output.write('var %s = %s.%s;' % (tmp_var, self.context_name, name))

                # add new value to context
                self.output.write('%s.%s = ' % (self.context_name, name))

                if is_assign_node:
                    self._process_node(node.node, **kwargs)
                else:
                    self.output.write(node.name)

                self.output.write(';')

            tmp_vars.append((tmp_var, name))

        yield

        # restore context
        for tmp_var, name in tmp_vars:
            with self._execution():
                self.output.write('%s.%s = %s;' % (self.context_name, name, tmp_var)) 
开发者ID:jonbretman,项目名称:jinja-to-js,代码行数:42,代码来源:__init__.py

示例8: parse_set

# 需要导入模块: from jinja2 import nodes [as 别名]
# 或者: from jinja2.nodes import Assign [as 别名]
def parse_set(self):
        """Parse an assign statement."""
        lineno = next(self.stream).lineno
        target = self.parse_assign_target()
        self.stream.expect('assign')
        expr = self.parse_tuple()
        return nodes.Assign(target, expr, lineno=lineno) 
开发者ID:chalasr,项目名称:Flask-P2P,代码行数:9,代码来源:parser.py


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