a
    xdW                     @   sh   d 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.    N   )
decompress)MessageStateErrorreraise)loads)
dictfilter)Message>   ACKREQUEUEDREJECTED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   a`  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 | _ |
| _|| _|| _|| _|| _|pFi | _|pPi | _d | _d| _	|	| _
| jd}| j s|rzt||}W n" ty   | j t  Y n0 | j s|rt|trz||}W n" ty   | j t  Y n0 || _d S )NZ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   Z
postencoder   r   kwargsr    r%   E/var/www/html/Ranjet/env/lib/python3.9/site-packages/kombu/message.py__init__<   s0    


zMessage.__init__c              
   C   sL   zt | jd   W n4 tyF } z|s( || | W Y d }~n
d }~0 0 d S )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rRz| jd }W n ty@   Y n0 || j jv rRdS | jrh| 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   Zno_ack_consumersr   KeyErroracknowledgedformatZ	basic_ackr   r   )r#   r/   r,   r%   r%   r&   ackc   s&    	
zMessage.ackc              
   C   s   z| j |d W np tyJ } z"|jd| j|dd  W Y d }~n@d }~0  |y } z |jd| j|dd W Y d }~n
d }~0 0 d S )Nr.   zCouldn't ack %r, reason:%rTr   )r3   BrokenPipeErrorcriticalr   )r#   loggerr   r/   r)   r%   r%   r&   ack_log_error~   s    zMessage.ack_log_errorc              
   C   sN   z| j |d W n8 |yH } z |jd| j|dd W Y d }~n
d }~0 0 d S )NrequeuezCouldn't reject %r, reason: %rTr4   )rejectr6   r   )r#   r7   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+   r-   r9   r   r   r   r1   r2   Z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 )a.  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+   r-   Tr9   r
   r=   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   _decoder>   r%   r%   r&   decode   s    	
zMessage.decodec                 C   s   t | j| j| j| jdS )N)r   )r   r   r   r   r   r>   r%   r%   r&   r?      s    
zMessage._decodec                 C   s
   | j tv S )z1Set to true if the message has been acknowledged.)r   
ACK_STATESr>   r%   r%   r&   r1      s    zMessage.acknowledgedc                 C   s   | j r| j S |  S )zThe decoded message body.)r   r@   r>   r%   r%   r&   payload   s    zMessage.payloadc                 C   sr   d t| jt| t| j| j| j| jd ur4t	| 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)rC   rD   exchangerouting_key)rE   rF   )stater   r   body_lengthr   r   )r2   rD   __name__idr   r   r   r   r   lenr   r   r   r>   r%   r%   r&   __repr__   s     



zMessage.__repr__)
NNNNNNNNNN)N)F)F)F)F)rI   
__module____qualname____doc__r   r   IS_PYPY	__slots__r'   r*   r3   r8   r<   r;   r:   r@   r?   propertyr1   rB   rL   r%   r%   r%   r&   r      s.       







r   )rO   r   r   r   
exceptionsr   r   Zserializationr   Zutils.functionalr   __all__rA   hasattrrP   r   r%   r%   r%   r&   <module>   s   
