a *NaZ@sdZddlZddlmZdZddddZed d d gZGd d d eZd dZ ddZ ddZ dddZ ddZ ddZd ddZd!ddZdS)"zGThis module provides functions for dumping information about responses.N)compat) dump_responsedump_alls0.9s1.0s1.1) PrefixSettingsrequestresponsecseZdZfddZZS)rcs$t|}t|}tt||||S)N)_coerce_to_bytessuperr__new__)clsr r  __class__w/private/var/folders/js/6pj4vh5d4zd0k6bxv74qrbhr0000gr/T/pip-target-22xwyzbs/lib/python/requests_toolbelt/utils/dump.pyr szPrefixSettings.__new__)__name__ __module__ __qualname__r __classcell__rrrrrscCs<t|jddr8i}|jj}|dr,d|d<||d<|SdS)N proxy_managerFzhttps://ZCONNECTmethod request_path)getattr connectionr url startswith)r proxy_info request_urlrrr_get_proxy_informations r cCst|dt|dS)Ns:  )r )namevaluerrr_format_header&sr$cCsVt|}|d}|dur,t|}||fSt|j}|jrN|dt|j7}||fS)Nr?)rurlparsegetr pathquery)rruri proxy_urlrrrr_build_request_path+s   r,c Cs|dur i}|j}t|d|j}t|j|\}}|||d|d|j}t|d|j } ||d| d| D]\} } ||t | | q||d|j rt |j tjr||t|j n |d|ddS)Nr s HTTP/1.1 HostsHost: r!s,<< Request body is not a string-like type >>)r r poprr,rextendheaderscopynetlocitemsr$body isinstancer basestring) r prefixesbytearrrprefixrrr*r1Z host_headerr"r#rrr_dump_request_data9s"  r;c Cs|j}|j}t|jd}||d|dt|jddt |j d|j }| D](}| |D]}||t||qnq`||d||jdS)Nr%sHTTP/r-asciir!)r raw HTTP_VERSIONSr'versionr0strstatusencoder reasonr1keysgetlistr$content) r r8r9r:r= version_strr1r"r#rrr_dump_response_dataWs$ rHcCs.t|tst|dr|d}|dur*|SdS)NrBzutf-8)r6byteshasattrrB)datarrrr ns r < > cCsX|dur |nt}t||}t|ds.tdt|}t|j|||dt||||S)aDump 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) bytearrayrrK ValueErrorr r;r rH)r request_prefixresponse_prefixZ data_arrayrLr8rrrrrus    rcCs>t}t|jdd}|||D]}t||||q&|S)aDump 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)rOlisthistoryappendr)r rQrRrLrTrrrrs  r)N)rMrNN)rMrN)__doc__ collectionsrequestsr__all__r> namedtupleZ_PrefixSettingsrr r$r,r;rHr rrrrrrs*    ,