Beispiel #1
0
 def Subtract(self, context, value):
     from prompto.value.SetValue import SetValue
     if isinstance(value, ListValue):
         setValue = SetValue(self.itype.itemType)
         value = setValue.Add(context, value)
     if isinstance(value, SetValue):
         return self.remove(value)
     else:
         return super(ListValue, self).Add(context, value)
Beispiel #2
0
 def convertSet(self, context, value, klass, returnType):
     if isinstance(returnType, SetType) and isinstance(value, set):
         itemType = returnType.itemType
         itemKlass = type(value[0]) if len(value)>0 else None
         items = [self.doConvertPythonValueToPromptoValue(context, item, itemKlass, itemType) for item in value]
         return SetValue(itemType, items=items)
     else:
         return None
Beispiel #3
0
 def getMemberValue(self, context, name, autoCreate=False):
     if "count" == name:
         return IntegerValue(self.size())
     elif "keys" == name:
         res = set([TextValue(k) for k in self.value.keys()])
         return SetValue(TextType.instance, items=res)
     elif "values" == name:
         return ListValue(self.itype.itemType, items=self.value.values())
     else:
         return super().getMemberValue(context, name, autoCreate)
Beispiel #4
0
 def interpret(self, context):
     if len(self.expressions)>0:
         self.check(context) # force computation of itemType
         value = set()
         for exp in self.expressions:
             o = exp.interpret(context)
             o = self.interpretPromotion(o)
             value.add(o)
         return SetValue(self.itemType, value)
     else:
         return self.value
 def getMemberValue(self, context, name, autoCreate=False):
     if "count" == name:
         return IntegerValue(self.size())
     elif "keys" == name:
         res = set([TextValue(k) for k in self.values.keys()])
         return SetValue(TextType.instance, items=res)
     elif "values" == name:
         return ListValue(AnyType.instance, items=self.values.values())
     else:
         result = self.values.get(name, None)
         if result is not None:
             return result
         elif "text" == name:
             return TextValue(str(self))
         elif autoCreate:
             result = DocumentValue()
             self.values[name] = result
             return result
         else:
             return NullValue.instance
Beispiel #6
0
 def toSetValue(self, context):
     from prompto.value.SetValue import SetValue
     return SetValue(self.itype.itemType, items=set(self.items))
Beispiel #7
0
 def toSetValue(self, context):
     items = [item for item in self.getIterator(context)]
     return SetValue(self.itemType, items=set(items))
Beispiel #8
0
 def __init__(self, expressions = []):
     strs = [ str(e) for e in expressions]
     super(SetLiteral, self).__init__("<" + ", ".join(strs) + ">", SetValue(MissingType.instance))
     self.expressions = expressions
     self.itemType = None
Beispiel #9
0
 def toSetValue(self, context):
     from prompto.value.SetValue import SetValue
     items = [item for item in self.getIterator(context)]
     return SetValue(self.value.itemType, items=set(items))