a Æ*NaZã@s’dZddlZddlmZdZddddœZe d d d g¡ZGd d „d eƒZd d„Z dd„Z dd„Z ddd„Z dd„Z dd„Zd dd„Zd!dd„ZdS)"zGThis module provides functions for dumping information about responses.éN)Úcompat)Ú dump_responseÚdump_alls0.9s1.0s1.1)é é é ÚPrefixSettingsÚrequestÚresponsecseZdZ‡fdd„Z‡ZS)rcs$t|ƒ}t|ƒ}tt|ƒ |||¡S)N)Ú_coerce_to_bytesÚsuperrÚ__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|jddƒr8i}|jj}| d¡r,d|d<||d<|SdS)NÚ proxy_managerFzhttps://ZCONNECTÚmethodÚ request_path)ÚgetattrÚ connectionr ÚurlÚ startswith)r Ú proxy_infoÚ request_urlrrrÚ_get_proxy_informations r cCst|ƒdt|ƒdS)Ns: ó )r )ÚnameÚvaluerrrÚ_format_header&sÿr$cCsVt |¡}| d¡}|dur,t|ƒ}||fSt|jƒ}|jrN|dt|jƒ7}||fS)Nró?)rÚurlparseÚgetr ÚpathÚquery)rrÚuriÚ 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 rèt |j tjƒrÞ| |t|j ƒ¡n | d¡| d¡dS)Nró s HTTP/1.1 ÚHostsHost: r!s,<< Request body is not a string-like type >>)r r Úpoprr,rÚextendÚheadersÚcopyÚnetlocÚitemsr$ÚbodyÚ isinstancerÚ basestring) r ÚprefixesÚbytearrrÚprefixrrr*r1Z host_headerr"r#rrrÚ_dump_request_data9s"  r;c Cs¨|j}|j}t |jd¡}| |d|dt|jƒ d¡dt |j ƒd¡|j }|  ¡D](}|  |¡D]}| |t||ƒ¡qnq`| |d¡| |j¡dS)Nr%sHTTP/r-Úasciir!)r ÚrawÚ HTTP_VERSIONSr'Úversionr0ÚstrÚstatusÚencoder Úreasonr1ÚkeysÚgetlistr$Úcontent) r r8r9r:r=Ú version_strr1r"r#rrrÚ_dump_response_dataWs$ÿÿþþ rHcCs.t|tƒst|dƒr| d¡}|dur*|SdS)NrBzutf-8ó)r6ÚbytesÚhasattrrB)Údatarrrr ns r ó< ó> cCsX|dur |ntƒ}t||ƒ}t|dƒs.tdƒ‚t|ƒ}t|j|||d�t|||ƒ|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_prefixÚresponse_prefixZ data_arrayrLr8rrrrrus   ÿ rcCs>tƒ}t|jdd…ƒ}| |¡|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)rOÚlistÚhistoryÚappendr)r rQrRrLrTrrrr¡s  r)N)rMrNN)rMrN)Ú__doc__Ú collectionsÚrequestsrÚ__all__r>Ú namedtupleZ_PrefixSettingsrr r$r,r;rHr rrrrrrÚs* ýÿ  ÿ ,