o
    �õ±jï  ã                   @   sÞ   d dl Z d dlZd dlZd dlZd dlmZmZ d dlm	Z	m
Z
mZmZ d dlmZ d dlmZ d dlmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZ e  d¡ZG dd„ dƒZdd„ Zdd„ Z e!dkrme ƒ  dS dS )é    N)ÚurlparseÚurljoin)ÚListÚTupleÚAnyÚDict)ÚUniCredential©ÚRequestManager)ÚHTTPAuthManager)ÚMockHTTPRequestÚHTTPResponse)ÚHTTPConnectionFactory)ÚHTTPClientTransport)ÚUniProxyTargetz^https?:\/\/c                   @   s  e Zd Zdi dddddfdedeeef dedee def
d	d
„Z	dd„ Z
dd„ Zdd„ Zdefdd„Zdefdd„Zdedeeeef  deeeef  fdd„Zdeeeef  deeeef  fdd„Zdg dœdedededefdd „Zddg d!œded"edededef
d#d$„ZdS )%ÚClientSessionNÚautoFÚurlÚstatic_headersÚ
credentialÚproxiesÚforce_sinle_connectionc                 C   s†   || _ tj ¡ | _d | _d | _|| _|| _|| _|| _	|| _
| j d ur+t || j
¡| _|d ur9tj| || j	d�| _g | _t ¡ | _d S )N)Ú	auth_type)r   ÚhttpÚ	cookiejarÚ	CookieJarÚfactoryÚauthmanagerÚssl_ctxr   r   r   r   r   Úfrom_urlr   Úfrom_credentialÚconnectionsÚasyncioÚEventÚsession_closed_evt)Úselfr   r   r   r   r   r   r   © r&   úŸ/root/aizidognhua/tmp/workspace/projects/ec89d86c-575f-41c9-af57-ac45cbdbf775/venv/lib/python3.10/site-packages/asysocks/unicomm/protocol/client/http/client.pyÚ__init__   s   
zClientSession.__init__c                 Ã   s   �| S ©Nr&   )r%   r&   r&   r'   Ú
__aenter__&   s   €zClientSession.__aenter__c                 Ã   s   �|   ¡ I d H  d S r)   )Úclose)r%   Úexc_typeÚexcÚtbr&   r&   r'   Ú	__aexit__)   s   €zClientSession.__aexit__c                 Ã   sB   �| j  ¡ du r
d S | j  ¡  | jD ]	}| ¡ I d H  qg | _d S )NT)r$   Úis_setÚsetr!   Ú
disconnect©r%   Úconnr&   r&   r'   r+   ,   s   €


zClientSession.closec                 C   sÎ   t t |¡ƒdu rJt|ƒ}|| _t || j¡| _| j 	¡ d ur+t
 | | j 	¡ | j¡| _|j}|dkr4d}| d¡du r?d| }|jdkrI||j7 }n|}|dkrRd}| d¡du r]d| }t| j|ƒ}||fS )NTÚ ú/F)ÚboolÚhttp_url_patternÚmatchr   r   r   r   r   r   Úget_credentialr   r    r   r   ÚpathÚ
startswithÚqueryr   )r%   r   Ú
parsed_urlÚtargetÚoriginal_urlr&   r&   r'   Úprocess_url4   s*   

€zClientSession.process_urlÚreturnc                 Ã   sb   �| j d u r
tdƒ‚| jdu rt| jƒdkr| jd S t| j  ¡ ƒ}| ¡ I d H  | j |¡ |S )NzNo URL was specified!Tr   )	r   Ú	Exceptionr   Úlenr!   r   Ú
get_targetÚconnectÚappendr3   r&   r&   r'   Úget_transportS   s   €

zClientSession.get_transportÚheadersc                 C   s8   t |ƒ}| j |¡ |jD ]}| ||j| f¡ q|S r)   )r   r   Úadd_cookie_headerÚ_headersrG   )r%   r   rI   ÚreqÚentryr&   r&   r'   Úapply_cookies]   s
   
zClientSession.apply_cookiesc                 C   sL   t  |¡}dd„ }| jD ]}|||ƒs| || j| f¡ q|  ||¡ |S )Nc                    s   t ‡ fdd„|D ƒƒS )Nc                 3   s   � | ]	}|d  ˆ kV  qdS )r   Nr&   )Ú.0Úx©rM   r&   r'   Ú	<genexpr>f   s   € z@ClientSession.apply_headers.<locals>.<lambda>.<locals>.<genexpr>)Úany)rM   Úlstr&   rQ   r'   Ú<lambda>f   s    z-ClientSession.apply_headers.<locals>.<lambda>)ÚcopyÚdeepcopyr   rG   rN   )r%   r   rI   Úfinal_headersÚentry_existsrM   r&   r&   r'   Úapply_headersd   s   


€zClientSession.apply_headersT©Úallow_redirectsrI   r\   Úkwargsc                K   s   t | |df||dœ|¤ŽS )NÚGETr[   r	   )r%   r   r\   rI   r]   r&   r&   r'   Úgetn   s   zClientSession.get)Údatar\   rI   r`   c                K   s   t | |df|||ddœ|¤ŽS )NÚPOSTT)r`   r\   rI   Úneed_lengthr	   )r%   r   r`   r\   rI   r]   r&   r&   r'   Úpostq   s   zClientSession.post)Ú__name__Ú
__module__Ú__qualname__Ústrr   r   r   r   r7   r(   r*   r/   r+   rA   r   rH   r   rN   rZ   r   r
   r_   Úbytesrc   r&   r&   r&   r'   r      s    :.
*"
,r   c               
   Ã   sä   �t ƒ 4 I d H š]} |  d¡4 I d H š}t|jƒ t| ¡ I d H ƒ W d   ƒI d H  n1 I d H s1w   Y  |  d¡4 I d H š}t|jƒ W d   ƒI d H  n1 I d H sUw   Y  W d   ƒI d H  d S 1 I d H skw   Y  d S )Nzhttp://www.google.com/)r   r_   ÚprintÚstatusÚtext)ÚsessionÚrespr&   r&   r'   Úamainu   s   €

(þ*ÿ.ürn   c                   C   s   t  tƒ ¡ d S r)   )r"   Úrunrn   r&   r&   r&   r'   Úmain—   s   rp   Ú__main__)"ÚrerV   r"   Úhttp.cookiejarr   Úurllib.parser   r   Útypingr   r   r   r   Úasyauth.common.credentialsr   Ú0asysocks.unicomm.protocol.client.http.requestmgrr
   Ú*asysocks.unicomm.protocol.client.http.authr   Ú6asysocks.unicomm.protocol.client.http.commons.messagesr   r   Ú5asysocks.unicomm.protocol.client.http.commons.factoryr   Ú/asysocks.unicomm.protocol.client.http.transportr   Úasysocks.unicomm.common.proxyr   Úcompiler8   r   rn   rp   rd   r&   r&   r&   r'   Ú<module>   s(   
a"
ÿ