
    f@                        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 G d dej                        Z G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d dej                        Zd Zy)z<Frame objects that do the frame demarshaling and marshaling.    N)amqp_object)
exceptions)spec)bytec                   &    e Zd ZdZd Zd Zd Zd Zy)FramezBase 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.

    c                      || _         || _        y)zCreate a new instance of a frame

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

        N)
frame_typechannel_number)selfr
   r   s      E/var/www/cs2snipe.com/venv/lib/python3.12/site-packages/pika/frame.py__init__zFrame.__init__   s     %,    c                     dj                  |      }t        j                  d| j                  | j                  t        |            |z   t        t        j                        z   S )z]Create the full AMQP wire protocol frame data representation

        :rtype: bytes

        r   z>BHI)	joinstructpackr
   r   lenr   r   	FRAME_END)r   piecespayloads      r   _marshalzFrame._marshal   sU     ((6"{{64??D4G4Gw<)+2359$..5IJ 	Jr   c                     t         )zKTo be ended by child classes

        :raises NotImplementedError

        )NotImplementedErrorr   s    r   marshalzFrame.marshal)   s
     "!r   N)__name__
__module____qualname____doc__NAMEr   r   r    r   r   r   r      s    
 D-J"r   r   c                        e Zd ZdZdZd Zd Zy)MethodzBase Method frame object mapping. AMQP method frames are mapped on top
    of this class for creating or accessing their data and attributes.

    METHODc                 \    t         j                  | t        j                  |       || _        y)zCreate a new instance of a frame

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

        N)r   r   r   FRAME_METHODmethod)r   r   r(   s      r   r   zMethod.__init__9   s!     	tT..?r   c                     | j                   j                         }|j                  dt        j                  d| j                   j
                               | j                  |      S )PReturn the AMQP binary encoded value of the frame

        :rtype: str

        r   >I)r(   encodeinsertr   r   INDEXr   r   r   s     r   r   zMethod.marshalC   sH     ##%aT4;;+<+<=>}}V$$r   Nr   r   r   r    r!   r   r   r"   r   r   r$   r$   2   s     D%r   r$   c                        e Zd ZdZd Zd Zd Zy)HeaderzHeader frame object mapping. AMQP content header frames are mapped
    on top of this class for creating or accessing their data and attributes.

    c                 j    t         j                  | t        j                  |       || _        || _        y)a
  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)r   r   r   FRAME_HEADER	body_size
properties)r   r   r5   propss       r   r   zHeader.__init__U   s(     	tT..?"r   c                     | j                   j                         }|j                  dt        j                  d| j                   j
                  | j                               | j                  |      S )r*   r   z>HxxQ)r6   r,   r-   r   r   r.   r5   r   r/   s     r   r   zHeader.marshala   sR     '')v{{7DOO$9$94>>J	L}}V$$r   Nr0   r"   r   r   r2   r2   N   s     D
 	%r   r2   c                        e Zd ZdZd Zd Zd Zy)BodyzBody frame object mapping class. AMQP content body frames are mapped on
    to this base class for getting/setting of attributes/data.

    c                 \    t         j                  | t        j                  |       || _        y)z_
        Parameters:

        - channel_number: int
        - fragment: unicode or str
        N)r   r   r   
FRAME_BODYfragment)r   r   r=   s      r   r   zBody.__init__t   s     	tT__n= r   c                 :    | j                  | j                  g      S r*   )r   r=   r   s    r   r   zBody.marshal~   s     }}dmm_--r   Nr0   r"   r   r   r:   r:   m   s     D!.r   r:   c                        e Zd ZdZd Zd Zd Zy)	HeartbeatzHeartbeat frame object mapping class. AMQP Heartbeat frames are mapped
    on to this class for a common access structure to the attributes/data
    values.

    c                 N    t         j                  | t        j                  d       y)z,Create a new instance of the Heartbeat framer   N)r   r   r   FRAME_HEARTBEATr   s    r   r   zHeartbeat.__init__   s    tT1115r   c                 4    | j                  t                     S r?   )r   listr   s    r   r   zHeartbeat.marshal   s     }}TV$$r   Nr0   r"   r   r   rA   rA      s    
 D6%r   rA   c                   "    e Zd ZdZd ZddZd Zy)ProtocolHeaderzqAMQP Protocol header frame class which provides a pythonic interface
    for creating AMQP Protocol headers

    Nc                     d| _         |xs t        j                  d   | _        |xs t        j                  d   | _        |xs t        j                  d   | _        y)zConstruct 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

        r         N)r
   r   PROTOCOL_VERSIONmajorminorrevision)r   rM   rN   rO   s       r   r   zProtocolHeader.__init__   sP     6d33A6
6d33A6
 <D$9$9!$<r   c                 v    dt        j                  dd| j                  | j                  | j                        z   S )zReturn the full AMQP wire protocol frame data representation of the
        ProtocolHeader frame

        :rtype: str

           AMQPBBBBr   )r   r   rM   rN   rO   r   s    r   r   zProtocolHeader.marshal   s3     VQ

DJJ%)]]4 4 	4r   )NNNr0   r"   r   r   rG   rG      s     D=4r   rG   c                 Z   	 | dd dk(  r*t        j                  d| d      \  }}}dt        |||      fS 	 	 t        j
                  d| dd	       \  }}}t        j                  |z   t        j                  z   }|t        |       kD  ry| |d
z
  | t        t        j                        k7  rt        j                  d      | t        j                  |d
z
   }|t        j                  k(  rPt        j                  d|      d   }	t        j                  |	          }
|
j!                  |d       |t#        ||
      fS |t        j$                  k(  rTt        j                  d|      \  }}}t        j&                  |          }|j!                  |dd       }|t)        |||      fS |t        j*                  k(  r|t-        ||      fS |t        j.                  k(  r|t1               fS t        j                  d|z        # t        t         j                  f$ r Y yw xY w# t         j                  $ r Y yw xY w)a   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

    r      rQ   BBB      )r   Nz>BHL   rJ   zInvalid FRAME_END markerr+   z>HHQ   NzUnknown frame type: %i)r   unpack_fromrG   
IndexErrorerrorunpackr   FRAME_HEADER_SIZEFRAME_END_SIZEr   r   r   r   InvalidFrameErrorr'   methodsdecoder$   r4   r7   r2   r<   r:   rC   rA   )data_inrM   rN   rO   r
   r   
frame_size	frame_end
frame_data	method_idr(   class_idweightr5   r6   outs                   r   decode_framerk      s5   1Q<7"%+%7%7w%J"E5(nUE8<<< #39==GAaL4"0^Z &&3d6I6III 3w< y1}Y'4+??**+EFF //	A>JT&&& &&tZ8;	 i(* 	j!$ &888	t((	( '-&8&8&L#&) ZZ)+
 
230 &JGGG	t	& $~z:::	t++	+ )+%%

&
&'?*'L
MM} %  << s"   1G5 H 5HHH*)H*)r    loggingr   pikar   r   r   pika.compatr   	getLoggerr   LOGGER
AMQPObjectr   r$   r2   r:   rA   rG   rk   r"   r   r   <module>rr      s    B      			8	$""K"" ""J%U %8%U %>.5 .4% %*4[++ 4@LNr   