* revert the list spec to the old flexible way, specfile requires that
:(
This commit is contained in:
+10
-4
@@ -505,8 +505,12 @@ class autoxml(oo.autosuper):
|
|||||||
|
|
||||||
def gen_list_tag(cls, tag, spec):
|
def gen_list_tag(cls, tag, spec):
|
||||||
"""generate a list datatype. stores comps in tag/comp_tag"""
|
"""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)
|
#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:
|
if len(tag_type) != 1:
|
||||||
raise Error(_('List type must contain only one element'))
|
raise Error(_('List type must contain only one element'))
|
||||||
@@ -519,7 +523,7 @@ class autoxml(oo.autosuper):
|
|||||||
|
|
||||||
def decode(node, errs, where):
|
def decode(node, errs, where):
|
||||||
l = []
|
l = []
|
||||||
nodes = getAllNodes(node, tag + '/' + comp_tag)
|
nodes = getAllNodes(node, path)
|
||||||
#print node, tag + '/' + comp_tag, nodes
|
#print node, tag + '/' + comp_tag, nodes
|
||||||
if len(nodes) is 0 and req is mandatory:
|
if len(nodes) is 0 and req is mandatory:
|
||||||
errs.append(where + _('Mandatory list empty'))
|
errs.append(where + _('Mandatory list empty'))
|
||||||
@@ -531,11 +535,13 @@ class autoxml(oo.autosuper):
|
|||||||
return l
|
return l
|
||||||
|
|
||||||
def encode(xml, node, l, errs):
|
def encode(xml, node, l, errs):
|
||||||
|
dom = node.ownerDocument
|
||||||
if l and len(l) > 0:
|
if l and len(l) > 0:
|
||||||
listnode = xml.newNode(tag)
|
|
||||||
for item in l:
|
for item in l:
|
||||||
|
listnode = xml.newNode("Dummy")
|
||||||
encode_item(xml, listnode, item, errs)
|
encode_item(xml, listnode, item, errs)
|
||||||
node.appendChild(listnode)
|
node = getNode(listnode, comp_tag)
|
||||||
|
addNode(dom, node, path)
|
||||||
else:
|
else:
|
||||||
if req is mandatory:
|
if req is mandatory:
|
||||||
errs.append(_('Mandatory list empty'))
|
errs.append(_('Mandatory list empty'))
|
||||||
|
|||||||
@@ -5,11 +5,9 @@
|
|||||||
<Number>868</Number>
|
<Number>868</Number>
|
||||||
<Description>Lazy Tin</Description>
|
<Description>Lazy Tin</Description>
|
||||||
<Description xml:lang="tr">Tembel Teneke</Description>
|
<Description xml:lang="tr">Tembel Teneke</Description>
|
||||||
<Projects>
|
|
||||||
<Project>pisi</Project>
|
<Project>pisi</Project>
|
||||||
<Project>noatun</Project>
|
<Project>noatun</Project>
|
||||||
<Project>kdevelop</Project>
|
<Project>kdevelop</Project>
|
||||||
</Projects>
|
|
||||||
<OtherInfo>
|
<OtherInfo>
|
||||||
<BirthDate>18071976</BirthDate>
|
<BirthDate>18071976</BirthDate>
|
||||||
<Interest>AI</Interest>
|
<Interest>AI</Interest>
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class XmlFileTestCase(unittest.TestCase):
|
|||||||
__metaclass__ = xmlfile.autoxml
|
__metaclass__ = xmlfile.autoxml
|
||||||
t_BirthDate = [types.StringType, xmlfile.mandatory]
|
t_BirthDate = [types.StringType, xmlfile.mandatory]
|
||||||
t_Interest = [types.StringType, xmlfile.optional]
|
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):
|
class A(xmlfile.XmlFile):
|
||||||
__metaclass__ = xmlfile.autoxml
|
__metaclass__ = xmlfile.autoxml
|
||||||
@@ -41,14 +41,14 @@ class XmlFileTestCase(unittest.TestCase):
|
|||||||
t_Number = [types.IntType, xmlfile.optional]
|
t_Number = [types.IntType, xmlfile.optional]
|
||||||
t_Email = [types.StringType, xmlfile.optional]
|
t_Email = [types.StringType, xmlfile.optional]
|
||||||
a_href = [types.StringType, xmlfile.mandatory]
|
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 ]
|
t_OtherInfo = [ OtherInfo, xmlfile.optional ]
|
||||||
|
|
||||||
a = A()
|
a = A()
|
||||||
self.assertEqual(a.href, None)
|
self.assertEqual(a.href, None)
|
||||||
dom = mdom.parse('tests/a.xml')
|
dom = mdom.parse('tests/a.xml')
|
||||||
node = getNode(dom, 'A')
|
node = getNode(dom, 'A')
|
||||||
self.assert_(len(A.decoders)>0)
|
self.assertEqual(len(A.decoders), 4)
|
||||||
errs = []
|
errs = []
|
||||||
print 'errs', errs
|
print 'errs', errs
|
||||||
a.decode(node, errs)
|
a.decode(node, errs)
|
||||||
|
|||||||
Reference in New Issue
Block a user