示例#1
0
 def convertPythonValueToPromptoValue(self, context, value, returnType):
     if isinstance(value, (list, set, tuple)):
         items = [self.itemType.convertPythonValueToPromptoValue(context, item, returnType) for item in value]
         from prompto.value.ListValue import ListValue
         return ListValue(self.itemType, items=items)
     else:
         return super(ListType, self).convertPythonValueToPromptoValue(context, value, returnType)
示例#2
0
 def __init__(self, expressions=[], mutable=False):
     strs = [str(e) for e in expressions]
     super(ListLiteral, self).__init__("[" + ", ".join(strs) + "]",
                                       ListValue(MissingType.instance))
     self.itemType = None
     self.expressions = expressions
     self.mutable = mutable
示例#3
0
 def interpret(self, context):
     from prompto.value.TextValue import TextValue
     from prompto.value.ListValue import ListValue
     value = self.getValue(context).value
     sep = context.getValue("separator").value
     parts = [TextValue(part) for part in value.split(sep)]
     return ListValue(TextType.instance, parts, mutable=False)
示例#4
0
 def convertList(self, context, value, klass, returnType):
     if isinstance(returnType, ListType) and isinstance(value, list):
         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 ListValue(itemType, items=items)
     else:
         return None
示例#5
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)
示例#6
0
 def interpret(self, context):
     if len(self.expressions) > 0:
         self.check(context)  # force computation of item type
         value = ListValue(self.itemType, mutable=self.mutable)
         for o in self.expressions:
             o = o.interpret(context)
             o = self.interpretPromotion(o)
             value.items.append(o)
         return value
     else:
         return self.value
示例#7
0
 def interpret(self, context):
     itype = self.source.check(context)
     if not isinstance(itype, (ListType, TupleType, SetType)):
         raise SyntaxError("Unsupported type: " + itype)
     o = self.source.interpret(context)
     if o is None:
         raise NullReferenceError()
     if not isinstance(o, (ListValue, TupleValue, SetValue)):
         raise InternalError("Unexpected type:" + type(o).__name__)
     items = o.getIterator(context)
     getter = itype.itemType.getSortKeyReader(context, self.key)
     list = sorted(items, key=getter, reverse=self.desc)
     return ListValue(itype.itemType, items=list)
示例#8
0
 def convertListElement(self, parent, tagName, element):
     list = None
     current = parent.getMemberValue(None, tagName, False)
     if isinstance(current, ListValue):
         list = current
     else:
         list = ListValue(AnyType.instance)
         list.add(current)
         parent.setMember(None, tagName, list)
     list.add(self.convertElementValue(element))
 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
示例#10
0
 def toListValue(self, context):
     items = [item for item in self.getIterator(context)]
     return ListValue(self.itype.itemType, items=items)
示例#11
0
 def toDocumentValue(self, context):
     items = [item.toDocumentValue(context) for item in self.items]
     from prompto.value.ListValue import ListValue
     from prompto.type.AnyType import AnyType
     return ListValue(AnyType.instance, items)
示例#12
0
 def filter(self, predicate):
     items = []
     for value in self.source:
         if predicate(value):
             items.append(value)
     return ListValue(self.itemType, items)
示例#13
0
def convertList(obj):
    items = [convert(o) for o in obj]
    return ListValue(AnyType.instance, items=items)
示例#14
0
 def toListValue(self, context):
     from prompto.value.ListValue import ListValue
     return ListValue(self.itype.itemType, items=list(self.items))
示例#15
0
def toList(node):
    items = [toValue(item) for item in node]
    return ListValue(AnyType.instance, items=items)
示例#16
0
 def toListValue(self, context):
     from prompto.value.ListValue import ListValue
     items = [item for item in self.value]
     return ListValue(self.value.itemType, items=items)