σ
.ΏWc           @@  s  d  Z  d d l m Z y d d l Z Wn@ e k
 rh d d l Z d d l m Z e j d e    n 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
 r
d Z n Xd e f d     YZ d e e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ  d S(   sK  
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.
i    (   t   absolute_importNi   (   t   DependencyWarningsΓ   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(   t   errort   timeout(   t   HTTPConnectiont   HTTPSConnection(   t   HTTPConnectionPoolt   HTTPSConnectionPool(   t   ConnectTimeoutErrort   NewConnectionError(   t   PoolManager(   t	   parse_urlt   SOCKSConnectionc           B@  s    e  Z d  Z d   Z d   Z RS(   sG   
    A plain-text HTTP connection that connects via a SOCKS proxy.
    c         O@  s/   | j  d  |  _ t t |   j | |   d  S(   Nt   _socks_options(   t   popR   t   superR   t   __init__(   t   selft   argst   kwargs(    (    sP   /tmp/pip-build-Q3rTTP/pip/pip/_vendor/requests/packages/urllib3/contrib/socks.pyR   9   s    c         C@  s  i  } |  j  r |  j  | d <n  |  j r8 |  j | d <n  yl t j |  j |  j f d |  j d d |  j d d |  j d d |  j d	 d
 |  j d d |  j | } WnΨ t k
 rΨ } t	 |  d |  j |  j f   n§ t j
 k
 rY} | j rC| j } t | t  r-t	 |  d |  j |  j f   qVt |  d |   qt |  d |   n& t k
 r~} t |  d |   n X| S(   sA   
        Establish a new connection via the SOCKS proxy.
        t   source_addresst   socket_optionst
   proxy_typet   socks_versiont
   proxy_addrt
   proxy_hostt
   proxy_portt   proxy_usernamet   usernamet   proxy_passwordt   passwordR   s0   Connection to %s timed out. (connect timeout=%s)s(   Failed to establish a new connection: %s(   R   R   t   sockst   create_connectiont   hostt   portR   R   t   SocketTimeoutR   t
   ProxyErrort
   socket_errt
   isinstanceR	   t   SocketError(   R   t   extra_kwt   connt   eR   (    (    sP   /tmp/pip-build-Q3rTTP/pip/pip/_vendor/requests/packages/urllib3/contrib/socks.pyt	   _new_conn=   sJ    				(   t   __name__t
   __module__t   __doc__R   R+   (    (    (    sP   /tmp/pip-build-Q3rTTP/pip/pip/_vendor/requests/packages/urllib3/contrib/socks.pyR   5   s   	t   SOCKSHTTPSConnectionc           B@  s   e  Z RS(    (   R,   R-   (    (    (    sP   /tmp/pip-build-Q3rTTP/pip/pip/_vendor/requests/packages/urllib3/contrib/socks.pyR/   z   s   t   SOCKSHTTPConnectionPoolc           B@  s   e  Z e Z RS(    (   R,   R-   R   t   ConnectionCls(    (    (    sP   /tmp/pip-build-Q3rTTP/pip/pip/_vendor/requests/packages/urllib3/contrib/socks.pyR0   ~   s   t   SOCKSHTTPSConnectionPoolc           B@  s   e  Z e Z RS(    (   R,   R-   R/   R1   (    (    (    sP   /tmp/pip-build-Q3rTTP/pip/pip/_vendor/requests/packages/urllib3/contrib/socks.pyR2      s   t   SOCKSProxyManagerc           B@  s7   e  Z d  Z i e d 6e d 6Z d d d d d  Z RS(   sh   
    A version of the urllib3 ProxyManager that routes connections via the
    defined SOCKS proxy.
    t   httpt   httpsi
   c   
      K@  sΐ   t  |  } | j d k r' t j } n+ | j d k rB t j } n t d |   | |  _ i | d 6| j d 6| j d 6| d 6| d 6}	 |	 | d	 <t	 t
 |   j | | |  t
 j |  _ d  S(
   Nt   socks5t   socks4s)   Unable to determine SOCKS version from %sR   R   R   R   R   R   (   R   t   schemeR   t   PROXY_TYPE_SOCKS5t   PROXY_TYPE_SOCKS4t
   ValueErrort	   proxy_urlR!   R"   R   R3   R   t   pool_classes_by_scheme(
   R   R<   R   R   t	   num_poolst   headerst   connection_pool_kwt   parsedR   t   socks_options(    (    sP   /tmp/pip-build-Q3rTTP/pip/pip/_vendor/requests/packages/urllib3/contrib/socks.pyR      s$    	



N(   R,   R-   R.   R0   R2   R=   t   NoneR   (    (    (    sP   /tmp/pip-build-Q3rTTP/pip/pip/_vendor/requests/packages/urllib3/contrib/socks.pyR3      s   
(!   R.   t
   __future__R    R   t   ImportErrort   warningst
   exceptionsR   t   warnt   socketR   R'   R   R#   t
   connectionR   R   t   connectionpoolR   R   R   R	   t   poolmanagerR
   t   util.urlR   t   sslRC   R   R/   R0   R2   R3   (    (    (    sP   /tmp/pip-build-Q3rTTP/pip/pip/_vendor/requests/packages/urllib3/contrib/socks.pyt   <module>   s2   
E