# defusedxml
#
# Copyright (c) 2013 by Christian Heimes <christian@python.org>
# Licensed to PSF under a Contributor Agreement.
# See https://www.python.org/psf/license for licensing details.
"""Defused xml.etree.cElementTree
"""
from __future__ import absolute_import

import warnings

from .common import _generate_etree_functions

from xml.etree.cElementTree import TreeBuilder as _TreeBuilder  # nosec B405
from xml.etree.cElementTree import parse as _parse  # nosec B405
from xml.etree.cElementTree import tostring  # nosec B405

# iterparse from ElementTree!
from xml.etree.ElementTree import iterparse as _iterparse  # nosec B405

# This module is an alias for ElementTree just like xml.etree.cElementTree
from .ElementTree import (
    XML,
    XMLParse,
    XMLParser,
    XMLTreeBuilder,
    fromstring,
    iterparse,
    parse,
    DefusedXMLParser,
    ParseError,
)

__origin__ = "xml.etree.cElementTree"


warnings.warn(
    "defusedxml.cElementTree is deprecated, import from defusedxml.ElementTree instead.",
    category=DeprecationWarning,
    stacklevel=2,
)

# XMLParse is a typo, keep it for backwards compatibility
XMLTreeBuilder = XMLParse = XMLParser = DefusedXMLParser  # noqa: F811

parse, iterparse, fromstring = _generate_etree_functions(  # noqa: F811
    DefusedXMLParser, _TreeBuilder, _parse, _iterparse
)
XML = fromstring  # noqa: F811

__all__ = [
    "ParseError",
    "XML",
    "XMLParse",
    "XMLParser",
    "XMLTreeBuilder",
    "fromstring",
    "iterparse",
    "parse",
    "tostring",
]
