我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用jinja2.nodes.Dict()。
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_dict(self): token = self.stream.expect('lbrace') items = [] while self.stream.current.type != 'rbrace': if items: self.stream.expect('comma') if self.stream.current.type == 'rbrace': break key = self.parse_expression() self.stream.expect('colon') value = self.parse_expression() items.append(nodes.Pair(key, value, lineno=key.lineno)) self.stream.expect('rbrace') return nodes.Dict(items, lineno=token.lineno)