o
    —¨Êh×  ã                   @  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(   ú?/var/www/html/env/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 )zùAcknowledge 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_tagú3Message 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 )záReject 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 )zæDeserialize 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    
