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 encode(node, l, errs): if l: for item in l: if list_tagpath: listnode = xmlext.addNode(node, list_tagpath, branch=False) else: listnode = node encode_item(listnode, item, errs) # encode_item(node, item, errs) else: if req is mandatory: errs.append(_('Mandatory list "%s" under "%s" node is empty.') % (path, node.name()))
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, l, errs): if l: for item in l: if list_tagpath: listnode = xmlext.addNode(node, list_tagpath, branch=False) else: listnode = node encode_item(listnode, item, errs) #encode_item(node, item, errs) else: if req is mandatory: errs.append( _('Mandatory list "%s" under "%s" node is empty.') % (path, node.name()))
def encode(self, node, errs): assert self.tag != "" for key in self.iterkeys(): newnode = xmlext.addNode(node, self.tag) xmlext.setNodeAttribute(newnode, "xml:lang", key) xmlext.addText(newnode, "", self[key])
def encode(self, node, errs): assert self.tag != '' for key in self.iterkeys(): newnode = xmlext.addNode(node, self.tag) xmlext.setNodeAttribute(newnode, 'xml:lang', key) xmlext.addText(newnode, '', self[key])