o
    wvXj;  ã                   @   sŽ   d Z ddlmZmZ ddlZddlmZ ddlmZ ddl	m
Z
mZmZ ddlmZ dd	lmZ d
Zh d£ZeedƒZe
G dd„ deƒƒZdS )zMessage class.é    )Úabsolute_importÚunicode_literalsNé   )Ú
decompress)ÚMessageStateError)Úpython_2_unicode_compatibleÚreraiseÚtext_t)Ú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   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 | _ |
| _|| _|| _|| _|| _|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Ú
isinstancer	   Úencoder   )Úselfr   r   r   r   r   r   r   Ú
postencoder   r   Úkwargsr   © r*   úJ/var/www/html/myproject/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 )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'   r4   r1   r*   r*   r+   Úackf   s(   
	ÿÿÿÿ
zMessage.ackc              
   C   óN   z	| j |d� W d S  |y& } z|jd| j|dd� W Y d }~d S d }~ww )Nr3   zCouldn't ack %r, reason:%rT©r$   )r:   Úcriticalr   )r'   Úloggerr   r4   r.   r*   r*   r+   Úack_log_error�   ó   ÿ€ÿzMessage.ack_log_errorc              
   C   r;   )N©ÚrequeuezCouldn't reject %r, reason: %rTr<   )Úrejectr=   r   )r'   r>   r   rB   r.   r*   r*   r+   Úreject_log_errorˆ   r@   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.
        Nr0   r2   rA   r   ©r   r   r7   r8   Úbasic_rejectr   r   )r'   rB   r*   r*   r+   rC   �   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.
        Nr0   r2   TrA   r   rE   ©r'   r*   r*   r+   rB   ¢   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   Ú_decoderG   r*   r*   r+   Údecode·   s   	
zMessage.decodec                 C   s   t | j| j| j| jd�S )N)r   )r
   r   r   r   r   rG   r*   r*   r+   rH   Ä   s   
ÿzMessage._decodec                 C   s
   | j tv S )z1Set to true if the message has been acknowledged.)r   Ú
ACK_STATESrG   r*   r*   r+   r7   È   s   
zMessage.acknowledgedc                 C   s   | j r| j S |  ¡ S )zThe decoded message body.)r   rI   rG   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)<{0} object at {1:#x} with details {2!r}>Úcorrelation_idÚtype)rL   rM   ÚexchangeÚrouting_key)rN   rO   )Ústater   r   Úbody_lengthr   r   )r8   rM   Ú__name__Úidr   r   r   r   r   Úlenr   r    r   rG   r*   r*   r+   Ú__repr__Ò   s    

þ

þ÷ÿzMessage.__repr__)
NNNNNNNNNN)N)F)rR   Ú
__module__Ú__qualname__Ú__doc__r   r   ÚIS_PYPYÚ	__slots__r,   r/   r:   r?   rD   rC   rB   rI   rH   Úpropertyr7   rK   rU   r*   r*   r*   r+   r      s0    
ý






r   )rX   Ú
__future__r   r   r#   r   r   Ú
exceptionsr   Úfiver   r   r	   Úserializationr
   Úutils.functionalr   Ú__all__rJ   ÚhasattrrY   Úobjectr   r*   r*   r*   r+   Ú<module>   s    
