Usage of an API that is not recommended
APIs that are not recommended were found. This could indicate a deeper problem in the code.
import xml.sax


class ContentHandler(xml.sax.ContentHandler):
    def __init__(self):
        xml.sax.ContentHandler.__init__(self)

    def start_element(self, name, attributes):
        print('start:', name)

    def end_element(self, name):
        print('end:', name)

    def characters(self, characters):
        print('characters:', characters)


def recommended_apis_noncompliant():
    xml_string = "<body>XML_STRING</body>"

    # Noncompliant: uses xml.sax which is an unrecommended API.
    xml.sax.parseString(xml_string, ContentHandler())


if __name__ == "__main__":
    recommended_apis_noncompliant()
import xml
import defusedxml.sax


class ContentHandler(xml.sax.ContentHandler):
    def __init__(self):
        xml.sax.ContentHandler.__init__(self)

    def start_element(self, name, attributes):
        print('start:', name)

    def end_element(self, name):
        print('end:', name)

    def characters(self, characters):
        print('characters:', characters)


def not_recommended_apis_compliant():
    xml_string = "<body>XML_STRING</body>"

    # Compliant: avoids using unrecommended APIs.
    defusedxml.sax.parseString(xml_string, ContentHandler())


if __name__ == "__main__":
    not_recommended_apis_compliant()