๓
O'^c           @@  sq  d  Z  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 d d l m Z d d	 l m Z m Z d d
 l m Z d d l m Z m Z d d l m Z d d l m Z m Z m Z m Z d d l m Z d d d g Z  e e!  Z" d a$ d Z% d e& f d     YZ' d   Z( e d    Z) d   Z* d   Z+ d e, f d     YZ- d S(   s>   
kombu.async.hub
===============

Event loop implementation.

i    (   t   absolute_importN(   t   deque(   t   contextmanager(   t   sleep(   t   GeneratorType(   t   promise(   t   Emptyt   range(   t
   get_logger(   t   cached_propertyt   fileno(   t	   get_errno(   t   READt   WRITEt   ERRt   polli   (   t   Timert   Hubt   get_event_loopt   set_event_loops<   Received unknown event %r for fd %r, please contact support!t   Stopc           B@  s   e  Z d  Z RS(   s   Stops the event loop.(   t   __name__t
   __module__t   __doc__(    (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyR   &   s   c           C@  s   t     d  S(   N(   R   (    (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt   _raise_stop_error*   s    c          o@  s	   d  Vd  S(   N(    (   t   argst   kwargs(    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt   _dummy_context.   s    c           C@  s   t  S(   N(   t   _current_loop(    (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyR   3   s    c         C@  s
   |  a  |  S(   N(   R   (   t   loop(    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyR   7   s    c           B@  sa  e  Z d  Z e Z e Z e Z d Z d d  Z d   Z	 d   Z
 d   Z d   Z d   Z d d d d  d	  Z d
   Z d! e d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z e  e! e" e# e$ e% e& e e e d 
 Z' d   Z( d   Z) e* d    Z+ e, d    Z- RS("   sC   Event loop object.

    :keyword timer: Specify timer object.

    c         C@  s   | d  k	 r | n t   |  _ i  |  _ i  |  _ t   |  _ t   |  _ t   |  _	 t
 |  _ d  |  _ t   |  _ d  |  _ d |  _ |  j   d  S(   N(    (   t   NoneR   t   timert   readerst   writerst   sett   on_tickt   on_closeR   t   _readyt   Falset   _runningt   _loopt   consolidatet   consolidate_callbackt   propagate_errorst   _create_poller(   t   selfR   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt   __init__P   s    							c         C@  s   |  j    |  j   d  S(   N(   t   closeR,   (   R-   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt   resetj   s    
c         C@  s.   t    |  _ |  j j |  _ |  j j |  _ d  S(   N(   R   t   pollert   registert   _register_fdt
   unregistert   _unregister_fd(   R-   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyR,   n   s    c         C@  s>   |  j  d  k	 r: |  j  j   d  |  _  d  |  _ d  |  _ n  d  S(   N(   R1   R   R/   R3   R5   (   R-   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt   _close_pollers   s
    		c         C@  s   |  j  t  d  S(   N(   t	   call_soonR   (   R-   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt   stopz   s    c         C@  s+   d j  t |   t |  j  t |  j   S(   Ns   <Hub@{0:#x}: R:{1} W:{2}>(   t   formatt   idt   lenR    R!   (   R-   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt   __repr__}   s    i   i
   c   
      C@  s  |  j  } d  } | r| j rxโ t |  D]ั } t |  j  \ } } | d  k rV Pn  y |   Wq+ | k
 rw   q+ t t f k
 r   q+ t k
 rำ }	 t	 |	  t
 j k rบ   n  t j d |	 d d q+ t k
 r๛ }	 t j d |	 d d q+ Xq+ Wn  t | p| |  S(   Ns   Error in timer: %rt   exc_infoi   (   R   R   t   _queueR   t   nextt	   schedulert   MemoryErrort   AssertionErrort   OSErrorR   t   errnot   ENOMEMt   loggert   errort	   Exceptiont   min(
   R-   t	   min_delayt	   max_delayt
   max_timerst	   propagateR   t   delayt   it   entryt   exc(    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt   fire_timers   s(    	!c         C@  s&   z |  j  |  Wd  |  j |  Xd  S(   N(   t   _unregistert   _discard(   R-   t   fd(    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt   _remove_from_loop   s    c         C@  s   t  |  } y |  j j | |  Wn! t k
 rF |  j |    nP X| t @rZ |  j n |  j } | r |  j j	 |  d  | | <n | | f | | <d  S(   N(   R
   R1   R2   t
   ValueErrorRV   R   R    R!   R)   t   addR   (   R-   RU   t   callbackt   flagsR   R)   t   dest(    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyRX      s    c         C@  s   t  |  } |  j |  d  S(   N(   R
   RV   (   R-   RU   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt   removeฎ   s    c         C@  sH   t  |  _ z. x' y |  j   Wq t k
 r1 Pq Xq WWd  t |  _ Xd  S(   N(   t   TrueR'   t   run_onceR   R&   (   R-   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt   run_foreverฒ   s    	c         C@  s2   y t  |  j  Wn t k
 r- d  |  _ n Xd  S(   N(   R?   R   t   StopIterationR   R(   (   R-   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyR^   ฝ   s    c         G@  s#   t  | |  } |  j j |  | S(   N(   R   R%   t   append(   R-   RY   R   t   handle(    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyR7   ร   s    c         G@  s   |  j  j | | |  S(   N(   R   t
   call_after(   R-   RN   RY   R   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt
   call_laterศ   s    c         G@  s   |  j  j | | |  S(   N(   R   t   call_at(   R-   t   whenRY   R   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyRe   ห   s    c         G@  s   |  j  j | | |  S(   N(   R   t   call_repeatedly(   R-   RN   RY   R   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyRg   ฮ   s    c         G@  s   |  j  | | t t B|  S(   N(   RX   R   R   (   R-   t   fdsRY   R   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt
   add_readerั   s    c         G@  s   |  j  | | t |  S(   N(   RX   R   (   R-   Rh   RY   R   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt
   add_writerิ   s    c         C@  se   | |  j  k } |  j  j |  } z |  j |  Wd  | r` | \ } } |  j | | t |  n  Xd  S(   N(   R!   t   getRV   RX   R   (   R-   RU   t   writablet   on_writet   cbR   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt   remove_readerื   s    c         C@  si   | |  j  k } |  j  j |  } z |  j |  Wd  | rd | \ } } |  j | | t t B|  n  Xd  S(   N(   R    Rk   RV   RX   R   R   (   R-   RU   t   readablet   on_readRn   R   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt   remove_writerแ   s    c         C@  s5   y |  j  j |  Wn t t t f k
 r0 n Xd  S(   N(   R1   R4   t   AttributeErrort   KeyErrorRC   (   R-   RU   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyRS   ๋   s    c         G@  s   g  |  j  D] } |  j |  ^ q
 |  j  j   g  |  j D] } |  j |  ^ q: |  j j   |  j j   |  j   x |  j D] } | |   q Wd  S(   N(   R    RS   t   clearR!   R)   R6   R$   (   R-   R   RU   RY   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyR/   ๑   s    ##
c         C@  sF   t  |  } |  j j | d   |  j j | d   |  j j |  d  S(   N(   R
   R    t   popR   R!   R)   t   discard(   R-   RU   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyRT   ๛   s    c   !      c@  sc  |  j  |  j } } |  j j } |  j } |  j } |  j j } |  j } |  j	 } |  j
 } |  j } |  j } x๒x | D] } |   qt Wx& | rญ | j   } | r |   q q W| rร | d |  n d } | sี | rCg  } y | |  } Wn t k
 r|    n Xx"| pd D]\ } } t } | | k r[| j |  d  k r[| j |  qn  d  } } | | @rชy | | \ } } Wq| k
 rฆ|  j |  qqXnq | |	 @r๏y | | \ } } Wq| k
 r๋|  j |  qqXn, | |
 @rt } n t j t | |  t } | r`y( | j |  p?| j |  \ } } Wq`t k
 r\q`Xn  | d  k r|  j |  qn  t | |  ry | |  Wq)t k
 rึ}  t |   t j k rษ  n  | |  q)| k
 rๆq)t k
 r| |    q)Xqy | |   Wq| k
 r(qXqW| rV| |  qVn | | | d   d  Vqm Wd  S(   NRM   i   gน?(    (    R    R!   R1   R   RR   R\   R   R>   R)   R*   R#   R%   R+   t   popleftRW   R&   Rk   R   Ra   Ro   Rr   R]   RF   t   infot   W_UNKNOWN_EVENTt	   TypeErrort
   isinstanceRC   R   RD   t   EBADFRH   (!   R-   t	   generatorR   RI   R?   R   R`   Rt   R   R   R   R    R!   R   RR   t
   hub_removet	   scheduledR)   R*   R#   t   todoRM   t   tick_callbackt   itemt   poll_timeoutt   to_consolidatet   eventsRU   t   eventt   general_errorRn   t   cbargsRQ   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt   create_loop  s    								





	

c         C@  s   d d l  m } | |   S(   Ni   (   t   repr_active(   t   debugR   (   R-   R   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyR   ^  s    c         C@  s   d d l  m } | |  |  S(   Ni   (   t   repr_events(   R   R   (   R-   R   R   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyR   b  s    c         C@  s   t  |  j  S(   N(   t   iterR   (   R-   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyR@   f  s    c         C@  s(   |  j  d  k r! |  j   |  _  n  |  j  S(   N(   R(   R   R   (   R-   (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyR   j  s    N(    (    (.   R   R   R   R   R   R   R   R$   R.   R0   R,   R6   R8   R<   RR   RV   R&   RX   R\   R_   R^   R7   Rd   Re   Rg   Ri   Rj   Ro   Rr   RS   R/   RT   R~   R   RI   R?   R   R`   Rt   R   R   R   R	   R@   t   propertyR   (    (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyR   =   sH   																	
	
		
	Z		(.   R   t
   __future__R    RD   t   collectionsR   t
   contextlibR   t   timeR   t   typesR   R~   t   amqpR   t
   kombu.fiveR   R   t	   kombu.logR   t   kombu.utilsR	   R
   t   kombu.utils.compatR   t   kombu.utils.eventioR   R   R   R   R   R   t   __all__R   RF   R   R   Rz   t   BaseExceptionR   R   R   R   R   t   objectR   (    (    (    s1   /tmp/pip-unpacked-wheel-UAnTfW/kombu/async/hub.pyt   <module>   s.   "			