o
    &=j
=  ã                   @  s$  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Zd dl
Zd dl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mZ ddlmZ ejrUd dlZd‘d
d„Zd’dd„Zd“d”dd„Zd•d d!„Zd“d–d"d#„Zd—d$d%„Zd˜d&d'„Z ej!ej!e"e"f d(f Z#ej!e#d(f Z$ej%e"ej&e"e$e#f f Z'd™d+d,„Z(	d“dšd1d2„Z)d›d5d6„Z*dœd=d>„Z+dœd?d@„Z,d�dAdB„Z-ej.ddC�ej/dDe"dE�ej0dFdGdHe"dIdJ�ej0dKdLdMe"e"fdNdOdP�ej0dQdRdSe"dTdJ�ej0dUdVdWe"e"fdNdXdP�ej0dYdZd[e"ej1d\d]�fdNd^dP�ej0d_d`dae"e+dbdc�ej0dddede"e"fdNdfdP�ej0dgdhe"e"fdNdidP�ej0djdke"e"fdle,dmdn�ej0dodpe"ddqdr�ej0dsdte2dudvdr�ej0dwdxdNddydz�ej0d{d|dNdNd}dz�ej0d~de3dNddd€�ej0d�e 1d‚¡dƒdJ�ej0d„d…e3dNdd†d€�ej0d‡dNdNde-dˆd‰�džd�d�„ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒZ4dS )Ÿé    )ÚannotationsNé   )ÚClient)ÚRequestError)ÚResponse)ÚcodesÚreturnÚNonec                  C  sT  t j ¡ } | jddd� |  ¡  | jddd� |  ¡  | jddd� |  ¡  t jjjddd	�}|jd
dddd� | d¡ | dd¡ | dd¡ | dd¡ | dd¡ | dd¡ | dd¡ | dd¡ | dd¡ | dd¡ | d d!¡ | d"d#¡ | d$d%¡ | d&d'¡ | d(d)¡ | d*d+¡ | d,d-¡ | d.d/¡ |  |¡ d S )0Nz[bold]HTTPX :butterfly:Úcenter)ÚjustifyzA next generation HTTP client.z7Usage: [bold]httpx[/bold] [cyan]<URL> [OPTIONS][/cyan] Úleftr   T)ÚpaddingZpad_edgeÚ	ParameterZbold)Zno_wrapr   ÚstyleÚDescriptionz-m, --method [cyan]METHODz{Request method, such as GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD.
[Default: GET, or POST if a request body is included]z#-p, --params [cyan]<NAME VALUE> ...ú/Query parameters to include in the request URL.z-c, --content [cyan]TEXTú,Byte content to include in the request body.z!-d, --data [cyan]<NAME VALUE> ...ú)Form data to include in the request body.z%-f, --files [cyan]<NAME FILENAME> ...ú*Form files to include in the request body.z-j, --json [cyan]TEXTú)JSON data to include in the request body.z$-h, --headers [cyan]<NAME VALUE> ...ú/Include additional HTTP headers in the request.z --cookies [cyan]<NAME VALUE> ...ú"Cookies to include in the request.z--auth [cyan]<USER PASS>úìUsername and password to include in the request. Specify '-' for the password to use a password prompt. Note that using --verbose/-v will expose the Authorization header, including the password encoding in a trivially reversible format.z--proxy [cyan]URLúISend the request via a proxy. Should be the URL giving the proxy address.z--timeout [cyan]FLOATúzTimeout value to use for network operations, such as establishing the connection, reading some data, etc... [Default: 5.0]ú--follow-redirectsúAutomatically follow redirects.ú--no-verifyúDisable SSL verification.ú--http2ú@Send the request using HTTP/2, if the remote server supports it.z--download [cyan]FILEú?Save the response content as a file, rather than displaying it.z-v, --verbosez1Verbose output. Show request as well as response.ú--helpúShow this message and exit.)	ÚrichÚconsoleÚConsoleÚprintÚtableZTableZgridZ
add_columnZadd_row)r%   r(   © r)   úUC:\Users\psant\Downloads\Anu Raj Backend\school\venv\Lib\site-packages\httpx/_main.pyÚ
print_help   s|   
ÿ
þþÿÿþþÿþþþÿþr+   Úresponser   Ústrc                 C  s^   | j  d¡}|d ur-| d¡\}}}zt ttj | 	¡ ¡j
¡W S  tjjy,   Y dS w dS )NzContent-Typeú;Ú )ÚheadersÚgetÚ	partitionÚtypingÚcastr-   ÚpygmentsZlexersZget_lexer_for_mimetypeÚstripÚnameÚutilZClassNotFound)r,   Úcontent_typeZ	mime_typeÚ_r)   r)   r*   Úget_lexer_for_responseg   s   ÿþr;   FÚrequestúhttpcore.RequestÚhttp2Úboolc                   sh   ˆ rdnd}‡ fdd„| j D ƒ}| j d¡}| jj d¡}|› d|› d|› �gdd„ |D ƒ }d |¡S )	NzHTTP/2zHTTP/1.1c                   s$   g | ]\}}ˆ r|  ¡ n||f‘qS r)   )Úlower©Ú.0r7   Úvalue©r>   r)   r*   Ú
<listcomp>v   s    ÿz*format_request_headers.<locals>.<listcomp>Úasciiú c                 S  ó*   g | ]\}}|  d ¡› d|  d ¡› �‘qS ©rF   ú: ©ÚdecoderA   r)   r)   r*   rE   {   ó    ÿÚ
)r0   ÚmethodrL   ÚurlÚtargetÚjoin)r<   r>   Úversionr0   rO   rQ   Úlinesr)   rD   r*   Úformat_request_headerst   s   
ÿÿ
rU   Úhttp_versionÚbytesÚstatusÚintÚreason_phraseúbytes | Noner0   úlist[tuple[bytes, bytes]]c                 C  sT   |   d¡}|d u rt |¡n|  d¡}|› d|› d|› �gdd„ |D ƒ }d |¡S )NrF   rG   c                 S  rH   rI   rK   rA   r)   r)   r*   rE   �   rM   z+format_response_headers.<locals>.<listcomp>rN   )rL   r   Zget_reason_phraserR   )rV   rX   rZ   r0   rS   ÚreasonrT   r)   r)   r*   Úformat_response_headers�   s   
ÿýÿ
r^   c                 C  sV   t j ¡ }t| |d�}t jj|dddd�}| |¡ t jjddddd�}| |¡ d S )NrD   ÚhttpÚ	ansi_darkT©ZthemeZ	word_wrapr/   )r$   r%   r&   rU   ÚsyntaxÚSyntaxr'   )r<   r>   r%   Ú	http_textrb   r)   r)   r*   Úprint_request_headers“   s   

