ó
ž{Uc           @   s8   d  Z  d d l Z d d l m Z d „  Z d „  Z d S(   s7   A collection of functions deprecated in requests.utils.iÿÿÿÿN(   t   utilsc         C   sf   t  j d d t  j ƒj } t  j d d t  j ƒj } t  j d ƒ j } | |  ƒ | |  ƒ | |  ƒ S(   sL  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
    s!   <meta.*?charset=["\']*(.+?)["\'>]t   flagss+   <meta.*?content=["\']*;?charset=(.+?)["\'>]s$   ^<\?xml.*?encoding=["\']*(.+?)["\'>](   t   ret   compilet   It   findall(   t   contentt   find_charsett   find_pragmat   find_xml(    (    sF   /usr/lib/python2.7/dist-packages/requests_toolbelt/utils/deprecated.pyt   get_encodings_from_content   s    c         C   s  t  ƒ  } t j |  j ƒ } | r_ y t |  j | ƒ SWq_ t k
 r[ | j | j ƒ  ƒ q_ Xn  t	 |  j ƒ } xa | D]Y } | j ƒ  } | | k r™ qu n  y t |  j | ƒ SWqu t k
 rÍ | j | ƒ qu Xqu W| r	y t |  j | d d ƒSWq	t
 k
 rq	Xn  |  j S(   sM  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
    t   errorst   replace(   t   setR    t   get_encoding_from_headerst   headerst   strR   t   UnicodeErrort   addt   lowerR
   t	   TypeErrort   text(   t   responset   tried_encodingst   encodingt	   encodingst	   _encoding(    (    sF   /usr/lib/python2.7/dist-packages/requests_toolbelt/utils/deprecated.pyt   get_unicode_from_response%   s,    	(   t   __doc__R   t   requestsR    R
   R   (    (    (    sF   /usr/lib/python2.7/dist-packages/requests_toolbelt/utils/deprecated.pyt   <module>   s   	