a
    ”˜ëjþ	  ã                   @   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   sD   t | ƒt| ƒ t| ƒ }dtj  kr.dk r@n n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
   úa/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/requests_toolbelt/utils/deprecated.pyÚ
<listcomp>(   ó    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¡}|rFzt| j|ƒW S  tyD   | | ¡ ¡ Y n0 t	| jƒ}|D ]F}| ¡ }||v rjqTzt| j|ƒW   S  ty˜   | |¡ Y qT0 qT|rÆzt| j|dd�W S  t
yÄ   Y n0 | 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,   s,    
r$   )Ú__doc__Úrer   Úrequestsr   ÚcompileÚIÚfindallr   r   r   r   r$   r
   r
   r
   r   Ú<module>   s   ÿÿÿ