Viewing File: /opt/alt/python35/lib/python3.5/site-packages/urllib3/contrib/__pycache__/socks.cpython-35.pyc



`W%@sdZddlmZyddlZWnAek
riddlZddlmZejdeYnXddl	m
ZmZ
ddlmZmZdd	lmZmZdd
lmZmZddlmZddlmZyddlZWnek
rdZYnXGd
ddeZGdddeeZGdddeZGdddeZGdddeZdS)aK
SOCKS support for urllib3
~~~~~~~~~~~~~~~~~~~~~~~~~

This contrib 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.

Known Limitations:

- Currently PySocks does not support contacting remote websites via literal
  IPv6 addresses. Any such connection attempt will fail.
- Currently PySocks does not support IPv6 connections to the SOCKS proxy. Any
  such connection attempt will fail.
)absolute_importN)DependencyWarningzSOCKS support in urllib3 requires the installation of optional dependencies: specifically, PySocks.  For more information, see https://urllib3.readthedocs.org/en/latest/contrib.html#socks-proxies)errortimeout)HTTPConnectionHTTPSConnection)HTTPConnectionPoolHTTPSConnectionPool)ConnectTimeoutErrorNewConnectionError)PoolManager)	parse_urlcs4eZdZdZfddZddZS)SOCKSConnectionzG
    A plain-text HTTP connection that connects via a SOCKS proxy.
    cs/|jd|_tt|j||dS)N_socks_options)poprsuperr__init__)selfargskwargs)	__class__	/socks.pyr9szSOCKSConnection.__init__cCsi}|jr|j|d<|jr2|j|d<yltj|j|jfd|jdd|jdd|jdd|jd	d
|jdd|j|}Wntk
r}z$t	|d
|j|jfWYdd}~Xntj
k
rw}zq|jrR|j}t|tr<t	|d
|j|jfqet
|d|nt
|d|WYdd}~Xn8tk
r}zt
|d|WYdd}~XnX|S)zA
        Establish a new connection via the SOCKS proxy.
        source_addresssocket_optionsZ
proxy_type
socks_versionZ
proxy_addr
proxy_host
proxy_portZproxy_usernameusernameZproxy_passwordpasswordrz0Connection to %s timed out. (connect timeout=%s)Nz(Failed to establish a new connection: %s)rrsockscreate_connectionhostportrr
SocketTimeoutrZ
ProxyErrorZ
socket_err
isinstancerSocketError)rZextra_kwconnerrrr	_new_conn=sJ	
	






(		#zSOCKSConnection._new_conn)__name__
__module____qualname____doc__rr*rr)rrr5src@seZdZdS)SOCKSHTTPSConnectionN)r+r,r-rrrrr/zsr/c@seZdZeZdS)SOCKSHTTPConnectionPoolN)r+r,r-r
ConnectionClsrrrrr0~sr0c@seZdZeZdS)SOCKSHTTPSConnectionPoolN)r+r,r-r/r1rrrrr2sr2csFeZdZdZdedeiZddddfddZS)SOCKSProxyManagerzh
    A version of the urllib3 ProxyManager that routes connections via the
    defined SOCKS proxy.
    ZhttpZhttpsN
c

st|}|jdkr'tj}n+|jdkrBtj}ntd|||_d|d|jd|jd|d|i}	|	|d	<t	t
|j|||t
j|_dS)
NZsocks5Zsocks4z)Unable to determine SOCKS version from %srrrrr r)
rschemer!ZPROXY_TYPE_SOCKS5ZPROXY_TYPE_SOCKS4
ValueError	proxy_urlr#r$rr3rpool_classes_by_scheme)
rr7rr Z	num_poolsZheadersZconnection_pool_kwZparsedrZ
socks_options)rrrrs"
			

zSOCKSProxyManager.__init__)r+r,r-r.r0r2r8rrr)rrr3s
r3) r.Z
__future__rr!ImportErrorwarnings
exceptionsrwarnsocketrr'rr%
connectionrrZconnectionpoolr	r
rrZpoolmanagerr
Zutil.urlrZsslrr/r0r2r3rrrr<module>s2

E
Back to Directory File Manager