Esempio n. 1
0
        def decode(node, errs, where, use_ondemand):

            if use_ondemand:
                l = ondemand.OnDemandList()
            else:
                l = []

            nodes = xmlext.getAllNodes(node, path)
            #print node, tag + '/' + comp_tag, nodes
            if len(nodes) == 0 and req == mandatory:
                errs.append(
                    where + ': ' +
                    _('Mandatory list "%s" under "%s" node is empty.') %
                    (path, node.name()))
            ix = 1
            for node in nodes:
                dummy = xmlext.newNode(node, "Dummy")
                xmlext.addNode(dummy, '', node)
                if use_ondemand:
                    l.append(
                        ondemand.OnDemandNode(decode_item, dummy,
                                              where + unicode("[%s]" % ix)))
                else:
                    l.append(
                        decode_item(dummy, errs, where + unicode("[%s]" % ix),
                                    use_ondemand))
                #l.append(decode_item(node, errs, where + unicode("[%s]" % ix)))
                ix += 1
            return l
Esempio n. 2
0
 def testAdd(self):
     node = xmlext.newDocument('pardus')
     #node = a.documentElement
     xmlext.addText(node, 'team/coder', 'zibidi1')
     xmlext.addText(node, 'team/coder', 'zibidi2')
     xmlext.addText(node, 'team/coder', 'zibidi3')
     reada = xmlext.getAllNodes(node, 'team/coder')
     self.assertEqual(len(reada), 3)
Esempio n. 3
0
 def testGet(self):
     self.doc = xmlext.parse('tests/a.xml')
     #self.doc = self.a.documentElement
     self.assertEqual(xmlext.getNodeText(self.doc, 'Number'), '868')
     self.assertEqual(xmlext.getNodeText(self.doc, 'OtherInfo/BirthDate'), '18071976')
     codeswith = xmlext.getAllNodes(self.doc, 'OtherInfo/CodesWith/Person')
     self.assertEqual(len(codeswith), 4)
     self.assertEqual(xmlext.getNodeText(codeswith[2]), 'Caglar')
Esempio n. 4
0
 def testAdd(self):
     node = xmlext.newDocument('pardus')
     #node = a.documentElement
     xmlext.addText(node, 'team/coder', 'zibidi1')
     xmlext.addText(node, 'team/coder', 'zibidi2')
     xmlext.addText(node, 'team/coder', 'zibidi3')
     reada = xmlext.getAllNodes(node, 'team/coder')
     self.assertEqual(len(reada), 3)
Esempio n. 5
0
 def testGet(self):
     self.doc = xmlext.parse('tests/a.xml')
     #self.doc = self.a.documentElement
     self.assertEqual(xmlext.getNodeText(self.doc, 'Number'), '868')
     self.assertEqual(xmlext.getNodeText(self.doc, 'OtherInfo/BirthDate'),
                      '18071976')
     codeswith = xmlext.getAllNodes(self.doc, 'OtherInfo/CodesWith/Person')
     self.assertEqual(len(codeswith), 5)
     self.assertEqual(xmlext.getNodeText(codeswith[1]), u'Çağlar')
Esempio n. 6
0
 def decode(node, errs, where):
     l = []
     nodes = xmlext.getAllNodes(node, path)
     #print node, tag + '/' + comp_tag, nodes
     if len(nodes)==0 and req==mandatory:
         errs.append(where + ': ' + _('Mandatory list "%s" under "%s" node is empty.') % (path, node.name()))
     ix = 1
     for node in nodes:
         dummy = xmlext.newNode(node, "Dummy")
         xmlext.addNode(dummy, '', node)
         l.append(decode_item(dummy, errs, where + unicode("[%s]" % ix)))
         #l.append(decode_item(node, errs, where + unicode("[%s]" % ix)))
         ix += 1
     return l
Esempio n. 7
0
 def decode(self, node, errs, where=""):
     # flags, tag name, instance attribute
     assert self.tag != ""
     nodes = xmlext.getAllNodes(node, self.tag)
     if not nodes:
         if self.req == mandatory:
             errs.append(where + ": " + _("At least one '%s' tag should have local text") % self.tag)
     else:
         for node in nodes:
             lang = xmlext.getNodeAttribute(node, "xml:lang")
             c = xmlext.getNodeText(node)
             if not c:
                 errs.append(where + ": " + _("'%s' language of tag '%s' is empty") % (lang, self.tag))
             # FIXME: check for dups and 'en'
             if not lang:
                 lang = "en"
             self[lang] = c
Esempio n. 8
0
 def decode(self, node, errs, where=""):
     # flags, tag name, instance attribute
     assert self.tag != ''
     nodes = xmlext.getAllNodes(node, self.tag)
     if not nodes:
         if self.req == mandatory:
             errs.append(where + ': ' +
                         _("At least one '%s' tag should have local text") %
                         self.tag)
     else:
         for node in nodes:
             lang = xmlext.getNodeAttribute(node, 'xml:lang')
             c = xmlext.getNodeText(node)
             if not c:
                 errs.append(where + ': ' +
                             _("'%s' language of tag '%s' is empty") %
                             (lang, self.tag))
             # FIXME: check for dups and 'en'
             if not lang:
                 lang = 'en'
             self[lang] = c
Esempio n. 9
0
        def decode(node, errs, where, use_ondemand):

            if use_ondemand:
                l = ondemand.OnDemandList()
            else:
                l = []

            nodes = xmlext.getAllNodes(node, path)
            # print node, tag + '/' + comp_tag, nodes
            if len(nodes) == 0 and req == mandatory:
                errs.append(where + ": " + _('Mandatory list "%s" under "%s" node is empty.') % (path, node.name()))
            ix = 1
            for node in nodes:
                dummy = xmlext.newNode(node, "Dummy")
                xmlext.addNode(dummy, "", node)
                if use_ondemand:
                    l.append(ondemand.OnDemandNode(decode_item, dummy, where + unicode("[%s]" % ix)))
                else:
                    l.append(decode_item(dummy, errs, where + unicode("[%s]" % ix), use_ondemand))
                # l.append(decode_item(node, errs, where + unicode("[%s]" % ix)))
                ix += 1
            return l