Python xml.dom.pulldom.SAX2DOM Examples

The following are 30 code examples of xml.dom.pulldom.SAX2DOM(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module xml.dom.pulldom , or try the search function .
Example #1
Source File: test_pulldom.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def testSAX2DOM(self):
        """Ensure SAX2DOM expands nodes as expected."""
        sax2dom = pulldom.SAX2DOM()
        sax2dom.startDocument()
        sax2dom.startElement("doc", {})
        sax2dom.characters("text")
        sax2dom.startElement("subelm", {})
        sax2dom.characters("text")
        sax2dom.endElement("subelm")
        sax2dom.characters("text")
        sax2dom.endElement("doc")
        sax2dom.endDocument()

        doc = sax2dom.document
        root = doc.documentElement
        (text1, elm1, text2) = root.childNodes
        text3 = elm1.childNodes[0]

        self.assertIsNone(text1.previousSibling)
        self.assertIs(text1.nextSibling, elm1)
        self.assertIs(elm1.previousSibling, text1)
        self.assertIs(elm1.nextSibling, text2)
        self.assertIs(text2.previousSibling, elm1)
        self.assertIsNone(text2.nextSibling)
        self.assertIsNone(text3.previousSibling)
        self.assertIsNone(text3.nextSibling)

        self.assertIs(root.parentNode, doc)
        self.assertIs(text1.parentNode, root)
        self.assertIs(elm1.parentNode, root)
        self.assertIs(text2.parentNode, root)
        self.assertIs(text3.parentNode, elm1)
        doc.unlink() 
Example #2
Source File: test_minidom.py    From CTFCrackTools with GNU General Public License v3.0 5 votes vote down vote up
def testSAX2DOM(self):
        from xml.dom import pulldom

        sax2dom = pulldom.SAX2DOM()
        sax2dom.startDocument()
        sax2dom.startElement("doc", {})
        sax2dom.characters("text")
        sax2dom.startElement("subelm", {})
        sax2dom.characters("text")
        sax2dom.endElement("subelm")
        sax2dom.characters("text")
        sax2dom.endElement("doc")
        sax2dom.endDocument()

        doc = sax2dom.document
        root = doc.documentElement
        (text1, elm1, text2) = root.childNodes
        text3 = elm1.childNodes[0]

        self.confirm(text1.previousSibling is None and
                text1.nextSibling is elm1 and
                elm1.previousSibling is text1 and
                elm1.nextSibling is text2 and
                text2.previousSibling is elm1 and
                text2.nextSibling is None and
                text3.previousSibling is None and
                text3.nextSibling is None, "testSAX2DOM - siblings")

        self.confirm(root.parentNode is doc and
                text1.parentNode is root and
                elm1.parentNode is root and
                text2.parentNode is root and
                text3.parentNode is elm1, "testSAX2DOM - parents")
        doc.unlink() 
Example #3
Source File: test_pulldom.py    From android_universal with MIT License 5 votes vote down vote up
def testSAX2DOM(self):
        """Ensure SAX2DOM expands nodes as expected."""
        sax2dom = pulldom.SAX2DOM()
        sax2dom.startDocument()
        sax2dom.startElement("doc", {})
        sax2dom.characters("text")
        sax2dom.startElement("subelm", {})
        sax2dom.characters("text")
        sax2dom.endElement("subelm")
        sax2dom.characters("text")
        sax2dom.endElement("doc")
        sax2dom.endDocument()

        doc = sax2dom.document
        root = doc.documentElement
        (text1, elm1, text2) = root.childNodes
        text3 = elm1.childNodes[0]

        self.assertIsNone(text1.previousSibling)
        self.assertIs(text1.nextSibling, elm1)
        self.assertIs(elm1.previousSibling, text1)
        self.assertIs(elm1.nextSibling, text2)
        self.assertIs(text2.previousSibling, elm1)
        self.assertIsNone(text2.nextSibling)
        self.assertIsNone(text3.previousSibling)
        self.assertIsNone(text3.nextSibling)

        self.assertIs(root.parentNode, doc)
        self.assertIs(text1.parentNode, root)
        self.assertIs(elm1.parentNode, root)
        self.assertIs(text2.parentNode, root)
        self.assertIs(text3.parentNode, elm1)
        doc.unlink() 
Example #4
Source File: test_pulldom.py    From android_universal with MIT License 5 votes vote down vote up
def test_basic(self):
        """Ensure SAX2DOM can parse from a stream."""
        with io.StringIO(SMALL_SAMPLE) as fin:
            sd = SAX2DOMTestHelper(fin, xml.sax.make_parser(),
                                   len(SMALL_SAMPLE))
            for evt, node in sd:
                if evt == pulldom.START_ELEMENT and node.tagName == "html":
                    break
            # Because the buffer is the same length as the XML, all the
            # nodes should have been parsed and added:
            self.assertGreater(len(node.childNodes), 0) 
Example #5
Source File: test_pulldom.py    From android_universal with MIT License 5 votes vote down vote up
def reset(self):
        self.pulldom = pulldom.SAX2DOM()
        # This content handler relies on namespace support
        self.parser.setFeature(xml.sax.handler.feature_namespaces, 1)
        self.parser.setContentHandler(self.pulldom) 
Example #6
Source File: test_pulldom.py    From android_universal with MIT License 5 votes vote down vote up
def test_thorough_sax2dom(self):
        """Test some of the hard-to-reach parts of SAX2DOM."""
        pd = SAX2DOMTestHelper(None, SAX2DOMExerciser(), 12)
        self._test_thorough(pd, False) 
Example #7
Source File: test_pulldom.py    From android_universal with MIT License 5 votes vote down vote up
def test_sax2dom_fail(self):
        """SAX2DOM can"t handle a PI before the root element."""
        pd = SAX2DOMTestHelper(None, SAXExerciser(), 12)
        self._test_thorough(pd) 
Example #8
Source File: test_minidom.py    From CTFCrackTools-V2 with GNU General Public License v3.0 5 votes vote down vote up
def testSAX2DOM(self):
        from xml.dom import pulldom

        sax2dom = pulldom.SAX2DOM()
        sax2dom.startDocument()
        sax2dom.startElement("doc", {})
        sax2dom.characters("text")
        sax2dom.startElement("subelm", {})
        sax2dom.characters("text")
        sax2dom.endElement("subelm")
        sax2dom.characters("text")
        sax2dom.endElement("doc")
        sax2dom.endDocument()

        doc = sax2dom.document
        root = doc.documentElement
        (text1, elm1, text2) = root.childNodes
        text3 = elm1.childNodes[0]

        self.confirm(text1.previousSibling is None and
                text1.nextSibling is elm1 and
                elm1.previousSibling is text1 and
                elm1.nextSibling is text2 and
                text2.previousSibling is elm1 and
                text2.nextSibling is None and
                text3.previousSibling is None and
                text3.nextSibling is None, "testSAX2DOM - siblings")

        self.confirm(root.parentNode is doc and
                text1.parentNode is root and
                elm1.parentNode is root and
                text2.parentNode is root and
                text3.parentNode is elm1, "testSAX2DOM - parents")
        doc.unlink() 
Example #9
Source File: test_minidom.py    From medicare-demo with Apache License 2.0 5 votes vote down vote up
def testSAX2DOM():
    from xml.dom import pulldom

    sax2dom = pulldom.SAX2DOM()
    sax2dom.startDocument()
    sax2dom.startElement("doc", {})
    sax2dom.characters("text")
    sax2dom.startElement("subelm", {})
    sax2dom.characters("text")
    sax2dom.endElement("subelm")
    sax2dom.characters("text")
    sax2dom.endElement("doc")
    sax2dom.endDocument()

    doc = sax2dom.document
    root = doc.documentElement
    (text1, elm1, text2) = root.childNodes
    text3 = elm1.childNodes[0]

    confirm(text1.previousSibling is None and
            text1.nextSibling is elm1 and
            elm1.previousSibling is text1 and
            elm1.nextSibling is text2 and
            text2.previousSibling is elm1 and
            text2.nextSibling is None and
            text3.previousSibling is None and
            text3.nextSibling is None, "testSAX2DOM - siblings")

    confirm(root.parentNode is doc and
            text1.parentNode is root and
            elm1.parentNode is root and
            text2.parentNode is root and
            text3.parentNode is elm1, "testSAX2DOM - parents")

    doc.unlink()

# --- MAIN PROGRAM 
Example #10
Source File: test_pulldom.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def testSAX2DOM(self):
        """Ensure SAX2DOM expands nodes as expected."""
        sax2dom = pulldom.SAX2DOM()
        sax2dom.startDocument()
        sax2dom.startElement("doc", {})
        sax2dom.characters("text")
        sax2dom.startElement("subelm", {})
        sax2dom.characters("text")
        sax2dom.endElement("subelm")
        sax2dom.characters("text")
        sax2dom.endElement("doc")
        sax2dom.endDocument()

        doc = sax2dom.document
        root = doc.documentElement
        (text1, elm1, text2) = root.childNodes
        text3 = elm1.childNodes[0]

        self.assertIsNone(text1.previousSibling)
        self.assertIs(text1.nextSibling, elm1)
        self.assertIs(elm1.previousSibling, text1)
        self.assertIs(elm1.nextSibling, text2)
        self.assertIs(text2.previousSibling, elm1)
        self.assertIsNone(text2.nextSibling)
        self.assertIsNone(text3.previousSibling)
        self.assertIsNone(text3.nextSibling)

        self.assertIs(root.parentNode, doc)
        self.assertIs(text1.parentNode, root)
        self.assertIs(elm1.parentNode, root)
        self.assertIs(text2.parentNode, root)
        self.assertIs(text3.parentNode, elm1)
        doc.unlink() 
Example #11
Source File: test_pulldom.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_basic(self):
        """Ensure SAX2DOM can parse from a stream."""
        with io.StringIO(SMALL_SAMPLE) as fin:
            sd = SAX2DOMTestHelper(fin, xml.sax.make_parser(),
                                   len(SMALL_SAMPLE))
            for evt, node in sd:
                if evt == pulldom.START_ELEMENT and node.tagName == "html":
                    break
            # Because the buffer is the same length as the XML, all the
            # nodes should have been parsed and added:
            self.assertGreater(len(node.childNodes), 0) 
Example #12
Source File: test_pulldom.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def reset(self):
        self.pulldom = pulldom.SAX2DOM()
        # This content handler relies on namespace support
        self.parser.setFeature(xml.sax.handler.feature_namespaces, 1)
        self.parser.setContentHandler(self.pulldom) 
Example #13
Source File: test_pulldom.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_thorough_sax2dom(self):
        """Test some of the hard-to-reach parts of SAX2DOM."""
        pd = SAX2DOMTestHelper(None, SAX2DOMExerciser(), 12)
        self._test_thorough(pd, False) 
Example #14
Source File: test_pulldom.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_sax2dom_fail(self):
        """SAX2DOM can"t handle a PI before the root element."""
        pd = SAX2DOMTestHelper(None, SAXExerciser(), 12)
        self._test_thorough(pd) 
Example #15
Source File: test_minidom.py    From gcblue with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def testSAX2DOM(self):
        from xml.dom import pulldom

        sax2dom = pulldom.SAX2DOM()
        sax2dom.startDocument()
        sax2dom.startElement("doc", {})
        sax2dom.characters("text")
        sax2dom.startElement("subelm", {})
        sax2dom.characters("text")
        sax2dom.endElement("subelm")
        sax2dom.characters("text")
        sax2dom.endElement("doc")
        sax2dom.endDocument()

        doc = sax2dom.document
        root = doc.documentElement
        (text1, elm1, text2) = root.childNodes
        text3 = elm1.childNodes[0]

        self.confirm(text1.previousSibling is None and
                text1.nextSibling is elm1 and
                elm1.previousSibling is text1 and
                elm1.nextSibling is text2 and
                text2.previousSibling is elm1 and
                text2.nextSibling is None and
                text3.previousSibling is None and
                text3.nextSibling is None, "testSAX2DOM - siblings")

        self.confirm(root.parentNode is doc and
                text1.parentNode is root and
                elm1.parentNode is root and
                text2.parentNode is root and
                text3.parentNode is elm1, "testSAX2DOM - parents")
        doc.unlink() 
Example #16
Source File: apk.py    From dcc with Apache License 2.0 5 votes vote down vote up
def parse_lxml_dom(tree):
    handler = SAX2DOM()
    lxml.sax.saxify(tree, handler)
    return handler.document 
Example #17
Source File: test_pulldom.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_basic(self):
        """Ensure SAX2DOM can parse from a stream."""
        with io.StringIO(SMALL_SAMPLE) as fin:
            sd = SAX2DOMTestHelper(fin, xml.sax.make_parser(),
                                   len(SMALL_SAMPLE))
            for evt, node in sd:
                if evt == pulldom.START_ELEMENT and node.tagName == "html":
                    break
            # Because the buffer is the same length as the XML, all the
            # nodes should have been parsed and added:
            self.assertGreater(len(node.childNodes), 0) 
Example #18
Source File: test_pulldom.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def reset(self):
        self.pulldom = pulldom.SAX2DOM()
        # This content handler relies on namespace support
        self.parser.setFeature(xml.sax.handler.feature_namespaces, 1)
        self.parser.setContentHandler(self.pulldom) 
Example #19
Source File: test_pulldom.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_thorough_sax2dom(self):
        """Test some of the hard-to-reach parts of SAX2DOM."""
        pd = SAX2DOMTestHelper(None, SAX2DOMExerciser(), 12)
        self._test_thorough(pd, False) 
Example #20
Source File: test_pulldom.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_sax2dom_fail(self):
        """SAX2DOM can"t handle a PI before the root element."""
        pd = SAX2DOMTestHelper(None, SAXExerciser(), 12)
        self._test_thorough(pd) 
Example #21
Source File: test_pulldom.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def testSAX2DOM(self):
        """Ensure SAX2DOM expands nodes as expected."""
        sax2dom = pulldom.SAX2DOM()
        sax2dom.startDocument()
        sax2dom.startElement("doc", {})
        sax2dom.characters("text")
        sax2dom.startElement("subelm", {})
        sax2dom.characters("text")
        sax2dom.endElement("subelm")
        sax2dom.characters("text")
        sax2dom.endElement("doc")
        sax2dom.endDocument()

        doc = sax2dom.document
        root = doc.documentElement
        (text1, elm1, text2) = root.childNodes
        text3 = elm1.childNodes[0]

        self.assertIsNone(text1.previousSibling)
        self.assertIs(text1.nextSibling, elm1)
        self.assertIs(elm1.previousSibling, text1)
        self.assertIs(elm1.nextSibling, text2)
        self.assertIs(text2.previousSibling, elm1)
        self.assertIsNone(text2.nextSibling)
        self.assertIsNone(text3.previousSibling)
        self.assertIsNone(text3.nextSibling)

        self.assertIs(root.parentNode, doc)
        self.assertIs(text1.parentNode, root)
        self.assertIs(elm1.parentNode, root)
        self.assertIs(text2.parentNode, root)
        self.assertIs(text3.parentNode, elm1)
        doc.unlink() 
Example #22
Source File: test_pulldom.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_basic(self):
        """Ensure SAX2DOM can parse from a stream."""
        with io.StringIO(SMALL_SAMPLE) as fin:
            sd = SAX2DOMTestHelper(fin, xml.sax.make_parser(),
                                   len(SMALL_SAMPLE))
            for evt, node in sd:
                if evt == pulldom.START_ELEMENT and node.tagName == "html":
                    break
            # Because the buffer is the same length as the XML, all the
            # nodes should have been parsed and added:
            self.assertGreater(len(node.childNodes), 0) 
Example #23
Source File: test_pulldom.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def reset(self):
        self.pulldom = pulldom.SAX2DOM()
        # This content handler relies on namespace support
        self.parser.setFeature(xml.sax.handler.feature_namespaces, 1)
        self.parser.setContentHandler(self.pulldom) 
Example #24
Source File: test_pulldom.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_thorough_sax2dom(self):
        """Test some of the hard-to-reach parts of SAX2DOM."""
        pd = SAX2DOMTestHelper(None, SAX2DOMExerciser(), 12)
        self._test_thorough(pd, False) 
Example #25
Source File: test_pulldom.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_sax2dom_fail(self):
        """SAX2DOM can"t handle a PI before the root element."""
        pd = SAX2DOMTestHelper(None, SAXExerciser(), 12)
        self._test_thorough(pd) 
Example #26
Source File: test_minidom.py    From oss-ftp with MIT License 5 votes vote down vote up
def testSAX2DOM(self):
        from xml.dom import pulldom

        sax2dom = pulldom.SAX2DOM()
        sax2dom.startDocument()
        sax2dom.startElement("doc", {})
        sax2dom.characters("text")
        sax2dom.startElement("subelm", {})
        sax2dom.characters("text")
        sax2dom.endElement("subelm")
        sax2dom.characters("text")
        sax2dom.endElement("doc")
        sax2dom.endDocument()

        doc = sax2dom.document
        root = doc.documentElement
        (text1, elm1, text2) = root.childNodes
        text3 = elm1.childNodes[0]

        self.confirm(text1.previousSibling is None and
                text1.nextSibling is elm1 and
                elm1.previousSibling is text1 and
                elm1.nextSibling is text2 and
                text2.previousSibling is elm1 and
                text2.nextSibling is None and
                text3.previousSibling is None and
                text3.nextSibling is None, "testSAX2DOM - siblings")

        self.confirm(root.parentNode is doc and
                text1.parentNode is root and
                elm1.parentNode is root and
                text2.parentNode is root and
                text3.parentNode is elm1, "testSAX2DOM - parents")
        doc.unlink() 
Example #27
Source File: test_minidom.py    From BinderFilter with MIT License 5 votes vote down vote up
def testSAX2DOM(self):
        from xml.dom import pulldom

        sax2dom = pulldom.SAX2DOM()
        sax2dom.startDocument()
        sax2dom.startElement("doc", {})
        sax2dom.characters("text")
        sax2dom.startElement("subelm", {})
        sax2dom.characters("text")
        sax2dom.endElement("subelm")
        sax2dom.characters("text")
        sax2dom.endElement("doc")
        sax2dom.endDocument()

        doc = sax2dom.document
        root = doc.documentElement
        (text1, elm1, text2) = root.childNodes
        text3 = elm1.childNodes[0]

        self.confirm(text1.previousSibling is None and
                text1.nextSibling is elm1 and
                elm1.previousSibling is text1 and
                elm1.nextSibling is text2 and
                text2.previousSibling is elm1 and
                text2.nextSibling is None and
                text3.previousSibling is None and
                text3.nextSibling is None, "testSAX2DOM - siblings")

        self.confirm(root.parentNode is doc and
                text1.parentNode is root and
                elm1.parentNode is root and
                text2.parentNode is root and
                text3.parentNode is elm1, "testSAX2DOM - parents")
        doc.unlink() 
Example #28
Source File: test_minidom.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def testSAX2DOM(self):
        from xml.dom import pulldom

        sax2dom = pulldom.SAX2DOM()
        sax2dom.startDocument()
        sax2dom.startElement("doc", {})
        sax2dom.characters("text")
        sax2dom.startElement("subelm", {})
        sax2dom.characters("text")
        sax2dom.endElement("subelm")
        sax2dom.characters("text")
        sax2dom.endElement("doc")
        sax2dom.endDocument()

        doc = sax2dom.document
        root = doc.documentElement
        (text1, elm1, text2) = root.childNodes
        text3 = elm1.childNodes[0]

        self.confirm(text1.previousSibling is None and
                text1.nextSibling is elm1 and
                elm1.previousSibling is text1 and
                elm1.nextSibling is text2 and
                text2.previousSibling is elm1 and
                text2.nextSibling is None and
                text3.previousSibling is None and
                text3.nextSibling is None, "testSAX2DOM - siblings")

        self.confirm(root.parentNode is doc and
                text1.parentNode is root and
                elm1.parentNode is root and
                text2.parentNode is root and
                text3.parentNode is elm1, "testSAX2DOM - parents")
        doc.unlink() 
Example #29
Source File: core.py    From pyaxmlparser with Apache License 2.0 5 votes vote down vote up
def parse_lxml_dom(tree):
    handler = SAX2DOM()
    lxml.sax.saxify(tree, handler)
    return handler.document 
Example #30
Source File: utils.py    From pyaxmlparser with Apache License 2.0 5 votes vote down vote up
def parse_lxml_dom(tree):
    handler = SAX2DOM()
    lxml.sax.saxify(tree, handler)
    return handler.document