File: //opt/alt/python35/lib/python3.5/site-packages/urllib3/contrib/__pycache__/socks.cpython-35.pyc
�`W% � @ s� d Z d d l m Z y d d l Z WnA e k
ri d d l Z d d l m Z e j d e � � Yn Xd 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 Wn e k
rd Z Yn XGd
d � d e � Z Gd d � d e e � Z Gd d � d e � Z Gd d � d e � Z Gd d � d e � Z d S)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� )�DependencyWarningz�SOCKS 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)�error�timeout)�HTTPConnection�HTTPSConnection)�HTTPConnectionPool�HTTPSConnectionPool)�ConnectTimeoutError�NewConnectionError)�PoolManager)� parse_urlc s4 e Z d Z d Z � f d d � Z d d � Z � S)�SOCKSConnectionzG
A plain-text HTTP connection that connects via a SOCKS proxy.
c s/ | j d � | _ t t | � j | | � d S)N�_socks_options)�popr �superr �__init__)�self�args�kwargs)� __class__� � /socks.pyr 9 s zSOCKSConnection.__init__c C s� i } | j r | j | d <| j r2 | j | d <yl t j | j | j f d | j d d | j d d | j d d | j d d
| j d d | j | �} Wnt k
r� } z$ t | d
| j | j f � � WYd d } ~ Xn� t j
k
rw} zq | j rR| j } t | t � r<t | d
| j | j f � � qet
| d | � � n t
| d | � � WYd d } ~ Xn8 t k
r�} z t
| d | � � WYd d } ~ Xn X| S)zA
Establish a new connection via the SOCKS proxy.
�source_address�socket_optionsZ
proxy_type�
socks_versionZ
proxy_addr�
proxy_host�
proxy_portZproxy_username�usernameZproxy_password�passwordr 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 Z
ProxyErrorZ
socket_err�
isinstancer �SocketError)r Zextra_kw�conn�er r r r � _new_conn= sJ
( #zSOCKSConnection._new_conn)�__name__�
__module__�__qualname__�__doc__r r* r r )r r r 5 s r c @ s e Z d Z d S)�SOCKSHTTPSConnectionN)r+ r, r- r r r r r/ z s r/ c @ s e Z d Z e Z d S)�SOCKSHTTPConnectionPoolN)r+ r, r- r �
ConnectionClsr r r r r0 ~ s r0 c @ s e Z d Z e Z d S)�SOCKSHTTPSConnectionPoolN)r+ r, r- r/ r1 r r r r r2 � s r2 c sF e Z d Z d Z d e d e i Z d d d d � f d d � Z � S)�SOCKSProxyManagerzh
A version of the urllib3 ProxyManager that routes connections via the
defined SOCKS proxy.
ZhttpZhttpsN�
c
s� t | � } | j d k r'