Пример #1
0
 def test_minidom_externals(self):
     try:
         defusedexpat.unmonkey_patch()
         # minidom does NOT retrieve DTDs
         dom = minidom.parse(self.xml_dtd)
         # and does NOT load  external entities by default
         minidom.parse(self.xml_external)
     finally:
         defusedexpat.monkey_patch()
Пример #2
0
 def test_minidom_externals(self):
     try:
         defusedexpat.unmonkey_patch()
         # minidom does NOT retrieve DTDs
         dom = minidom.parse(self.xml_dtd)
         # and does NOT load  external entities by default
         minidom.parse(self.xml_external)
     finally:
         defusedexpat.monkey_patch()
Пример #3
0
 def test_sax_external_entity(self):
     try:
         defusedexpat.unmonkey_patch()
         # IOError caused by proxy settings, works only on POSIX
         if os.name == "posix":
             self.assertRaises(IOError, self.parse_sax, self.xml_external)
             self.assertRaises(IOError, self.parse_sax, self.xml_dtd)
     finally:
         defusedexpat.monkey_patch()
     value = self.parse_sax(self.xml_external)
     self.assertIn("<root></root>", value)
Пример #4
0
 def test_sax_external_entity(self):
     try:
         defusedexpat.unmonkey_patch()
         # IOError caused by proxy settings, works only on POSIX
         if os.name == "posix":
             self.assertRaises(IOError, self.parse_sax, self.xml_external)
             self.assertRaises(IOError, self.parse_sax, self.xml_dtd)
     finally:
         defusedexpat.monkey_patch()
     value = self.parse_sax(self.xml_external)
     self.assertIn("<root></root>", value)
Пример #5
0
    def test_pulldom_externals(self):
        try:
            defusedexpat.unmonkey_patch()
            # pulldom does DTD retrieval
            dom = pulldom.parse(self.xml_dtd)
            if os.name == "posix":
                self.assertRaises(IOError, list, dom)
            # and loads external entities by default
            dom = pulldom.parse(self.xml_external)
            if os.name == "posix":
                self.assertRaises(IOError, list, dom)
        finally:
            defusedexpat.monkey_patch()

        events = list(pulldom.parse(self.xml_dtd))
        self.assertEqual(events[9][0], 'CHARACTERS')
        self.assertEqual(events[9][1].data, "text")

        events = list(pulldom.parse(self.xml_external))
        self.assertEqual([e[0] for e in events],
                         ['START_DOCUMENT', 'START_ELEMENT', 'END_ELEMENT'])
Пример #6
0
    def test_pulldom_externals(self):
        try:
            defusedexpat.unmonkey_patch()
            # pulldom does DTD retrieval
            dom = pulldom.parse(self.xml_dtd)
            if os.name == "posix":
                self.assertRaises(IOError, list, dom)
            # and loads external entities by default
            dom = pulldom.parse(self.xml_external)
            if os.name == "posix":
                self.assertRaises(IOError, list, dom)
        finally:
            defusedexpat.monkey_patch()

        events = list(pulldom.parse(self.xml_dtd))
        self.assertEqual(events[9][0], 'CHARACTERS')
        self.assertEqual(events[9][1].data, "text")

        events = list(pulldom.parse(self.xml_external))
        self.assertEqual([e[0] for e in events],
                         ['START_DOCUMENT', 'START_ELEMENT', 'END_ELEMENT'])