ó
O'—^c           @@  s‰  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z y d  d l m Z Wn! e k
 rw d  d l m Z n Xy d  d l m	 Z	 Wn' e k
 rµ d e
 f d „  ƒ  YZ	 n Xd  d l m Z m Z d	 d
 l m Z d	 d l m Z m Z e j e j e j f Z d Z e ƒ  Z d j d ƒ Z e j d ƒ Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ  d e f d „  ƒ  YZ! e" d „ Z# d S(   i    (   t   absolute_importN(   t   SOL_TCP(   t   IPPROTO_TCP(   t   SSLErrorR   c           B@  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyR       s   (   t   packt   unpacki   (   t   UnexpectedFrame(   t	   get_errnot   set_cloexeci(  s   AMQP 	t   latin_1s   \[([\.0-9a-f:]+)\](?::(\d+))?t   _AbstractTransportc           B@  sk   e  Z d  Z e Z d „  Z d „  Z e d „ Z d „  Z d „  Z	 d „  Z
 d „  Z e d „ Z d	 „  Z RS(
   s,   Common superclass for TCP and SSL transportsc         C@  sH  t  |  _ d  } t } t j | ƒ } | rc | j d ƒ } | j d ƒ r– t | j d ƒ ƒ } q– n3 d | k r– | j d d ƒ \ } } t | ƒ } n  d  |  _	 d  } xÞ t
 j | | d t
 j t ƒ D]¾ } | \ } }	 }
 } } yd t
 j
 | |	 |
 ƒ |  _	 y t |  j	 t  ƒ Wn t k
 r!n X|  j	 j | ƒ |  j	 j | ƒ Wn; t
 j k
 r€} | } |  j	 j ƒ  d  |  _	 | } qÄ n XPqÄ W|  j	 s¡t
 j | ƒ ‚ n  y` |  j	 j d  ƒ |  j	 j t t
 j d ƒ |  j	 j t
 j t
 j d ƒ |  j ƒ  |  j t ƒ Wn@ t t t
 j f k
 rC} t | ƒ t k r=t |  _ n  ‚  n Xd  S(   Ni   i   t   :i    (    t   Truet	   connectedt   Nonet	   AMQP_PORTt   IPV6_LITERALt   matcht   groupt   intt   rsplitt   sockt   sockett   getaddrinfot   SOCK_STREAMR   R
   t   NotImplementedErrort
   settimeoutt   connectt   errort   closet
   setsockoptt   TCP_NODELAYt
   SOL_SOCKETt   SO_KEEPALIVEt   _setup_transportt   _writet   AMQP_PROTOCOL_HEADERt   OSErrort   IOErrorR	   t   _UNAVAILt   False(   t   selft   hostt   connect_timeoutt   msgt   portt   mt   last_errt   rest   aft   socktypet   protot	   canonnamet   sat   exc(    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyt   __init__9   sV    				
c         C@  sI   z8 t  d  k	 r7 y |  j ƒ  Wq7 t  j k
 r3 q7 Xn  Wd  d  |  _ Xd  S(   N(   R   R   R   R   R   (   R+   (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyt   __del__n   s    c         C@  s   t  d ƒ ‚ d S(   s"   Read exactly n bytes from the peers   Must be overriden in subclassN(   R   (   R+   t   nt   initial(    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyt   _readz   s    c         C@  s   d S(   sO   Do any additional initialization of the class (used
        by the subclasses).N(    (   R+   (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyR$   ~   s    c         C@  s   d S(   s8   Do any preliminary work in shutting down the connection.N(    (   R+   (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyt   _shutdown_transportƒ   s    c         C@  s   t  d ƒ ‚ d S(   s&   Completely write a string to the peer.s   Must be overriden in subclassN(   R   (   R+   t   s(    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyR%   ‡   s    c         C@  sR   |  j  d  k	 rE |  j ƒ  |  j  j t j ƒ |  j  j ƒ  d  |  _  n  t |  _ d  S(   N(	   R   R   R>   t   shutdownR   t	   SHUT_RDWRR   R*   R   (   R+   (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyR   ‹   s    
c         C@  s7  |  j  } t } y] | d t ƒ } | | 7} | d | ƒ \ } } } | | ƒ } | | 7} t | d ƒ ƒ }	 Wn– t j k
 r• | |  j |  _ ‚  np t t t j	 f k
 r}
 t
 |
 t ƒ rà d t |
 ƒ k rà t j ƒ  ‚ n  t |
 ƒ t k rþ t |  _ n  ‚  n X|	 d k r| | | f St d j |	 ƒ ƒ ‚ d  S(   Ni   s   >BHIi   s	   timed outiÎ   s'   Received 0x{0:02x} while expecting 0xce(   R=   t   EMPTY_BUFFERR   t   ordR   t   timeoutt   _read_bufferR'   R(   R   t
   isinstanceR   t   strR	   R)   R*   R   R   t   format(   R+   R   t   readt   read_frame_buffert   frame_headert
   frame_typet   channelt   sizet   payloadt   chR8   (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyt
   read_frame–   s,    	

!c         C@  s“   t  | ƒ } y* |  j t d | | | | | d ƒ ƒ WnV t j k
 rO ‚  n@ t t t j f k
 rŽ } t | ƒ t	 k rˆ t
 |  _ n  ‚  n Xd  S(   Ns   >BHI%dsBiÎ   (   t   lenR%   R   R   RD   R'   R(   R   R	   R)   R*   R   (   R+   RL   RM   RO   RN   R8   (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyt   write_frame±   s    	(   R   R   t   __doc__R*   R   R9   R:   R=   R$   R>   R%   R   R   RQ   RS   (    (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyR   5   s   	5					t   SSLTransportc           B@  sS   e  Z d  Z d „  Z d „  Z d „  Z e e j e j	 e j
 f d „ Z d „  Z RS(   s   Transport that works over SSLc         C@  sA   t  | t ƒ r | |  _ n  t |  _ t t |  ƒ j | | ƒ d  S(   N(   RF   t   dictt   ssloptsRB   RE   t   superRU   R9   (   R+   R,   R-   t   ssl(    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyR9   Ã   s    	c         C@  sb   t  |  d ƒ r- t j |  j |  j  |  _ n t j |  j ƒ |  _ |  j j ƒ  |  j j |  _ d S(   s!   Wrap the socket in an SSL object.RW   N(   t   hasattrRY   t   wrap_socketR   RW   t   do_handshakeRI   t   _quick_recv(   R+   (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyR$   É   s
    c         C@  sG   |  j  d k	 rC y |  j  j } Wn t k
 r3 d SX| ƒ  |  _  n  d S(   s9   Unwrap a Python 2.6 SSL socket, so we can call shutdown()N(   R   R   t   unwrapt   AttributeError(   R+   R^   (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyR>   Ò   s    c   	      C@  sÒ   |  j  } |  j } yŽ x‡ t | ƒ | k  rž y | | t | ƒ ƒ } Wn5 t j k
 r{ } | ru | j | k ru q n  ‚  n X| s‘ t d ƒ ‚ n  | | 7} q WWn | |  _ ‚  n X| |  | | } |  _ | S(   Ns   Socket closed(   R]   RE   RR   R   R   t   errnoR(   (	   R+   R;   R<   t   _errnost   recvt   rbufR?   R8   t   result(    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyR=   Û   s$    			c         C@  sl   y |  j  j } Wn t k
 r/ t d ƒ ‚ n9 Xx5 | rg | | ƒ } | sZ t d ƒ ‚ n  | | } q3 Wd S(   s+   Write a string out to the SSL socket fully.s   Socket closedN(   R   t   writeR_   R(   (   R+   R?   Re   R;   (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyR%   õ   s    	(   R   R   RT   R9   R$   R>   R*   R`   t   ENOENTt   EAGAINt   EINTRR=   R%   (    (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyRU   À   s   					t   TCPTransportc           B@  s2   e  Z d  Z d „  Z e e j e j f d „ Z RS(   s.   Transport that deals directly with TCP socket.c         C@  s+   |  j  j |  _ t |  _ |  j  j |  _ d S(   sP   Setup to _write() directly to the socket, and
        do our own buffered reads.N(   R   t   sendallR%   RB   RE   Rb   R]   (   R+   (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyR$     s    	c   	      C@  sÒ   |  j  } |  j } yŽ x‡ t | ƒ | k  rž y | | t | ƒ ƒ } Wn5 t j k
 r{ } | ru | j | k ru q n  ‚  n X| s‘ t d ƒ ‚ n  | | 7} q WWn | |  _ ‚  n X| |  | | } |  _ | S(   s$   Read exactly n bytes from the sockets   Socket closed(   R]   RE   RR   R   R   R`   R(   (	   R+   R;   R<   Ra   Rb   Rc   R?   R8   Rd   (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyR=     s$    			(	   R   R   RT   R$   R*   R`   Rg   Rh   R=   (    (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyRi     s   	c         C@  s'   | r t  |  | | ƒ St |  | ƒ Sd S(   so   Given a few parameters from the Connection constructor,
    select and create a subclass of _AbstractTransport.N(   RU   Ri   (   R,   R-   RY   (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyt   create_transport%  s    ($   t
   __future__R    R`   t   reR   RY   R   t   ImportErrorR   R   t	   Exceptiont   structR   R   t
   exceptionsR   t   utilsR	   R
   Rg   Rh   Rf   R)   R   t   bytesRB   t   encodeR&   t   compileR   t   objectR   RU   Ri   R*   Rk   (    (    (    s0   /tmp/pip-unpacked-wheel-9igm28/amqp/transport.pyt   <module>   s0   	‹D!