o
    Vhz                     @   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__ p/var/www/html/construction_image-detection-poc/venv/lib/python3.10/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ri }| jj}|drd|d< ||d< |S d S )Nproxy_managerFzhttps://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r'|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|
|  qD||d  | jryt| jtjro||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,   r3   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||  q7q0||d  || j d S )Nr'   s   HTTP/r/   asciir#   )r
   rawHTTP_VERSIONSr)   versionr2   strstatusencoder   reasonr3   keysgetlistr&   content)	r
   r:   r;   r<   r@   version_strr3   r$   r%   r   r   r   _dump_response_dataX   s&   rK   c                 C   s.   t | tst| dr| d} | d ur| S dS )NrE   zutf-8    )r8   byteshasattrrE   )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   rN   
ValueErrorr"   r>   r	   rK   )r
   request_prefixresponse_prefix
data_arrayrO   r:   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)rR   listhistoryappendr   )r
   rT   rU   rO   rX   r   r   r   r      s   
r   r   )rP   rQ   N)rP   rQ   )__doc__collectionsrequestsr   __all__rA   
namedtuple_PrefixSettingsr   r"   r&   r.   r>   rK   r   r   r   r   r   r   r   <module>   s,    

,