def decode(node, errs, where, use_ondemand): if use_ondemand: l = ondemand.OnDemandList() else: l = [] nodes = xmlext.getAllNodes(node, path) #print node, tag + '/' + comp_tag, nodes if len(nodes) == 0 and req == mandatory: errs.append( where + ': ' + _('Mandatory list "%s" under "%s" node is empty.') % (path, node.name())) ix = 1 for node in nodes: dummy = xmlext.newNode(node, "Dummy") xmlext.addNode(dummy, '', node) if use_ondemand: l.append( ondemand.OnDemandNode(decode_item, dummy, where + unicode("[%s]" % ix))) else: l.append( decode_item(dummy, errs, where + unicode("[%s]" % ix), use_ondemand)) #l.append(decode_item(node, errs, where + unicode("[%s]" % ix))) ix += 1 return l
def encode(node, obj, errs): if node and obj: try: # FIXME: this doesn't look pretty classnode = xmlext.newNode(node, tag) obj.encode(classnode, errs) xmlext.addNode(node, "", classnode) except Error: if req == mandatory: # note: we can receive an error if obj has no content errs.append(_("Object cannot be encoded")) else: if req == mandatory: errs.append(_("Mandatory argument not available"))
def decode(node, errs, where): l = [] nodes = xmlext.getAllNodes(node, path) #print node, tag + '/' + comp_tag, nodes if len(nodes)==0 and req==mandatory: errs.append(where + ': ' + _('Mandatory list "%s" under "%s" node is empty.') % (path, node.name())) ix = 1 for node in nodes: dummy = xmlext.newNode(node, "Dummy") xmlext.addNode(dummy, '', node) l.append(decode_item(dummy, errs, where + unicode("[%s]" % ix))) #l.append(decode_item(node, errs, where + unicode("[%s]" % ix))) ix += 1 return l
def encode(node, obj, errs): if node and obj: try: #FIXME: this doesn't look pretty classnode = xmlext.newNode(node, tag) obj.encode(classnode, errs) xmlext.addNode(node, '', classnode) except Error: if req == mandatory: # note: we can receive an error if obj has no content errs.append(_('Object cannot be encoded')) else: if req == mandatory: errs.append(_('Mandatory argument not available'))
def decode(node, errs, where, use_ondemand): if use_ondemand: l = ondemand.OnDemandList() else: l = [] nodes = xmlext.getAllNodes(node, path) # print node, tag + '/' + comp_tag, nodes if len(nodes) == 0 and req == mandatory: errs.append(where + ": " + _('Mandatory list "%s" under "%s" node is empty.') % (path, node.name())) ix = 1 for node in nodes: dummy = xmlext.newNode(node, "Dummy") xmlext.addNode(dummy, "", node) if use_ondemand: l.append(ondemand.OnDemandNode(decode_item, dummy, where + unicode("[%s]" % ix))) else: l.append(decode_item(dummy, errs, where + unicode("[%s]" % ix), use_ondemand)) # l.append(decode_item(node, errs, where + unicode("[%s]" % ix))) ix += 1 return l