ó
O'^c           @@  sİ   d  Z  d d l m Z d d l m Z d d l Z d e f d     YZ d e f d     YZ d	 e f d
     YZ	 d e f d     YZ
 i e d 6e	 d 6e
 d 6Z d S(   s°   
kombu.transport.virtual.exchange
================================

Implementations of the standard exchanges defined
by the AMQ protocol  (excluding the `headers` exchange).

i    (   t   absolute_import(   t   escape_regexNt   ExchangeTypec           B@  s8   e  Z d  Z d Z d   Z d   Z d   Z d   Z RS(   sU   Implements the specifics for an exchange type.

    :param channel: AMQ Channel

    c         C@  s   | |  _  d  S(   N(   t   channel(   t   selfR   (    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyt   __init__   s    c         C@  s   t  d   d S(   st   Lookup all queues matching `routing_key` in `exchange`.

        :returns: `default` if no queues matched.

        s   subclass responsibilityN(   t   NotImplementedError(   R   t   tablet   exchanget   routing_keyt   default(    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyt   lookup   s    c         C@  s   | d | f S(   sa   Return tuple of `(routing_key, regex, queue)` to be stored
        for bindings to this exchange.N(   t   None(   R   t   queueR   R	   t	   arguments(    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyt   prepare_bind#   s    c         C@  sJ   | | d k oI | | d k oI | | d k oI | p9 i  | d pF i  k S(   s3   Return true if `prev` and `exchange` is equivalent.t   typet   durablet   auto_deleteR   (    (   R   t   prevR   R   R   R   R   (    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyt
   equivalent(   s    N(	   t   __name__t
   __module__t   __doc__R   R   R   R   R   R   (    (    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyR      s   			t   DirectExchangec           B@  s&   e  Z d  Z d Z d   Z d   Z RS(   s9   The `direct` exchange routes based on exact routing keys.t   directc         C@  s,   g  | D]! \ } } } | | k r | ^ q S(   N(    (   R   R   R   R	   R
   t   rkeyt   _R   (    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyR   5   s    c         K@  sF   |  j  j } |  j  j } x' | | |  D] } | | | |  q( Wd  S(   N(   R   t   _lookupt   _put(   R   t   messageR   R	   t   kwargsR   R   R   (    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyt   deliver9   s    (   R   R   R   R   R   R    (    (    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyR   1   s   	t   TopicExchangec           B@  s[   e  Z d  Z d Z i d d 6d d 6Z i  Z d   Z d   Z d   Z d	   Z	 d
   Z
 RS(   s    The `topic` exchange routes messages based on words separated by
    dots, using wildcard characters ``*`` (any single word), and ``#``
    (one or more words).t   topics   .*?[^\.]t   *s   .*?t   #c         C@  s2   g  | D]' \ } } } |  j  | |  r | ^ q S(   N(   t   _match(   R   R   R   R	   R
   R   t   patternR   (    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyR   M   s    c   
      K@  sw   |  j  j } |  j  j } |  j  j } xL g  | | |  D] } | r7 | | k r7 | ^ q7 D] }	 | |	 | |  qY Wd  S(   N(   R   R   R   t   deadletter_queue(
   R   R   R   R	   R   R   R   t
   deadlettert   qR   (    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyR    Q   s    "c         C@  s   | |  j  |  | f S(   N(   t   key_to_pattern(   R   R   R   R	   R   (    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyR   Y   s    c         @  s3   d d j    f d   t | d  j d  D  S(   s0   Get the corresponding regex for any routing key.s   ^%s$s   \.c         3@  s$   |  ] }   j  j | |  Vq d  S(   N(   t	   wildcardst   get(   t   .0t   word(   R   (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pys	   <genexpr>_   s   s   .#*t   .(   t   joinR   t   split(   R   R   (    (   R   sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyR*   \   s    	c         C@  sR   y |  j  | } Wn1 t k
 rD t j | t j  } |  j  | <n X| j |  S(   s   Same as :func:`re.match`, except the regex is compiled and cached,
        then reused on subsequent matches with the same pattern.(   t	   _compiledt   KeyErrort   ret   compilet   Ut   match(   R   R&   t   stringt   compiled(    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyR%   c   s
    $(   R   R   R   R   R+   R2   R   R    R   R*   R%   (    (    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyR!   @   s   

				t   FanoutExchangec           B@  s&   e  Z d  Z d Z d   Z d   Z RS(   sÏ  The `fanout` exchange implements broadcast messaging by delivering
    copies of all messages to all queues bound to the exchange.

    To support fanout the virtual channel needs to store the table
    as shared state.  This requires that the `Channel.supports_fanout`
    attribute is set to true, and the `Channel._queue_bind` and
    `Channel.get_table` methods are implemented.  See the redis backend
    for an example implementation of these methods.

    t   fanoutc         C@  s    g  | D] \ } } } | ^ q S(   N(    (   R   R   R   R	   R
   R   R   (    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyR   z   s    c         K@  s,   |  j  j r( |  j  j | | | |  n  d  S(   N(   R   t   supports_fanoutt   _put_fanout(   R   R   R   R	   R   (    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyR    }   s    	(   R   R   R   R   R   R    (    (    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyR:   m   s   
	R   R"   R;   (   R   t
   __future__R    t   kombu.utilsR   R4   t   objectR   R   R!   R:   t   STANDARD_EXCHANGE_TYPES(    (    (    sB   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/virtual/exchange.pyt   <module>   s   !-
