From d089a0a592646ef37545dba655d2acd4b8d3a75c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Wed, 28 Sep 2005 12:43:36 +0000 Subject: [PATCH] * at least get the normal members right --- pisi/xmlfile.py | 37 +++++++++++++++++++------------------ tests/xmlfiletests.py | 5 ++--- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pisi/xmlfile.py b/pisi/xmlfile.py index 59e7eb14..1094492a 100644 --- a/pisi/xmlfile.py +++ b/pisi/xmlfile.py @@ -210,11 +210,10 @@ class autoxml(type): cls.decode = decode cls.encoders = encoders - def encode(self, xml): - node = xml.newNode(cls.tag) + def encode(self, xml, node): for encode_member in self.__class__.encoders: encode_member(self, xml, node) - return node + return cls.encode = encode cls.formatters = formatters @@ -299,12 +298,13 @@ class autoxml(type): value = getattr(self, name) else: value = None - newnode = encode_a(xml, value) - if newnode: - mergetext(node, newnode) - else: - if req == mandatory: - raise Error('Mandatory variable %s not available' % name) + encode_a(xml, node, value) + #newnode = + #if newnode: + # mergetext(node, newnode) + #else: + # if req == mandatory: + # raise Error('Mandatory variable %s not available' % name) def format(self): @@ -375,10 +375,10 @@ class autoxml(type): else: return None - def encode(xml, value): + def encode(xml, node, value): """encode given value inside DOM node""" if value: - node = createnode(xml, token) + #node = createnode(xml, token) writetext(xml, node, token, str(value)) return node else: @@ -416,10 +416,10 @@ class autoxml(type): else: return None - def encode(xml, obj): + def encode(xml, node, obj): if obj: try: - node = obj.encode(xml) + node = obj.encode(xml, node) #FIXME: change node's tag? return except Error: @@ -460,13 +460,14 @@ class autoxml(type): l.append(decode_item(dummy)) return l - def encode(xml, l): - dummy = xml.newNode("Dummy") + def encode(xml, node, l): + listnode = xml.newNode(tag) if len(l) > 0: for item in l: - item_node = encode_item(xml, item) - xml.addNodeUnder(dummy, comp_tag, item_node) - return getNode(dummy, "Dummy") + encode_item(xml, listnode, item) + #item_node = encode_item(xml, item) + #xml.addNodeUnder(listnode, comp_tag, item_node) + #return getNode(dummy, "Dummy") else: if req is mandatory: raise Error('Mandatory list empty') diff --git a/tests/xmlfiletests.py b/tests/xmlfiletests.py index 5c1bff3d..c61015ca 100644 --- a/tests/xmlfiletests.py +++ b/tests/xmlfiletests.py @@ -57,9 +57,8 @@ class XmlFileTestCase(unittest.TestCase): #self.assert_(string.startswith('Name')) xml = xmlfile.XmlFile('A') xml.newDOM() - node = a.encode(xml) - print 'allah', node - xml.rootNode().appendChild(node) + a.encode(xml, xml.rootNode()) + #xml.rootNode().appendChild(node) xml.writexml('/tmp/a.xml') print '/tmp/a.xml written' return