
    |hz                         d Z ddlZddlmZ dZddddZ ej                  d	d
dg      Z G d d	e      Zd Z	d Z
d ZddZd Zd Z	 	 ddZddZy)zGThis module provides functions for dumping information about responses.    N)compat)dump_responsedump_alls   0.9s   1.0s   1.1)	   
      PrefixSettingsrequestresponsec                        e Zd Z fdZ xZS )r	   c                 Z    t        |      }t        |      }t        t        |   | ||      S N)_coerce_to_bytessuperr	   __new__)clsr
   r   	__class__s      [/var/www/html/test/engine/venv/lib/python3.12/site-packages/requests_toolbelt/utils/dump.pyr   zPrefixSettings.__new__   s-    "7+#H-^S1#wII    )__name__
__module____qualname__r   __classcell__)r   s   @r   r	   r	      s    J Jr   c                     t        | j                  dd      r5i }| j                  j                  }|j	                  d      rd|d<   ||d<   |S y )Nproxy_managerFzhttps://CONNECTmethodrequest_path)getattr
connectionr
   url
startswith)r   
proxy_inforequest_urls      r   _get_proxy_informationr%      sU    x""OU;
&&**!!*-#,Jx %0
>"r   c                 <    t        |       dz   t        |      z   dz   S )Ns   :    
)r   )namevalues     r   _format_headerr*   &   s'    T"U*-=e-DD r   c                     t        j                  |       }|j                  d      }|t        |      }||fS t        |j                        }|j
                  r|dt        |j
                        z   z  }||fS )Nr      ?)r   urlparsegetr   pathquery)r!   r#   uri	proxy_urlr   s        r   _build_request_pathr3   +   sr    
//#
C~.I'	2S  #CHH-L
yy/		:::r   c                 6   |i }|j                   }t        |j                  d| j                              }t	        | j
                  |      \  }}|j                  ||z   dz   |z   dz          | j                  j                         }t        |j                  d|j                              }	|j                  |dz   |	z   dz          |j                         D ]#  \  }
}|j                  |t        |
|      z          % |j                  |dz          | j                  rnt        | j                  t        j                        r(|j                  |t        | j                        z          n|j                  d       |j                  d       |j                  d       y )Nr       s    HTTP/1.1
Hosts   Host: r'   s,   << Request body is not a string-like type >>)r
   r   popr   r3   r!   extendheaderscopynetlocitemsr*   body
isinstancer   
basestring)r
   prefixesbytearrr#   prefixr   r   r1   r9   host_headerr(   r)   s               r   _dump_request_datarD   9   sQ   
FjnnXw~~FGF+GKKDL# NN6F?T)L8;KKL oo""$G"7;;vszz#BCKNN6I%3g=>}} =evtU ;;<= NN6G#$||gllF$5$56NN6$4W\\$BBC NNJKwNN7r   c           	      2   |j                   }| j                  }t        j                  |j                  d      }|j                  |dz   |z   dz   t        |j                        j                  d      z   dz   t        | j                        z   dz          |j                  }|j                         D ]6  }|j                  |      D ]   }|j                  |t        ||      z          " 8 |j                  |dz          |j                  | j                         y )Nr,   s   HTTP/r5   asciir'   )r   rawHTTP_VERSIONSr.   versionr8   strstatusencoder   reasonr9   keysgetlistr*   content)	r   r@   rA   rB   rG   version_strr9   r(   r)   s	            r   _dump_response_datarR   X   s   F
,,C  ##CKK6K NN6H${2T9szz?))'2359:#HOO457>? @ kkG A__T* 	AENN6N4$??@	AA NN6G#$NN8##$r   c                 h    t        | t              st        | d      r| j                  d      } | | S dS )NrL   zutf-8r   )r>   byteshasattrrL   )datas    r   r   r   o   s3    dE"wtX'>{{7##4,,r   c                     ||n	t               }t        ||      }t        | d      st        d      t	        |       }t        | j                  |||       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`
    r
   z"Response has no associated request)r#   )	bytearrayr	   rU   
ValueErrorr%   rD   r
   rR   )r   request_prefixresponse_prefix
data_arrayrV   r@   r#   s          r   r   r   v   sf    > $/:Y[Dno>H8Y'=>>'1Jx''4",.(D1Kr   c                     t               }t        | j                  dd       }|j                  |        |D ]  } t	        | |||        |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)rX   listhistoryappendr   )r   rZ   r[   rV   r_   s        r   r   r      sR    8 ;D8##A&'GNN8 GhFG Kr   r   )   <    > N)ra   rb   )__doc__collectionsrequestsr   __all__rH   
namedtuple_PrefixSettingsr	   r%   r*   r3   rD   rR   r   r   r    r   r   <module>rj      s    M   (  )+(()9*3Z)@BJ_ J	
>%.- CH!)X$r   