コード例 #1
0
 def convertElement(self, parent: DocumentValue, element: minidom.Element):
     tagName = element.tagName
     # cater for repeated elements
     if parent.hasMember(tagName):
         self.convertListElement(parent, tagName, element)
     else:
         parent.setMember(None, tagName, self.convertElementValue(element))
コード例 #2
0
 def toDocumentValue(self, context):
     from prompto.value.DocumentValue import DocumentValue
     doc = DocumentValue()
     for key in self.values.keys():
         value = self.values[key].toDocumentValue(context)
         doc.setMember(context, key, value)
     return doc
コード例 #3
0
 def readJSONValue(self, context, node, parts):
     from prompto.value.DocumentValue import DocumentValue
     instance = DocumentValue()
     for key, node in node.items():
         value = self.readJSONField(context, node, parts)
         instance.setMember(context, key, value)
     return instance
コード例 #4
0
 def interpret(self, context):
     if len(self.entries) > 0:
         self.check(context)
         doc = DocumentValue()
         for e in self.entries:
             key = e.getKey().interpret(context)
             val = e.getValue().interpret(context)
             doc.setMember(context, key.value, val)
         return doc
     else:
         return self.value
コード例 #5
0
 def convertListElement(self, parent: DocumentValue, tagName: str,
                        element: minidom.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))
コード例 #6
0
 def convertDocument(self, context, value, klass, returnType):
     if isinstance(returnType, DocumentType) and isinstance(value, dict):
         doc = DocumentValue()
         for key, val in value.iteritems():
             klass = type(val)
             itype = self.pythonToPromptoMap.get(klass.__name__, DocumentType.instance)
             if itype is not None:
                 ival = itype.convertPythonValueToPromptoValue(context, val, None)
             else:
                 ival = self.doConvertPythonValueToPromptoValue(context, val, klass, itype)
             doc.setMember(context, str(key), ival)
         return doc
     else:
         return None
コード例 #7
0
    def getGlobalMethodSortKeyReader(self, context, name):
        from prompto.statement.MethodCall import MethodCall
        from prompto.value.DocumentValue import DocumentValue
        exp = ValueExpression(self, DocumentValue())
        arg = Argument(None, exp)
        args = ArgumentList(items=[arg])
        from prompto.expression.MethodSelector import MethodSelector
        call = MethodCall(MethodSelector(name), args)

        def keyGetter(o):
            argument = call.arguments[0]
            argument.setExpression(ValueExpression(self, o))
            return call.interpret(context)

        return keyGetter
コード例 #8
0
 def convertElementValue(self, element):
     hasAttributes = self.keepAttributes and element.hasAttributes()
     hasChildren = self.elementHasChildren(element)
     if hasAttributes or hasChildren:
         result = DocumentValue()
         if self.keepAttributes:
             for attr in element.attributes:
                 result.setMember(None, "@" + attr.name, TextValue(attr.value))
         if hasChildren:
             for node in element.childNodes:
                 if isinstance(node, minidom.Element):
                     self.convertElement(result, node)
         else:
             result.setMember(None, "$value", element.firstChild.nodeValue)
         return result
     else:
         return TextValue(element.firstChild.nodeValue)
コード例 #9
0
def convertDocument(obj):
    values = {}
    for k, v in obj.items():
        values[k] = convert(v)
    return DocumentValue(values=values)
コード例 #10
0
 def interpret(self, context):
     if self.source is None:
         return DocumentValue()
     else:
         value = self.source.interpret(context)
         return self.documentFromValue(context, value)
コード例 #11
0
 def convertDocument(self, doc):
     result = DocumentValue()
     self.convertElement(result, doc.documentElement)
     return result
コード例 #12
0
def toDocument(node):
    values = {}
    for k, v in node.items():
        values[k] = toValue(v)
    return DocumentValue(values=values)
コード例 #13
0
 def __init__(self, entries=None):
     if entries is None:
         entries = DocEntryList()
     super().__init__("{}", DocumentValue())
     self.entries = entries