o
    Vh	                     @   sd   d Z ddlZddlZddlmZ ejdejdjZejdejdjZ	edjZ
dd	 Zd
d ZdS )z7A collection of functions deprecated in requests.utils.    N)utilss!   <meta.*?charset=["\']*(.+?)["\'>])flagss+   <meta.*?content=["\']*;?charset=(.+?)["\'>]s$   ^<\?xml.*?encoding=["\']*(.+?)["\'>]c                 C   sF   t | t|  t|  }dtj  krdk r!n |S dd |D }|S )a  Return encodings from given content string.

    .. code-block:: python

        import requests
        from requests_toolbelt.utils import deprecated

        r = requests.get(url)
        encodings = deprecated.get_encodings_from_content(r)

    :param content: bytestring to extract encodings from
    :type content: bytes
    :return: encodings detected in the provided content
    :rtype: list(str)
    )   r   )   r   c                 S   s   g | ]}| d qS )utf8)decode).0encoding r
   v/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/requests_toolbelt/utils/deprecated.py
<listcomp>(   s    z.get_encodings_from_content.<locals>.<listcomp>)find_charsetfind_pragmafind_xmlsysversion_info)content	encodingsr
   r
   r   get_encodings_from_content   s   r   c              	   C   s   t  }t| j}|r#zt| j|W S  ty"   ||  Y nw t	| j}|D ]"}| }||v r5q*z	t| j|W   S  tyL   || Y q*w |rdz	t| j|ddW S  t
yc   Y | jS w | jS )aM  Return the requested content back in unicode.

    This will first attempt to retrieve the encoding from the response
    headers. If that fails, it will use
    :func:`requests_toolbelt.utils.deprecated.get_encodings_from_content`
    to determine encodings from HTML elements.

    .. code-block:: python

        import requests
        from requests_toolbelt.utils import deprecated

        r = requests.get(url)
        text = deprecated.get_unicode_from_response(r)

    :param response: Response object to get unicode content from.
    :type response: requests.models.Response
    replace)errors)setr   get_encoding_from_headersheadersstrr   UnicodeErroraddlowerr   	TypeErrortext)responsetried_encodingsr	   r   	_encodingr
   r
   r   get_unicode_from_response,   s4   
r#   )__doc__rer   requestsr   compileIfindallr   r   r   r   r#   r
   r
   r
   r   <module>   s*   