๓
jทร^c           @@  s   d  d l  m Z d  d l Z d d l m Z m Z d d l m Z d   Z e j	 d d d  Z d	   Z d
   Z d   Z e d  Z d S(   i    (   t   absolute_importNi   (   t   NoWayToWaitForSocketErrort   wait_for_readi   (   t   _appengine_environc         C@  s_   t  |  d t  } | t k r" t S| d k r2 t Sy t | d d SWn t k
 rZ t SXd S(   s   
    Returns True if the connection is dropped and should be closed.

    :param conn:
        :class:`httplib.HTTPConnection` object.

    Note: For platforms like AppEngine, this will always return ``False`` to
    let the platform handle connection recycling transparently for us.
    t   sockt   timeoutg        N(   t   getattrt   Falset   Nonet   TrueR   R   (   t   connR   (    (    s4   site-packages/pip/_vendor/urllib3/util/connection.pyt   is_connection_dropped   s    
c         C@  sO  |  \ } } | j  d  r- | j d  } n  d } t   } x่ t j | | | t j  D]ห } | \ }	 }
 } } } d } yl t j |	 |
 |  } t | |  | t j k	 rฝ | j	 |  n  | rำ | j
 |  n  | j |  | SWqX t j k
 r"} | } | d k	 r#| j   d } q#qX XqX W| d k	 r<|  n  t j d   d S(   sd  Connect to *address* and return the socket object.

    Convenience function.  Connect to *address* (a 2-tuple ``(host,
    port)``) and return the socket object.  Passing the optional
    *timeout* parameter will set the timeout on the socket instance
    before attempting to connect.  If no *timeout* is supplied, the
    global default timeout setting returned by :func:`getdefaulttimeout`
    is used.  If *source_address* is set it must be a tuple of (host, port)
    for the socket to bind as a source address before making the connection.
    An host of '' or port 0 tells the OS to use the default.
    t   [s   []s!   getaddrinfo returns an empty listN(   t
   startswitht   stripR   t   allowed_gai_familyt   sockett   getaddrinfot   SOCK_STREAMt   _set_socket_optionst   _GLOBAL_DEFAULT_TIMEOUTt
   settimeoutt   bindt   connectt   errort   close(   t   addressR   t   source_addresst   socket_optionst   hostt   portt   errt   familyt   rest   aft   socktypet   protot	   canonnamet   saR   t   e(    (    s4   site-packages/pip/_vendor/urllib3/util/connection.pyt   create_connection!   s2    	"
	c         C@  s2   | d  k r d  Sx | D] } |  j |   q Wd  S(   N(   R   t
   setsockopt(   R   t   optionst   opt(    (    s4   site-packages/pip/_vendor/urllib3/util/connection.pyR   Y   s    c          C@  s   t  j }  t r t  j }  n  |  S(   sณ   This function is designed to work in the context of
    getaddrinfo, where family=socket.AF_UNSPEC is the default and
    will perform a DNS search for both IPv6 and IPv4 records.(   R   t   AF_INETt   HAS_IPV6t	   AF_UNSPEC(   R    (    (    s4   site-packages/pip/_vendor/urllib3/util/connection.pyR   a   s    	c         C@  s   d } t } t j   r t St j rk y/ t j t j  } | j |  d f  t } Wqk t	 k
 rg qk Xn  | r~ | j
   n  | S(   s6    Returns True if the system can bind an IPv6 address. i    N(   R   R   R   t   is_appengine_sandboxR   t   has_ipv6t   AF_INET6R   R	   t	   ExceptionR   (   R   R   R0   (    (    s4   site-packages/pip/_vendor/urllib3/util/connection.pyt	   _has_ipv6l   s    	
s   ::1(   t
   __future__R    R   t   waitR   R   t   contribR   R   R   R   R(   R   R   R3   R-   (    (    (    s4   site-packages/pip/_vendor/urllib3/util/connection.pyt   <module>   s   	4			