
    .Phz                         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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                        e Zd Z fdZ xZS )r	   c                     t          |          }t          |          }t          t          |                               | ||          S N)_coerce_to_bytessuperr	   __new__)clsr
   r   	__class__s      \/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/requests_toolbelt/utils/dump.pyr   zPrefixSettings.__new__   s?    "7++#H--^S))11#wIII    )__name__
__module____qualname__r   __classcell__)r   s   @r   r	   r	      sA        J J J J J J J J Jr   c                     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_urls      r   _get_proxy_informationr%      s^    x"OU;; 
&*!!*-- 	-#,Jx %0
>"4r   c                 L    t          |           dz   t          |          z   dz   S )Ns   :    
)r   )namevalues     r   _format_headerr*   &   s-    T""U*-=e-D-DD r   c                     t          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   +   s~    
/#

C~..I'	22S  #CH--L
y ;/	::::r   c                 l   |i }|j         }t          |                    d| j                            }t	          | j        |          \  }}|                    ||z   dz   |z   dz              | j                                        }t          |                    d|j	                            }	|                    |dz   |	z   dz              |
                                D ]+\  }
}|                    |t          |
|          z              ,|                    |dz              | j        rtt          | j        t          j                  r+|                    |t          | j                  z              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   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   s   
FjnnXw~FFGGF+GKDDL# NN6F?T)L8;KKLLL o""$$G"7;;vsz#B#BCCKNN6I%3g=>>>}} = =evtU ; ;;<<<<NN6G#$$$|  glF$566 	LNN6$4W\$B$BBCCCC NNJKKKwNN7r   c           	      @   |j         }| j        }t                              |j        d          }|                    |dz   |z   dz   t          |j                                      d          z   dz   t          | j
                  z   dz              |j        }|                                D ]@}|                    |          D ](}|                    |t          ||          z              )A|                    |dz              |                    | j                   d S )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   s3   F
,C  ##CK66K NN6H${2T9sz??))'22359:#HO4457>? @ @ @ kG A A__T** 	A 	AENN6N4$?$??@@@@	A NN6G#$$$NN8#$$$$$r   c                     t          | t                    s%t          | d          r|                     d          } | | ndS )NrL   zutf-8r   )r>   byteshasattrrL   )datas    r   r   r   o   sE    dE"" $wtX'>'> ${{7###44,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`
    Nr
   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   s    > $/::Y[[Dno>>H8Y'' ?=>>>'11Jx'4",. . . .(D111Kr   c                     t                      }t          | j        dd                   }|                    |            |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)rZ   listhistoryappendr   )r   r\   r]   rV   ra   s        r   r   r      se    8 ;;D8#AAA&''GNN8 G GhFFFFKr   r   )rW   rX   N)rW   rX   )__doc__collectionsrequestsr   __all__rH   
namedtuple_PrefixSettingsr	   r%   r*   r3   rD   rR   r   r   r    r   r   <module>rj      s8   M M           (   )+()9*3Z)@B BJ J J J J_ J J J	 	 	  
     >% % %.- - - CH!) ) ) )X$ $ $ $ $ $r   