Commits

Christian Heimes committed 03dcdcd

tests for iterparse

Comments (0)

Files changed (1)

 from defusedxml.common import PY3, PY26, PY31
 
 if PY3:
-    from xmlrpclib.client import ExpatParser as XmlRpcParser
+    from xmlrpc.client import ExpatParser as XmlRpcParser
 else:
     from xmlrpclib import ExpatParser as XmlRpcParser
 
 
     external_ref_exception = ExternalReferenceForbidden
     cyclic_error = None
-
+    iterparse = None
 
     def test_simple_parse(self):
         self.parse(self.xml_simple)
         self.assertRaises(EntitiesForbidden, self.parseString,
                           self.get_content(self.xml_external))
 
+        if self.iterparse:
+            self.assertRaises(EntitiesForbidden, self.iterparse,
+                              self.xml_bomb)
+            self.assertRaises(EntitiesForbidden, self.iterparse,
+                              self.xml_quadratic)
+            self.assertRaises(EntitiesForbidden, self.iterparse,
+                              self.xml_external)
+
     def test_entity_cycle(self):
         self.assertRaises(self.cyclic_error, self.parse, self.xml_cyclic,
                           forbid_entities=False)
                           self.get_content(self.xml_dtd),
                           forbid_dtd=True)
 
+        if self.iterparse:
+            self.assertRaises(DTDForbidden, self.iterparse,
+                              self.xml_bomb, forbid_dtd=True)
+            self.assertRaises(DTDForbidden, self.iterparse,
+                              self.xml_quadratic, forbid_dtd=True)
+            self.assertRaises(DTDForbidden, self.iterparse,
+                              self.xml_external, forbid_dtd=True)
+            self.assertRaises(DTDForbidden, self.iterparse,
+                              self.xml_dtd, forbid_dtd=True)
+
+
     def test_dtd_with_external_ref(self):
         if self.dtd_external_ref:
             self.assertRaises(self.external_ref_exception, self.parse,
         tree = self.module.fromstring(xmlstring, **kwargs)
         return self.module.tostring(tree)
 
-    def iterparse(self, source, events=None):
-        return self.module.iterparse(source, events)
+    def iterparse(self, source, **kwargs):
+        return list(self.module.iterparse(source, **kwargs))
 
 
 class TestDefusedcElementTree(TestDefusedElementTree):
     cyclic_error = SAXParseException
 
     dtd_external_ref = True
-    iterparse = None
 
     def parse(self, xmlfile, **kwargs):
         events = self.module.parse(xmlfile, **kwargs)
     content_binary = True
     dtd_external_ref = True
 
-    iterparse = None
-
     def parse(self, xmlfile, **kwargs):
         if PY3:
             result = io.StringIO()
     cyclic_error = XMLSyntaxError
 
     content_binary = True
-    iterparse = None
 
     def parse(self, xmlfile, **kwargs):
         tree = self.module.parse(xmlfile, **kwargs)
         parser.close()
         return target
 
-    def test_xmlrpc(self):
-        self.parse(self.xml_bomb)
-        self.parse(self.xml_quadratic)
+    #def test_xmlrpc(self):
+    #    self.parse(self.xml_bomb)
+    #    self.parse(self.xml_quadratic)
 
 
 def test_main():