
    8iz                         S r SSKrSSKJr  SrSSSS.r\R                  " S	S
S/5      r " S S	\5      rS r	S r
S rSS jrS rS r  SS jrSS jrg)zGThis module provides functions for dumping information about responses.    N)compat)dump_responsedump_alls   0.9s   1.0s   1.1)	   
      PrefixSettingsrequestresponsec                   (   ^  \ rS rSrU 4S jrSrU =r$ )r	      c                 X   > [        U5      n[        U5      n[        [        U ]  XU5      $ N)_coerce_to_bytessuperr	   __new__)clsr
   r   	__class__s      l/home/dmtnaga/Documents/work/airagagent/rag_env/lib/python3.13/site-packages/requests_toolbelt/utils/dump.pyr   PrefixSettings.__new__   s+    "7+#H-^S1#II     )__name__
__module____qualname____firstlineno__r   __static_attributes____classcell__)r   s   @r   r	   r	      s    J Jr   c                     [        U R                  SS5      (       a9  0 nU R                  R                  nUR	                  S5      (       a  SUS'   X!S'   U$ g )Nproxy_managerFzhttps://CONNECTmethodrequest_path)getattr
connectionr
   url
startswith)r   
proxy_inforequest_urls      r   _get_proxy_informationr*      sY    x""OU;;
&&**!!*--#,Jx %0>"r   c                 <    [        U 5      S-   [        U5      -   S-   $ )Ns   :    
)r   )namevalues     r   _format_headerr/   &   s'    T"U*-=e-DD r   c                     [         R                  " U 5      nUR                  S5      nUb  [        U5      nXB4$ [        UR                  5      nUR
                  (       a  US[        UR
                  5      -   -  nXB4$ )Nr#      ?)r   urlparsegetr   pathquery)r&   r(   uri	proxy_urlr#   s        r   _build_request_pathr8   +   sn    
//#
C~.I'	2  #CHH-L
yy/		:::r   c                 H   Uc  0 nUR                   n[        UR                  SU R                  5      5      n[	        U R
                  U5      u  pgUR                  XE-   S-   U-   S-   5        U R                  R                  5       n[        UR                  SUR                  5      5      n	UR                  US-   U	-   S-   5        UR                  5        H"  u  pUR                  U[        X5      -   5        M$     UR                  US-   5        U R                  (       as  [        U R                  [        R                  5      (       a(  UR                  U[        U R                  5      -   5        OUR                  S5        UR                  S5        UR                  S5        g )Nr"       s    HTTP/1.1
Hosts   Host: r,   s,   << Request body is not a string-like type >>)r
   r   popr"   r8   r&   extendheaderscopynetlocitemsr/   body
isinstancer   
basestring)r
   prefixesbytearrr(   prefixr"   r#   r6   r>   host_headerr-   r.   s               r   _dump_request_datarI   9   sG   
FjnnXw~~FGF+GKKDL NN6?T)L8;KKL oo""$G"7;;vszz#BCKNN6I%3g=>}}vt ;;< ' NN6G#$||gllF$5$566NN6$4W\\$BBC NNJKwNN7r   c           	      8   UR                   nU R                  n[        R                  UR                  S5      nUR                  US-   U-   S-   [        UR                  5      R                  S5      -   S-   [        U R                  5      -   S-   5        UR                  nUR                  5        H8  nUR                  U5       H   nUR                  U[        Xx5      -   5        M"     M:     UR                  US-   5        UR                  U R                  5        g )Nr1   s   HTTP/r:   asciir,   )r   rawHTTP_VERSIONSr3   versionr=   strstatusencoder   reasonr>   keysgetlistr/   content)	r   rE   rF   rG   rL   version_strr>   r-   r.   s	            r   _dump_response_datarW   X   s    F
,,C  ##CKK6K NN6H${2T9szz?))'2359:#HOO457>? @ kkG__T*ENN6N4$??@ +  NN6G#$NN8##$r   c                 ~    [        U [        5      (       d"  [        U S5      (       a  U R                  S5      n U b  U $ S$ )NrQ   zutf-8r   )rC   byteshasattrrQ   )datas    r   r   r   o   s9    dE""wtX'>'>{{7##4,,r   c                     Ub  UO	[        5       n[        X5      n[        U S5      (       d  [        S5      e[	        U 5      n[        U R                  XTUS9  [        XU5        U$ )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	   rZ   
ValueErrorr*   rI   r
   rW   )r   request_prefixresponse_prefix
data_arrayr[   rE   r(   s          r   r   r   v   sc    > $/:Y[Dn>H8Y''=>>'1Jx''",.D1Kr   c                     [        5       n[        U R                  SS 5      nUR                  U 5        U H  n [	        XX#5        M     U$ )aG  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   r_   r`   r[   rd   s        r   r   r      sG    8 ;D8##A&'GNN8hF  Kr   r   )   <    > N)rf   rg   )__doc__collectionsrequestsr   __all__rM   
namedtuple_PrefixSettingsr	   r*   r/   r8   rI   rW   r   r   r   r   r   r   <module>rn      s    M   (  (()9*3Z)@BJ_ J	
>%.- CH!)X$r   