
    )Jf@                     ,   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dS )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dS )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                 "    || _         || _        dS )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      M/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/pika/frame.py__init__zFrame.__init__   s     %,    c                     d                     |          }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   sY     ((6""{64?D4Gw<<) )+2359$.5I5I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      sU         
 D- - -J J J" " " " "r   r   c                   "    e Zd ZdZdZd Zd ZdS )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                               | t          j        |           || _        dS )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                                         }|                    dt          j        d| 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   sN     ##%%aT4;+<==>>>}}V$$$r   Nr   r   r   r    r!   r   r   r"   r   r   r$   r$   2   sC          D  % % % % %r   r$   c                   "    e Zd ZdZd Zd Zd ZdS )HeaderzHeader frame object mapping. AMQP content header frames are mapped
    on top of this class for creating or accessing their data and attributes.

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

    c                 `    t                               | t          j        |           || _        dS )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                 8    |                      | j        g          S r*   )r   r=   r   s    r   r   zBody.marshal~   s     }}dm_---r   Nr0   r"   r   r   r:   r:   m   sC          D! ! !. . . . .r   r:   c                   "    e Zd ZdZd Zd Zd ZdS )	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                 R    t                               | t          j        d           dS )z,Create a new instance of the Heartbeat framer   N)r   r   r   FRAME_HEARTBEATr   s    r   r   zHeartbeat.__init__   s!    tT1155555r   c                 D    |                      t                                S r?   )r   listr   s    r   r   zHeartbeat.marshal   s     }}TVV$$$r   Nr0   r"   r   r   rA   rA      sC         
 D6 6 6% % % % %r   rA   c                   $    e Zd ZdZd ZddZd ZdS )ProtocolHeaderzqAMQP Protocol header frame class which provides a pythonic interface
    for creating AMQP Protocol headers

    Nc                     d| _         |pt          j        d         | _        |pt          j        d         | _        |pt          j        d         | _        dS )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__   sK     6d3A6
6d3A6
 <D$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   s0     VQ
DJ%)]4 4 4 	4r   )NNNr0   r"   r   r   rG   rG      sH          D= = = =4 4 4 4 4r   rG   c                    	 | dd         dk    r-t          j        d| d          \  }}}dt          |||          fS n# t          t           j        f$ r Y dS w xY w	 t          j        d| dd	                   \  }}}n# t           j        $ r Y dS w xY wt          j        |z   t          j        z   }|t          |           k    rdS | |d
z
  |         t          t          j                  k    rt          j        d          | t          j        |d
z
           }|t          j        k    r\t          j        d|          d         }	t          j        |	                     }
|
                    |d           |t#          ||
          fS |t          j        k    rbt          j        d|          \  }}}t          j        |                     }|                    |dd                   }|t)          |||          fS |t          j        k    r|t-          ||          fS |t          j        k    r|t1                      fS t          j        d|z            )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      s   1Q3<7""%+%7w%J%J"E5(nUE8<<<< # %   ww39=GAaCL4" 4"0^ZZ<   ww &3d6III 3w<<w y1}Y&'4+?+???*+EFFF /	A=>JT&&& &tZ88;	 i(** 	j!$$$ &8888	t(	(	( '-&8&L&L#&) Z)++
 
23300 &JGGGG	t	&	& $~z::::	t+	+	+ )++%%

&'?*'L
M
MMs!   :> AA!A> >BB)r    loggingr   pikar   r   r   pika.compatr   	getLoggerr   LOGGER
AMQPObjectr   r$   r2   r:   rA   rG   rk   r"   r   r   <module>rr      s   B B                          		8	$	$"" "" "" "" ""K" "" "" ""J% % % % %U % % %8% % % % %U % % %>. . . . .5 . . .4% % % % % % % %*4 4 4 4 4[+ 4 4 4@LN LN LN LN LNr   