Edit File: deprecated.cpython-36.pyc
3 �P\� � @ sd d Z ddlZddlZddlmZ ejdejd�jZejdejd�jZ ejd�jZ dd � Zd d� ZdS )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| � }dtj ko,dk n r@dd� |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 � c S s g | ]}|j d ��qS )�utf8)�decode)�.0�encoding� r � /usr/lib/python3.6/deprecated.py� <listcomp>( s z.get_encodings_from_content.<locals>.<listcomp>)r r )r r )�find_charset�find_pragma�find_xml�sys�version_info)�content� encodingsr r r �get_encodings_from_content s r c C s� t � }tj| j�}|rFyt| j|�S tk rD |j|j� � Y nX t | j�}xJ|D ]B}|j� }||krlqVyt| j|�S tk r� |j|� Y qVX qVW |r�yt| j|dd�S t k r� Y nX | jS )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 Zget_encoding_from_headersZheaders�strr �UnicodeError�add�lowerr � TypeError�text)ZresponseZtried_encodingsr r Z _encodingr r r �get_unicode_from_response, s, r ) �__doc__�rer Zrequestsr �compile�I�findallr r r r r r r r r �<module> s
Back to File Manager