σ
ΠH/\c           @` sϊ  d  Z  d d l m Z m Z 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 d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z e j j d  rά d   Z n e Z y< d d l m Z d d l m Z m Z m Z d d g Z Wn  e  k
 r@d Z d g Z n Xd g e Z" d d l Z# e# j$ Z$ e e# e%   d e" d d Z& d Z' d Z( d   Z) d e* f d     YZ+ d d  Z e d k	 rσd e* f d     YZ, d e* f d     YZ n  [ d S(    s   
Waiting for I/O completion.
i    (   t   absolute_importt   divisiont   print_functionN(   t   Event(   t   _get_hub_noargs(   t   sleep(   t   integer_types(   t	   iteritems(   t   copy_globals(   t   _NONE(   t   EINTR(   t   selectt   win32c         C` s5   |  r" | r" | r" d d d f St  |  | | |  S(   N(    (    (    (   t   _real_original_select(   t   rt   wt   xt   t(    (    s,   lib/python2.7/site-packages/gevent/select.pyt   _original_select   s    (   t   poll(   t   POLLINt   POLLOUTt   POLLNVALR   R   t   errort   names_to_ignoret   dunder_names_to_keepi   i   c         C` sR   y |  j  } Wn7 t k
 rF t |  t  sB t d |  f   n  |  SX|   Sd  S(   Ns6   argument must be an int, or have a fileno() method: %r(   t   filenot   AttributeErrort
   isinstanceR   t	   TypeError(   t   objt   fileno_f(    (    s,   lib/python2.7/site-packages/gevent/select.pyt
   get_fileno3   s    t   SelectResultc           B` s_   e  Z d
 Z d   Z d   Z e e _ d   Z e e _ d   Z	 d   Z
 d   Z d	   Z RS(   t   readt   writet   eventc         C` s"   g  |  _  g  |  _ t   |  _ d  S(   N(   R"   R#   R   R$   (   t   self(    (    s,   lib/python2.7/site-packages/gevent/select.pyt   __init__A   s    		c         C` s!   |  j  j |  |  j j   d  S(   N(   R"   t   appendR$   t   set(   R%   t   socket(    (    s,   lib/python2.7/site-packages/gevent/select.pyt   add_readF   s    c         C` s!   |  j  j |  |  j j   d  S(   N(   R#   R'   R$   R(   (   R%   R)   (    (    s,   lib/python2.7/site-packages/gevent/select.pyt	   add_writeL   s    c         C` sS   xL | D]D } | t  |  | j  } | | _ | j |  | j | |  q Wd  S(   N(   R    R$   t   priorityR'   t   start(   R%   t   watcherst   fdlistt   callbackt   iot   prit   fdt   watcher(    (    s,   lib/python2.7/site-packages/gevent/select.pyt   __add_watchersR   s
    	c         C` s   t    j } | j } | j } y< |  j | | |  j | |  |  j | | |  j | |  Wn" t k
 r~ } t | j	    n Xd  S(   N(
   t   get_hubt   loopR1   t   MAXPRIt   _SelectResult__add_watchersR*   R+   t   IOErrorR   t   args(   R%   R.   t   rlistt   wlistR7   R1   R8   t   ex(    (    s,   lib/python2.7/site-packages/gevent/select.pyt   _make_watchersY   s    		 c         C` s-   x" | D] } | j    | j   q W| 2d  S(   N(   t   stopt   close(   R%   R.   R4   (    (    s,   lib/python2.7/site-packages/gevent/select.pyt	   _closealld   s    
c         C` sX   g  } z= |  j  | | |  |  j j d |  |  j |  j g  f SWd  |  j |  Xd  S(   Nt   timeout(   R?   R$   t   waitR"   R#   RB   (   R%   R<   R=   RC   R.   (    (    s,   lib/python2.7/site-packages/gevent/select.pyR   j   s    (   R"   R#   R$   (   t   __name__t
   __module__t	   __slots__R&   R*   t   _EV_READR$   R+   t	   _EV_WRITER9   R?   RB   R   (    (    (    s,   lib/python2.7/site-packages/gevent/select.pyR!   >   s   								c         C` sσ   | d k	 r' | d k  r' t d   n  d d d	 f } y t |  | | d  } WnD t k
 r } t | d d  p} | j d } | t k r   q n X| d sΜ | d sΜ | d sΜ | d k	 rΧ | d k rΧ t   | St   } | j	 |  | |  S(
   sΎ  An implementation of :meth:`select.select` that blocks only the current greenlet.

    .. caution:: *xlist* is ignored.

    .. versionchanged:: 1.2a1
       Raise a :exc:`ValueError` if timeout is negative. This matches Python 3's
       behaviour (Python 2 would raise a ``select.error``). Previously gevent had
       undefined behaviour.
    .. versionchanged:: 1.2a1
       Raise an exception if any of the file descriptors are invalid.
    i    s   timeout must be non-negativet   errnoi   i   N(    (    (    (
   t   Nonet
   ValueErrorR   R   t   getattrR;   R
   t   _g_sleepR!   R   (   R<   R=   t   xlistRC   t   sel_resultst   et   enumbert   result(    (    s,   lib/python2.7/site-packages/gevent/select.pyR   t   s    
6	t
   PollResultc           B` s    e  Z d Z d   Z d   Z RS(   t   eventsR$   c         C` s   t    |  _ t   |  _ d  S(   N(   R(   RU   R   R$   (   R%   (    (    s,   lib/python2.7/site-packages/gevent/select.pyR&   °   s    c         C` sl   | d k  r t  } n0 d } | t @r. t } n  | t @rE | t O} n  |  j j | | f  |  j j   d  S(   Ni    (	   R   RH   R   RI   R   RU   t   addR$   R(   (   R%   RU   R3   t   result_flags(    (    s,   lib/python2.7/site-packages/gevent/select.pyt	   add_event΄   s    	
	
(   RU   R$   (   RE   RF   RG   R&   RX   (    (    (    s,   lib/python2.7/site-packages/gevent/select.pyRT   ­   s   	c           B` sA   e  Z d  Z d   Z e d  Z d   Z d d  Z d   Z	 RS(   sΌ   
        An implementation of :class:`select.poll` that blocks only the current greenlet.

        .. caution:: ``POLLPRI`` data is not supported.

        .. versionadded:: 1.1b1
        c         C` s   i  |  _  t   j |  _ d  S(   N(   t   fdsR6   R7   (   R%   (    (    s,   lib/python2.7/site-packages/gevent/select.pyR&   Ι   s    	c         C` sf   | t  k r t t B} n0 d } | t @r2 t } n  | t @rI | t O} n  t |  } | |  j | <d  S(   Ni    (   R	   RH   RI   R   R   R    RY   (   R%   R3   t	   eventmaskt   flagsR   (    (    s,   lib/python2.7/site-packages/gevent/select.pyt   registerΡ   s    
	
c         C` s   |  j  | |  d  S(   N(   R\   (   R%   R3   RZ   (    (    s,   lib/python2.7/site-packages/gevent/select.pyt   modifyΰ   s    c   
      C` s  t    } g  } |  j j } |  j j } zΉ x[ t |  j  D]J \ } } | | |  } | j |  | | _ | j | j	 | d t
 q: W| d k	 rΏ | d k  r© d } qΏ | rΏ | d } qΏ n  | j j d |  t | j  SWd x" | D] }	 |	 j   |	 j   qκ WXd S(   sd  
            poll the registered fds.

            .. versionchanged:: 1.2a1
               File descriptors that are closed are reported with POLLNVAL.

            .. versionchanged:: 1.3a2
               Under libuv, interpret *timeout* values less than 0 the same as *None*,
               i.e., block. This was always the case with libev.
            t   pass_eventsi    g     @@RC   N(   RT   R7   R1   R8   R   RY   R'   R,   R-   RX   t   TrueRK   R$   RD   t   listRU   R@   RA   (
   R%   RC   RS   R.   R1   R8   R3   R[   R4   t   awatcher(    (    s,   lib/python2.7/site-packages/gevent/select.pyR   γ   s(    			
c         C` s   t  |  } |  j | =d S(   sά   
            Unregister the *fd*.

            .. versionchanged:: 1.2a1
               Raise a `KeyError` if *fd* was not registered, like the standard
               library. Previously gevent did nothing.
            N(   R    RY   (   R%   R3   R   (    (    s,   lib/python2.7/site-packages/gevent/select.pyt
   unregister  s    N(
   RE   RF   t   __doc__R&   R	   R\   R]   RK   R   Rb   (    (    (    s,   lib/python2.7/site-packages/gevent/select.pyR   Α   s   		0(    (-   Rc   t
   __future__R    R   R   t   syst   gevent.eventR   t
   gevent.hubR   R6   R   RN   t   gevent._compatR   R   t   gevent._utilR   R	   RJ   R
   R   R   t   platformt
   startswithR   R   t   original_pollR   R   R   t   __implements__t   ImportErrorRK   t   __all__t
   __select__R   t   globalst   __imports__RH   RI   R    t   objectR!   RT   (    (    (    s,   lib/python2.7/site-packages/gevent/select.pyt   <module>   sH   			68]