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"
