我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用jinja2.nodes.Assign()。
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)
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
def parse(self, parser): stream = parser.stream lineno = stream.next().lineno call_node = self.call_method('render') if stream.next_if('name:as'): var = nodes.Name(stream.expect('name').value, 'store') return nodes.Assign(var, call_node).set_lineno(lineno) else: return nodes.Output([call_node]).set_lineno(lineno)
def parse(self, parser): stream = parser.stream lineno = stream.next().lineno path = parser.parse_expression() call_node = self.call_method('get_statc_url', args=[path]) if stream.next_if('name:as'): var = nodes.Name(stream.expect('name').value, 'store') return nodes.Assign(var, call_node).set_lineno(lineno) else: return nodes.Output([call_node]).set_lineno(lineno)
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)