o
    øT·jó  ã                   @  s¢   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dl	Z	d dl
mZ ddlmZmZmZ ddlmZmZ 								d&d'dd „Z	!d(d)d$d%„ZdS )*é    )ÚannotationsN)ÚBufferedReader)ÚAny)ÚSessioné   )Údetermine_print_specÚhandle_downloadÚprint_output)Úparse_request_itemsÚprocess_urlÚargsúargparse.NamespaceÚmethodÚstrÚurlÚheadersúdict[str, str] | NoneÚparamsúlist[tuple[str, str]] | NoneÚdataúdict[str, str] | str | NoneÚ	json_bodyúdict[str, Any] | NoneÚfilesú dict[str, BufferedReader] | NoneÚcookiesÚauthútuple[str, str] | NoneÚsessionúSession | NoneÚreturnÚintc              
   C  sº  |
r|
j ntj }z~zA|di d|“d|“d|“d|“d|“d|“d|“d|“d	|	“d
| j“d| j“d| j“d| j“d| j“d| j“dt| ddƒ“Ž}W n- t	yw } z!t
d|› �tjd� W Y d}~W |ro| ¡ D ]}| ¡  qhdS dS d}~ww W |r†| ¡ D ]}| ¡  qn|r”| ¡ D ]}| ¡  q�w w t| ƒ}| jr´| js©t||||ddƒ t||| j| jd� n d}|durÃtj|ddd�}n|durËt|ƒ}t||||||ƒ |jdkrÛdS dS )z`Execute a single HTTP request and handle output.

    Returns:
        0 on success, 1 on error.r   r   r   r   r   Újsonr   r   r   ÚtimeoutÚverifyÚproxyÚallow_redirectsÚmax_redirectsÚimpersonateÚhttp_versionNzError: )Úfiler   Úh)Úquieté   F)ÚindentÚensure_asciii�  r   © )ÚrequestÚ	curl_cffir#   r$   r%   Úfollowr'   r(   ÚgetattrÚ	ExceptionÚprintÚsysÚstderrÚvaluesÚcloser   Údownloadr,   r	   r   Úoutputr"   Údumpsr   Ústatus_code)r   r   r   r   r   r   r   r   r   r   r   Ú
request_fnÚresponseÚeÚfÚ
print_specÚrequest_bodyr0   r0   úX/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/curl_cffi/cli/request.pyÚ_execute_request   sŠ   ÿþýüûúùø	÷
öõôóòñð
þ€ûî
€þ
þ
rF   TÚexit_on_errorÚboolc                 C  s  t | jƒ}t| jƒ}d}d}| js| jr|jrt|jƒ}n|js#|jr2t|jƒ}| 	t|jƒ¡ |}d}|j
rHi }|j
D ]\}	}
t|
dƒ||	< q<d}| jrd| j dd¡}|d t|ƒdkra|d ndf}t| |||j|j||||j|d�
}|dkr€|r€t d¡ |S )zqEntrypoint for building and executing a request from parsed args.

    Returns:
        0 on success, 1 on error.NÚrbú:r   r   Ú )r   r   r   r   r   r   r   )r   r   r
   ÚitemsÚformÚ	multipartÚdata_fieldsÚdictÚjson_fieldsÚupdater   Úopenr   ÚsplitÚlenrF   r   Úquery_paramsr   r7   Úexit)r   r   rG   r   Úparsedr   r   Úbodyr   Ú
field_nameÚfilepathr   ÚpartsÚrcr0   r0   rE   Úhandle_requestP   sH   


€
 ö
r^   )NNNNNNNN)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   )T)r   r   r   r   rG   rH   r    r!   )Ú
__future__r   Úargparser"   r7   Úior   Útypingr   r2   Úcurl_cffi.requestsr   r<   r   r   r	   Úparser
   r   rF   r^   r0   r0   r0   rE   Ú<module>   s*    õAÿ