
    ڈiC                     (   d dl Z d dlZd dlmZ d dlmZmZmZmZm	Z	m
Z
 d dlmZmZ d dlmZmZ d dlmZ d dlZd dlmZmZ d dlmZ d	d
lmZmZmZ  G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z  G d de      Z!y)    N)
SSLContext)AnyIterable
NamedTupleOptionalListTuple)ClientConnectorErrorTCPConnector)AbstractResolverResolveResult)ResponseHandler)	ProxyTypeparse_proxy_url)Proxy   )ProxyConnectionErrorProxyTimeoutError
ProxyErrorc            
       ^    e Zd Zdej                  fdededej                  dee	   fdZ
d Zy)	
NoResolverr   hostportfamilyreturnc                    K   ||||dddgS w)Nr   )hostnamer   r   r   protoflags )selfr   r   r   s       Y/var/www/html/bot/test_files/venv/lib/python3.12/site-packages/aiohttp_socks/connector.pyresolvezNoResolver.resolve   s)      ! 	
 		
s   c                    K   y wNr    )r!   s    r"   closezNoResolver.close#   s	     s   N)__name__
__module____qualname__socketAF_INETstrintAddressFamilyr   r   r#   r&   r        r"   r   r      sI     '-~~	

 
 $$	

 
m	
"r/   r   c                   X     e Zd ZdZdej
                  dej                  ddf fdZ xZS )_ResponseHandlera   
    To fix issue https://github.com/romis2012/aiohttp-socks/issues/27
    In Python>=3.11.5 we need to keep a reference to the StreamWriter
    so that the underlying transport is not closed during garbage collection.
    See StreamWriter.__del__ method (was added in Python 3.11.5)
    loopwriterr   Nc                 2    t         |   |       || _        y r%   )super__init___writer)r!   r2   r3   	__class__s      r"   r6   z_ResponseHandler.__init__/   s     	r/   )	r'   r(   r)   __doc__asyncioAbstractEventLoopStreamWriterr6   __classcell__r8   s   @r"   r1   r1   '   s6    --7>7K7K	 r/   r1   c                       e Zd Zeddeej                  ef   fdZ	 	 d
de	de
dee   dee   deej                  ef   f
d	Zy)_BaseProxyConnector)client_errorr   c                  K   	 |d   d   d   }|d   d   d   }|j                  d      }
	 | j                  |||
|j                         d {   S # t         $ r}	t        d      |	d }	~	ww xY w7 !# t
        j                  $ r}	t        t        |	            |	d }	~	wt
        j                  $ r}	t        t        |	            |	d }	~	wt
        j                  $ r&}	t        t        |	      |	j                        |	d }	~	ww xY ww)Nr      r   zInvalid arg: `addr_infos`ssl)r   r   rD   timeout)
error_code)
IndexError
ValueErrorget_connect_via_proxysock_connectpython_socksr   r,   r   r   rF   )r!   
addr_infosreqrE   rA   argskwargsr   r   erD   s              r"   _wrap_create_connectionz+_BaseProxyConnector._wrap_create_connection7   s    	A"1a(+D"1a(+D %+JJu$5	E00,,	 1     	A89q@	A
 00 	6&s1v.A5-- 	3#CF+2&& 	ESV=1D	Est   DA D"A2 A0A2 D	A-A((A--D0A2 2DBD0CD!C<<DDNr   r   rD   rE   c                    K   t         wr%   )NotImplementedError)r!   r   r   rD   rE   s        r"   rJ   z&_BaseProxyConnector._connect_via_proxyU   s      "!s   	NN)r'   r(   r)   r
   r	   r:   	Transportr   rR   r,   r-   r   r   floatrJ   r    r/   r"   r@   r@   6   s     *E 
w  /1	2ED %)#'"" " j!	"
 %" 
w  /1	2"r/   r@   c                        e Zd Zej                  ddddfdedededee   dee   dee   dee	   d	e
d
df fdZ	 	 ddededee	   dee   d
eej                  ef   f
dZeded	e
d
d fd       Z xZS )ProxyConnectorNr   r   
proxy_typeusernamepasswordrdns	proxy_sslrP   r   c                     t               |d<   t        	|   di | || _        || _        || _        || _        || _        || _        || _	        y Nresolverr    )
r   r5   r6   _proxy_type_proxy_host_proxy_port_proxy_username_proxy_password_rdns
_proxy_ssl)
r!   r   r   rZ   r[   r\   r]   r^   rP   r8   s
            r"   r6   zProxyConnector.__init__`   sW     (\z"6"%''
