a
    ^gz                     @   s   d Z ddlZddlmZ dZddddZed	d
dgZG dd	 d	eZdd Z	dd Z
dd ZdddZdd Zdd Zd ddZd!ddZdS )"zGThis module provides functions for dumping information about responses.    N)compat)dump_responsedump_alls   0.9s   1.0s   1.1)	   
      PrefixSettingsrequestresponsec                       s   e Zd Z fddZ  ZS )r   c                    s$   t |}t |}tt| | ||S )N)_coerce_to_bytessuperr   __new__)clsr	   r
   	__class__ j/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/requests_toolbelt/utils/dump.pyr      s    zPrefixSettings.__new__)__name__
__module____qualname__r   __classcell__r   r   r   r   r      s   c                 C   s<   t | jddr8i }| jj}|dr,d|d< ||d< |S d S )Nproxy_managerFzhttps://ZCONNECTmethodrequest_path)getattr
connectionr	   url
startswith)r
   
proxy_inforequest_urlr   r   r   _get_proxy_information   s    
r    c                 C   s   t | d t | d S )Ns   :    
)r   )namevaluer   r   r   _format_header&   s    r$   c                 C   sV   t | }|d}|d ur,t|}||fS t|j}|jrN|dt|j 7 }||fS )Nr      ?)r   urlparsegetr   pathquery)r   r   uri	proxy_urlr   r   r   r   _build_request_path+   s    


r,   c                 C   s   |d u ri }|j }t|d| j}t| j|\}}||| d | d  | j }t|d|j	}	||d |	 d  |
 D ]\}
}||t|
|  q||d  | jrt| jtjr||t| j  n
|d |d |d d S )Nr       s    HTTP/1.1
Hosts   Host: r!   s,   << Request body is not a string-like type >>)r	   r   popr   r,   r   extendheaderscopynetlocitemsr$   body
isinstancer   
basestring)r	   prefixesbytearrr   prefixr   r   r*   r1   Zhost_headerr"   r#   r   r   r   _dump_request_data9   s$    


r;   c           	      C   s   |j }| j}t|jd}||d | d t|jd d t	| j
 d  |j}| D ](}||D ]}||t||  qnq`||d  || j d S )Nr%   s   HTTP/r-   asciir!   )r
   rawHTTP_VERSIONSr'   versionr0   strstatusencoder   reasonr1   keysgetlistr$   content)	r
   r8   r9   r:   r=   version_strr1   r"   r#   r   r   r   _dump_response_dataX   s$    rH   c                 C   s.   t | tst| dr| d} | d ur*| S dS )NrB   zutf-8    )r6   byteshasattrrB   )datar   r   r   r   o   s    
r      <    > c                 C   sX   |dur|nt  }t||}t| ds.tdt| }t| j|||d t| || |S )a  Dump 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   )	bytearrayr   rK   
ValueErrorr    r;   r	   rH   )r
   request_prefixresponse_prefixZ
data_arrayrL   r8   r   r   r   r   r   v   s    


r   c                 C   s>   t  }t| jdd }||  |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)rO   listhistoryappendr   )r
   rQ   rR   rL   rT   r   r   r   r      s    
r   )N)rM   rN   N)rM   rN   )__doc__collectionsrequestsr   __all__r>   
namedtupleZ_PrefixSettingsr   r    r$   r,   r;   rH   r   r   r   r   r   r   r   <module>   s*   
  
,