re   c                 C  sX   t j ¡ }t| |||ƒ}t jj|dddd�}| |¡ t jjddddd�}| |¡ d S )Nr_   r`   Tra   r/   )r$   r%   r&   r^   rb   rc   r'   )rV   rX   rZ   r0   r%   rd   rb   r)   r)   r*   Úprint_response_headersœ   s   

rf   c                 C  sš   t j ¡ }t| ƒ}|r?| ¡ dkr+z|  ¡ }tj|dd�}W n ty*   | j}Y nw | j}t j	j
||ddd�}| |¡ d S | dt| jƒ› d�¡ d S )	NÚjsoné   )Úindentr`   Tra   ú<z bytes of binary data>)r$   r%   r&   r;   r@   rg   ÚdumpsÚ
ValueErrorÚtextrb   rc   r'   ÚlenÚcontent)r,   r%   Z
lexer_nameÚdatarm   rb   r)   r)   r*   Úprint_responseª   s   

ÿrq   .ÚcertÚ_PeerCertRetDictTypec              
   C  sÖ   g }|   ¡ D ]_\}}t|ttfƒrZ| d|› d�¡ |D ]H}|dv r6|D ]4}| d|d › d|d ›�¡ q$t|tƒrQt|ƒdkrQ| d|d › d|d ›�¡ q| d|›�¡ q| d|› d|›�¡ qd	 |¡S )
