diff options
author | Christian Heimes <christian@python.org> | 2019-04-14 11:37:42 +0200 |
---|---|---|
committer | Christian Heimes <christian@python.org> | 2019-04-14 11:45:26 +0200 |
commit | 0c5f8700f1bb775f14415150b2ccd4633e199183 (patch) | |
tree | bac0918274ab974ae4686fe2f43d109c600e36d6 | |
parent | 454e17f51b905574ce9fa1a9c112a5f5850d83fe (diff) | |
download | defusedxml-git-0c5f8700f1bb775f14415150b2ccd4633e199183.tar.gz |
Fail early when pyexpat is missing
Fixes: https://github.com/tiran/defusedxml/issues/10
Signed-off-by: Christian Heimes <christian@python.org>
-rw-r--r-- | CHANGES.txt | 2 | ||||
-rw-r--r-- | defusedxml/common.py | 5 |
2 files changed, 7 insertions, 0 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 3edecb3..e7ee54d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -12,6 +12,8 @@ defusedxml 0.6.0.dev1 ignored for a long time. The DefusedXMLParser still takes a html argument. A deprecation warning is issued when the argument is False and a TypeError when it's True. +- defusedxml now fails early when pyexpat stdlib module is not available or + broken. defusedxml 0.5.0 diff --git a/defusedxml/common.py b/defusedxml/common.py index be23e97..1995d61 100644 --- a/defusedxml/common.py +++ b/defusedxml/common.py @@ -6,9 +6,14 @@ """Common constants, exceptions and helpe functions """ import sys +import xml.parsers.expat PY3 = sys.version_info[0] == 3 +# Fail early when pyexpat is not installed correctly +if not hasattr(xml.parsers.expat, "ParserCreate"): + raise ImportError('pyexpat') + class DefusedXmlException(ValueError): """Base exception |