ó
_XîTc           @   s™   d  d l  Z  y d  d l m Z m Z WnE e k
 rm e Z y d  d l m Z Wqn e k
 ri e Z qn Xn Xd „  Z e  j d d d „ Z	 d „  Z
 d S(   iÿÿÿÿN(   t   pollt   POLLIN(   t   selectc         C   sÎ   t  |  d t ƒ } | t k r" t S| d k r2 t St s{ t sB t Sy t | g g  g  d ƒ d SWq{ t j k
 rw t SXn  t ƒ  } | j | t	 ƒ x3 | j d ƒ D]" \ } } | | j
 ƒ  k r¤ t Sq¤ Wd 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   sockg        i    N(   t   getattrt   Falset   Nonet   TrueR    R   t   sockett   errort   registerR   t   fileno(   t   connR   t   pt   fnot   ev(    (    s;   /usr/lib/python2.7/site-packages/urllib3/util/connection.pyt   is_connection_dropped   s"    
	c         C   s%  |  \ } } d } xè t j | | d 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	 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.
    i    s!   getaddrinfo returns an empty listN(   R   R   t   getaddrinfot   SOCK_STREAMt   _set_socket_optionst   _GLOBAL_DEFAULT_TIMEOUTt
   settimeoutt   bindt   connectR	   t   close(   t   addresst   timeoutt   source_addresst   socket_optionst   hostt   portt   errt   rest   aft   socktypet   protot	   canonnamet   saR   t   _(    (    s;   /usr/lib/python2.7/site-packages/urllib3/util/connection.pyt   create_connection0   s,    "
	c         C   s2   | d  k r d  Sx | D] } |  j | Œ  q Wd  S(   N(   R   t
   setsockopt(   R   t   optionst   opt(    (    s;   /usr/lib/python2.7/site-packages/urllib3/util/connection.pyR   ]   s    (   R   R   R    R   t   ImportErrorR   R   R   R   R'   R   (    (    (    s;   /usr/lib/python2.7/site-packages/urllib3/util/connection.pyt   <module>   s   	$,