Nz*   ú:)ÚsubjectZissuerz*     r   rJ   r   é   rN   )ÚitemsÚ
isinstanceÚlistÚtupleÚappendrn   rR   )rr   rT   ÚkeyrC   ÚitemZsub_itemr)   r)   r*   Úformat_certificateÂ   s     €€
r~   r7   Úinfoútyping.Mapping[str, typing.Any]Úverbosec                 C  s¢  t j ¡ }| dkr|r|d }| d|›�¡ d S | dkr9|r9|d }| d¡}| d|d ›d	|d
 › �¡ d S | dkr|r|d }| d¡}| ¡ }| ¡ }	| ¡ }
| ¡ }| d|›d|	d ›�¡ | d|›�¡ |
r}| d¡ | t	|
ƒ¡ d S d S | dkr‘|r‘|d }t
|dd� d S | dkr£|r£|d }t
|dd� d S | dkr¸|d \}}}}t||||ƒ d S | dkrÏ|d \}}d}d }t||||ƒ d S d S )Nzconnection.connect_tcp.startedÚhostz* Connecting to zconnection.connect_tcp.completeÚreturn_valueÚserver_addrz* Connected to r   z	 on port r   zconnection.start_tls.completeÚ
ssl_objectz* SSL established using z / z* Selected ALPN protocol: z* Server certificate:z#http11.send_request_headers.startedr<   FrD   z"http2.send_request_headers.startedTz(http11.receive_response_headers.completez'http2.receive_response_headers.completes   HTTP/2)r$   r%   r&   r'   Úget_extra_inforS   ÚcipherÚgetpeercertÚselected_alpn_protocolr~   re   rf   )r7   r   r�   r%   r‚   Ústreamr„   r…   rS   r‡   Zserver_certZalpnr<   rV   rX   rZ   r0   r)   r)   r*   ÚtraceÔ   sH   

"

þür‹   Údownloadútyping.BinaryIOc                 C  sÆ   t j ¡ }| ¡  | j d¡}t j ddt jjd d�t j 	¡ t j 
¡ ¡�5}dt j |j¡› �}|j|t|p6dƒ|d ud�}|  ¡ D ]}| |¡ |j|| jd� qAW d   ƒ d S 1 s\w   Y  d S )	NzContent-Lengthz([progress.description]{task.description}z-[progress.percentage]{task.percentage:>3.0f}%)Z	bar_widthzDownloading [bold]r   )ÚtotalÚstart)Ú	completed)r$   r%   r&   r'   r0   r1   ÚprogressÚProgressZ	BarColumnZDownloadColumnZTransferSpeedColumnZmarkupÚescaper7   Zadd_taskrY   Z
iter_bytesÚwriteÚupdateZnum_bytes_downloaded)r,   rŒ   r%   Úcontent_lengthr‘   ÚdescriptionZdownload_taskÚchunkr)   r)   r*   Údownload_responseû   s,   
û
ý
þ"ór™   Úctxúclick.ContextÚparamúclick.Option | click.ParameterrC   ú
typing.Anyc                 C  s4   |d u rd S zt  |¡W S  t jy   t d¡‚w )NzNot valid JSON)rg   ÚloadsÚJSONDecodeErrorÚclickZBadParameter©rš   rœ   rC   r)   r)   r*   Úvalidate_json  s   
ÿr£   c                 C  s2   |dkrd S |\}}|dkrt jddd�}||fS )N©NNú-ZPasswordT)Z
hide_input)r¡   Úprompt)rš   rœ   rC   ÚusernameÚpasswordr)   r)   r*   Úvalidate_auth  s   r©   c                 C  s    |r| j rd S tƒ  |  ¡  d S )N)Zresilient_parsingr+   Úexitr¢   r)   r)   r*   Úhandle_help-  s   
r«   )Úadd_help_optionrP   )Útypez--methodz-mrO   z{Request method, such as GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD. [Default: GET, or POST if a request body is included])r­   Úhelpz--paramsz-pÚparamsTr   )r­   Úmultipler®   z	--contentz-cro   r   z--dataz-drp   r   z--filesz-fÚfilesÚrb)Úmoder   z--jsonz-jrg   r   )r­   Úcallbackr®   z	--headersz-hr   z	--cookiesÚcookiesr   z--authÚauthr¤   r   )r­   Údefaultr´   r®   z--proxyÚproxyr   )r­   r·   r®   z	--timeoutÚtimeoutg      @r   r   Úfollow_redirectsr   )Úis_flagr·   r®   r   Úverifyr   r   r    )r­   r»   r·   r®   z
--downloadÚwbr!   z	--verbosez-vz*Verbose. Show request as well as response.r"   r#   )r»   Zis_eagerZexpose_valuer´   r®   úlist[tuple[str, str]]úlist[tuple[str, click.File]]útuple[str, str] | NoneÚfloatútyping.BinaryIO | Nonec                 C  sJ  |s|s
|s
|s
|rdnd}z]t |
|||d��K}|j|| t|ƒ|t|ƒ|||t|ƒ|	|dtjt|d�id��}|durAt||ƒ n| ¡  |j	rLt
|ƒ W d  ƒ n1 sVw   Y  W d  ƒ n1 sew   Y  W n* ty• } ztj ¡ }| dt|ƒj› d	|› �¡ t d
¡ W Y d}~nd}~ww t |jr d¡ dS d
¡ dS )zU
    An HTTP command line client.
    Sends a request and displays the response.
    ÚPOSTÚGET)r¸   r¹   r>   r¼   r‹   )r�   )
