我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用jinja2.nodes.And()。
def eval_condition(self, condition): # exceptions are handled by the caller parser = BooleanParser(env, condition, state='variable') expr = parser.parse_expression() if not parser.stream.eos: raise ValueError('chunk after expression') def eval_node(node): if isinstance(node, nodes.CondExpr): if eval_node(node.test): return eval_node(node.expr1) else: return eval_node(node.expr2) elif isinstance(node, nodes.And): return eval_node(node.left) and eval_node(node.right) elif isinstance(node, nodes.Or): return eval_node(node.left) or eval_node(node.right) elif isinstance(node, nodes.Not): return not eval_node(node.node) elif isinstance(node, nodes.Name): return self.tags.get(node.name, False) else: raise ValueError('invalid node, check parsing') return eval_node(expr)
def parse_and(self): lineno = self.stream.current.lineno left = self.parse_not() while self.stream.skip_if('name:and'): right = self.parse_not() left = nodes.And(left, right, lineno=lineno) lineno = self.stream.current.lineno return left