B
    @)H[ï  ã               @   s(  d Z ddlmZ yddlZW n6 ek
rR   ddlZddlmZ e de¡ ‚ Y nX ddl	m
ZmZ ddl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mZ yddlZW n ek
rÐ   dZY nX G dd„ deƒZG dd„ deeƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )aí  
This module contains provisional support for SOCKS proxies from within
urllib3. This module supports SOCKS4 (specifically the SOCKS4A variant) and
SOCKS5. To enable its functionality, either install PySocks 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:

- SOCKS4
- SOCKS4a
- SOCKS5
- Usernames and passwords for the SOCKS proxy

Known Limitations:

- Currently PySocks does not support contacting remote websites via literal
  IPv6 addresses. Any such connection attempt will fail. You must use a domain
  name.
- Currently PySocks does not support IPv6 connections to the SOCKS proxy. Any
  such connection attempt will fail.
é    )Úabsolute_importNé   )ÚDependencyWarningzÂSOCKS support in urllib3 requires the installation of optional dependencies: specifically, PySocks.  For more information, see https://urllib3.readthedocs.io/en/latest/contrib.html#socks-proxies)ÚerrorÚtimeout)ÚHTTPConnectionÚHTTPSConnection)ÚHTTPConnectionPoolÚHTTPSConnectionPool)ÚConnectTimeoutErrorÚNewConnectionError)ÚPoolManager)Ú	parse_urlc                   s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚSOCKSConnectionzG
    A plain-text HTTP connection that connects via a SOCKS proxy.
    c                s"   |  d¡| _tt| ƒj||Ž d S )NÚ_socks_options)Úpopr   Úsuperr   Ú__init__)ÚselfÚargsÚkwargs)Ú	__class__© úbC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-qz7kpjmn\pip\pip\_vendor\urllib3\contrib\socks.pyr   ?   s    zSOCKSConnection.__init__c          
   C   sX  i }| j r| j |d< | jr$| j|d< yTtj| j| jff| jd | jd | jd | jd | jd | jd | jd	œ|—Ž}W nÚ tk
r° } zt	| d
| j| jf ƒ‚W dd}~X Y n¤ tj
k
�r" } zR|j�r|j}t|tƒrôt	| d
| j| jf ƒ‚nt| d| ƒ‚nt| d| ƒ‚W dd}~X Y n2 tk
�rR } zt| d| ƒ‚W dd}~X Y nX |S )zA
        Establish a new connection via the SOCKS proxy.
        Úsource_addressÚsocket_optionsÚsocks_versionÚ
proxy_hostÚ
proxy_portÚusernameÚpasswordÚrdns)Ú
proxy_typeZ
proxy_addrr   Zproxy_usernameZproxy_passwordZ
proxy_rdnsr   z0Connection to %s timed out. (connect timeout=%s)Nz(Failed to establish a new connection: %s)r   r   ÚsocksÚcreate_connectionÚhostÚportr   r   ÚSocketTimeoutr   Ú
ProxyErrorZ
socket_errÚ
isinstancer   ÚSocketError)r   Úextra_kwÚconnÚer   r   r   r   Ú	_new_connC   sL    

 
zSOCKSConnection._new_conn)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r.   Ú__classcell__r   r   )r   r   r   ;   s   r   c               @   s   e Zd ZdS )ÚSOCKSHTTPSConnectionN)r/   r0   r1   r   r   r   r   r4   �   s   r4   c               @   s   e Zd ZeZdS )ÚSOCKSHTTPConnectionPoolN)r/   r0   r1   r   ÚConnectionClsr   r   r   r   r5   …   s   r5   c               @   s   e Zd ZeZdS )ÚSOCKSHTTPSConnectionPoolN)r/   r0   r1   r4   r6   r   r   r   r   r7   ‰   s   r7   c                   s,   e Zd ZdZeedœZd‡ fdd„	Z‡  ZS )ÚSOCKSProxyManagerzh
    A version of the urllib3 ProxyManager that routes connections via the
    defined SOCKS proxy.
    )ÚhttpÚhttpsNé
   c                s²   t |ƒ}|jdkrtj}d}	nN|jdkr4tj}d}	n8|jdkrJtj}d}	n"|jdkr`tj}d}	ntd| ƒ‚|| _||j|j|||	dœ}
|
|d	< t	t
| ƒj||f|Ž t
j| _d S )
NZsocks5FZsocks5hTZsocks4Zsocks4az)Unable to determine SOCKS version from %s)r   r   r   r   r    r!   r   )r   Úschemer#   ZPROXY_TYPE_SOCKS5ZPROXY_TYPE_SOCKS4Ú
ValueErrorÚ	proxy_urlr%   r&   r   r8   r   Úpool_classes_by_scheme)r   r>   r   r    Ú	num_poolsÚheadersÚconnection_pool_kwÚparsedr   r!   Zsocks_options)r   r   r   r   —   s4    





zSOCKSProxyManager.__init__)NNr;   N)	r/   r0   r1   r2   r5   r7   r?   r   r3   r   r   )r   r   r8   �   s
    r8   ) r2   Ú
__future__r   r#   ÚImportErrorÚwarningsÚ
exceptionsr   ÚwarnÚsocketr   r*   r   r'   Ú
connectionr   r   Úconnectionpoolr	   r
   r   r   Úpoolmanagerr   Zutil.urlr   Ússlr   r4   r5   r7   r8   r   r   r   r   Ú<module>   s2   
F