r¯   ro   rp   r±   rg   r0   rµ   r¶   rº   Ú
extensionsNz[red]z[/red]: r   r   )r   rŠ   ry   ÚdictÚ	functoolsÚpartialr‹   r™   Úreadro   rq   r   r$   r%   r&   r'   r­   Ú__name__Úsysrª   Z
is_success)rP   rO   r¯   ro   rp   r±   rg   r0   rµ   r¶   r¸   r¹   rº   r¼   r>   rŒ   r�   Úclientr,   Úexcr%   r)   r)   r*   Úmain9  sJ    #ô€í€ÿ€
€ýrÎ   )r   r	   )r,   r   r   r-   )F)r<   r=   r>   r?   r   r-   )
rV   rW   rX   rY   rZ   r[   r0   r\   r   r-   )r<   r=   r>   r?   r   r	   )
rV   rW   rX   rY   rZ   r[   r0   r\   r   r	   )r,   r   r   r	   )rr   rs   r   r-   )r7   r-   r   r€   r�   r?   r   r	   )r,   r   rŒ   r�   r   r	   )rš   r›   rœ   r�   rC   rž   r   rž   )rš   r›   rœ   r�   rC   rž   r   r	   )$rP   r-   rO   r-   r¯   r¾   ro   r-   rp   r¾   r±   r¿   rg   r-   r0   r¾   rµ   r¾   r¶   rÀ   r¸   r-   r¹   rÁ   rº   r?   r¼   r?   r>   r?   rŒ   rÂ   r�   r?   r   r	   )5Ú
__future__r   rÇ   rg   rË   r3   r¡   Zpygments.lexersr5   Zpygments.utilZrich.consoler$   Zrich.markupZrich.progressZrich.syntaxZ
rich.tableZ_clientr   Ú_exceptionsr   Z_modelsr   Z_status_codesr   ÚTYPE_CHECKINGZhttpcorer+   r;   rU   r^   re   rf   rq   ÚTupler-   Z_PCTRTTZ_PCTRTTTÚDictÚUnionrs   r~   r‹   r™   r£   r©   r«   ÚcommandZargumentÚoptionÚFilerÁ   r?   rÎ   r)   r)   r)   r*   Ú<module>   sJ   

M

	

ÿ
'



ú
úûúúúúûùûú
ûûúýúú4