
    nbiB                    
   U d Z ddlmZ ddlZdZded<   	 ddlmZmZm	Z	m
Z
 ddlmZ d	d
lmZ nF# e$ r> ddlmZ 	 ddlZd	dlmZmZmZmZmZ dZn# e$ r  ej        de           Y nw xY wes Y nw xY wesddlZddlmZ ddlmZ ddlmZm Z  ddl!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.m/Z/ ddl0m1Z1 ddlm2Z2m3Z3 ddl4m5Z5 ddl6m7Z7 	 ddl8Z8n# e$ r dZ8Y nw xY w G d de+          Z G d d ee,          Z G d! d"e.          Z G d# d$e/          Z G d% d&e5          Z G d' d(e          Z9 G d) d*e9e           Z: G d+ d,e"          Z; G d- d.e#          Z< G d/ d0e%          Z=g d1Z>es	e>g d2z  Z>dS dS )3a  
This module contains provisional support for SOCKS proxies from within
urllib3. This module supports SOCKS4, SOCKS4A (an extension of SOCKS4), and
SOCKS5. To enable its functionality, either install python-socks or install this
module with the ``socks`` extra.

The SOCKS implementation supports the full range of urllib3 features. It also
supports the following SOCKS features:

- SOCKS4A (``proxy_url='socks4a://...``)
- SOCKS4 (``proxy_url='socks4://...``)
- SOCKS5 with remote DNS (``proxy_url='socks5h://...``)
- SOCKS5 with local DNS (``proxy_url='socks5://...``)
- Usernames and passwords for the SOCKS proxy

.. note::
   It is recommended to use ``socks5h://`` or ``socks4a://`` schemes in
   your ``proxy_url`` to ensure that DNS resolution is done from the remote
   server instead of client-side when connecting to a domain name.

SOCKS4 supports IPv4 and domain names with the SOCKS4A extension. SOCKS5
supports IPv4, IPv6, and domain names.

When connecting to a SOCKS4 proxy the ``username`` portion of the ``proxy_url``
will be sent as the ``userid`` section of the SOCKS request:

.. code-block:: python

    proxy_url="socks4a://<userid>@proxy-host"

When connecting to a SOCKS5 proxy the ``username`` and ``password`` portion
of the ``proxy_url`` will be sent as the username/password to authenticate
with the proxy:

.. code-block:: python

    proxy_url="socks5h://<username>:<password>@proxy-host"

    )annotationsNFboolBYPASS_SOCKS_LEGACY)ProxyConnectionError
ProxyErrorProxyTimeoutError	ProxyType)Proxy   )AsyncioProxy   )DependencyWarning)SOCKSConnectionSOCKSHTTPConnectionPoolSOCKSHTTPSConnectionSOCKSHTTPSConnectionPoolSOCKSProxyManagerTzSOCKS support in urllib3.future requires the installation of an optional dependency: python-socks. For more information, see https://urllib3future.readthedocs.io/en/latest/contrib.html#socks-proxies)socket)timeout)AsyncHTTPConnectionAsyncHTTPSConnection)AsyncHTTPConnectionPoolAsyncHTTPSConnectionPool)AsyncPoolManager)_TYPE_SOCKS_OPTIONS)HttpVersion)HTTPConnectionHTTPSConnection)HTTPConnectionPoolHTTPSConnectionPool)AsyncSocket)ConnectTimeoutErrorNewConnectionError)PoolManager)	parse_urlc                  ,     e Zd ZdZd fd	ZddZ xZS )r   O
        A plain-text HTTP connection that connects via a SOCKS proxy.
        _socks_optionsr   args
typing.AnykwargsreturnNonec                H    || _          t                      j        |i | d S Nr(   super__init__selfr(   r)   r+   	__class__s       l/var/www/html/mdtn/previsions/meteo_cartes/venv/lib/python3.11/site-packages/urllib3_future/contrib/socks.pyr2   zSOCKSConnection.__init__w   /     #1DEGGd-f-----    r   c           	         i } j         r
 j         |d<    j        rg } j        D ]|}t          |          dk    r|                    |           +t          |          dk    r>|d                                         }|dk    r_|                    |dd                    }||d<   	  j        d         J  j        d         J t           j        d	          j        d         t           j        d                    j        d
          j        d          j        d                   } j        	                     j        d         t           j        d                   f j
         j         |d         d fd          }t          j                    5  t          j        dt                     |                     j         j         j
        |          cddd           S # 1 swxY w Y   dS # t$          t&          f$ r'}t)           d j         d j
         d          |d}~wt*          t,          f$ r}t/           d|           |d}~wt0          $ r}t/           d|           |d}~ww xY w)I
            Establish a new connection via the SOCKS proxy.
            source_address      udpNsocket_options
