o
    1li@                     @   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	e
ZG dd dejZG d	d
 d
eZG dd deZG dd deZG dd deZG dd dejZdd ZdS )z<Frame objects that do the frame demarshaling and marshaling.    N)amqp_object)
exceptions)spec)bytec                   @   s,   e Zd ZdZd Zdd Zdd Zd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                 C   s   || _ || _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    r
   Z/var/www/html/tatsat2dev/dashboard-backend/venv/lib/python3.10/site-packages/pika/frame.py__init__   s   
zFrame.__init__c                 C   s0   d |}td| j| jt|| ttj S )z]Create the full AMQP wire protocol frame data representation

        :rtype: bytes

            z>BHI)	joinstructpackr   r   lenr   r   	FRAME_END)r	   piecespayloadr
   r
   r   _marshal   s   
zFrame._marshalc                 C   s   t )zKTo be ended by child classes

        :raises NotImplementedError

        )NotImplementedErrorr	   r
   r
   r   marshal)   s   zFrame.marshalN)__name__
__module____qualname____doc__NAMEr   r   r   r
   r
   r
   r   r      s    

r   c                   @   s$   e Zd ZdZdZdd Zd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                 C      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"   r
   r
   r   r   9      
zMethod.__init__c                 C   s,   | j  }|dtd| j j | |S )PReturn the AMQP binary encoded value of the frame

        :rtype: str

        r   >I)r"   encodeinsertr   r   INDEXr   r	   r   r
   r
   r   r   C   s   

zMethod.marshalNr   r   r   r   r   r   r   r
   r
   r
   r   r   2   
    
r   c                   @   $   e Zd ZdZd Zdd Zd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                 C   s    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   r/   propsr
   r
   r   r   U   s   
zHeader.__init__c                 C   s0   | j  }|dtd| j j| j | |S )r$   r   z>HxxQ)r0   r&   r'   r   r   r(   r/   r   r)   r
   r
   r   r   a   s
   

zHeader.marshalNr*   r
   r
   r
   r   r-   N   s
    r-   c                   @   r,   )BodyzBody frame object mapping class. AMQP content body frames are mapped on
    to this base class for getting/setting of attributes/data.

    c                 C   r    )z_
        Parameters:

        - channel_number: int
        - fragment: unicode or str
        N)r   r   r   
FRAME_BODYfragment)r	   r   r4   r
   r
   r   r   t   r#   zBody.__init__c                 C   s   |  | jgS r$   )r   r4   r   r
   r
   r   r   ~   s   zBody.marshalNr*   r
   r
   r
   r   r2   m   r+   r2   c                   @   r,   )	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                 C   s   t | tjd dS )z,Create a new instance of the Heartbeat framer   N)r   r   r   FRAME_HEARTBEATr   r
   r
   r   r      s   zHeartbeat.__init__c                 C   s   |  t S r5   )r   listr   r
   r
   r   r      s   zHeartbeat.marshalNr*   r
   r
   r
   r   r6      s
    r6   c                   @   s&   e Zd ZdZd ZdddZdd ZdS )ProtocolHeaderzqAMQP Protocol header frame class which provides a pythonic interface
    for creating AMQP Protocol headers

    Nc                 C   s:   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	   r>   r?   r@   r
   r
   r   r      s   	zProtocolHeader.__init__c                 C   s   dt dd| j| j| j S )zReturn the full AMQP wire protocol frame data representation of the
        ProtocolHeader frame

        :rtype: str

           AMQPBBBBr   )r   r   r>   r?   r@   r   r
   r
   r   r      s   zProtocolHeader.marshal)NNNr*   r
   r
   r
   r   r9      s
    
r9   c              	   C   s  z| dd dkrt d| d\}}}dt|||fW S W n tt jfy*   Y dS w zt d| dd	 \}}}W n t jyE   Y dS w tj| tj }|t	| krVdS | |d
 | t
tjkrhtd| tj|d
  }|tjkrt d|d }	tj|	  }
|
|d |t||
fS |tjkrt d|\}}}tj|  }||dd }|t|||fS |tjkr|t||fS |tjkr|t fS td| )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      rA   BBB      )r   Nz>BHL   r;   zInvalid FRAME_END markerr%   z>HHQ   NzUnknown frame type: %i)r   unpack_fromr9   
IndexErrorerrorunpackr   FRAME_HEADER_SIZEFRAME_END_SIZEr   r   r   r   InvalidFrameErrorr!   methodsdecoder   r.   r1   r-   r3   r2   r7   r6   )data_inr>   r?   r@   r   r   
frame_size	frame_end
frame_data	method_idr"   class_idweightr/   r0   outr
   r
   r   decode_frame   sH   






rZ   )r   loggingr   pikar   r   r   pika.compatr   	getLoggerr   LOGGER
AMQPObjectr   r   r-   r2   r6   r9   rZ   r
   r
   r
   r   <module>   s    
% 