* implement encode and format for class and list types

* start testing encode
This commit is contained in:
Eray Özkural
2005-09-22 10:49:18 +00:00
parent 5b278c1083
commit 228ec8f64b
2 changed files with 26 additions and 9 deletions
+21 -7
View File
@@ -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
+5 -2
View File
@@ -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)