
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 m	 Z	 d d l
 m Z d d l m Z d d	 l m Z m Z 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 m Z d d l m  Z  d d l! m" Z" d d l# m$ Z$ m% Z% m& Z& m' Z' d d d g Z( i d d 6d d 6Z) e j* j+ d e,  Z- e j* j+ d e,  Z. e e/  Z0 e	 Z1 i e1 d 6e d 6Z2 d e3 f d     YZ4 e4 Z5 d e3 f d     YZ6 d e6 f d     YZ7 d e6 f d     YZ8 d   Z9 d    Z: d S(!   sB   
kombu.connection
================

Broker connection and pools.

i    (   t   absolute_importN(   t   contextmanager(   t   countt   cycle(   t
   itemgetter(   t
   exceptionsi   (   t   Emptyt   ranget   string_tt   text_tt	   LifoQueue(   t
   get_logger(   t   get_transport_clst   supports_librabbitmq(   t   cached_propertyt   retry_over_timet   shufflecyclet	   HashedSeq(   t   OrderedDict(   t   lazy(   t   as_urlt	   parse_urlt   quotet   urlparset
   Connectiont   ConnectionPoolt   ChannelPoolt   amqpt   pyamqpt   librabbitmqt   KOMBU_LOG_CONNECTIONt   KOMBU_LOG_CHANNELs   round-robint   shufflec           B@  sf  e  Z d  Z dF Z d Z d Z dF Z dF Z dF Z	 dF Z
 e Z dF Z dF Z dF Z dF Z d Z e Z dF Z dF Z Z Z Z Z d dF dF dF dF e e dF d dF dF dF d d dF d  Z d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z  d d  Z! d   Z" d   Z# d   Z$ d   Z% dF d  Z& d   Z' e' Z( dF dF d d d dF d  Z) d   Z* d   Z+ d   Z, dF dF d d d dF d  Z- dF d  Z. d   Z/ d   Z0 d    Z1 d!   Z2 e3 d"  Z4 d#   Z5 d$   Z6 e d% e7 d& d' d( d) d*  d+  Z8 dF dF d,  Z9 dF dF d-  Z: dF d.  Z; dF dF d/  Z< dF dF dF dF d0  Z= dF dF dF dF d1  Z> d2   Z? d3   Z@ d4   ZA d5   ZB d6   ZC d7   ZD eE d8    ZF eE d9    ZG eE d:    ZH eE d;    ZI eE d<    ZJ eE d=    ZK eL d>    ZM d?   ZN eL d@    ZO eL dA    ZP eL dB    ZQ eL dC    ZR eE dD    ZS eE dE    ZT RS(G   s	  A connection to the broker.

    :param URL:  Broker URL, or a list of URLs, e.g.

    .. code-block:: python

        Connection('amqp://guest:guest@localhost:5672//')
        Connection('amqp://foo;amqp://bar', failover_strategy='round-robin')
        Connection('redis://', transport_options={
            'visibility_timeout': 3000,
        })

        import ssl
        Connection('amqp://', login_method='EXTERNAL', ssl={
            'ca_certs': '/etc/pki/tls/certs/something.crt',
            'keyfile': '/etc/something/system.key',
            'certfile': '/etc/something/system.cert',
            'cert_reqs': ssl.CERT_REQUIRED,
        })

    .. admonition:: SSL compatibility

        SSL currently only works with the py-amqp, amqplib, and qpid
        transports.  For other transports you can use stunnel.

    :keyword ssl: Use SSL to connect to the server. Default is ``False``.
      May not be supported by the specified transport.
    :keyword transport: Default transport if not specified in the URL.
    :keyword connect_timeout: Timeout in seconds for connecting to the
      server. May not be supported by the specified transport.
    :keyword transport_options: A dict of additional connection arguments to
      pass to alternate kombu channel implementations.  Consult the transport
      documentation for available options.
    :keyword heartbeat: Heartbeat interval in int/float seconds.
        Note that if heartbeats are enabled then the :meth:`heartbeat_check`
        method must be called regularly, around once per second.

    .. note::

        The connection is established lazily when needed. If you need the
        connection to be established, then force it by calling
        :meth:`connect`::

            >>> conn = Connection('amqp://')
            >>> conn.connect()

        and always remember to close the connection::

            >>> conn.release()

    *Legacy options*

    These options have been replaced by the URL argument, but are still
    supported for backwards compatibility:

    :keyword hostname: Host name/address.
        NOTE: You cannot specify both the URL argument and use the hostname
        keyword argument at the same time.
    :keyword userid: Default user name if not provided in the URL.
    :keyword password: Default password if not provided in the URL.
    :keyword virtual_host: Default virtual host if not provided in the URL.
    :keyword port: Default port if not provided in the URL.

    t   /i   s   round-robint	   localhosti    c         K@  s:  | d  k r g  n | } i | d 6| d 6| d 6| d 6| d 6| d 6| d 6| d 6|	 d	 6| d
 6| d 6} |  _ | r t | t  r | j |  | d } n  | rwd | k rwd | k r | j | j d   | d } n  d | | j d   k r0| j d d  \ | d <| d <| d } |  _ qw| pBt |  j	 } t
 |  j sj| j t |   n  | | d <n  |  j |   | |  _ | pd |  _ |  j j |  j  p| |  _ |  j r|  j |  j  |  _ t |  j  n  |
 d  k ri  }
 n  |
 |  _ t rt |  _ n  | r*| |  _ n  t   |  _ d  S(   Nt   hostnamet   useridt   passwordt   virtual_hostt   portt   insistt   sslt	   transportt   connect_timeoutt   login_methodt	   heartbeati    s   ://t   ;t   +i   s   round-robin(   t   Nonet   _initial_paramst
   isinstanceR   t   extendt   splitt   indext
   uri_prefixR   t   schemeR   t   can_parse_urlt   updateR   t   _init_paramst   altt   _failover_strategy_argt   failover_strategiest   gett   failover_strategyR   t   nextt   transport_optionst   _LOG_CONNECTIONt   Truet   _loggert   sett   declared_entities(   t   selfR#   R$   R%   R&   R'   R(   R)   R*   R+   RA   R,   R6   R-   R?   t
   alternatest   kwargsR;   t   params(    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   __init__   sJ     					c         C@  sC   |  j    |  j j   t |  _ |  j t |  j t |     d S(   sJ   Switch connection parameters to use a new URL (does not
        reconnect)N(	   t   closeRF   t   cleart   Falset   _closedR:   t   dictR1   R   (   RG   t   url(    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   switch   s    
	c         C@  s&   |  j  r" |  j t |  j    n  d S(   sK   Switch to next URL given by the current failover strategy (if
        any).N(   R   RR   R@   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   maybe_switch_next   s    	c         C@  s   | p	 d } | d k r* t    r* d } n  | |  _ | |  _ | |  _ |
 |  _ | pZ |  j |  _ | pl |  j |  _ | |  _ |	 |  _ | |  _	 | |  _
 | o t |  |  _ d  S(   NR   R   (   R   R#   R$   R%   R,   R&   R'   R(   R+   R)   t   transport_clst   floatR-   (   RG   R#   R$   R%   R&   R'   R(   R)   R*   R+   R,   R-   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR:      s    									c         C@  s   |  j  j |  j |  d  S(   N(   R*   t   register_with_event_loopt
   connection(   RG   t   loop(    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyRV      s    c         O@  sG   |  j  rC d } t j | j d t |   d t |   | |  n  d  S(   Ns!   [Kombu connection:0x{id:x}] {msg}t   idt   msg(   RD   t   loggert   debugt   formatRY   R	   (   RG   RZ   t   argsRI   t   fmt(    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   _debug   s    	'c         C@  s   t  |  _ |  j S(   s+   Establish connection to server immediately.(   RN   RO   RW   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   connect   s    	c         C@  sL   |  j  d  |  j j |  j  } t rH d d l m } | | d d  S| S(   s    Create and return a new channel.s   create channeli   (   t
   Logwrappeds   kombu.channels   [Kombu channel:{0.channel_id}] (   R`   R*   t   create_channelRW   t   _LOG_CHANNELt   utils.debugRb   (   RG   t   chanRb   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   channel   s    	i   c         C@  s   |  j  j |  j d | S(   s8  Allow the transport to perform any periodic tasks
        required to make heartbeats work.  This should be called
        approximately every second.

        If the current transport does not support heartbeats then
        this is a noop operation.

        :keyword rate: Rate is how often the tick is called
            compared to the actual heartbeat value.  E.g. if
            the heartbeat is set to 3 seconds, and the tick
            is called every 3 / 2 seconds, then the rate is 2.
            This value is currently unused by any transports.

        t   rate(   R*   t   heartbeat_checkRW   (   RG   Rh   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyRi     s    c         K@  s   |  j  j |  j |  S(   s   Wait for a single event from the server.

        :keyword timeout: Timeout in seconds before we give up.


        :raises :exc:`socket.timeout`: if the timeout is exceeded.

        (   R*   t   drain_eventsRW   (   RG   RI   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyRj     s    	c         C@  s0   y | j    Wn |  j |  j k
 r+ n Xd S(   s>   Close given channel, but ignore connection and channel errors.N(   RL   t   connection_errorst   channel_errors(   RG   Rg   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   maybe_close_channel"  s    c         C@  s}   |  j  j   |  j r) |  j |  j  n  |  j ry y |  j j |  j  Wn! |  j t t	 j
 f k
 rl n Xd  |  _ n  d  S(   N(   RF   RM   t   _default_channelRm   t   _connectionR*   t   close_connectionRk   t   AttributeErrort   sockett   errorR0   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   _do_close_self)  s    		c         C@  sE   |  j    |  j r+ d |  j _ d |  _ n  |  j d  t |  _ d S(   s;   Really close connection, even if part of a connection pool.t   closedN(   Rt   t
   _transportR0   t   clientR`   RC   RO   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   _close5  s    
	c         C@  s   y |  j  j } Wnd t k
 rv t j   } t j |  z) y |  j   Wn t j k
 r` n XWd  t j |  XnE X| |  j  |  j  r d  |  j  _
 d  |  _  n  |  j j   d  |  _ d  S(   N(   Rv   t   _collectRq   Rr   t   getdefaulttimeoutt   setdefaulttimeoutRx   t   timeoutRo   R0   Rw   RF   RM   (   RG   t   socket_timeoutt   gc_transportt   _timeo(    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   collect>  s"     	c         C@  s   |  j    d S(   s   Close the connection (if open).N(   Rx   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   releaseU  s    i   c         @  sD   d    f d  } t   j  j d i  | | | | | | 
  S(   sn  Ensure we have a connection to the server.

        If not retry establishing the connection with the settings
        specified.

        :keyword errback: Optional callback called each time the connection
          can't be established. Arguments provided are the exception
          raised and the interval that will be slept ``(exc, interval)``.

        :keyword max_retries: Maximum number of times to retry.
          If this limit is exceeded the connection error will be re-raised.

        :keyword interval_start: The number of seconds we start sleeping for.
        :keyword interval_step: How many seconds added to the interval
          for each retry.
        :keyword interval_max: Maximum number of seconds to sleep between
          each retry.
        :keyword callback: Optional callback that is called for every
           internal iteration (1 s)

        i    c         @  sR    j  |  } | r$ t |  } n    r:   |  |  n   j   | rN | Sd S(   Ni    (   t   completes_cycleR@   RS   (   t   exct	   intervalst   retriest   intervalt   round(   t   errbackRG   (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   on_errorr  s    
(    (   R   Ra   t   recoverable_connection_errors(   RG   R   t   max_retriest   interval_startt   interval_stept   interval_maxt   callbackR   (    (   R   RG   s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   ensure_connectionZ  s
    
c         C@  s#   |  j  r | d t |  j   St S(   s?   Return true if the cycle is complete after number of `retries`.i   (   R;   t   lenRC   (   RG   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         C@  s)   |  j  r% |  j |  j   d |  _  n  d S(   s2   Revive connection after connection re-established.N(   Rn   Rm   R0   (   RG   t   new_channel(    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   revive  s    	c         C@  s   t  j d | | d t d  S(   Ns)   Ensure: Operation error: %r. Retry in %sst   exc_info(   R[   Rs   RC   (   RG   R   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   _default_ensure_callback  s    	i   c	   
   	   @  sS             f	 d   }	 d  j  |	 _   j |	 _  j |	 _ |	 S(   s  Ensure operation completes, regardless of any channel/connection
        errors occurring.

        Will retry by establishing the connection, and reapplying
        the function.

        :param fun: Method to apply.

        :keyword errback: Optional callback called each time the connection
          can't be established. Arguments provided are the exception
          raised and the interval that will be slept ``(exc, interval)``.

        :keyword max_retries: Maximum number of times to retry.
          If this limit is exceeded the connection error will be re-raised.

        :keyword interval_start: The number of seconds we start sleeping for.
        :keyword interval_step: How many seconds added to the interval
          for each retry.
        :keyword interval_max: Maximum number of seconds to sleep between
          each retry.

        **Example**

        This is an example ensuring a publish operation::

            >>> from kombu import Connection, Producer
            >>> conn = Connection('amqp://')
            >>> producer = Producer(conn)

            >>> def errback(exc, interval):
            ...     logger.error('Error: %r', exc, exc_info=1)
            ...     logger.info('Retry in %s seconds.', interval)

            >>> publish = conn.ensure(producer, producer.publish,
            ...                       errback=errback, max_retries=3)
            >>> publish({'hello': 'world'}, routing_key='dest')

        c    
      @  s  d }  j  }  j } t  j d  } xt d  D]w} y  |  |   SWq7 | k
 rT} | rs | rs   n   d  k	 r |  k r   n   j d | d d d   _  j     o   | d  d  }  d  k	 r t	  | d  } n   j
   |      j   }	  j |	   j |	   rG |	  n  | d 7} q7 | k
 r}  d  k	 r|  k r  n   j d | d d   o  | d  q7 Xq7 Wd  S(   Ni    R   s   ensure connection error: %rR   i   s   ensure channel error: %r(   R   t   recoverable_channel_errorst   hasattrR*   R   R0   R`   Ro   Rt   t   maxR   Rg   R   (
   R^   RI   t   got_connectiont   conn_errorst   chan_errorst   has_modern_errorsR   R   t   remaining_retriesR   (	   R   t   funR   R   R   R   t   objt	   on_reviveRG   (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   _ensured  sH    			
	s   %s(ensured)(   t   __name__t   __doc__t
   __module__(
   RG   R   R   R   R   R   R   R   R   R   (    (	   R   R   R   R   R   R   R   R   RG   s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   ensure  s
    )'*c         @  sP   | g   |  j   d t f     f d     Y} |   } |  j | | |  S(   s  Decorator for functions supporting a ``channel`` keyword argument.

        The resulting callable will retry calling the function if
        it raises connection or channel related errors.
        The return value will be a tuple of ``(retval, last_created_channel)``.

        If a ``channel`` is not provided, then one will be automatically
        acquired (remember to close it afterwards).

        See :meth:`ensure` for the full list of supported keyword arguments.

        Example usage::

            channel = connection.channel()
            try:
                ret, channel = connection.autoretry(publish_messages, channel)
            finally:
                channel.close()
        t   Revivalc           @  sb   e  Z e  d  d  Z  e  d d  Z e  d d  Z   f d   Z     f d   Z RS(   R   R   R   c         @  s   |   d <d  S(   Ni    (    (   RG   Rg   (   t   channels(    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         @  sD     d d  k r# |  j     n   d   d | |    d f S(   Ni    Rg   (   R0   R   (   RG   R^   RI   (   R   Rc   R   (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   __call__  s    N(   R   R   t   getattrR0   R   R   R   (    (   R   Rc   R   (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s
   (   Rg   t   objectR   (   RG   R   Rg   t   ensure_optionsR   R   (    (   R   Rc   R   s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt	   autoretry  s
    		"	c         C@  s   |  j    d |   S(   NRw   (   R   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   create_transport  s    c         C@  s2   |  j  } | s t | t  r. t |  } n  | S(   s'   Get the currently used transport class.(   RT   R2   R   R   (   RG   RT   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    	c         K@  s"   |  j  t |  j d t  |    S(   sJ   Create a copy of the connection with the same connection
        settings.t   resolve(   t	   __class__RP   t   _infoRN   (   RG   RI   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   clone  s    c         C@  s   |  j  j |  j  S(   N(   R*   t   get_heartbeat_intervalRW   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         C@  sj  |  j  } | r$ t j | |  } n  |  j j } |  j pE | j d  } |  j rg d |  j | f } n  d | f d |  j p | j d  f d |  j p | j d  f d |  j	 p | j d  f d |  j
 p | j d  f d |  j f d |  j f d	 | f d
 |  j f d |  j f d |  j p-| j d  f d |  j f d |  j f d |  j f d |  j f f } | S(   NR#   s   %s+%sR$   R%   R&   R'   R(   R)   R*   R+   RA   R,   R6   R-   R?   RH   (   RT   t   RESOLVE_ALIASESR>   R*   t   default_connection_paramsR#   R6   R$   R%   R&   R'   R(   R)   R+   RA   R,   R-   R<   R;   (   RG   R   RT   t   DR#   t   info(    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR      s.    				c         C@  s   t  |  j    S(   s   Get connection info.(   R   R   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR   =  s    c      	   C@  s7   t  |  j |  j |  j |  j |  j |  j t |  j   S(   N(	   R   RT   R#   R$   R%   R&   R'   t   reprRA   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt
   __eqhash__A  s    s   **R'   R$   R%   R&   R*   c         C@  s   |  j  p d } |  j j r< |  j r5 d |  j | f S|  j  S|  j rV d |  j | f S|  j   } | |  \ } } } }	 }
 t |
 | | | | t |	  d | d | S(   s*   Convert connection parameters to URL form.R"   s   %s+%st   sanitizet   mask(   R#   R*   R8   R6   R   R   R   (   RG   t   include_passwordR   t	   getfieldsR#   t   fieldsR'   R$   R%   t   vhostR*   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   as_uriF  s    		c         C@  s   t  |  | |  S(   sJ  Pool of connections.

        See :class:`ConnectionPool`.

        :keyword limit: Maximum number of active connections.
          Default is no limit.
        :keyword preload: Number of connections to preload
          when the pool is created.  Default is 0.

        *Example usage*::

            >>> connection = Connection('amqp://')
            >>> pool = connection.Pool(2)
            >>> c1 = pool.acquire()
            >>> c2 = pool.acquire()
            >>> c3 = pool.acquire()
            Traceback (most recent call last):
              File "<stdin>", line 1, in <module>
              File "kombu/connection.py", line 354, in acquire
              raise ConnectionLimitExceeded(self.limit)
                kombu.exceptions.ConnectionLimitExceeded: 2
            >>> c1.release()
            >>> c3 = pool.acquire()

        (   R   (   RG   t   limitt   preload(    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   PoolY  s    c         C@  s   t  |  | |  S(   s?  Pool of channels.

        See :class:`ChannelPool`.

        :keyword limit: Maximum number of active channels.
          Default is no limit.
        :keyword preload: Number of channels to preload
          when the pool is created.  Default is 0.

        *Example usage*::

            >>> connection = Connection('amqp://')
            >>> pool = connection.ChannelPool(2)
            >>> c1 = pool.acquire()
            >>> c2 = pool.acquire()
            >>> c3 = pool.acquire()
            Traceback (most recent call last):
              File "<stdin>", line 1, in <module>
              File "kombu/connection.py", line 354, in acquire
              raise ChannelLimitExceeded(self.limit)
                kombu.connection.ChannelLimitExceeded: 2
            >>> c1.release()
            >>> c3 = pool.acquire()

        (   R   (   RG   R   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR   u  s    c         O@  s&   d d l  m } | | p |  | |  S(   sJ   Create new :class:`kombu.Producer` instance using this
        connection.i   (   t   Producer(   t	   messagingR   (   RG   Rg   R^   RI   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         O@  s)   d d l  m } | | p |  | | |  S(   sJ   Create new :class:`kombu.Consumer` instance using this
        connection.i   (   t   Consumer(   R   R   (   RG   t   queuesRg   R^   RI   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         K@  s/   d d l  m } | | p |  | | | | |  S(   sp  Create new :class:`~kombu.simple.SimpleQueue`, using a channel
        from this connection.

        If ``name`` is a string, a queue and exchange will be automatically
        created using that name as the name of the queue and exchange,
        also it will be used as the default routing key.

        :param name: Name of the queue/or a :class:`~kombu.Queue`.
        :keyword no_ack: Disable acknowledgements. Default is false.
        :keyword queue_opts: Additional keyword arguments passed to the
          constructor of the automatically created
          :class:`~kombu.Queue`.
        :keyword exchange_opts: Additional keyword arguments passed to the
          constructor of the automatically created
          :class:`~kombu.Exchange`.
        :keyword channel: Custom channel to use. If not specified the
            connection default channel is used.

        i   (   t   SimpleQueue(   t   simpleR   (   RG   t   namet   no_ackt
   queue_optst   exchange_optsRg   RI   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         K@  s/   d d l  m } | | p |  | | | | |  S(   s|  Create new :class:`~kombu.simple.SimpleQueue` using a channel
        from this connection.

        Same as :meth:`SimpleQueue`, but configured with buffering
        semantics. The resulting queue and exchange will not be durable, also
        auto delete is enabled. Messages will be transient (not persistent),
        and acknowledgements are disabled (``no_ack``).

        i   (   t   SimpleBuffer(   R   R   (   RG   R   R   R   R   Rg   RI   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         C@  s0   |  j  d  |  j j   } |  j  d |  | S(   Ns   establishing connection...s   connection established: %r(   R`   R*   t   establish_connection(   RG   t   conn(    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   _establish_connection  s    c         C@  s   d j  |  j   t |    S(   s   ``x.__repr__() <==> repr(x)``s   <Connection: {0} at 0x{1:x}>(   R]   R   RY   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   __repr__  s    c         C@  s
   |  j    S(   s   ``x.__copy__() <==> copy(x)``(   R   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   __copy__  s    c         C@  s"   |  j  t |  j   j    d  f S(   N(   R   t   tupleR   t   valuesR0   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt
   __reduce__  s    c         C@  s   |  S(   N(    (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt	   __enter__  s    c         G@  s   |  j    d  S(   N(   R   (   RG   R^   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   __exit__  s    c         C@  s   |  j  j |  j  S(   N(   R*   t   qos_semantics_matches_specRW   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         C@  s,   |  j  o+ |  j d k	 o+ |  j j |  j  S(   s3   Return true if the connection has been established.N(   RO   Ro   R0   R*   t   verify_connection(   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt	   connected  s    
c         C@  sN   |  j  sJ |  j sC |  j j   d |  _ |  j   |  _ t |  _  n  |  j Sd S(   s   The underlying connection object.

        .. warning::
            This instance is transport specific, so do not
            depend on the interface of this object.

        N(	   RO   R   RF   RM   R0   Rn   R   Ro   RN   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyRW     s    				c         C@  s/   |  j  |  j d k r( |  j   |  _ n  |  j S(   sD  Default channel, created upon access and closed when the connection
        is closed.

        Can be used for automatic channel handling when you only need one
        channel, and also it is the channel implicitly used if a connection
        is passed instead of a channel, to functions that require a channel.

        N(   RW   Rn   R0   Rg   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   default_channel  s    c         C@  s   d j  |  j t |  j  g  S(   s5   The host as a host name/port pair separated by colon.t   :(   t   joinR#   t   strR'   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   host  s    c         C@  s(   |  j  d  k r! |  j   |  _  n  |  j  S(   N(   Rv   R0   R   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR*     s    c         C@  s
   |  j  j S(   sw   Experimental manager that can be used to manage/monitor the broker
        instance.  Not available for all transports.(   R*   t   manager(   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         O@  s   |  j  j | |   S(   N(   R*   t   get_manager(   RG   R^   RI   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         C@  s1   y |  j  j SWn t k
 r, |  j |  j SXd S(   s   List of connection related exceptions that can be recovered from,
        but where the connection must be closed and re-established first.N(   R*   R   Rq   Rk   Rl   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         C@  s'   y |  j  j SWn t k
 r" d SXd S(   s{   List of channel related exceptions that can be automatically
        recovered from without re-establishing the connection.N(    (   R*   R   Rq   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR   )  s    c         C@  s
   |  j  j S(   s8   List of exceptions that may be raised by the connection.(   R*   Rk   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyRk   2  s    c         C@  s
   |  j  j S(   s5   List of exceptions that may be raised by the channel.(   R*   Rl   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyRl   7  s    c         C@  s
   |  j  j S(   N(   R*   t   supports_heartbeats(   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR   <  s    c         C@  s
   |  j  j S(   N(   R*   t   supports_ev(   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt
   is_evented@  s    N(U   R   R   R   R0   R'   R&   R+   RO   Ro   Rn   Rv   RN   RD   R6   RF   R   RA   R?   R=   R-   R#   R$   R%   R)   R,   RK   RR   RS   R:   RV   R`   Ra   Rg   Ri   Rj   Rm   Rt   Rx   R   R   RL   R   R   R   R   R   R   R   R   R   R   RC   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   propertyR   R   RW   R   R   R*   R   R   R   R   R   Rk   Rl   R   R   (    (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR   -   s   @		6							
							%				V'														t   Resourcec           B@  s   e  Z e j Z d d d   Z d   Z d   Z e d d  Z	 d   Z
 d   Z d   Z d   Z d   Z d	   Z d
   Z e j j d  r e	 Z e Z d Z d   Z	 d   Z n  RS(   c         C@  sG   | |  _  | p d |  _ t |  _ t   |  _ t   |  _ |  j   d  S(   Ni    (	   R   R   RN   RO   t
   _LifoQueuet	   _resourceRE   t   _dirtyt   setup(   RG   R   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyRK   I  s    		c         C@  s   t  d   d  S(   Ns   subclass responsibility(   t   NotImplementedError(   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR   R  s    c         C@  sP   |  j  r6 t |  j  |  j  k r6 |  j |  j    n  |  j j |  j    d  S(   N(   R   R   R   t   LimitExceededR   t
   put_nowaitt   new(   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   _add_when_emptyU  s    !c         @  s   j  r t d   n   j r x y  j j d | d |    Wn t k
 r`  j   q$ Xy  j      WnC t k
 r t	   t
  r  j j    n  j      n X j j    Pq$ Wn  j  j         f d   } |   _   S(   sK  Acquire resource.

        :keyword block: If the limit is exceeded,
          block until there is an available item.
        :keyword timeout: Timeout to wait
          if ``block`` is true. Default is :const:`None` (forever).

        :raises LimitExceeded: if block is false
          and the limit has been exceeded.

        s   Acquire on closed poolt   blockR|   c           @  s    j     d S(   s   Release resource so it can be used by another thread.

            The caller is responsible for discarding the object,
            and to never use the resource again.  A new resource must
            be acquired if so needed.

            N(   R   (    (   t   RRG   (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    (   RO   t   RuntimeErrorR   R   R>   R   R   t   preparet   BaseExceptionR2   R   R   R   R   t   addR   (   RG   R   R|   R   (    (   R   RG   s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   acquire]  s*    				c         C@  s   | S(   N(    (   RG   t   resource(    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         C@  s   | j    d  S(   N(   RL   (   RG   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   close_resource  s    c         C@  s   d  S(   N(    (   RG   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   release_resource  s    c         C@  s-   |  j  r |  j j |  n  |  j |  d S(   s_   Replace resource with a new instance.  This can be used in case
        of defective resources.N(   R   R   t   discardR   (   RG   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   replace  s    	c         C@  sJ   |  j  r9 |  j j |  |  j j |  |  j |  n |  j |  d  S(   N(   R   R   R   R   R   R   R   (   RG   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s
    	c         C@  s   d  S(   N(    (   RG   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   collect_resource  s    c         C@  s   t  |  _ |  j } |  j } xN y | j   } Wn t k
 rB Pn Xy |  j |  Wq t k
 rg q Xq WxQ y | j j   } Wn t	 k
 r Pn Xy |  j |  Wqo t k
 r qo Xqo Wd S(   s   Close and remove all resources in the pool (also those in use).

        Can be used to close resources from parent processes
        after fork (e.g. sockets/connections).

        N(
   RC   RO   R   R   t   popt   KeyErrorR   Rq   t   queuet
   IndexError(   RG   t   dirtyR   t   drest   res(    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   force_close_all  s*    			t   KOMBU_DEBUG_POOLi    c         O@  s   d d  l  } |  j d } |  _ d j | |  j j  GH|  j | |   } | | _ d j | |  j j  GHt | d  s g  | _ n  | j j	 | j
    | S(   Ni    i   s   +{0} ACQUIRE {1}s   -{0} ACQUIRE {1}t   acquired_by(   t	   tracebackt   _next_resource_idR]   R   R   t   _orig_acquiret   _resource_idR   R  t   appendt   format_stack(   RG   R^   RI   R  RY   t   r(    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    	c         C@  sY   | j  } d j | |  j j  GH|  j |  } d j | |  j j  GH|  j d 8_ | S(   Ns   +{0} RELEASE {1}s   -{0} RELEASE {1}i   (   R
  R]   R   R   t   _orig_releaseR  (   RG   R   RY   R  (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    	N(   R   R   R   R   R0   RK   R   R   RN   R   R   R   R   R   R   R   R  t   ost   environR>   R	  R  R  (    (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR   F  s$   				1							 	c           B@  sk   e  Z e j Z d	 d	 d   Z d   Z d   Z d   Z	 d d  Z
 e e d   Z d   Z d   Z RS(
   c         C@  s,   | |  _  t t |   j d | d |  d  S(   NR   R   (   RW   t   superR   RK   (   RG   RW   R   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyRK     s    	c         C@  s   |  j  j   S(   N(   RW   R   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         C@  s)   y | j  d  Wn t k
 r$ n Xd  S(   Nt   released(   R`   Rq   (   RG   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         C@  s   | j    d  S(   N(   Rx   (   RG   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    g?c         C@  s   | j  |  S(   N(   R   (   RG   R   R}   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         c@  s-   |  j  d |   } | | j f VWd  QXd  S(   NR   (   R   R   (   RG   R   RW   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   acquire_channel  s    c         C@  sq   |  j  rm xa t |  j   D]M } | |  j k  rG |  j   } | j   n t |  j  } |  j j |  q Wn  d  S(   N(   R   R   R   R   Ra   R   R   R   (   RG   t   iR   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR      s    	c         C@  s)   t  |  r |   } n  | j d  | S(   Nt   acquired(   t   callableR`   (   RG   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR   
  s    N(   R   R   R   t   ConnectionLimitExceededR   R0   RK   R   R   R   R   R   RN   R  R   R   (    (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s   					
c           B@  s;   e  Z e j Z d d d   Z d   Z d   Z d   Z	 RS(   c         C@  s,   | |  _  t t |   j d | d |  d  S(   NR   R   (   RW   R  R   RK   (   RG   RW   R   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyRK     s    	c         C@  s   t  |  j j  S(   N(   R   RW   Rg   (   RG   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s    c         C@  sd   |  j    } |  j r` xH t |  j  D]4 } |  j j | |  j k  rL |   pU t |   q% Wn  d  S(   N(   R   R   R   R   R   R   R   (   RG   Rg   R  (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s
    		c         C@  s   t  |  r |   } n  | S(   N(   R  (   RG   Rg   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR   #  s    N(
   R   R   R   t   ChannelLimitExceededR   R0   RK   R   R   R   (    (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyR     s
   			c         C@  s   t  |  t  r |  j S|  S(   sm   Return the default channel if argument is a connection instance,
    otherwise just return the channel given.(   R2   R   R   (   Rg   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   maybe_channel)  s    c         C@  s   t  |  t  S(   N(   R2   R   (   R   (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   is_connection1  s    (;   R   t
   __future__R    R  Rr   t
   contextlibR   t	   itertoolsR   R   t   operatorR   t   kombuR   t   fiveR   R   R   R	   R
   R   t   logR   R*   R   R   t   utilsR   R   R   R   t   utils.compatR   t   utils.functionalR   t	   utils.urlR   R   R   R   t   __all__R   R  R>   RN   RB   Rd   R   R[   t   roundrobin_failoverR=   R   R   t   BrokerConnectionR   R   R   R  R  (    (    (    s2   /tmp/pip-unpacked-wheel-UAnTfW/kombu/connection.pyt   <module>   sD   (""


   -	