ó
Ð²Ebc           @@  s«   d  d l  m Z d  d l Z d  d l m Z d d l m Z d d l m Z d d l	 m
 Z
 m Z d	 „  Z e j d d d
 „ Z d „  Z d „  Z d „  Z e d ƒ Z d S(   i    (   t   absolute_importN(   t   LocationParseErrori   (   t   _appengine_environ(   t   sixi   (   t   NoWayToWaitForSocketErrort   wait_for_readc         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:`http.client.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   (    (    s@   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/util/connection.pyt   is_connection_dropped   s    
c         C@  s‹  |  \ } } | j  d ƒ r- | j d ƒ } n  d } t ƒ  } y | j d ƒ Wn( t k
 rw t j t d | ƒ d ƒ SXxè t	 j
 | | | t	 j ƒ D]Ë } | \ }	 }
 } } } d } yl t	 j	 |	 |
 | ƒ } t | | ƒ | t	 j k	 rù | j | ƒ n  | r| j | ƒ n  | j | ƒ | SWq” t	 j k
 r^} | } | d k	 r_| j ƒ  d } q_q” Xq” W| d k	 rx| ‚ n  t	 j d ƒ ‚ d S(   sk  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:`socket.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   []t   idnau   '%s', label empty or too longs!   getaddrinfo returns an empty listN(   t
   startswitht   stripR
   t   allowed_gai_familyt   encodet   UnicodeErrorR   t
   raise_fromR   t   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(    (    s@   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/util/connection.pyt   create_connection&   s<    	"
	c         C@  s2   | d  k r d  Sx | D] } |  j | Œ  q Wd  S(   N(   R
   t
   setsockopt(   R   t   optionst   opt(    (    s@   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/util/connection.pyR   e   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&   (    (    s@   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/util/connection.pyR   m   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   R6   (    (    s@   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/util/connection.pyt	   _has_ipv6x   s    	
s   ::1(   t
   __future__R    R   t   pip._vendor.urllib3.exceptionsR   t   contribR   t   packagesR   t   waitR   R   R   R   R
   R.   R   R   R9   R3   (    (    (    s@   /tmp/pip-build-UPPWic/pip/pip/_vendor/urllib3/util/connection.pyt   <module>   s   	;			