o
    Df                     @  st   d Z ddlmZ ddlZddlmZ ddlmZmZ ddl	m
Z
 ddlmZ d	Zh d
ZeedZG dd dZdS )zMessage class.    )annotationsN   )
decompress)MessageStateErrorreraise)loads)
dictfilter)Message>   ACKREJECTEDREQUEUEDpypy_version_infoc                   @  s   e Zd ZdZeZdZesdZ				dddZdddZ	dd	d
Z
dddZdddZdddZdd Zdd Zdd Zedd Zedd Zdd ZdS ) r	   au  Base class for received messages.

    Keyword Arguments:
    -----------------
        channel (ChannelT): If message was received, this should be the
            channel that the message was received on.

        body (str): Message body.

        delivery_mode (bool): Set custom delivery mode.
            Defaults to :attr:`delivery_mode`.

        priority (int): Message priority, 0 to broker configured
            max priority, where higher is better.

        content_type (str): The messages content_type.  If content_type
            is set, no serialization occurs as it is assumed this is either
            a binary object, or you've done your own serialization.
            Leave blank if using built-in serialization as our library
            properly sets content_type.

        content_encoding (str): The character set in which this object
            is encoded. Use "binary" if sending in raw binary objects.
            Leave blank if using built-in serialization as our library
            properly sets content_encoding.

        properties (Dict): Message properties.

        headers (Dict): Message headers.
    N)_statechanneldelivery_tagcontent_typecontent_encodingdelivery_infoheaders
propertiesbody_decoded_cacheaccept__dict__c                 K  s   |si n|}| j d u rg n| j | _ |
| _|| _|| _|| _|| _|p#i | _|p(i | _d | _d| _	|	| _
| jd}| j sW|rWzt||}W n tyV   | j t  Y nw | j sz|rzt|trzz||}W n tyy   | j t  Y nw || _d S )NRECEIVEDcompression)errorsr   r   r   r   r   r   r   r   r   r   getr   	Exceptionappendsysexc_info
isinstancestrencoder   )selfr   r   r   r   r   r   r   
postencoder   r   kwargsr    r(   F/home/ubuntu/webapp/venv/lib/python3.10/site-packages/kombu/message.py__init__>   s4   



zMessage.__init__c              
   C  sL   z
t | jd   W d S  ty% } z|s || | W Y d }~d S d }~ww )Nr   )r   r   r   )r%   callbackexcr(   r(   r)   _reraise_error]   s   zMessage._reraise_errorFc                 C  s   | j du r
| d| j jdur)z| jd }W n	 ty    Y n	w || j jv r)dS | jr4| d| | j j| j|d d| _	dS )zAcknowledge this message as being processed.

        This will remove the message from the queue.

        Raises
        ------
            MessageStateError: If the message has already been
                acknowledged/requeued/rejected.
        N.This message does not have a receiving channelconsumer_tag3Message already acknowledged with state: {0._state}multipler
   )
r   r   no_ack_consumersr   KeyErroracknowledgedformat	basic_ackr   r   )r%   r2   r/   r(   r(   r)   acke   s(   


zMessage.ackc              
   C  sz   z	| j |d W d S  ty  } z|jd| j|dd  d }~w |y< } z|jd| j|dd W Y d }~d S d }~ww )Nr1   zCouldn't ack %r, reason:%rTr!   )r8   BrokenPipeErrorcriticalr   )r%   loggerr   r2   r,   r(   r(   r)   ack_log_error   s   zMessage.ack_log_errorc              
   C  sN   z	| j |d W d S  |y& } z|jd| j|dd W Y d }~d S d }~ww )NrequeuezCouldn't reject %r, reason: %rTr9   )rejectr;   r   )r%   r<   r   r?   r,   r(   r(   r)   reject_log_error   s   zMessage.reject_log_errorc                 C  sF   | j du r
| d| jr| d| | j j| j|d d| _dS )zReject this message.

        The message will be discarded by the server.

        Raises
        ------
            MessageStateError: If the message has already been
                acknowledged/requeued/rejected.
        Nr.   r0   r>   r   r   r   r5   r6   basic_rejectr   r   )r%   r?   r(   r(   r)   r@      s   


zMessage.rejectc                 C  sF   | j du r
| d| jr| d| | j j| jdd d| _dS )aL  Reject this message and put it back on the queue.

        Warning:
        -------
            You must not use this method as a means of selecting messages
            to process.

        Raises
        ------
            MessageStateError: If the message has already been
                acknowledged/requeued/rejected.
        Nr.   r0   Tr>   r   rB   r%   r(   r(   r)   r?      s   

zMessage.requeuec                 C  s   | j s|  | _ | j S )zDeserialize the message body.

        Returning the original python structure sent by the publisher.

        Note:
        ----
            The return value is memoized, use `_decode` to force
            re-evaluation.
        )r   _decoderD   r(   r(   r)   decode   s   

zMessage.decodec                 C  s   t | j| j| j| jdS )N)r   )r   r   r   r   r   rD   r(   r(   r)   rE      s   
zMessage._decodec                 C  s
   | j tv S )z1Set to true if the message has been acknowledged.)r   
ACK_STATESrD   r(   r(   r)   r5      s   
zMessage.acknowledgedc                 C  s   | j r| j S |  S )zThe decoded message body.)r   rF   rD   r(   r(   r)   payload   s   zMessage.payloadc                 C  sr   d t| jt| t| j| j| j| jd urt	| jnd t| j
d| j
ddt| jd| jdddS )	Nz&<{} object at {:#x} with details {!r}>correlation_idtype)rI   rJ   exchangerouting_key)rK   rL   )stater   r   body_lengthr   r   )r6   rJ   __name__idr   r   r   r   r   lenr   r   r   rD   r(   r(   r)   __repr__   s    



zMessage.__repr__)
NNNNNNNNNN)N)F)rO   
__module____qualname____doc__r   r   IS_PYPY	__slots__r*   r-   r8   r=   rA   r@   r?   rF   rE   propertyr5   rH   rR   r(   r(   r(   r)   r	      s0    







r	   )rU   
__future__r   r    r   r   
exceptionsr   r   serializationr   utils.functionalr   __all__rG   hasattrrV   r	   r(   r(   r(   r)   <module>   s    
