我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用jinja2.nodes.List()。
def parse(self, parser): lineno = next(parser.stream).lineno args = [parser.parse_expression()] # ??????,?? timeout if parser.stream.skip_if('comma'): args.append(parser.parse_expression()) else: args.append(nodes.Const('%s%s' % (parser.filename, lineno))) vary_on = [] while parser.stream.skip_if('comma'): vary_on.append(parser.parse_expression()) if vary_on: args.append(nodes.List(vary_on)) else: args.append(nodes.Const([])) body = parser.parse_statements(['name:endcache'], drop_needle=True) return nodes.CallBlock(self.call_method('_cache', args), [], [], body).set_lineno(lineno)
def parse(self, parser): stream = parser.stream tag = stream.next() # get arguments args = [] kwargs = [] while not stream.current.test_any('block_end'): if args or kwargs: stream.expect('comma') if stream.current.test('name') and stream.look().test('assign'): key = nodes.Const(stream.next().value) stream.skip() value = parser.parse_expression() kwargs.append(nodes.Pair(key, value, lineno=key.lineno)) else: args.append(parser.parse_expression()) def make_call_node(*kw): return self.call_method('_call', args=[ nodes.List(args), nodes.Dict(kwargs), ], kwargs=kw) return nodes.Output([make_call_node()]).set_lineno(tag.lineno)
def parse_list(self): token = self.stream.expect('lbracket') items = [] while self.stream.current.type != 'rbracket': if items: self.stream.expect('comma') if self.stream.current.type == 'rbracket': break items.append(self.parse_expression()) self.stream.expect('rbracket') return nodes.List(items, lineno=token.lineno)
def parse(self, parser): lineno = next(parser.stream).lineno #: Parse timeout args = [parser.parse_expression()] #: Parse fragment name #: Grab the fragment name if it exists #: otherwise, default to the old method of using the templates #: lineno to maintain backwards compatibility. if parser.stream.skip_if('comma'): args.append(parser.parse_expression()) else: args.append(nodes.Const("%s%s" % (parser.filename, lineno))) #: Parse vary_on parameters vary_on = [] while parser.stream.skip_if('comma'): vary_on.append(parser.parse_expression()) if vary_on: args.append(nodes.List(vary_on)) else: args.append(nodes.Const([])) body = parser.parse_statements(['name:endcache'], drop_needle=True) return nodes.CallBlock(self.call_method('_cache', args), [], [], body).set_lineno(lineno)