σ
O'^c           @@  sV  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 y d d	 l m Z Wn' e k
 r« d
 e f d     YZ n Xd d l m Z d e f d     YZ yT 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 WnZ e k
 rd e f d     YZ  e Z e e _! e Z Z e  e _" e _# e Z Z n Xd Z$ e% e d  Z& e d  e _' d e j" f d     YZ" e" e _" d e j# f d     YZ# e# e _# d e j! f d     YZ! d e j( f d      YZ( d! e e j) f d"     YZ d# e j* f d$     YZ* d S(%   sF   
kombu.transport.amqplib
=======================

amqplib transport.

i    (   t   absolute_importN(   t   items(   t   str_to_bytes(   t   get_manageri   (   t   base(   t   SSLErrorR   c           B@  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR      s   (   t   unpackt   NAc           B@  s   e  Z RS(    (   R   R   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR	      s   (   t
   client_0_8(   t	   transport(   t   Channel(   t   AMQPConnectionException(   t   AMQPChannelExceptiont   NAxc           B@  s   e  Z RS(    (   R   R   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR   &   s   i(  t   MSG_PEEKs   AMQP t   TCPTransportc           B@  s&   e  Z d    Z e d  Z d   Z RS(   c         C@  su   t  d |  j d t   \ } } } |  j |  } t |  j d   } | d k ra | | | f St d |   d  S(   Ns   >BHIi   i   iΞ   s3   Framing Error, received 0x%02x while expecting 0xce(   R   t   _readt   Truet   ordt	   Exception(   t   selft
   frame_typet   channelt   sizet   payloadt   ch(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyt
   read_frame;   s    $c         C@  sΐ   |  j  } x t |  | k  r€ y  |  j j | t |   } WnA t j k
 r } | r{ | j t j t j f k r{ q n    n X| s t	 d   n  | | 7} q W| |  } | | |  _  | S(   Ns   Socket closed(
   t   _read_buffert   lent   sockt   recvt   sockett   errort   errnot   EAGAINt   EINTRt   IOError(   R   t   nt   initialt   read_buffert   st   exct   result(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR   E   s    	 "
c         C@  s7   z& y |  j    Wn t k
 r$ n XWd  d  |  _ Xd  S(   N(   t   closeR   t   NoneR   (   R   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyt   __del__W   s     (   R   R   R   t   FalseR   R/   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR   9   s   	
t   SSLTransportc           B@  s/   e  Z d    Z d   Z e d  Z d   Z RS(   c         C@  s>   t  | t  r | |  _ n  d  |  _ t j j |  | |  d  S(   N(   t
   isinstancet   dictt   ssloptsR.   t   sslobjR   t   _AbstractTransportt   __init__(   R   t   hostt   connect_timeoutt   ssl(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR7   d   s    	c         C@  su   t  d |  j d t   \ } } } |  j |  } t |  j d   } | d k ra | | | f St d |   d  S(   Ns   >BHIi   i   iΞ   s3   Framing Error, received 0x%02x while expecting 0xce(   R   R   R   R   R   (   R   R   R   R   R   R   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR   k   s    $c         C@  s¦   d } x t  |  | k  r‘ y  |  j j | t  |   } WnA t j k
 r~ } | rx | j t j t j f k rx q	 n    n X| s t d   n  | | 7} q	 W| S(   Nt    s   Socket closed(	   R   R5   t   readR!   R"   R#   R$   R%   R&   (   R   R'   R(   R,   R*   R+   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR   u   s     "c         C@  s7   z& y |  j    Wn t k
 r$ n XWd  d  |  _ Xd  S(   N(   R-   R   R.   R   (   R   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR/      s     (   R   R   R7   R   R0   R   R/   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR1   b   s   		
t
   Connectionc           B@  sY   e  Z e Z d    Z d   Z d   Z d d  Z d d  Z	 d d  Z
 d d  Z RS(   c         O@  s8   y t  t |   j | |   Wn t j k
 r3 n Xd  S(   N(   t   superR=   t	   _do_closeR!   R"   (   R   t   argst   kwargs(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR?      s    c   
      C@  s   | j    } | j   } | j   } | j   } t | | d  } | j d r} x1 | j d D] }	 |	 | | | |  q] Wn |  d  S(   Ni2   i<   t   basic_return(   i2   i<   (   t
   read_shortt   read_shortstrR   t   events(
   R   R   R@   t   msgt
   reply_codet
   reply_textt   exchanget   routing_keyR+   t   callback(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyt   _dispatch_basic_return   s    c         O@  s0   t  t |   j | |   i |  j d 6|  _ d  S(   Ni<   i2   (   i<   i2   (   R>   R=   R7   RL   t   _method_override(   R   R@   RA   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR7   §   s    c   	      C@  sϋ   |  j  } |  j | d d | \ } } } } | | } | r | j r t | d  r y | j j | j  | _ Wq t k
 r q Xn  |  j	 j
 |  p¬ | j j
 | d  } | d k rΞ t d |   n  | d k rη | | |  S| | | |  Sd S(   s   Wait for an event on a channel.t   timeoutt   content_encodings   Unknown AMQP method (%d, %d)N(   t   channelst   _wait_multipleR.   t   auto_decodet   hasattrt   bodyt   decodeRO   R   RM   t   gett   _METHOD_MAP(	   R   RN   t   chanmapt   chanidt
   method_sigR@   t   contentR   t   amqp_method(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyt   drain_events«   s$    	
	c         C@  sα   | d  k r |  j j   S|  j j } | j   } | | k rM | j |  n  zp y |  j j   SWnX t k
 r» } d t |  k r t	 j
    n  d t |  k r΅ t	 j
    n    n XWd  | | k rά | j |  n  Xd  S(   Ns	   timed outs   The operation did not complete(   R.   t   method_readert   read_methodR   R   t
   gettimeoutt
   settimeoutR   t   strR!   RN   (   R   RN   R   t   prevR+   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyt   read_timeoutΖ   s"    c         C@  s9  x t  |  D] \ } } | j } xh | D]` } | d } | d  k s] | | k s] | d k r) | j |  | \ } }	 }
 | | |	 |
 f Sq) Wq W|  j } |  j } x | |  \ } } }	 }
 | | k rΦ | d  k sξ | | k sξ | d k rώ | | |	 |
 f S| | j j | |	 |
 f  | d k r¦ |   q¦ q¦ Wd  S(   Ni    i   i(   (   i   i(   (   i   i(   (   R   t   method_queueR.   t   removeRd   t   waitt   append(   R   RP   t   allowed_methodsRN   t
   channel_idR   Re   t   queued_methodRZ   R@   R[   Rd   Rg   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyRQ   ά   s,    	
		c         C@  s1   y |  j  | SWn t k
 r, t |  |  SXd  S(   N(   RP   t   KeyErrorR   (   R   Rj   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR      s    N(   R   R   R   t	   connectedR?   RL   R7   R.   R]   Rd   RQ   R   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR=      s   			$t   Messagec           B@  s   e  Z d    Z RS(   c         K@  s}   | j  } t t |   j | d | j d | j d | j d  d | j d  d | j d | j  d | j d  pr i  | d  S(	   NRT   t   delivery_tagt   content_typeRO   t   delivery_infot
   propertiest   headerst   application_headers(   Rr   R>   Rn   R7   RT   Ro   RV   Rq   (   R   R   RF   RA   t   props(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR7   	  s    					(   R   R   R7   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyRn     s   R   c           B@  sc   e  Z e Z i e   d  6Z d   Z d d d d d d  Z d   Z d   Z	 d   Z
 d   Z RS(   RB   c         O@  s)   t    |  _ t t |   j | |   d  S(   N(   t   sett   no_ack_consumersR>   R   R7   (   R   R@   RA   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR7     s    c         C@  s(   t  j | d | d | d | d | | S(   s%   Encapsulate data into a AMQP message.t   priorityRp   RO   Rt   (   t   amqpRn   (   R   RT   Rx   Rp   RO   Rs   Rr   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyt   prepare_message  s
    c         C@  s   |  j  |  |  S(   s4   Convert encoded message body back to a Python value.(   Rn   (   R   t   raw_message(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyt   message_to_python(  s    c         C@  s(   z t  t |   j   Wd  d  |  _ Xd  S(   N(   R>   R   R-   R.   t
   connection(   R   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR-   ,  s    c         O@  s<   t  t |   j | |   } | d r8 |  j j |  n  | S(   Nt   no_ack(   R>   R   t   basic_consumeRw   t   add(   R   R@   RA   t   consumer_tag(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR   2  s    
c         K@  s)   |  j  j |  t t |   j | |  S(   N(   Rw   t   discardR>   R   t   basic_cancel(   R   R   RA   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR   8  s    N(   R   R   Rn   Rv   RE   R7   R.   Rz   R|   R-   R   R   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR     s   				t	   Transportc           B@  s»   e  Z e Z e Z e j j e e	 j
 e e e f Z e j j e f Z d  Z d Z e Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d	   Z e d
    Z d   Z RS(   t   amqplibRy   c         K@  sC   | |  _  | j d  p |  j |  _ t t k r? t d   n  d  S(   Nt   default_ports-   Missing amqplib library (pip install amqplib)(   t   clientRV   R   Ry   R	   t   ImportError(   R   R   RA   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR7   O  s    	c         C@  s
   | j    S(   N(   R   (   R   R}   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyt   create_channelV  s    c         K@  s   | j  |   S(   N(   R]   (   R   R}   RA   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR]   Y  s    c         C@  sΝ   |  j  } xB t |  j  D]1 \ } } t | | d  s t | | |  q q W| j d k ri d | _ n  |  j d | j d | j	 d | j
 d | j d | j d | j d	 | j d
 | j  } |  j  | _  | S(   s(   Establish connection to the AMQP broker.t	   localhosts	   127.0.0.1R8   t   useridt   passwordt   login_methodt   virtual_hostt   insistR:   R9   N(   R   R   t   default_connection_paramst   getattrR.   t   setattrt   hostnameR=   R8   R   R   R   R   R   R:   R9   (   R   t   conninfot   namet   default_valuet   conn(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyt   establish_connection\  s     							c         C@  s   d | _ | j   d S(   s!   Close the AMQP broker connection.N(   R.   R   R-   (   R   R}   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyt   close_connectiono  s    	c         C@  s   t  r | j j } | j   } | j d  zF y | j d t j  Wn( t j k
 r[ n t j	 k
 ro t
 SXWd  | j |  Xn  t S(   Ng-Cλβ6?i   (   t   HAS_MSG_PEEKR   R   R`   Ra   R    R!   R   RN   R"   R0   R   (   R   R}   R   Rc   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyt   is_alivet  s     	c         C@  s   | j  d  k	 o |  j |  S(   N(   RP   R.   R   (   R   R}   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyt   verify_connection  s    c         C@  s&   | j  | j j j |  j | |  d  S(   N(   t
   add_readerR^   t   sourceR   t   on_readable(   R   R}   t   loop(    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyt   register_with_event_loop  s    c         C@  s*   i d d 6d d 6|  j  d 6d d 6d d 6S(	   Nt   guestR   R   t   portR   R   t   AMQPLAINR   (   R   (   R   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR     s    
c         O@  s   t  |  j | |  S(   N(   R   R   (   R   R@   RA   (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR     s    (   R   R   R=   t   DEFAULT_PORTR   R   R   t   connection_errorsR   R!   R"   R&   t   OSErrort   AttributeErrort   channel_errorsR   t   driver_namet   driver_typeR   t   supports_evR7   R   R]   R   R   R   R   R‘   t   propertyR   R   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyR   =  s&   									(+   t   __doc__t
   __future__R    R#   R!   t
   kombu.fiveR   t   kombu.utils.encodingR   t   kombu.utils.amq_managerR   R;   R   R:   R   R   R   t   structR   t   objectR	   R   R
   Ry   t   amqplib.client_0_8R   t   amqplib.client_0_8.channelR   t   _Channelt   amqplib.client_0_8.exceptionsR   R   R   R=   R   R1   R₯   RS   R   t   AMQP_PROTOCOL_HEADERRn   t
   StdChannelR   (    (    (    s9   /tmp/pip-unpacked-wheel-UAnTfW/kombu/transport/amqplib.pyt   <module>   sJ   	
&	*	x&