summaryrefslogtreecommitdiff
path: root/defusedxml
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2019-04-14 10:57:12 +0200
committerChristian Heimes <christian@python.org>2019-04-14 11:45:26 +0200
commit454e17f51b905574ce9fa1a9c112a5f5850d83fe (patch)
tree32c4da6a80355d6b40892758e703cd95e298fa83 /defusedxml
parent44586bdd49b04e0b600321e66db135ca1d0a914e (diff)
downloaddefusedxml-git-454e17f51b905574ce9fa1a9c112a5f5850d83fe.tar.gz
Deprecate html argument from Parsers
The defused XMLParse subclass no longer passes the html argument down to the XMLParse class. The argument has been deprecated and 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. Fixes: https://github.com/tiran/defusedxml/issues/34 Co-authored-by: Erik Cederstrand <erik@cederstrand.dk> Signed-off-by: Christian Heimes <christian@python.org>
Diffstat (limited to 'defusedxml')
-rw-r--r--defusedxml/ElementTree.py20
1 files changed, 17 insertions, 3 deletions
diff --git a/defusedxml/ElementTree.py b/defusedxml/ElementTree.py
index 5d5cdf5..b350d8d 100644
--- a/defusedxml/ElementTree.py
+++ b/defusedxml/ElementTree.py
@@ -8,13 +8,13 @@
from __future__ import print_function, absolute_import
import sys
+import warnings
from xml.etree.ElementTree import TreeBuilder as _TreeBuilder
from xml.etree.ElementTree import parse as _parse
from xml.etree.ElementTree import tostring
from .common import PY3
-
if PY3:
import importlib
else:
@@ -58,14 +58,28 @@ def _get_py3_cls():
if PY3:
_XMLParser, _iterparse, ParseError = _get_py3_cls()
+_sentinel = object()
+
class DefusedXMLParser(_XMLParser):
- def __init__(self, html=0, target=None, encoding=None,
+ def __init__(self, html=_sentinel, target=None, encoding=None,
forbid_dtd=False, forbid_entities=True,
forbid_external=True):
# Python 2.x old style class
- _XMLParser.__init__(self, html, target, encoding)
+ _XMLParser.__init__(self, target=target, encoding=encoding)
+ if html is not _sentinel:
+ # the 'html' argument has been deprecated and ignored in all
+ # supported versions of Python. Python 3.8 finally removed it.
+ if html:
+ raise TypeError("'html=True' is no longer supported.")
+ else:
+ warnings.warn(
+ "'html' keyword argument is no longer supported. Pass "
+ "in arguments as keyword arguments.",
+ category=DeprecationWarning
+ )
+
self.forbid_dtd = forbid_dtd
self.forbid_entities = forbid_entities
self.forbid_external = forbid_external