
O'^c           @@  s  d  Z  d d l m Z d d l 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 m Z d d l m Z m Z m Z d d l m Z d d l m Z m Z d d l m Z m Z m Z d d l  m! Z! d d l" m# Z# d d l$ m% Z% y d d l& m' Z' WnB e( k
 ry d d l) m' Z' Wn e( k
 rd   Z' n Xn Xy d d l* Z* Wn e( k
 re+ Z* n Xe d  Z, e, j- e, j. f \ Z/ Z. d Z0 d Z1 d d d d g Z2 e d d d f  Z3 d Z4 d   Z5 d   Z6 d  e7 f d!     YZ8 e	 d"    Z9 d# e% j: f d$     YZ: d% e; f d&     YZ< d' e% j= f d(     YZ= d) e% j> f d*     YZ> d S(+   s@   
kombu.transport.redis
=====================

Redis transport.

i    (   t   absolute_importN(   t   bisect(   t
   namedtuple(   t   contextmanager(   t   time(   t   promise(   t   loadst   dumps(   t   InconsistencyErrort   VersionMismatch(   t   Emptyt   valuest   string_t(   t
   get_logger(   t   cached_propertyt   uuid(   t   pollt   READt   ERR(   t   bytes_to_str(   t
   _parse_urli   (   t   virtual(   t   register_after_forkc          O@  s   d  S(   N(    (   t   argst   kwargs(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR   %   s    s   kombu.transport.redisi  i   i   i	   t   error_classes_tt   connection_errorst   channel_errorss   
Cannot route message for exchange {0!r}: Table empty or key no longer exists.
Probably the key ({1!r}) has been removed from the Redis database.
c          C@  s   d d l  m }  t |  d  r+ |  j } n	 |  j } t t j j t	 t
 d  t t j t t |  j |  j t |  d d   f   t j j | |  j |  j f  S(   Ni    (   t
   exceptionst   InvalidDatat   TimeoutError(   t   redisR   t   hasattrR   t	   DataErrorR   R   t	   TransportR   t   tuplet   filtert   NoneR   t   sockett   errort   IOErrort   OSErrort   ConnectionErrort   AuthenticationErrort   getattrR   t   InvalidResponset   ResponseError(   R   R!   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   get_redis_error_classesM   s"    		c          C@  s   d d l  m }  |  j S(   Ni    (   R   (   R   R   R*   (   R   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   get_redis_ConnectionErrord   s    t	   MutexHeldc           B@  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR1   i   s   c      	   c@  s   t    } |  j | |  } zM | r< |  j | |  d  Vn+ |  j |  s^ |  j | |  n  t    Wd  | r yl |  j t  W } | j |  | j |  | k r | j	   | j
 |  | j   n  | j   Wd  QXWq t j k
 r q Xn  Xd  S(   N(   R   t   setnxt   expiret   ttlR1   t   pipelinet   Truet   watcht   gett   multit   deletet   executet   unwatchR   t
   WatchError(   t   clientt   nameR5   t   lock_idt   i_wont   pipe(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   Mutexm   s(    	
t   QoSc           B@  s   e  Z e Z d    Z d   Z d d  Z d   Z e	 d  Z
 e d d d   Z d d  Z d d d d	  Z d e	 d
  Z e d    Z e d    Z e d    Z e d    Z e d    Z RS(   c         O@  s&   t  t |   j | |   d |  _ d  S(   Ni    (   t   superRF   t   __init__t   _vrestore_count(   t   selfR   R   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRH      s    c         C@  s   | j  } | d | d } } |  j   c } | j |  j | t    j |  j | t | j | | g   j	   t
 t |   j | |  Wd  QXd  S(   Nt   exchanget   routing_key(   t   delivery_infot   pipe_or_acquiret   zaddt   unacked_index_keyR   t   hsett   unacked_keyR   t   _rawR=   RG   RF   t   append(   RJ   t   messaget   delivery_tagt   deliveryt   EXt   RKRD   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRT      s    		c      	   C@  sS   |  j  j |  . } x$ |  j D] } |  j | d | q WWd  QX|  j j   d  S(   NR@   (   t   channelt   conn_or_acquiret
   _deliveredt   restore_by_tagt   clear(   RJ   R@   t   tag(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   restore_unacked   s    c         C@  s-   |  j  |  j   t t |   j |  d  S(   N(   t   _remove_from_indicesR=   RG   RF   t   ack(   RJ   RV   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRb      s    c         C@  s-   | r |  j  | d t n  |  j |  d  S(   Nt   leftmost(   R]   R8   Rb   (   RJ   RV   t   requeue(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   reject   s    c         c@  s8   | r | Vn& |  j  j |   } | j   VWd  QXd  S(   N(   RZ   R[   R7   (   RJ   RD   R@   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRN      s    c         C@  s>   |  j  |  ) } | j |  j |  j |  j |  SWd  QXd  S(   N(   RN   t   zremRP   t   hdelRR   (   RJ   RV   RD   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRa      s    i    i
   c   	      C@  s   |  j  d 7_  |  j  d | r$ d  S|  j j    } t   |  j } y t | |  j |  j  b | j |  j	 | d d | o | d | d t
 } x* | p g  D] \ } } |  j | |  q WWd  QXWn t k
 r n XWd  QXd  S(   Ni   i    t   startt   numt
   withscores(   RI   RZ   R[   R   t   visibility_timeoutRE   t   unacked_mutex_keyt   unacked_mutex_expiret   zrevrangebyscoreRP   R8   R]   R1   (	   RJ   Rh   Ri   t   intervalR@   t   ceilt   visibleR_   t   score(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   restore_visible   s    c   
      C@  s   |  j  j |   } | j   7 } |  j | | j |  j |   j   \ } } } Wd  QX| r t t |   \ } } }	 |  j  j	 | | |	 | |  n  Wd  QXd  S(   N(
   RZ   R[   R7   Ra   t   hgetRR   R=   R   R   t   _do_restore_message(
   RJ   R_   R@   Rc   RD   t   pt   _t   MRX   RY   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR]      s    0c         C@  s
   |  j  j S(   N(   RZ   RR   (   RJ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRR      s    c         C@  s
   |  j  j S(   N(   RZ   RP   (   RJ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRP      s    c         C@  s
   |  j  j S(   N(   RZ   Rl   (   RJ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRl      s    c         C@  s
   |  j  j S(   N(   RZ   Rm   (   RJ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRm      s    c         C@  s
   |  j  j S(   N(   RZ   Rk   (   RJ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRk      s    N(   R2   R3   R8   t   restore_at_shutdownRH   RT   R%   R`   Rb   t   FalseRe   R   RN   Ra   Rs   R]   R   RR   RP   Rl   Rm   Rk   (    (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRF      s    		
		t   MultiChannelPollerc           B@  s   e  Z e e BZ e 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 d   Z d d  Z e d    Z RS(   c         C@  s:   t    |  _ i  |  _ i  |  _ t   |  _ t    |  _ d  S(   N(   t   sett	   _channelst   _fd_to_chant   _chan_to_sockR   t   pollert
   after_read(   RJ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRH      s
    		c         C@  ss   xE t  |  j  D]4 } y |  j j |  Wq t t f k
 rC q Xq W|  j j   |  j j   |  j j   d  S(   N(	   R   R   R   t
   unregistert   KeyErrort
   ValueErrorR}   R^   R~   (   RJ   t   fd(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   close   s    c         C@  s   |  j  j |  d  S(   N(   R}   t   add(   RJ   RZ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    c         C@  s   |  j  j |  d  S(   N(   R}   t   discard(   RJ   RZ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    c         C@  s5   y |  j  j | j  Wn t t f k
 r0 n Xd  S(   N(   R   R   t   _sockt   AttributeErrort	   TypeError(   RJ   t
   connection(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _on_connection_disconnect  s    c         C@  s   | | | f |  j  k r. |  j | | |  n  | j j d  k rP | j j   n  | j j } | | f |  j | j   <| |  j  | | | f <|  j j	 | |  j
  d  S(   N(   R   t   _unregisterR   R   R%   t   connectR~   t   filenoR   t   registert
   eventflags(   RJ   RZ   R@   t   typet   sock(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt	   _register  s    c         C@  s$   |  j  j |  j | | | f  d  S(   N(   R   R   R   (   RJ   RZ   R@   R   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    c         C@  si   | | j  d f } | j  j j d k s6 | |  j k rO t | _ |  j |   n  | j se | j   n  d S(   s   enable BRPOP mode for channel.t   BRPOPN(	   R@   R   R   R%   R   Rz   t   _in_pollR   t   _brpop_start(   RJ   RZ   t   ident(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _register_BRPOP  s    		c         C@  sQ   | j  j j d k r7 t | _ |  j | | j  d  n  | j sM | j   n  d S(   s   enable LISTEN mode for channel.t   LISTENN(   t	   subclientR   R   R%   Rz   t
   _in_listenR   t
   _subscribe(   RJ   RZ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _register_LISTEN&  s
    		c         C@  s\   xU |  j  D]J } | j r; | j j   r; |  j |  q; n  | j r
 |  j |  q
 q
 Wd  S(   N(   R}   t   active_queuest   qost   can_consumeR   t   active_fanout_queuesR   (   RJ   RZ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   on_poll_start.  s    		c         C@  s4   | |  _  x$ |  j D] } | j j d | j  SWd  S(   NRi   (   R   R}   R   Rs   t   unacked_restore_limit(   RJ   R   RZ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   on_poll_init6  s    	c         C@  s7   x0 |  j  D]% } | j r
 | j j d | j  Sq
 Wd  S(   NRi   (   R}   R   R   Rs   R   (   RJ   RZ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   maybe_restore_messages=  s    	c         C@  sM   y |  j  | \ } } Wn t k
 r+ d  SX| j j   rI | j |   Sd  S(   N(   R~   R   R   R   t   handlers(   RJ   R   t   chanR   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   on_readableE  s    c         C@  sN   | t  @r |  j |  |  f S| t @rJ |  j | \ } } | j |  n  d  S(   N(   R   R   R   R~   t   _poll_error(   RJ   R   t   eventR   R   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   handle_eventM  s
    

c         C@  s  t  |  _ z xU |  j D]J } | j rG | j j   rG |  j |  qG n  | j r |  j |  q q W|  j	 j
 |  } x6 | p g  D]( \ } } |  j | |  } | r | Sq W|  j   t    Wd  t |  _ x< |  j ry |  j j   } Wn t k
 rPq X|   q WXd  S(   N(   R8   t   _in_protected_readR}   R   R   R   R   R   R   R   R   R   R   R
   Rz   R   t   popR   (   RJ   t   timeoutRZ   t   eventsR   R   t   rett   fun(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR:   T  s,    			
	c         C@  s   |  j  S(   N(   R~   (   RJ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   fdss  s    N(   R2   R3   R   R   R   Rz   R   R%   R   RH   R   R   R   R   R   R   R   R   R   R   R   R   R   R:   t   propertyR   (    (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR{      s&   
		
				
								t   Channelc           B@  s  e  Z e Z dK Z dK Z e Z e Z	 d  Z
 d Z d Z e Z e Z i  Z e Z d Z d Z d Z d Z dK Z d Z e Z dK Z dK Z dK Z dK Z d Z e Z e Z dK Z  dK Z! e Z" e# j$ j% dL Z% d   Z& d   Z' d   Z( d   Z) dK e d  Z* e d  Z+ d   Z, d    Z- d!   Z. d"   Z/ d#   Z0 d$   Z1 d%   Z2 d&   Z3 d'   Z4 d(   Z5 d) d*  Z6 d+   Z7 d,   Z8 d-   Z9 d.   Z: d/   Z; d0   Z< d1   Z= d2   Z> e d3  Z? d4   Z@ d5   ZA d6   ZB d7   ZC d8   ZD d9   ZE d:   ZF d;   ZG dK dK d<  ZH e dM d=  ZI e d>  ZJ e d?  ZK d@   ZL eM dK dA   ZN eO dB    ZP eO dC    ZQ eR dD    ZS eR dE    ZT dF   ZU dG   ZV dH   ZW dI   ZX eO dJ    ZY RS(N   s   _kombu.binding.%ss   /{db}.s   t   unackedt   unacked_indext   unacked_mutexi,  i  i
   t   ack_emulationRR   RP   Rl   Rm   Rk   R   t   fanout_prefixt   fanout_patternst   socket_timeoutt   socket_connect_timeoutt   socket_keepalivet   socket_keepalive_optionst   queue_order_strategyt   max_connectionst   priority_stepsc         O@  sF  t  t |   } | j | |   |  j s7 t j |  _ n  g  |  _ |  j   |  _ t	 j
 |  _ |  j   |  _ t   |  _ t   |  _ i  |  _ i |  j d 6|  j d 6|  _ |  j r t |  j t  r |  j |  _ q n	 d |  _ y |  j j   Wn t k
 r|  j     n X|  j j j |   |  j j  |  _  t! |  |  j"  d  S(   NR   R   t    (#   RG   R   RH   R   R   RF   t   _queue_cyclet   _get_async_clientt   AsyncClientR   t   Redist   Clientt   _get_response_errorR.   R|   R   t   auto_delete_queuest   _fanout_to_queuet   _brpop_readt   _receiveR   R   t
   isinstanceR   t   keyprefix_fanoutR@   t   infot	   Exceptiont   _disconnect_poolsR   t   cycleR   R   R   t   _after_fork(   RJ   R   R   t   super_(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRH     s0    					
c         C@  s   |  j    d  S(   N(   R   (   RJ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    c         C@  sx   |  j  st t |  _  zR |  j d  k	 r4 |  j j   n  |  j d  k	 rS |  j j   n  d  |  _ |  _ Wd  t |  _  Xn  d  S(   N(   t   _disconnecting_poolsR8   t   _async_poolR%   t
   disconnectt   _poolRz   (   RJ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    		c         C@  s`   t  |  _ t  |  _ |  j r= |  j j r= |  j j j |  n  |  j   |  j s\ t    n  d  S(   N(	   Rz   R   R   R   R   R   R   t   _closingR0   (   RJ   R   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    		
	c      	   C@  s   |  j  |   } yl y t | d d <Wn t k
 r: n Xx? |  j | |  D]+ } | rc | j n | j | t |   qN WWn$ t k
 r t d | d t n XWd  QXd  S(   Nt   headerst   redelivereds   Could not restore message: %rt   exc_info(	   R[   R8   R   t   _lookupt   lpusht   rpushR   R   t   crit(   RJ   t   payloadRK   RL   R@   Rc   t   queue(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRu     s    c         C@  s   |  j  s t t |   j |  S| j } |  j    } | j   7 } | j |  j |  j	 |  j |  j
   \ } } Wd  QX| r t t |   \ } }	 }
 |  j | |	 |
 | |  n  Wd  QXd  S(   N(   R   RG   R   t   _restoreRV   R[   R7   Rt   RR   Rg   R=   R   R   Ru   (   RJ   RU   Rc   R_   R@   RD   t   PRw   Rx   RX   RY   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    		!c         C@  s   |  j  | d t S(   NRc   (   R   R8   (   RJ   RU   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _restore_at_beginning  s    c         O@  sn   | |  j  k rB |  j  | \ } } |  j j |  | |  j | <n  t t |   j | | |  } |  j   | S(   N(   t   _fanout_queuesR   R   R   RG   R   t   basic_consumet   _update_cycle(   RJ   R   R   R   RK   Rw   R   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    
c         C@  sN   |  j  } | rJ | j j r= | j j j t |  j | f   S|  j |  Sd  S(   N(   R   R   R   R   R   R   t   _basic_cancel(   RJ   t   consumer_tagR   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   basic_cancel  s    	c         C@  s   y |  j  | } Wn t k
 r% d  SXy |  j j |  Wn t k
 rM n X|  j |  y' |  j | \ } } |  j j |  Wn t k
 r n Xt t	 |   j
 |  } |  j   | S(   N(   t   _tag_to_queueR   R   t   removet   _unsubscribe_fromR   R   R   RG   R   R   R   (   RJ   R   R   RK   Rw   R   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR   )  s"    
c         C@  sA   | r+ |  j  r+ d j |  j | d | g  Sd j |  j | g  S(   NR   t   /(   R   t   joinR   (   RJ   RK   RL   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _get_publish_topic=  s    c         C@  s#   |  j  | \ } } |  j | |  S(   N(   R   R   (   RJ   R   RK   RL   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _get_subscribe_topicB  s    c         C@  st   g  |  j  D] } |  j |  ^ q
 } | s/ d  S|  j } | j j d  k rZ | j j   n  t |  _ | j	 |  d  S(   N(
   R   R   R   R   R   R%   R   R8   R   t
   psubscribe(   RJ   R   t   keyst   c(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR   F  s    "		c         C@  s   |  j  |  } |  j } t } | j j d  k rF | j j   t } n  z | j | g  Wd  | r| | j r| | j j	   n  Xd  S(   N(
   R   R   Rz   R   R   R%   R   R8   t   unsubscribeR   (   RJ   R   t   topicR   t   should_disconnect(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR   Q  s    		c         C@  s   t  | d  d k r2 | d d k r2 t | _ nr t  | d  d k rx i | d d 6| d d 6| d d 6| d	 d
 6Si | d d 6d  d 6| d d 6| d d
 6Sd  S(   Ni    R   i   t   pmessageR   i   t   patternRZ   i   t   data(   R   Rz   t
   subscribedR%   (   RJ   R@   t   r(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _handle_message^  s    &c         C@  s[  |  j  } d  } y | j   } Wn& |  j k
 rG t |  _ t    n X| d  k	 rN|  j | |  } t | d  j	 d  rNt | d  } | d rK| d d k r | j
 d  \ } } } n  y t t | d   } Wn@ t t f k
 r t d | t |  d	  d
 d t    n X| j d d  d } | |  j | f SqNn  t    d  S(   NR   RU   RZ   R   i    R   t   .s&   Cannot process event on channel %r: %si   R   i   (   R   R%   t   parse_responseR   Rz   R   R
   R   R   t   endswitht	   partitionR   R   R   t   warnt   reprt   splitR   (   RJ   R   t   responseR   RZ   Rw   RU   RK   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR   h  s.    		
i   c         C@  sx   |  j    } | s d  Sg  t D]% } | D] } |  j | |  ^ q' q | pN d g } t |  _ |  j j j d |  d  S(   Ni    R   (   t   _consume_cyclet   PRIORITY_STEPSt
   _q_for_priR8   R   R@   R   t   send_command(   RJ   R   t   queuest   priR   R   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    2	c         K@  s   z y" |  j  j |  j  j d |  } Wn- |  j k
 rT |  j  j j   t    n X| r | \ } } t |  j |  j d  d } |  j	 |  t
 t |   | f St    Wd  t |  _ Xd  S(   NR   i   i    (   R@   R  R   R   R   R
   R   t   rsplitt   sept   _rotate_cycleR   Rz   R   (   RJ   t   optionst
   dest__itemt   destt   item(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    c         K@  s9   | d k r |  j  j   n |  j j |  j j |  d  S(   NR   (   R   R  R@   R   (   RJ   R   R  (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    c      	   C@  sd   |  j    R } x? t D]7 } | j |  j | |   } | r t t |   Sq Wt    Wd  QXd  S(   N(   R[   R
  t   rpopR  R   R   R
   (   RJ   R   R@   R  R  (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _get  s    c         C@  sz   |  j    h } | j   S } x) t D]! } | j |  j | |   } q% W| j   } t d   | D  SWd  QXWd  QXd  S(   Nc         s@  s'   |  ] } t  | t j  r | Vq d  S(   N(   R   t   numberst   Integral(   t   .0t   size(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pys	   <genexpr>  s    (   R[   R7   R
  t   llenR  R=   t   sum(   RJ   R   R@   RD   R  t   sizes(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _size  s    c         C@  s8   |  j  |  } d | r* | |  j | f n | d d f S(   Ns   %s%s%sR   (   t   priorityR  (   RJ   R   R  (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR    s    c         C@  s   |  j  } | t | |  d S(   Ni   (   R   R   (   RJ   t   nt   steps(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    	c         K@  s   y. t  t t | d d d  d  d  } Wn  t t t f k
 rP d } n X|  j   ) } | j |  j | |  t	 |   Wd QXd S(   s   Deliver message.t
   propertiesRM   R   i	   i    N(
   t   maxt   mint   intR   R   R   R[   R   R  R   (   RJ   R   RU   R   R  R@   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _put  s    	%
c         K@  s;   |  j    ) } | j |  j | |  t |   Wd QXd S(   s   Deliver fanout message.N(   R[   t   publishR   R   (   RJ   RK   RU   RL   R   R@   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _put_fanout  s    c         K@  s   | r |  j  j |  n  d  S(   N(   R   R   (   RJ   R   t   auto_deleteR   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt
   _new_queue  s    c      
   C@  s   |  j  |  j d k r: | | j d d  f |  j | <n  |  j   H } | j |  j | f |  j j | pn d | pw d | p d g   Wd  QXd  S(   Nt   fanoutt   #t   *R   (	   t   typeofR   t   replaceR   R[   t   saddt   keyprefix_queueR  R   (   RJ   RK   RL   R   R   R@   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _queue_bind  s    "	c   	      G@  s   |  j  j |  |  j    } | j |  j | f |  j j | pD d | pM d | pV d g   | j   = } x) t D]! } | j	 |  j
 | |   } qv W| j   Wd  QXWd  QXd  S(   NR   (   R   R   R[   t   sremR2  R  R   R7   R
  R<   R  R=   (	   RJ   R   RK   RL   R   R   R@   RD   R  (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _delete  s    	c         K@  sj   |  j    X } | j   C } x) t D]! } | j |  j | |   } q% Wt | j    SWd  QXWd  QXd  S(   N(   R[   R7   R
  t   existsR  t   anyR=   (   RJ   R   R   R@   RD   R  (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt
   _has_queue  s
    c      	   C@  s   |  j  | } |  j   f } | j |  } | sL t t j | |    n  g  | D]$ } t t |  j |  j	   ^ qS SWd  QXd  S(   N(
   R2  R[   t   smembersR   t   NO_ROUTE_ERRORt   formatR#   R   R  R  (   RJ   RK   t   keyR@   R   t   val(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt	   get_table  s    c         C@  s   |  j    z } | j   e } x8 t D]0 } |  j | |  } | j |  j |  } q% W| j   } t | d  d  d   SWd  QXWd  QXd  S(   Ni   (   R[   R7   R
  R  R  R<   R=   R  (   RJ   R   R@   RD   R  t   priqR  (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _purge  s    c         C@  s   t  |  _ |  j   |  j so |  j j j |   x0 |  j D]% } | |  j k r9 |  j	 |  q9 q9 W|  j
   n  t t |   j   d  S(   N(   R8   R   R   t   closedR   R   R   R   R   t   queue_deletet   _close_clientsRG   R   R   (   RJ   R   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    	
	c         C@  sM   xF d D]> } y |  j  | j j   Wq t t |  j f k
 rD q Xq Wd  S(   NR@   R   (   R@   R   (   t   __dict__R   R   R   R   R.   (   RJ   t   attr(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRC    s
    c         C@  s   t  | t j  s | s% | d k r. t } n | j d  rJ | d } n  y t |  } Wq t k
 r t d j |    q Xn  | S(   NR   i   s0   Database is int between 0 and limit - 1, not {0}(   R   R  R  t
   DEFAULT_DBt
   startswithR&  R   R;  (   RJ   t   vhost(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _prepare_virtual_host  s    	c         K@  s   | S(   N(    (   RJ   R   R   t   params(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _filter_tcp_connparams+  s    c         @  s  |  j  j } i	 | j p d d 6| j p+ t d 6| j d 6| j d 6|  j d 6|  j d 6|  j	 d 6|  j
 d	 6|  j d
 6} t j d k  r xG | D]< } | j | d   } | d  k	 r t d j |    q q Wn  | d } d | k rt |  \ } }	 }	 }	 }
 } } | d k r|  j |   } | j i t j d 6d | d 6|
 d 6|  | j d d   | j d	 d   | j d
 d   n  | j d d   | j d d   n  |  j | j d d    | d <|   | j d  pt j } | rd | f    f d     Y    | d <n  | S(   Ns	   127.0.0.1t   hostt   portt   virtual_hostt   passwordR   R   R   R   R   i   i
   s,   redis: {0!r} requires redis 2.10.0 or highers   ://R&   t   connection_classR   t   patht   dbt
   Connectionc           @  s   e  Z    f d    Z RS(   c         @  s$   t    |   j    j |   d  S(   N(   RG   R   R   (   RJ   (   RS  RZ   (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR   `  s    (   R2   R3   R   (    (   RS  RZ   (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRS  _  s   (   i   i
   (   R   R@   t   hostnameRM  t   DEFAULT_PORTRN  RO  R   R   R   R   R   R   t   VERSIONR   R%   R	   R;  R   RK  t   updatet   UnixDomainSocketConnectionRI  R:   RS  (   RJ   t   asynct   _r210_optionst   conninfot
   connparamst   paramR=  RL  t   schemeRw   RO  RQ  t   queryt   connection_cls(    (   RS  RZ   s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _connparams/  sR    






!	
	c         C@  s,   | r |  j  d |  j  S|  j d |  j  S(   Nt   connection_pool(   R   t
   async_poolR   t   pool(   RJ   RY  (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _create_clientg  s    c         C@  s;   |  j  d |  } |  j j d | d  |  _ t j |   S(   NRY  RR  (   Ra  R   R;  R   t   ConnectionPool(   RJ   RY  RJ  (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt	   _get_pooll  s    c         @  sJ   t  j d k  r' t d j t     n  d t  j f   f d     Y    S(   Ni   i   sS   Redis transport requires redis-py versions 2.4.4 or later. You have {0.__version__}t
   AsyncRedisc           @  s   e  Z   f d    Z RS(   c         @  s2   t    |   j | |   |  j j d  |  _ d  S(   NRw   (   RG   RH   Rb  t   get_connectionR   (   RJ   R   R   (   Rh  (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRH   |  s    (   R2   R3   RH   (    (   Rh  (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRh  z  s   (   i   i   i   (   R   RV  R	   R;  R   (   RJ   (    (   Rh  s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR   q  s    c         c@  s   | r | Vn |  j    Vd  S(   N(   Re  (   RJ   R@   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR[     s    c         C@  s(   |  j  d  k r! |  j   |  _  n  |  j  S(   N(   R   R%   Rg  (   RJ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRd    s    c         C@  s.   |  j  d  k r' |  j d t  |  _  n  |  j  S(   NRY  (   R   R%   Rg  R8   (   RJ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRc    s    c         C@  s   |  j  d t  S(   s+   Client used to publish messages, BRPOP etc.RY  (   Re  R8   (   RJ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR@     s    c         C@  sC   |  j  d t  } | j   } | j } | j d | j  | _ | S(   s1   Pub/Sub connection used to consume fanout queues.RY  t   pubsub(   Re  R8   Rj  Rb  Ri  t
   shard_hintR   (   RJ   R@   Rj  Rd  (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s
    	c         C@  s   t  |  j  |  _ d S(   s  Update fair cycle between queues.

        We cycle between queues fairly to make sure that
        each queue is equally likely to be consumed from,
        so that a very busy queue will not block others.

        This works by using Redis's `BRPOP` command and
        by rotating the most recently used queue to the
        and of the list.  See Kombu github issue #166 for
        more discussion of this method.

        N(   t   listR   R   (   RJ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    c         C@  s   t  |  j  } |  j d | !S(   s0   Get a fresh list of queues from the queue cycle.i    (   t   lenR   R   (   RJ   t   active(    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR	    s    c         C@  sD   |  j  } y# | j | j | j |    Wn t k
 r? n Xd S(   s-   Move most recently used queue to end of list.N(   R   RT   R   t   indexR   (   RJ   t   usedR   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR    s
    	#c         C@  s   d d l  m } | j S(   Ni    (   R   (   R   R   R.   (   RJ   R   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    c         @  s   t    f d     j D  S(   s<   Set of queues being consumed from (excluding fanout queues).c         3@  s$   |  ] } |   j  k r | Vq d  S(   N(   R   (   R  R   (   RJ   (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pys	   <genexpr>  s    (   R|   t   _active_queues(   RJ   (    (   RJ   s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    N(   R   RR   RP   Rl   Rm   Rk   R   R   R   R   R   R   R   R   R   R   (   R   R   R   (Z   R2   R3   RF   R%   t   _clientt
   _subclientRz   R   R8   t   supports_fanoutR2  R   R  R   R   R   R   RR   RP   Rl   Rm   R   Rk   R
  R   R   R   R   R   R   R   R   R   R   R   R   R   t   from_transport_optionsRH   R   R   R   Ru   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R  R  R  R   R'  R)  R+  R3  R5  R8  R>  R@  R   RC  RI  RK  Ra  Re  Rg  R   R   R[   R   Rd  Rc  R   R@   R   R   R	  R  R   R   (    (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR   x  s   	               	&			
										
										
										 6						R"   c           B@  sY   e  Z e Z d Z e Z e Z d  Z	 d  Z
 d   Z d   Z d   Z d   Z d   Z RS(   R   c         O@  s\   t  d  k r t d   n  t t |   j | |   |  j   \ |  _ |  _ t	   |  _
 d  S(   Ns)   Missing redis library (pip install redis)(   R   R%   t   ImportErrorRG   R"   RH   t   _get_errorsR   R   R{   R   (   RJ   R   R   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRH     s
    c         C@  s   t  j S(   N(   R   t   __version__(   RJ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   driver_version  s    c         @  s   |  j    j  j   j   j   |  j   f d   } |  _      f d   }  j j |   j	 d  j
  d  S(   Nc         @  s    |  j  r   j |  j   n  d  S(   N(   R   R   (   R   (   t   loop(    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   _on_disconnect  s    	c          @  s1      g   j  D] }    |   |   ^ q d  S(   N(   R   (   R   (   t
   add_readerR   t   cycle_poll_startR   (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    i
   (   R   R   R   R   R|  R   R   t   on_tickR   t   call_repeatedlyR   (   RJ   R   Rz  R{  R   (    (   R|  R   R}  Rz  R   s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   register_with_event_loop  s    					c         C@  sm   |  j  j |  } | ri | \ } } | s: | |  j k rU t d j | |    n  |  j | |  n  d S(   s1   Handle AIO event for one of our file descriptors.s.   Message for queue {0!r} without consumers: {1}N(   R   R   t
   _callbacksR   R;  (   RJ   R   R  RU   R   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR     s    c         C@  s   t    S(   s3   Utility to import redis-py's exceptions at runtime.(   R/   (   RJ   (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyRw    s    N(   R2   R3   R   R%   t   polling_intervalRU  t   default_portR8   t   supports_evt   driver_typet   driver_nameRH   Ry  R  R   Rw  (    (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyR"     s   	
			(?   t   __doc__t
   __future__R    R  R&   R   t   collectionsR   t
   contextlibR   R   t   amqpR   t   anyjsonR   R   t   kombu.exceptionsR   R	   t
   kombu.fiveR
   R   R   t	   kombu.logR   t   kombu.utilsR   R   t   kombu.utils.eventioR   R   R   t   kombu.utils.encodingR   t   kombu.utils.urlR   R   R   t   billiard.utilR   Rv  t   multiprocessing.utilR   R%   t   loggert   criticalR  R   RU  RF  R
  R   R:  R/   R0   R   R1   RE   RF   t   objectR{   R   R"   (    (    (    s7   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/redis.pyt   <module>   s\   
		\  T