diff --git a/pisi/xmlfile.py b/pisi/xmlfile.py index 04c8213b..caccd166 100644 --- a/pisi/xmlfile.py +++ b/pisi/xmlfile.py @@ -299,6 +299,8 @@ class autoxml(type): return identifier_p def parse_spec(cls, token, spec): + """decompose member specification""" + name = cls.mixed_case(token) token_type = spec[0] req = spec[1] @@ -378,12 +380,18 @@ class autoxml(type): else: return None - def encode(xml, value): - pass - - def format(l): - s = '' - return s + def encode(xml, obj): + if obj: + try: + obj.encode(xml) + except Error: + raise Error('Object cannot be encoded') + else: + if req == mandatory: + raise Error('Mandatory argument not available') + + def format(obj): + return obj.format() return (init, decode, encode, format) @@ -415,7 +423,13 @@ class autoxml(type): return l def encode(xml, l): - pass + if len(l) > 0: + for elt in l: + node = xml.newNode(path) + encode_item(xml, node) + else: + if req is mandatory: + raise Error('Mandatory list empty') def format(l): #print 'format:', name diff --git a/tests/xmlfiletests.py b/tests/xmlfiletests.py index b1191e05..a5870a7c 100644 --- a/tests/xmlfiletests.py +++ b/tests/xmlfiletests.py @@ -54,14 +54,17 @@ class XmlFileTestCase(unittest.TestCase): string = a.format() print '*', string #self.assert_(string.startswith('Name')) - outfn = '/tmp/a2.xml' + xml = xmlfile.XmlFile('A') + elta = a.encode(xml) + xml.writexml('/tmp/a.xml') xml = xmlfile.XmlFile('A') a2 = A() a2.name = "Baris Metin" a2.email = "baris@uludag.org.tr" a2.href = 'http://cekirdek.uludag.org.tr/~baris' a2.projects = [ 'pisi', 'tasma', 'plasma' ] - elt = a2.encode(xml) + elta2 = a2.encode(xml) + xml.writexml('/tmp/a2.xml') string = a2.format() suite = unittest.makeSuite(XmlFileTestCase)