def deserialize_from_text(
        cls,
        data: Optional[Union[AnyStr, IO[AnyStr]]],
        mime_type: Optional[str] = None,
        response: Optional[HTTPResponseType] = None,
    ) -> Any:
        """Decode response data according to content-type.

        Accept a stream of data as well, but will be load at once in memory for now.
        If no content-type, will return the string version (not bytes, not stream)

        :param data: The data to deserialize.
        :type data: str or bytes or file-like object
        :param response: The HTTP response.
        :type response: ~azure.core.pipeline.transport.HttpResponse
        :param str mime_type: The mime type. As mime type, charset is not expected.
        :param response: If passed, exception will be annotated with that response
        :type response: any
        :raises ~azure.core.exceptions.DecodeError: If deserialization fails
        :returns: A dict (JSON), XML tree or str, depending of the mime_type
        :rtype: dict[str, Any] or xml.etree.ElementTree.Element or str
        """
        if not data:
            return None

        if hasattr(data, "read"):
            # Assume a stream
            data = cast(IO, data).read()

        if isinstance(data, bytes):
            data_as_str = data.decode(encoding="utf-8-sig")
        else:
            # Explain to mypy the correct type.
            data_as_str = cast(str, data)

        if mime_type is None:
            return data_as_str

        if cls.JSON_REGEXP.match(mime_type):
            try:
                return json.loads(data_as_str)
            except ValueError as err:
                raise DecodeError(
                    message="JSON is invalid: {}".format(err),
                    response=response,
                    error=err,
                ) from err
        elif "xml" in (mime_type or []):
            try:
                return ET.fromstring(data_as_str)  # nosec
            except ET.ParseError as err:
                # It might be because the server has an issue, and returned JSON with
                # content-type XML....
                # So let's try a JSON load, and if it's still broken
                # let's flow the initial exception
                def _json_attemp(data):
                    try:
                        return True, json.loads(data)
                    except ValueError:
                        return False, None  # Don't care about this one

                success, json_result = _json_attemp(data)
                if success:
                    return json_result
                # If i'm here, it's not JSON, it's not XML, let's scream
                # and raise the last context in this block (the XML exception)
                # The function hack is because Py2.7 messes up with exception
                # context otherwise.
                _LOGGER.critical("Wasn't XML not JSON, failing")
                raise DecodeError("XML is invalid", response=response) from err
        elif mime_type.startswith("text/"):
            return data_as_str
        raise DecodeError("Cannot deserialize content-type: {}".format(mime_type))
Decode response data according to content-type.

        Accept a stream of data as well, but will be load at once in memory for now.
        If no content-type, will return the string version (not bytes, not stream)

        :param data: The data to deserialize.
        :type data: str or bytes or file-like object
        :param response: The HTTP response.
        :type response: ~azure.core.pipeline.transport.HttpResponse
        :param str mime_type: The mime type. As mime type, charset is not expected.
        :param response: If passed, exception will be annotated with that response
        :type response: any
        :raises ~azure.core.exceptions.DecodeError: If deserialization fails
        :returns: A dict (JSON), XML tree or str, depending of the mime_type
        :rtype: dict[str, Any] or xml.etree.ElementTree.Element or str
        
Solutions/CyberArkAudit/Data Connectors/.python_packages/lib/site-packages/azure/core/pipeline/policies/_universal.py