Kaydet (Commit) 0da7c4c3 authored tarafından Eray Özkural's avatar Eray Özkural

* revert the list spec to the old flexible way, specfile requires that

:(
üst 51d35343
......@@ -505,8 +505,12 @@ class autoxml(oo.autosuper):
def gen_list_tag(cls, tag, spec):
"""generate a list datatype. stores comps in tag/comp_tag"""
name, tag_type, req, comp_tag = cls.parse_spec(tag, spec)
name, tag_type, req, path = cls.parse_spec(tag, spec)
#head, last = cls.tagpath_head_last(path)
pathcomps = path.split('/')
list_tagpath = path[:path.rfind('/')]
comp_tag = pathcomps[len(pathcomps)-1]
#TODO: make default path ... tag + '/' + comp_tag when comp is class!
if len(tag_type) != 1:
raise Error(_('List type must contain only one element'))
......@@ -519,7 +523,7 @@ class autoxml(oo.autosuper):
def decode(node, errs, where):
l = []
nodes = getAllNodes(node, tag + '/' + comp_tag)
nodes = getAllNodes(node, path)
#print node, tag + '/' + comp_tag, nodes
if len(nodes) is 0 and req is mandatory:
errs.append(where + _('Mandatory list empty'))
......@@ -531,11 +535,13 @@ class autoxml(oo.autosuper):
return l
def encode(xml, node, l, errs):
dom = node.ownerDocument
if l and len(l) > 0:
listnode = xml.newNode(tag)
for item in l:
listnode = xml.newNode("Dummy")
encode_item(xml, listnode, item, errs)
node.appendChild(listnode)
node = getNode(listnode, comp_tag)
addNode(dom, node, path)
else:
if req is mandatory:
errs.append(_('Mandatory list empty'))
......
......@@ -5,11 +5,9 @@
<Number>868</Number>
<Description>Lazy Tin</Description>
<Description xml:lang="tr">Tembel Teneke</Description>
<Projects>
<Project>pisi</Project>
<Project>noatun</Project>
<Project>kdevelop</Project>
</Projects>
<OtherInfo>
<BirthDate>18071976</BirthDate>
<Interest>AI</Interest>
......
......@@ -32,7 +32,7 @@ class XmlFileTestCase(unittest.TestCase):
__metaclass__ = xmlfile.autoxml
t_BirthDate = [types.StringType, xmlfile.mandatory]
t_Interest = [types.StringType, xmlfile.optional]
t_CodesWith = [ [types.StringType], xmlfile.optional, 'Person']
t_CodesWith = [ [types.StringType], xmlfile.optional, 'CodesWith/Person']
class A(xmlfile.XmlFile):
__metaclass__ = xmlfile.autoxml
......@@ -41,14 +41,14 @@ class XmlFileTestCase(unittest.TestCase):
t_Number = [types.IntType, xmlfile.optional]
t_Email = [types.StringType, xmlfile.optional]
a_href = [types.StringType, xmlfile.mandatory]
t_Projects = [ [types.StringType], xmlfile.mandatory, 'Project', '']
t_Projects = [ [types.StringType], xmlfile.mandatory, 'Project']
t_OtherInfo = [ OtherInfo, xmlfile.optional ]
a = A()
self.assertEqual(a.href, None)
dom = mdom.parse('tests/a.xml')
node = getNode(dom, 'A')
self.assert_(len(A.decoders)>0)
self.assertEqual(len(A.decoders), 4)
errs = []
print 'errs', errs
a.decode(node, errs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment