
R/oV4  ã               @   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 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 SWn t j k
 r{ d SYn Xt ƒ  } | 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)Zconnr   ÚpZfnoZev© r   ú9/usr/lib/python3/dist-packages/urllib3/util/connection.pyÚis_connection_dropped   s"    
		r   c             C   sI  |  \ } } | j  d ƒ r* | j d ƒ } d } xñ t j | | d t j ƒ D]Ô } | \ } }	 }
 } } d } yf t j | |	 |
 ƒ } t | | ƒ | t j k	 r® | j | ƒ | rÁ | j | ƒ | j	 | ƒ | SWqL t j
 k
 r} z' | } | d k	 r| j ƒ  d } WYd d } ~ XqL XqL W| d k	 r6| ‚ 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[]Nr   z!getaddrinfo returns an empty list)Ú
startswithÚstripr   ZgetaddrinfoZSOCK_STREAMÚ_set_socket_optionsÚ_GLOBAL_DEFAULT_TIMEOUTZ
settimeoutZbindZconnectr	   Úclose)ZaddressZtimeoutZsource_addressZsocket_optionsÚhostZportÚerrÚresZafZsocktypeÚprotoZ	canonnameZsar   Úer   r   r   Úcreate_connection1   s0    "
r   c             C   s2   | d  k r d  Sx | D] } |  j  | Œ  q Wd  S)N)Z
setsockopt)r   ZoptionsZoptr   r   r   r   `   s    r   )Z
__future__r   r   r   r   r   ÚImportErrorr   r   r   r   r   r   r   r   Ú<module>   s   $.