* implement encode and format for class and list types
* start testing encode
This commit is contained in:
+21
-7
@@ -299,6 +299,8 @@ class autoxml(type):
|
|||||||
return identifier_p
|
return identifier_p
|
||||||
|
|
||||||
def parse_spec(cls, token, spec):
|
def parse_spec(cls, token, spec):
|
||||||
|
"""decompose member specification"""
|
||||||
|
|
||||||
name = cls.mixed_case(token)
|
name = cls.mixed_case(token)
|
||||||
token_type = spec[0]
|
token_type = spec[0]
|
||||||
req = spec[1]
|
req = spec[1]
|
||||||
@@ -378,12 +380,18 @@ class autoxml(type):
|
|||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def encode(xml, value):
|
def encode(xml, obj):
|
||||||
pass
|
if obj:
|
||||||
|
try:
|
||||||
def format(l):
|
obj.encode(xml)
|
||||||
s = ''
|
except Error:
|
||||||
return s
|
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)
|
return (init, decode, encode, format)
|
||||||
|
|
||||||
@@ -415,7 +423,13 @@ class autoxml(type):
|
|||||||
return l
|
return l
|
||||||
|
|
||||||
def encode(xml, 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):
|
def format(l):
|
||||||
#print 'format:', name
|
#print 'format:', name
|
||||||
|
|||||||
@@ -54,14 +54,17 @@ class XmlFileTestCase(unittest.TestCase):
|
|||||||
string = a.format()
|
string = a.format()
|
||||||
print '*', string
|
print '*', string
|
||||||
#self.assert_(string.startswith('Name'))
|
#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')
|
xml = xmlfile.XmlFile('A')
|
||||||
a2 = A()
|
a2 = A()
|
||||||
a2.name = "Baris Metin"
|
a2.name = "Baris Metin"
|
||||||
a2.email = "baris@uludag.org.tr"
|
a2.email = "baris@uludag.org.tr"
|
||||||
a2.href = 'http://cekirdek.uludag.org.tr/~baris'
|
a2.href = 'http://cekirdek.uludag.org.tr/~baris'
|
||||||
a2.projects = [ 'pisi', 'tasma', 'plasma' ]
|
a2.projects = [ 'pisi', 'tasma', 'plasma' ]
|
||||||
elt = a2.encode(xml)
|
elta2 = a2.encode(xml)
|
||||||
|
xml.writexml('/tmp/a2.xml')
|
||||||
string = a2.format()
|
string = a2.format()
|
||||||
|
|
||||||
suite = unittest.makeSuite(XmlFileTestCase)
|
suite = unittest.makeSuite(XmlFileTestCase)
|
||||||
|
|||||||
Reference in New Issue
Block a user