Exemplo n.º 1
0
    def startElement(self, name, attrs: AttributesNSImpl):
        self.parser_path.append(name)
        xpath = '/' + ('/'.join(self.parser_path))
        copy_path = list(self.parser_path)
        node_name = ('_'.join(self.parser_path))

        curr_schema = self.schema.get(xpath)  # type: OrderedDict
        if curr_schema is None:
            fc_ = FeedColumn(
                type="TEXT",
                search_path=xpath,
                path=copy_path,
                name=name,
                display_name=node_name
            )
            curr_schema = self.schema.setdefault(xpath, fc_)

        if curr_schema:
            attrs_names = attrs.getNames()
            if attrs_names:
                for attr_name in attrs_names:
                    attr_xpath = xpath + "/@" + attr_name
                    attr_node = self.schema.get(attr_xpath)
                    if attr_node is None:
                        fc_ = FeedColumn(
                            type="TEXT",
                            search_path=attr_xpath,
                            path=copy_path,
                            name=attr_name,
                            display_name=node_name + "_" + attr_name
                        )
                        self.schema.setdefault(attr_xpath, fc_)
Exemplo n.º 2
0
    def startElement(self, name, attrs: AttributesNSImpl):
        self.parser_path.append(name)
        xpath = '/' + ('/'.join(self.parser_path))
        copy_path = list(self.parser_path)
        node_name = ('_'.join(self.parser_path))

        curr_schema = self.schema.get(xpath)  # type: OrderedDict
        if curr_schema is None:
            fc_ = FeedColumn(type="TEXT",
                             search_path=xpath,
                             path=copy_path,
                             name=name,
                             display_name=node_name)
            curr_schema = self.schema.setdefault(xpath, fc_)

        if curr_schema:
            attrs_names = attrs.getNames()
            if attrs_names:
                for attr_name in attrs_names:
                    attr_xpath = xpath + "/@" + attr_name
                    attr_node = self.schema.get(attr_xpath)
                    if attr_node is None:
                        fc_ = FeedColumn(type="TEXT",
                                         search_path=attr_xpath,
                                         path=copy_path,
                                         name=attr_name,
                                         display_name=node_name + "_" +
                                         attr_name)
                        self.schema.setdefault(attr_xpath, fc_)
Exemplo n.º 3
0
    def test_nsattrs_wattr(self):
        attrs = AttributesNSImpl({(ns_uri, "attr"): "val"}, {(ns_uri, "attr"): "ns:attr"})

        self.assertEqual(attrs.getLength(), 1)
        self.assertEqual(attrs.getNames(), [(ns_uri, "attr")])
        self.assertEqual(attrs.getQNames(), ["ns:attr"])
        self.assertEqual(len(attrs), 1)
        self.assertIn((ns_uri, "attr"), attrs)
        self.assertEqual(list(attrs.keys()), [(ns_uri, "attr")])
        self.assertEqual(attrs.get((ns_uri, "attr")), "val")
        self.assertEqual(attrs.get((ns_uri, "attr"), 25), "val")
        self.assertEqual(list(attrs.items()), [((ns_uri, "attr"), "val")])
        self.assertEqual(list(attrs.values()), ["val"])
        self.assertEqual(attrs.getValue((ns_uri, "attr")), "val")
        self.assertEqual(attrs.getValueByQName("ns:attr"), "val")
        self.assertEqual(attrs.getNameByQName("ns:attr"), (ns_uri, "attr"))
        self.assertEqual(attrs[(ns_uri, "attr")], "val")
        self.assertEqual(attrs.getQNameByName((ns_uri, "attr")), "ns:attr")
Exemplo n.º 4
0
 def test_nsattrs_wattr(self):
     attrs = AttributesNSImpl({(ns_uri, 'attr'): 'val'},
                              {(ns_uri, 'attr'): 'ns:attr'})
     self.assertEqual(attrs.getLength(), 1)
     self.assertEqual(attrs.getNames(), [(ns_uri, 'attr')])
     self.assertEqual(attrs.getQNames(), ['ns:attr'])
     self.assertEqual(len(attrs), 1)
     self.assertIn((ns_uri, 'attr'), attrs)
     self.assertEqual(list(attrs.keys()), [(ns_uri, 'attr')])
     self.assertEqual(attrs.get((ns_uri, 'attr')), 'val')
     self.assertEqual(attrs.get((ns_uri, 'attr'), 25), 'val')
     self.assertEqual(list(attrs.items()), [((ns_uri, 'attr'), 'val')])
     self.assertEqual(list(attrs.values()), ['val'])
     self.assertEqual(attrs.getValue((ns_uri, 'attr')), 'val')
     self.assertEqual(attrs.getValueByQName('ns:attr'), 'val')
     self.assertEqual(attrs.getNameByQName('ns:attr'), (ns_uri, 'attr'))
     self.assertEqual(attrs[ns_uri, 'attr'], 'val')
     self.assertEqual(attrs.getQNameByName((ns_uri, 'attr')), 'ns:attr')
