l
Ì	g]c               @   sò   d  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 e j	 e
 ƒ Z Gd „  d e j ƒ Z Gd	 „  d
 e ƒ Z Gd „  d e ƒ Z Gd „  d e ƒ Z Gd „  d e ƒ Z Gd „  d e j ƒ Z d „  Z d S(   u<   Frame objects that do the frame demarshaling and marshaling.i    N(   u   amqp_object(   u
   exceptions(   u   spec(   u   bytec             B   s5   |  Ee  Z d  Z d Z d „  Z d „  Z d „  Z d S(   uÝ   Base Frame object mapping. Defines a behavior for all child classes for
    assignment of core attributes and implementation of the a core _marshal
    method which child classes use to create the binary AMQP frame.

    u   Framec             C   s   | |  _  | |  _ d S(   u   Create a new instance of a frame

        :param int frame_type: The frame type
        :param int channel_number: The channel number for the frame

        N(   u
   frame_typeu   channel_number(   u   selfu
   frame_typeu   channel_number(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   __init__   s    	c             C   sB   d j  | ƒ } t j d |  j |  j t | ƒ ƒ | t t j ƒ S(   u]   Create the full AMQP wire protocol frame data representation

        :rtype: bytes

        s    u   >BHI(	   u   joinu   structu   packu
   frame_typeu   channel_numberu   lenu   byteu   specu	   FRAME_END(   u   selfu   piecesu   payload(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   _marshal   s    c             C   s
   t  ‚ d S(   uK   To be ended by child classes

        :raises NotImplementedError

        N(   u   NotImplementedError(   u   self(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   marshal)   s    N(   u   __name__u
   __module__u   __doc__u   NAMEu   __init__u   _marshalu   marshal(   u
   __locals__(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   Frame   s
   
	
	
u   Framec             B   s,   |  Ee  Z d  Z d Z d „  Z d „  Z d S(   u“   Base Method frame object mapping. AMQP method frames are mapped on top
    of this class for creating or accessing their data and attributes.

    u   METHODc             C   s#   t  j |  t j | ƒ | |  _ d S(   u¡   Create a new instance of a frame

        :param int channel_number: The frame type
        :param pika.Spec.Class.Method method: The AMQP Class.Method

        N(   u   Frameu   __init__u   specu   FRAME_METHODu   method(   u   selfu   channel_numberu   method(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   __init__9   s    c             C   s>   |  j  j ƒ  } | j d t j d |  j  j ƒ ƒ |  j | ƒ S(   uP   Return the AMQP binary encoded value of the frame

        :rtype: str

        i    u   >I(   u   methodu   encodeu   insertu   structu   packu   INDEXu   _marshal(   u   selfu   pieces(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   marshalC   s    "N(   u   __name__u
   __module__u   __doc__u   NAMEu   __init__u   marshal(   u
   __locals__(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   Method2   s   
	
u   Methodc             B   s,   |  Ee  Z d  Z d Z d „  Z d „  Z d S(   u–   Header frame object mapping. AMQP content header frames are mapped
    on top of this class for creating or accessing their data and attributes.

    u   Headerc             C   s,   t  j |  t j | ƒ | |  _ | |  _ d S(   u
  Create a new instance of a AMQP ContentHeader object

        :param int channel_number: The channel number for the frame
        :param int body_size: The number of bytes for the body
        :param pika.spec.BasicProperties props: Basic.Properties object

        N(   u   Frameu   __init__u   specu   FRAME_HEADERu	   body_sizeu
   properties(   u   selfu   channel_numberu	   body_sizeu   props(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   __init__U   s    	c             C   sD   |  j  j ƒ  } | j d t j d |  j  j |  j ƒ ƒ |  j | ƒ S(   uP   Return the AMQP binary encoded value of the frame

        :rtype: str

        i    u   >HxxQ(   u
   propertiesu   encodeu   insertu   structu   packu   INDEXu	   body_sizeu   _marshal(   u   selfu   pieces(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   marshala   s    "N(   u   __name__u
   __module__u   __doc__u   NAMEu   __init__u   marshal(   u
   __locals__(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   HeaderN   s   
	u   Headerc             B   s,   |  Ee  Z d  Z d Z d „  Z d „  Z d S(   uŒ   Body frame object mapping class. AMQP content body frames are mapped on
    to this base class for getting/setting of attributes/data.

    u   Bodyc             C   s#   t  j |  t j | ƒ | |  _ d S(   u_   
        Parameters:

        - channel_number: int
        - fragment: unicode or str
        N(   u   Frameu   __init__u   specu
   FRAME_BODYu   fragment(   u   selfu   channel_numberu   fragment(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   __init__t   s    c             C   s   |  j  |  j g ƒ S(   uP   Return the AMQP binary encoded value of the frame

        :rtype: str

        (   u   _marshalu   fragment(   u   self(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   marshal~   s    N(   u   __name__u
   __module__u   __doc__u   NAMEu   __init__u   marshal(   u
   __locals__(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   Bodym   s   
	
u   Bodyc             B   s,   |  Ee  Z d  Z d Z d „  Z d „  Z d S(   u¢   Heartbeat frame object mapping class. AMQP Heartbeat frames are mapped
    on to this class for a common access structure to the attributes/data
    values.

    u	   Heartbeatc             C   s   t  j |  t j d ƒ d S(   u,   Create a new instance of the Heartbeat framei    N(   u   Frameu   __init__u   specu   FRAME_HEARTBEAT(   u   self(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   __init__   s    c             C   s   |  j  t ƒ  ƒ S(   uP   Return the AMQP binary encoded value of the frame

        :rtype: str

        (   u   _marshalu   list(   u   self(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   marshal“   s    N(   u   __name__u
   __module__u   __doc__u   NAMEu   __init__u   marshal(   u
   __locals__(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu	   Heartbeat‡   s   
	u	   Heartbeatc             B   s5   |  Ee  Z d  Z d Z d d d d „ Z d „  Z d S(   uq   AMQP Protocol header frame class which provides a pythonic interface
    for creating AMQP Protocol headers

    u   ProtocolHeaderc             C   sO   d |  _  | p t j d |  _ | p/ t j d |  _ | pE t j d |  _ d S(   uÞ   Construct a Protocol Header frame object for the specified AMQP
        version

        :param int major: Major version number
        :param int minor: Minor version number
        :param int revision: Revision

        i   i    i   Niÿÿÿÿ(   u
   frame_typeu   specu   PROTOCOL_VERSIONu   majoru   minoru   revision(   u   selfu   majoru   minoru   revision(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   __init__£   s    		c             C   s&   d t  j d d |  j |  j |  j ƒ S(   u   Return the full AMQP wire protocol frame data representation of the
        ProtocolHeader frame

        :rtype: str

        s   AMQPu   BBBBi    (   u   structu   packu   majoru   minoru   revision(   u   self(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   marshal±   s    N(   u   __name__u
   __module__u   __doc__u   NAMEu   Noneu   __init__u   marshal(   u
   __locals__(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   ProtocolHeaderœ   s   
u   ProtocolHeaderc             C   sA  yN |  d d … d k rM t  j d |  d ƒ \ } } } d t | | | ƒ f SWn t t  j f k
 ro d SYn Xy) t  j d |  d d … ƒ \ } } } Wn t  j k
 r´ d SYn Xt j | t j	 } | t
 |  ƒ k rß d S|  | d	 | … t t j ƒ k rt j d
 ƒ ‚ n  |  t j | d	 … } | t j k rƒt  j d | ƒ d }	 t j |	 ƒ  }
 |
 j | d ƒ | t | |
 ƒ f S| t j k rìt  j d | ƒ \ } } } t j | ƒ  } | j | d d … ƒ } | t | | | ƒ f S| t j k r| t | | ƒ f S| t j k r*| t ƒ  f St j d | ƒ ‚ d S(   u   Receives raw socket data and attempts to turn it into a frame.
    Returns bytes used to make the frame and the frame

    :param str data_in: The raw data stream
    :rtype: tuple(bytes consumed, frame)
    :raises: pika.exceptions.InvalidFrameError

    i    i   s   AMQPu   BBBi   i   u   >BHLi   i   u   Invalid FRAME_END markeru   >Iu   >HHQi   Nu   Unknown frame type: %i(   i    N(   i    N(   i    N(   u   structu   unpack_fromu   ProtocolHeaderu
   IndexErroru   erroru   Noneu   unpacku   specu   FRAME_HEADER_SIZEu   FRAME_END_SIZEu   lenu   byteu	   FRAME_ENDu
   exceptionsu   InvalidFrameErroru   FRAME_METHODu   methodsu   decodeu   Methodu   FRAME_HEADERu   propsu   Headeru
   FRAME_BODYu   Bodyu   FRAME_HEARTBEATu	   Heartbeat(   u   data_inu   majoru   minoru   revisionu
   frame_typeu   channel_numberu
   frame_sizeu	   frame_endu
   frame_datau	   method_idu   methodu   class_idu   weightu	   body_sizeu
   propertiesu   out(    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   decode_frame¼   s@    
	#	#(   u   __doc__u   loggingu   structu   pikau   amqp_objectu
   exceptionsu   specu   pika.compatu   byteu	   getLoggeru   __name__u   LOGGERu
   AMQPObjectu   Frameu   Methodu   Headeru   Bodyu	   Heartbeatu   ProtocolHeaderu   decode_frame(    (    (    u/   /srv/kernel/kteam-tools/dashboard/pika/frame.pyu   <module>   s   % 