def _not(self, x, elem=None, **kw): if 'in' in kw: assertResult(x, "test for membership") assertResult(elem, "test for membership") return ast.Compare(topy(elem), [('not in', topy(x))]) else: assertResult(x, "negate") if elem != None: raise CompileError("invalid 'not'") return ast.Not(topy(x))
def simplify(clause): if isinstance(clause, ast.And): if len(clause.nodes) == 1: result = clause.nodes[0] else: return clause elif isinstance(clause, ast.Or): if len(clause.nodes) == 1: result = ast.Not(clause.nodes[0]) else: return clause else: return clause if getattr(result, 'endpos', 0) < clause.endpos: result.endpos = clause.endpos return result
def _generate(node): if node.type == node.TERM: return ast.Compare(ast.Const(node.value), [('in', ast.Name('text'))]) elif node.type == node.AND: return ast.And([_generate(node.left), _generate(node.right)]) elif node.type == node.OR: return ast.Or([_generate(node.left), _generate(node.right)]) elif node.type == node.NOT: return ast.Not(_generate(node.left)) elif node.type == node.ATTR: raise NotImplementedError
def UNARY_NOT(decompiler): return ast.Not(decompiler.stack.pop())