Your IP : 216.73.216.224


Current Path : /lib/python3/dist-packages/requests_toolbelt/utils/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/requests_toolbelt/utils/__pycache__/dump.cpython-38.pyc

U

�ˀX��@s�dZddlZddlmZdZdddd�Ze�d	d
dg�ZGdd	�d	e�Zd
d�Z	dd�Z
dd�Zddd�Zdd�Z
dd�Zd dd�Zd!dd�ZdS)"zGThis module provides functions for dumping information about responses.�N)�compat)�
dump_response�dump_alls0.9s1.0s1.1)�	�
��PrefixSettings�request�responsecseZdZ�fdd�Z�ZS)rcs$t|�}t|�}tt|��|||�S)N)�_coerce_to_bytes�superr�__new__)�clsr	r
��	__class__��>/usr/lib/python3/dist-packages/requests_toolbelt/utils/dump.pyr
szPrefixSettings.__new__)�__name__�
__module__�__qualname__r
�
__classcell__rrrrrscCs<t|jdd�r8i}|jj}|�d�r,d|d<||d<|SdS)NZ
proxy_managerFzhttps://ZCONNECT�method�request_path)�getattrZ
connectionr	�url�
startswith)r
�
proxy_infoZrequest_urlrrr�_get_proxy_informations
rcCst|�dt|�dS)Ns: �
)r)�name�valuerrr�_format_header&s�r!cCsNt�|�}|�d�}|dk	r$||fSt|j�}|jrF|dt|j�7}||fS)Nr�?)rZurlparse�getr�pathZquery)rr�uriZ	proxy_urlrrrr�_build_request_path+s


r&cCs�|dkri}|j}t|�d|j��}t|j|�\}}|�||d|d�|j��}t|�d|j	��}	|�|d|	d�|�
�D]\}
}|�|t|
|��q�|�|d�|jr�t
|jtj�r�|�|t|j��n
|�d�|�d�dS)Nr� s HTTP/1.1
ZHostsHost: rz,<< Request body is not a string-like type >>)r	r�poprr&r�extend�headers�copyZnetloc�itemsr!Zbody�
isinstancerZ
basestring)r	�prefixes�bytearrr�prefixrrr%r*Zhost_headerrr rrr�_dump_request_data8s"

r1c	Cs�|j}|j}t�|jd�}|�|d|dt|j��d�dt	|j
�d�|j}|��D](}|�
|�D]}|�|t||��qnq`|�|d�|�|j�dS)Nr"sHTTP/r'�asciir)r
�raw�
HTTP_VERSIONSr#�versionr)�strZstatus�encoder�reasonr*�keysZgetlistr!Zcontent)	r
r.r/r0r3Zversion_strr*rr rrr�_dump_response_dataVs$����r:cCs"t|t�st|d�r|�d�}|S)Nr7zutf-8)r-�bytes�hasattrr7)�datarrrrms
r�< �> cCsX|dk	r|nt�}t||�}t|d�s.td��t|�}t|j|||d�t|||�|S)aDump a single request-response cycle's information.

    This will take a response object and dump only the data that requests can
    see for that single request-response cycle.

    Example::

        import requests
        from requests_toolbelt.utils import dump

        resp = requests.get('https://api.github.com/users/sigmavirus24')
        data = dump.dump_response(resp)
        print(data.decode('utf-8'))

    :param response:
        The response to format
    :type response: :class:`requests.Response`
    :param request_prefix: (*optional*)
        Bytes to prefix each line of the request data
    :type request_prefix: :class:`bytes`
    :param response_prefix: (*optional*)
        Bytes to prefix each line of the response data
    :type response_prefix: :class:`bytes`
    :param data_array: (*optional*)
        Bytearray to which we append the request-response cycle data
    :type data_array: :class:`bytearray`
    :returns: Formatted bytes of request and response information.
    :rtype: :class:`bytearray`
    Nr	z"Response has no associated request)r)�	bytearrayrr<�
ValueErrorrr1r	r:)r
�request_prefix�response_prefixZ
data_arrayr=r.rrrrrss


�rcCs>t�}t|jdd��}|�|�|D]}t||||�q&|S)a�Dump all requests and responses including redirects.

    This takes the response returned by requests and will dump all
    request-response pairs in the redirect history in order followed by the
    final request-response.

    Example::

        import requests
        from requests_toolbelt.utils import dump

        resp = requests.get('https://httpbin.org/redirect/5')
        data = dump.dump_all(resp)
        print(data.decode('utf-8'))

    :param response:
        The response to format
    :type response: :class:`requests.Response`
    :param request_prefix: (*optional*)
        Bytes to prefix each line of the request data
    :type request_prefix: :class:`bytes`
    :param response_prefix: (*optional*)
        Bytes to prefix each line of the response data
    :type response_prefix: :class:`bytes`
    :returns: Formatted bytes of request and response information.
    :rtype: :class:`bytearray`
    N)r@�list�history�appendr)r
rBrCr=rErrrr�s
r)N)r>r?N)r>r?)�__doc__�collectionsZrequestsr�__all__r4�
namedtupleZ_PrefixSettingsrrr!r&r1r:rrrrrrr�<module>s*��
�
,