ó
¨9Vc           @   s  d  d l  Z  d  d l Z d  d l Z d  d l m Z d  d l Z d d l m Z y d  d l m	 Z
 m Z Wn' e k
 r d  d l m	 Z
 m Z n Xd e f d     YZ y e Z d  d l Z e j Z Wn3 e e f k
 rţ d Z d e f d	     YZ n Xy
 e Z Wn' e k
 r2d
 e f d     YZ n Xd d l m Z m Z m Z d d l m Z d d l  m! Z! m" Z" m# Z# m$ Z$ d d l% m& Z& i d d 6d d 6Z' e  j( d d d  Z) d e
 e f d     YZ	 d e	 f d     YZ d e f d     YZ* e re Z+ e* Z n e Z d S(   i˙˙˙˙N(   t   timeouti   (   t   six(   t   HTTPConnectiont   HTTPExceptiont   DummyConnectionc           B   s   e  Z d  Z RS(   s-   Used to detect a failed ConnectionCls import.(   t   __name__t
   __module__t   __doc__(    (    (    sM   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/connection.pyR      s   t   BaseSSLErrorc           B   s   e  Z RS(    (   R   R   (    (    (    sM   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/connection.pyR      s   t   ConnectionErrorc           B   s   e  Z RS(    (   R   R   (    (    (    sM   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/connection.pyR	   "   s   (   t   ConnectTimeoutErrort   SystemTimeWarningt   SecurityWarning(   t   match_hostname(   t   resolve_cert_reqst   resolve_ssl_versiont   ssl_wrap_sockett   assert_fingerprint(   t
   connectioniP   t   httpiť  t   httpsiŢ  R   c           B   sZ   e  Z d  Z e d Z e j e j d f g Z e	 Z
 d   Z d   Z d   Z d   Z RS(   s{  
    Based on httplib.HTTPConnection but provides an extra constructor
    backwards-compatibility layer between older and newer Pythons.

    Additional keyword parameters are used to configure attributes of the connection.
    Accepted parameters include:

      - ``strict``: See the documentation on :class:`urllib3.connectionpool.HTTPConnectionPool`
      - ``source_address``: Set the source address for the current connection.

        .. note:: This is ignored for Python 2.6. It is only applied for 2.7 and 3.x

      - ``socket_options``: Set specific options on the underlying socket. If not specified, then
        defaults are loaded from ``HTTPConnection.default_socket_options`` which includes disabling
        Nagle's algorithm (sets TCP_NODELAY to 1) unless the connection is behind a proxy.

        For example, if you wish to enable TCP Keep Alive in addition to the defaults,
        you might pass::

            HTTPConnection.default_socket_options + [
                (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
            ]

        Or you may want to disable the defaults by passing an empty list (e.g., ``[]``).
    R   i   c         O   s   t  j r | j d d   n  | j d  |  _ t j d k  rP | j d d   n  | j d |  j  |  _	 t
 j |  | |  d  S(   Nt   strictt   source_addressi   i   t   socket_options(   i   i   (   R   t   PY3t   popt   Nonet   getR   t   syst   version_infot   default_socket_optionsR   t   _HTTPConnectiont   __init__(   t   selft   argst   kw(    (    sM   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/connection.pyR    c   s    	c         C   s   i  } |  j  r |  j  | d <n  |  j r8 |  j | d <n  y( t j |  j |  j f |  j |  } Wn0 t k
 r t |  d |  j |  j f   n X| S(   sp    Establish a socket connection and set nodelay settings on it.

        :return: New socket connection.
        R   R   s0   Connection to %s timed out. (connect timeout=%s)(	   R   R   R   t   create_connectiont   hostt   portR    t   SocketTimeoutR
   (   R!   t   extra_kwt   conn(    (    sM   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/connection.pyt	   _new_connx   s    		"c         C   s5   | |  _  t |  d d   r1 |  j   d |  _ n  d  S(   Nt   _tunnel_hosti    (   t   sockt   getattrR   t   _tunnelt	   auto_open(   R!   R)   (    (    sM   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/connection.pyt   _prepare_conn   s    	
c         C   s   |  j    } |  j |  d  S(   N(   R*   R0   (   R!   R)   (    (    sM   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/connection.pyt   connect   s    (   R   R   R   t   port_by_schemet   default_portt   sockett   IPPROTO_TCPt   TCP_NODELAYR   t   Falset   is_verifiedR    R*   R0   R1   (    (    (    sM   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/connection.pyR   ?   s   
			t   HTTPSConnectionc           B   s6   e  Z e d  Z d d d d e j d  Z d   Z RS(   R   c      	   K   sA   t  j |  | | d | d | | | |  _ | |  _ d |  _ d  S(   NR   R    R   (   R   R    t   key_filet	   cert_filet	   _protocol(   R!   R%   R&   R:   R;   R   R    R#   (    (    sM   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/connection.pyR    ˘   s
    
		c         C   s;   |  j    } |  j |  t j | |  j |  j  |  _ d  S(   N(   R*   R0   t   sslt   wrap_socketR:   R;   R,   (   R!   R)   (    (    sM   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/connection.pyR1   Ż   s    N(	   R   R   R2   R3   R   R4   t   _GLOBAL_DEFAULT_TIMEOUTR    R1   (    (    (    sM   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/connection.pyR9      s   
	t   VerifiedHTTPSConnectionc           B   sJ   e  Z d  Z d Z d Z d Z d Z d d d d d d d  Z d   Z	 RS(   s[   
    Based on httplib.HTTPSConnection but wraps the socket with
    SSL certification.
    c         C   s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   R:   R;   t	   cert_reqst   ca_certst   assert_hostnameR   (   R!   R:   R;   RA   RB   RC   R   (    (    sM   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/connection.pyt   set_certż   s    					c         C   s  |  j    } t |  j  } t |  j  } |  j } t |  d d   rm | |  _ |  j	   d |  _
 |  j } n  t j j   t k  } | r¤ t j d j t  t  n  t | |  j |  j d | d |  j d | d | |  _ |  j rt |  j j d t  |  j  nk | t j k rp|  j t k	 rp|  j j   } | j d	 d  sWt j d
 t   n  t! | |  j pi|  n  | t j" k p|  j d  k	 |  _# d  S(   NR+   i    sW   System time is way off (before {0}). This will probably lead to SSL verification errorsRA   RB   t   server_hostnamet   ssl_versiont   binary_formt   subjectAltNamesâ   Certificate has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/shazow/urllib3/issues/497 for details.)(    ($   R*   R   RA   R   RF   R%   R-   R   R,   R.   R/   R+   t   datetimet   datet   todayt   RECENT_DATEt   warningst   warnt   formatR   R   R:   R;   RB   R   t   getpeercertt   TrueR=   t	   CERT_NONERC   R7   R   R   R   t   CERT_REQUIREDR8   (   R!   R)   t   resolved_cert_reqst   resolved_ssl_versiont   hostnamet   is_time_offt   cert(    (    sM   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/connection.pyR1   Ę   sB    		
	
		
N(
   R   R   R   R   RA   RB   RF   R   RD   R1   (    (    (    sM   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/connection.pyR@   ľ   s   	(,   RI   R   R4   R    R'   RM   t   packagesR   t   http.clientR   R   R   t   ImportErrort   httplibt   objectR   R9   R=   t   SSLErrorR   t   AttributeErrorR   t   BaseExceptionR	   t	   NameErrort	   Exceptiont
   exceptionsR
   R   R   t   packages.ssl_match_hostnameR   t	   util.ssl_R   R   R   R   t   utilR   R2   RJ   RL   R@   t   UnverifiedHTTPSConnection(    (    (    sM   /tmp/pip-build-5Z5nTX/pip/pip/_vendor/requests/packages/urllib3/connection.pyt   <module>   sH   
"
`N	