î
)Ú Xˆ  ã               @   sØ   d  d l  m Z d  d l Z y d  d l m Z m Z WnG e k
 r d Z y d  d l m Z Wn e k
 rz d Z Yn XYn Xd d „  Z e j d d d d	 „ Z	 d
 d „  Z
 d d „  Z d d „  Z e d ƒ Z d S)é    )Úabsolute_importN)ÚpollÚPOLLINF)Úselectc             C   sÒ   t  |  d d ƒ } | d k r" d S| d k r2 d St s t sB d Sy t | g g  g  d ƒ d SWq t j k
 r{ d SYq Xn  t ƒ  } | j | t ƒ x3 | j d ƒ D]" \ } } | | j ƒ  k r¨ d Sq¨ Wd S)a   
    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.
    ÚsockFNTg        r   )Úgetattrr   r   ÚsocketÚerrorÚregisterr   Úfileno)Úconnr   ÚpÚfnoÚev© r   úY/home/ubuntu/projects/ifolica/build/requests/requests/packages/urllib3/util/connection.pyÚis_connection_dropped   s"    
	r   c             C   sa  |  \ } } | 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
 r4} z* | } | d k	 r"| j ƒ  d } n  WYd d } ~ XqX XqX W| d k	 rN| ‚ n  t j d ƒ ‚ d S)ad  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.
    ú[z[]Nz!getaddrinfo returns an empty list)Ú
startswithÚstripÚallowed_gai_familyr   ÚgetaddrinfoÚSOCK_STREAMÚ_set_socket_optionsÚ_GLOBAL_DEFAULT_TIMEOUTÚ
settimeoutÚbindÚconnectr	   Úclose)ÚaddressÚtimeoutÚsource_addressZsocket_optionsÚhostÚportÚerrÚfamilyÚresÚafÚsocktypeÚprotoÚ	canonnameÚsar   Úer   r   r   Úcreate_connection3   s2    	"
 	r-   c             C   s2   | d  k r d  Sx | D] } |  j  | Œ  q Wd  S)N)Ú
setsockopt)r   ÚoptionsÚoptr   r   r   r   g   s    r   c              C   s   t  j }  t r t  j }  n  |  S)z³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   ÚAF_INETÚHAS_IPV6Ú	AF_UNSPEC)r%   r   r   r   r   o   s    	r   c             C   ss   d } d } t  j r\ y/ t  j  t  j ƒ } | j |  d f ƒ d } Wq\ t k
 rX Yq\ Xn  | ro | j ƒ  n  | S)z6 Returns True if the system can bind an IPv6 address. NFr   T)r   Úhas_ipv6ÚAF_INET6r   Ú	Exceptionr   )r"   r   r4   r   r   r   Ú	_has_ipv6z   s    	
r7   z::1)Ú
__future__r   r   r   r   r   ÚImportErrorr   r   r-   r   r   r7   r2   r   r   r   r   Ú<module>   s    &3