proxy_host
proxy_portsocks_versionusernamepasswordrdns
proxy_typehostportrC   rD   rE   Fc                &    t          d|           S N_connect_timingssetattr_r4   s    r6   <lambda>z+SOCKSConnection._new_conn.<locals>.<lambda>       '$8JA*N*N r8   r   r;   r?   quic_upgrade_via_dns_rrtiming_hookignore)_socketConnection to  timed out. (connect timeout=)&Failed to establish a new connection: )r;   r?   lenappendlowerr(   r
   int	_resolvercreate_connectionr   warningscatch_warningssimplefilterDeprecationWarningconnectrH   rI   SocketTimeoutr   r"   r   r   r#   OSErrorr4   extra_kwonly_tcp_optionsoptprotocolprW   es   `       r6   	_new_connzSOCKSConnection._new_conn   s;    /1H" A-1-@)*" >#% . 9 9C3xx1}}(//4444SQ(+A#u,,$(//BQB888-=)*4*<8DDD*<8DDD#2?C,\:T0>??!0<!0<,V4   .::+L9D/=>> !L#'#6#+,<#=,1 N N N N ; 
 
" ,..  )(4FGGG99		 '	 %                    "#45   )\TY\\T\\\\  
 )*5   (F1FF     (F1FF sV   (C-G1 AG$G1 $G((G1 +G(,G1 1I2"H$$I28II2I--I2r(   r   r)   r*   r+   r*   r,   r-   )r,   r   __name__
__module____qualname____doc__r2   rp   __classcell__r5   s   @r6   r   r   r   sc        	 		. 	. 	. 	. 	. 	.J	 J	 J	 J	 J	 J	 J	 J	r8   r   c                      e Zd ZdS )r   Nrs   rt   ru    r8   r6   r   r              r8   r   c                      e Zd ZeZdS )r   N)rs   rt   ru   r   ConnectionClsr{   r8   r6   r   r      s        'r8   r   c                      e Zd ZeZdS )r   N)rs   rt   ru   r   r~   r{   r8   r6   r   r              ,r8   r   c                  8     e Zd ZdZeedZ	 	 	 	 dd fdZ xZS )r   t
        A version of the urllib3 ProxyManager that routes connections via the
        defined SOCKS proxy.
        httphttpsN
   	proxy_urlstrrC   
str | NonerD   	num_poolsr_   headerstyping.Mapping[str, str] | Noneconnection_pool_kwr*   c                   t          |          }|;|9|j        2|j                            d          }t          |          dk    r|\  }}|j        dk    rt
          j        }	d}
n`|j        dk    rt
          j        }	d}
nF|j        dk    rt
          j        }	d}
n,|j        dk    rt
          j        }	d}
nt          d	|           || _	        |	|j
        |j        |||
d
}||d<   d|vrt                      |d<   |d                             t          j                    t!                      j        ||fi | t$          j        | _        d S N:r   socks5Fsocks5hTsocks4socks4az'Unable to determine SOCKS version from )rB   r@   rA   rC   rD   rE   r(   disabled_svn)r%   authsplitr\   schemer	   SOCKS5SOCKS4
ValueErrorr   rH   rI   setaddr   h3r1   r2   r   pool_classes_by_schemer4   r   rC   rD   r   r   r   parsedr   rB   rE   socks_optionsr5   s               r6   r2   zSOCKSProxyManager.__init__   s|    y))FH$49P))#..u::??).&Hh}(( ) 0)++ ) 0(** ) 0)++ ) 0 !V9!V!VWWW&DN "/$k$k$$ M 4A/0%77758UU">2~.22;>BBBEGGYFF3EFFF*;*RD'''r8   NNr   Nr   r   rC   r   rD   r   r   r_   r   r   r   r*   )	rs   rt   ru   rv   r   r   r   r2   rw   rx   s   @r6   r   r      sz        	 	 ,-"
 "
 $(#'7;1	S 1	S 1	S 1	S 1	S 1	S 1	S 1	S 1	S 1	S 1	Sr8   r   c                  ,     e Zd ZdZd fd	ZddZ xZS )AsyncSOCKSConnectionr'   r(   r   r)   r*   r+   r,   r-   c                H    || _          t                      j        |i | d S r/   r0   r3   s       r6   r2   zAsyncSOCKSConnection.__init__  r7   r8   r!   c           	     v   K   i } j         r
 j         |d<    j        rg } j        D ]|}t          |          dk    r|                    |           +t          |          dk    r>|d                                         }|dk    r_|                    |dd                    }||d<   	  j        d         J  j        d         J t           j        d	          j        d         t           j        d                    j        d
          j        d          j        d                   } j        	                     j        d         t           j        d                   f j
         j         |d         d fd           d{V }|                     j         j         j
        |           d{V S # t          t          f$ r'}t!           d j         d j
         d          |d}~wt"          t$          f$ r}t'           d|           |d}~wt(          $ r}t'           d|           |d}~ww xY w)r:   r;   r<   r=   r>   Nr?   r@   rA   rB   rC   rD   rE   rF   Fc                &    t          d|           S rK   rM   rO   s    r6   rQ   z0AsyncSOCKSConnection._new_conn.<locals>.<lambda>Q  rR   r8   rS   rX   rY   rZ   r[   )r;   r?   r\   r]   r^   r(   r   r_   r`   ra   r   rf   rH   rI   rg   r   r"   r   r   r#   rh   ri   s   `       r6   rp   zAsyncSOCKSConnection._new_conn%  s      /1H" A-1-@)*" >#% . 9 9C3xx1}}(//4444SQ(+A#u,,$(//BQB888-=)*-*<8DDD*<8DDD #2?C,\:T0>??!0<!0<,V4   !% @ @+L9D/=>> !L#'#6#+,<#=,1 N N N N !A 