#r/   rD   rE   c           	        K   t        | j                  | j                  | j                  | j                  | j
                  | j                  | j                        }|j                  ||||       d {   }|j                  j                  }t        | j                  |j                        }|j                  |       |j                  |       ||fS 7 aw)N)rZ   r   r   r[   r\   r]   r^   	dest_host	dest_portdest_sslrE   r2   r3   )r   rb   rc   rd   re   rf   rg   rh   connectr3   	transportr1   _loopset_protocolconnection_made)	r!   r   r   rD   rE   proxystreamrp   protocols	            r"   rJ   z!ProxyConnector._connect_via_proxyv   s      ''!!!!))))oo
 }}	 % 
 
 (.}}'>'>	$4==%

 	x(  +(""!
s   A1C3C4A"Curlc           	      @    t        |      \  }}}}} | d|||||d|S )NrZ   r   r   r[   r\   r    )r   )clsrw   rP   rZ   r   r   r[   r\   s           r"   from_urlzProxyConnector.from_url   sB    5DS5I2
D$( 
!
 
 	
r/   rU   )r'   r(   r)   r   SOCKS5r,   r-   r   boolr   r   r6   rW   r	   r:   rV   r   rJ   classmethodr{   r=   r>   s   @r"   rY   rY   _   s	   
 !* 0 0"&"&#*.$$ $ 	$
 3-$ 3-$ tn$ J'$ $ 
$4 %)#'!#!# !# j!	!#
 %!# 
w  /1	2!#F 	
3 	
# 	
2B 	
 	
r/   rY   c                   h    e Zd ZU eed<   eed<   eed<   dZee   ed<   dZ	ee   ed<   dZ
ee   ed<   y)	ProxyInforZ   r   r   Nr[   r\   r]   )r'   r(   r)   r   __annotations__r,   r-   r[   r   r\   r]   r}   r    r/   r"   r   r      s<    
I
I"Hhsm""Hhsm"D(4.r/   r   c                        e Zd Zdee   f fdZ	 	 ddededee	   dee
   deej                  ef   f
dZed	ee   d
edd fd       Z xZS )ChainProxyConnectorproxy_infosc                 L    t               |d<   t        |   di | || _        y r`   )r   r5   r6   _proxy_infos)r!   r   rP   r8   s      r"   r6   zChainProxyConnector.__init__   s'    '\z"6"'r/   r   r   rD   rE   r   c           
        K   d }d }| j                   D ]R  }t        |j                  |j                  |j                  |j
                  |j                  |j                  |      }|}T |J |j                  ||||       d {   }|j                  j                  }	t        | j                  |j                        }
|	j                  |
       |
j                  |	       |	|
fS 7 aw)N)rZ   r   r   r[   r\   r]   forwardrj   rn   )r   r   rZ   r   r   r[   r\   r]   ro   r3   rp   r1   rq   rr   rs   )r!   r   r   rD   rE   r   rt   inforu   rp   rv   s              r"   rJ   z&ChainProxyConnector._connect_via_proxy   s      %% 
	D??YYYYYYE G
	    }}	 % 
 
 (.}}'>'>	$4==%

 	x(  +(""!
s   BC(C&A"C(urlsrP   c                     g }|D ]4  }t        |      \  }}}}}	t        |||||	      }
|j                  |
       6  | |fi |S )Nry   )r   r   append)rz   r   rP   infosrw   rZ   r   r   r[   r\   
proxy_infos              r"   	from_urlszChainProxyConnector.from_urls   sd     		%C9H9M6JdHh"%!!J LL$		% 5#F##r/   rU   )r'   r(   r)   r   r   r6   r,   r-   r   r   rW   r	   r:   rV   r   rJ   r~   r   r   r=   r>   s   @r"   r   r      s    (HY$7 ( %)#''#'# '# j!	'#
 %'# 
w  /1	2'#R $Xc] $c $>S $ $r/   r   )"r:   r*   rD   r   typingr   r   r   r   r   r	   aiohttpr
   r   aiohttp.abcr   r   aiohttp.client_protor   rL   r   r   python_socks.async_.asyncio.v2r   _errorsr   r   r   r   r1   r@   rY   r   r   r    r/   r"   <module>r      s{       C C 6 7 0  3 0 H H! , &", &"RD
( D
N 
  >$- >$r/   