Exemplo n.º 5
0
def test_nsattrs_wattr():
    attrs = AttributesNSImpl({(ns_uri, "attr"): "val"},
                             {(ns_uri, "attr"): "ns:attr"})

    return attrs.getLength() == 1 and \
           attrs.getNames() == [(ns_uri, "attr")] and \
           attrs.getQNames() == ["ns:attr"] and \
           len(attrs) == 1 and \
           attrs.has_key((ns_uri, "attr")) and \
           attrs.keys() == [(ns_uri, "attr")] and \
           attrs.get((ns_uri, "attr")) == "val" and \
           attrs.get((ns_uri, "attr"), 25) == "val" and \
           attrs.items() == [((ns_uri, "attr"), "val")] and \
           attrs.values() == ["val"] and \
           attrs.getValue((ns_uri, "attr")) == "val" and \
           attrs.getValueByQName("ns:attr") == "val" and \
           attrs.getNameByQName("ns:attr") == (ns_uri, "attr") and \
           attrs[(ns_uri, "attr")] == "val" and \
           attrs.getQNameByName((ns_uri, "attr")) == "ns:attr"
Exemplo n.º 6
0
    def test_nsattrs_wattr(self):
        attrs = AttributesNSImpl({(ns_uri, "attr"): "val"},
                                 {(ns_uri, "attr"): "ns:attr"})

        self.assertEqual(attrs.getLength(), 1)
        self.assertEqual(attrs.getNames(), [(ns_uri, "attr")])
        self.assertEqual(attrs.getQNames(), ["ns:attr"])
        self.assertEqual(len(attrs), 1)
        self.assertIn((ns_uri, "attr"), attrs)
        self.assertEqual(list(attrs.keys()), [(ns_uri, "attr")])
        self.assertEqual(attrs.get((ns_uri, "attr")), "val")
        self.assertEqual(attrs.get((ns_uri, "attr"), 25), "val")
        self.assertEqual(list(attrs.items()), [((ns_uri, "attr"), "val")])
        self.assertEqual(list(attrs.values()), ["val"])
        self.assertEqual(attrs.getValue((ns_uri, "attr")), "val")
        self.assertEqual(attrs.getValueByQName("ns:attr"), "val")
        self.assertEqual(attrs.getNameByQName("ns:attr"), (ns_uri, "attr"))
        self.assertEqual(attrs[(ns_uri, "attr")], "val")
        self.assertEqual(attrs.getQNameByName((ns_uri, "attr")), "ns:attr")
Exemplo n.º 7
0
def test_nsattrs_wattr():
    attrs = AttributesNSImpl({(ns_uri, "attr") : "val"},
                             {(ns_uri, "attr") : "ns:attr"})

    return attrs.getLength() == 1 and \
           attrs.getNames() == [(ns_uri, "attr")] and \
           attrs.getQNames() == ["ns:attr"] and \
           len(attrs) == 1 and \
           attrs.has_key((ns_uri, "attr")) and \
           attrs.keys() == [(ns_uri, "attr")] and \
           attrs.get((ns_uri, "attr")) == "val" and \
           attrs.get((ns_uri, "attr"), 25) == "val" and \
           attrs.items() == [((ns_uri, "attr"), "val")] and \
           attrs.values() == ["val"] and \
           attrs.getValue((ns_uri, "attr")) == "val" and \
           attrs.getValueByQName("ns:attr") == "val" and \
           attrs.getNameByQName("ns:attr") == (ns_uri, "attr") and \
           attrs[(ns_uri, "attr")] == "val" and \
           attrs.getQNameByName((ns_uri, "attr")) == "ns:attr"
Exemplo n.º 8
0
# regression test for SAX 2.0