! 
! 
 
 
 
 
 
 YYIIL	         "#45   )\TY\\T\\\\  
 )*5   (F1FF     (F1FF s1   *DF7 7H8"G**H8>HH8H33H8rq   )r,   r!   rr   rx   s   @r6   r   r     sc        	 		. 	. 	. 	. 	. 	.C	 C	 C	 C	 C	 C	 C	 C	r8   r   c                      e Zd ZdS )AsyncSOCKSHTTPSConnectionNrz   r{   r8   r6   r   r   n  r|   r8   r   c                      e Zd ZeZdS )AsyncSOCKSHTTPConnectionPoolN)rs   rt   ru   r   r~   r{   r8   r6   r   r   q  r   r8   r   c                      e Zd ZeZdS )AsyncSOCKSHTTPSConnectionPoolN)rs   rt   ru   r   r~   r{   r8   r6   r   r   t  s        1r8   r   c                  8     e Zd ZdZeedZ	 	 	 	 dd fdZ xZS )AsyncSOCKSProxyManagerr   r   Nr   r   r   rC   r   rD   r   r_   r   r   r   r*   c                   t          |          }|;|9|j        2|j                            d          }t          |          dk    r|\  }}|j        dk    rt
          j        }	d}
n`|j        dk    rt
          j        }	d}
nF|j        dk    rt
          j        }	d}
n,|j        dk    rt
          j        }	d}
nt          d	|           || _	        |	|j
        |j        |||
d
}||d<   d|vrt                      |d<   |d                             t          j                    t!                      j        ||fi | t$          j        | _        d S r   )r%   r   r   r\   r   r	   r   r   r   r   rH   rI   r   r   r   r   r1   r2   r   r   r   s               r6   r2   zAsyncSOCKSProxyManager.__init__  s|    y))FH$49P))#..u::??).&Hh}(( ) 0)++ ) 0(** ) 0)++ ) 0 !V9!V!VWWW&DN "/$k$k$$ M 4A/0%77758UU">2~.22;>BBBEGGYFF3EFFF*@*WD'''r8   r   r   )	rs   rt   ru   rv   r   r   r   r2   rw   rx   s   @r6   r   r   w  sz        	 	 12"
 "
 $(#'7;1	X 1	X 1	X 1	X 1	X 1	X 1	X 1	X 1	X 1	X 1	Xr8   r   )r   r   r   r   r   )r   r   r   r   r   )?rv   
__future__r   rb   r   __annotations__python_socksr   r   r   r	   python_socks.syncr
   _socks_overrider   ImportError
exceptionsr   socks_socks_legacyr   r   r   r   r   warntypingr   r   rg   _async.connectionr   r   _async.connectionpoolr   r   _async.poolmanagerr   _typingr   backendr   
connectionr   r   connectionpoolr   r    contrib.ssar!   r"   r#   poolmanagerr$   util.urlr%   sslr   r   r   r   r   __all__r{   r8   r6   <module>r      s  & & &P # " " " " "  "  ! ! ! !$            ('''''-------   ......#	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 #%  
 
 
\ 	
 	
 	
 	
 	

(   38  ]XMMM////// NMMMMMMM        655555------%%%%%% =<<<<<<<HHHHHHHH))))))DDDDDDDD))))))$$$$$$



   X X X X X. X X X|       ( ( ( ( ("4 ( ( (- - - - -#6 - - -<S <S <S <S <SK <S <S <S|Q Q Q Q Q2 Q Q Qn    $8:N   - - - - -'> - - -2 2 2 2 2(@ 2 2 2<X <X <X <X <X!1 <X <X <X~        GGG sC   / A2AA2A)&A2(A))A21A2C C#"C#