
    Ih                        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      Zy)zMessage class.    )annotationsN   )
decompress)MessageStateErrorreraise)loads)
dictfilter)Message>   ACKREJECTEDREQUEUEDpypy_version_infoc                      e Zd ZdZeZdZesdZ	 	 	 	 ddZddZ	ddZ
ddZddZdd	Zd
 Zd Zd Zed        Zed        Zd Zy)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                   |si n|}| j                   g n| j                   | _         |
| _        || _        || _        || _        || _        |xs i | _        |xs i | _        d | _        d| _	        |	| _
        | j                  j                  d      }| j                   s|r	 t        ||      }| j                   s,|r*t#        |t$              r	 |j'                  |      }|| _        y || _        y # t        $ r0 | j                   j                  t        j                                 Y xw xY w# t        $ r7 | j                   j                  t        j                                 Y || _        y w xY w)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   s                F/var/www/html/planif/env/lib/python3.12/site-packages/kombu/message.py__init__zMessage.__init__>   s3    #0] KK/bT[[(( 0*}"$*" ll&&}5{{{3!$4 {{zjs.C3{{:. 	D	  3""3<<>23  3""3<<>2	3s$   C* 	D& *6D#"D#&6E&%E&c                t    	 t        | j                  d     y # t        $ r}|s  || |       Y d }~y d }~ww xY w)Nr   )r   r   r!   )r(   callbackexcs      r+   _reraise_errorzMessage._reraise_error]   s:    	 T[[^$ 	 T3	 s    	727c                   | j                   | j                  d      | j                   j                  )	 | j                  d   }|| j                   j                  v ry| j
                  r | j                  dj                  |             | j                   j                  | j                  |       d| _	        y# t        $ r Y fw xY w)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(   r6   r3   s      r+   ackzMessage.acke   s     <<((@B B<<((4#11.A  4<<#@#@@((ELL  	t008D  s   B8 8	CCc                    	 | j                  |       y # t        $ r%}|j                  d| j                  |d        d }~w|$ r)}|j                  d| j                  |d       Y d }~y d }~ww xY w)Nr5   zCouldn't ack %r, reason:%rTr$   )r<   BrokenPipeErrorcriticalr   )r(   loggerr   r6   r/   s        r+   ack_log_errorzMessage.ack_log_error   s~    	CHHhH' 	OO8 --sT  C 	COO8 --sT  C C	Cs    	A/ >A/A**A/c                    	 | j                  |       y # |$ r)}|j                  d| j                  |d       Y d }~y d }~ww xY w)NrequeuezCouldn't reject %r, reason: %rTr>   )rejectr@   r   )r(   rA   r   rE   r/   s        r+   reject_log_errorzMessage.reject_log_error   sP    	CKKK( 	COO< --sT  C C	Cs    A>Ac                    | j                   | j                  d      | j                  r | j                  dj                  |             | j                   j	                  | j
                  |       d| _        y)zReject this message.

        The message will be discarded by the server.

        Raises
        ------
            MessageStateError: If the message has already been
                acknowledged/requeued/rejected.
        Nr2   r4   rD   r   r   r   r9   r:   basic_rejectr   r   )r(   rE   s     r+   rF   zMessage.reject   sy     <<((@B B((ELL  	!!$"3"3W!E     c                    | j                   | j                  d      | j                  r | j                  dj                  |             | j                   j	                  | j
                  d       d| _        y)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.
        Nr2   r4   TrD   r   rI   r(   s    r+   rE   zMessage.requeue   sy     <<((@B B((ELL  	!!$"3"3T!B rK   c                \    | j                   s| j                         | _         | 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   _decoderM   s    r+   decodezMessage.decode   s'     """&,,.D"""rK   c                p    t        | j                  | j                  | j                  | j                        S )N)r   )r   r   r   r   r   rM   s    r+   rO   zMessage._decode   s.    TYY 1 1**4;;@ 	@rK   c                &    | j                   t        v S )z1Set to true if the message has been acknowledged.)r   
ACK_STATESrM   s    r+   r9   zMessage.acknowledged   s     {{j((rK   c                R    | j                   r| j                   S | j                         S )zThe decoded message body.)r   rP   rM   s    r+   payloadzMessage.payload   s#     '+&9&9t""Lt{{}LrK   c                   dj                  t        |       j                  t        |       t	        | j
                  | j                  | j                  | j                  t        | j                        nd t	        | j                  j                  d      | j                  j                  d            t	        | j                  j                  d      | j                  j                  d                        S )	Nz&<{} object at {:#x} with details {!r}>correlation_idtype)rW   rX   exchangerouting_key)rY   rZ   )stater   r   body_lengthr   r   )r:   rX   __name__idr	   r   r   r   r   lenr   r    r   rM   s    r+   __repr__zMessage.__repr__   s    7>>JD:kk!..!...2ii.CC		N%#'??#6#67G#H,,V4 )!//33J? $ 2 2 6 6} E,
 	
rK   )
NNNNNNNNNN)N)F)r]   
__module____qualname____doc__r   r   IS_PYPY	__slots__r,   r0   r<   rB   rG   rF   rE   rP   rO   propertyr9   rU   r`    rK   r+   r
   r
      s    > *F
	 04IM;?&*> 8	CC!(!.#@ ) ) M M
rK   r
   )rc   
__future__r   r#   r   r   
exceptionsr   r   serializationr   utils.functionalr	   __all__rS   hasattrrd   r
   rg   rK   r+   <module>rn      s=     " 
 # 2   (
,

#*
+X
 X
rK   