Commits

Christian Heimes committed 91d4328

grab ParseError from pure Python module / pyexpat

  • Participants
  • Parent commits 6c9f83c

Comments (0)

Files changed (1)

defusedxml/ElementTree.py

 from __future__ import print_function, absolute_import, division
 
 import sys
-from .common import PY3
+from .common import PY3, PY26
 if PY3:
     import importlib
-    _XMLParser, _iterparse, _IterParseIterator = None, None, None
+    _XMLParser = None
+    _iterparse = None
+    _IterParseIterator = None
+    ParseError = None
 else:
     from xml.etree.ElementTree import XMLParser as _XMLParser
     from xml.etree.ElementTree import iterparse as _iterparse
+    if PY26:
+        from xml.parsers.expat import ExpatError as ParseError
+    else:
+        from xml.etree.ElementTree import ParseError
     _IterParseIterator = None
 from xml.etree.ElementTree import TreeBuilder as _TreeBuilder
 from xml.etree.ElementTree import parse as _parse
 
 
 from .common import (DTDForbidden, EntitiesForbidden,
-                     ExternalEntitiesForbidden, PY26)
+                     ExternalEntitiesForbidden)
 
 
 def _get_python_classes():
 
     The code is based on test.support.import_fresh_module
     """
-    global _XMLParser, _iterparse, _IterParseIterator
+    global _XMLParser, _iterparse, _IterParseIterator, ParseError
     pymodname = "xml.etree.ElementTree"
     cmodname = "_elementtree"
 
     _XMLParser = pure_pymod.XMLParser
     _iterparse = pure_pymod.iterparse
     _IterParseIterator = pure_pymod._IterParseIterator
+    ParseError = pure_pymod.ParseError
 
 if PY3:
     _get_python_classes()