예제 #1
0
 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__)
예제 #2
0
 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__)
예제 #3
0
 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)
예제 #4
0
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__)
예제 #5
0
 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)))
예제 #6
0
 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)
예제 #7
0
 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)
예제 #8
0
 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
예제 #9
0
def toBoolean(node):
    return BooleanValue.ValueOf(node)
예제 #10
0
 def __init__(self, text):
     super(BooleanLiteral, self).__init__(text, BooleanValue.Parse(text))