def interpretValue(self, context, lval, rval): if isinstance(lval, IValue) and isinstance(rval, IValue): result = None if self.operator in [ContOp.IN, ContOp.NOT_IN]: if rval is NullValue.instance: result = False elif isinstance(rval, IContainer): result = rval.hasItem(context, lval) elif self.operator in [ContOp.HAS, ContOp.NOT_HAS]: if lval is NullValue.instance: result = False elif isinstance(lval, IContainer): result = lval.hasItem(context, rval) elif self.operator in [ContOp.HAS_ALL, ContOp.NOT_HAS_ALL]: if lval is NullValue.instance or rval is NullValue.instance: result = False elif isinstance(lval, IContainer) and isinstance(rval, IContainer): result = self.containsAll(context, lval, rval) elif self.operator in [ContOp.HAS_ANY, ContOp.NOT_HAS_ANY]: if lval is NullValue.instance or rval is NullValue.instance: result = False elif isinstance(lval, IContainer) and isinstance(rval, IContainer): result = self.containsAny(context, lval, rval) if result is not None: if self.operator.name.find("NOT") == 0: result = not result return BooleanValue.ValueOf(result) #prepare exception if self.operator.name.find("IN") >= 0: tmp = lval lval = rval rval = tmp lowerName = self.operator.name.lower().replace('_', ' ') raise SyntaxError("Illegal comparison: " + type(lval).__name__ + \ " " + lowerName + " " + type(rval).__name__)
def interpretValue(self, context, lval, rval): if isinstance(lval, BooleanValue): if isinstance(rval, BooleanValue): return BooleanValue.ValueOf(lval.getValue() or rval.getValue()) else: raise SyntaxError("Illegal: Boolean and " + type(rval).__name__) else: raise SyntaxError("Illegal: " + type(lval).__name__ + " + " + type(rval).__name__)
def interpretContainerPredicate(self, context, container, predicate): result = None if self.operator in [ContOp.HAS_ALL, ContOp.NOT_HAS_ALL]: result = self.allMatch(context, container, predicate) elif self.operator in [ContOp.HAS_ANY, ContOp.NOT_HAS_ANY]: result = self.anyMatch(context, container, predicate) if isinstance(result, bool): if self.operator in [ContOp.NOT_HAS_ALL, ContOp.NOT_HAS_ANY]: result = not result return BooleanValue.ValueOf(result) lowerName = self.operator.name.lower().replace('_', ' ') raise SyntaxError("Illegal filter: " + type(container) + " " + lowerName)
def convert(obj): if obj is None: return NullValue.instance elif inspect.isgenerator(obj): return convert(list(obj)) elif isinstance(obj, list): return convertList(obj) elif isinstance(obj, dict): return convertDocument(obj) elif isinstance(obj, int): return IntegerValue(obj) elif isinstance(obj, float): return DecimalValue(obj) elif isinstance(obj, bool): return BooleanValue(obj) elif isinstance(obj, str): return TextValue(obj) else: raise ReadWriteError("Cannot convert: " + type(obj).__name__)
def readJSONField(self, context, node, parts): if node is None: return NullValue.instance elif isinstance(node, bool): return BooleanValue.ValueOf(node) elif isinstance(node, int): return IntegerValue(node) elif isinstance(node, float): return DecimalValue(node) elif isinstance(node, str): return TextValue(node) elif isinstance(node, list): raise Exception("list") elif isinstance(node, dict): raise Exception("dict") elif isinstance(node, object): raise Exception("object") else: raise Exception(str(type(node)))
def interpretValues(self, context, lval, rval): if self.operator is EqOp.IS: equal = id(lval) == id(rval) elif self.operator is EqOp.IS_NOT: equal = id(lval) != id(rval) elif self.operator is EqOp.IS_A: equal = self.isA(context, lval, rval) elif self.operator is EqOp.IS_NOT_A: equal = not self.isA(context, lval, rval) elif self.operator is EqOp.EQUALS: equal = self.areEqual(context, lval, rval) elif self.operator is EqOp.NOT_EQUALS: equal = not self.areEqual(context, lval, rval) elif self.operator is EqOp.CONTAINS: equal = self.contains(context, lval, rval) elif self.operator is EqOp.NOT_CONTAINS: equal = not self.contains(context, lval, rval) else: equal = self.roughly(context, lval, rval) return BooleanValue.ValueOf(equal)
def interpret(self, context): from prompto.value.BooleanValue import BooleanValue value = self.getValue(context).value find = context.getValue("value").value endsWith = value.endswith(find) return BooleanValue.ValueOf(endsWith)
def convertPythonValueToPromptoValue(self, context, value, returnType): if isinstance(value, bool): from prompto.value.BooleanValue import BooleanValue return BooleanValue.ValueOf(value) else: return value # TODO for now
def toBoolean(node): return BooleanValue.ValueOf(node)
def __init__(self, text): super(BooleanLiteral, self).__init__(text, BooleanValue.Parse(text))