3 P\ @sddZddlZddlZddlmZejdejdjZejdejdjZ ejdjZ dd Z d d Z dS) z7A collection of functions deprecated in requests.utils.N)utilss!])flagss+]s$^<\?xml.*?encoding=["\']*(.+?)["\'>]cCsDt|t|t|}dtjko,dknr@dd|D}|S)aReturn 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) rcSsg|]}|jdqS)utf8)decode).0encodingr /usr/lib/python3.6/deprecated.py (sz.get_encodings_from_content..)rr)rr) find_charset find_pragmafind_xmlsys version_info)content encodingsr r r get_encodings_from_contentsrcCst}tj|j}|rFy t|j|Stk rD|j|jYnXt |j}xJ|D]B}|j}||krlqVy t|j|Stk r|j|YqVXqVW|ryt|j|ddSt k rYnX|j S)aMReturn 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) setrZget_encoding_from_headersZheadersstrr UnicodeErroraddlowerr TypeErrortext)ZresponseZtried_encodingsr rZ _encodingr r r get_unicode_from_response,s,     r) __doc__rerZrequestsrcompileIfindallr rrrrr r r r s