Ë
    UV.j¬  ã                  óz   — d Z ddlmZ ddlmZmZmZmZ ddlm	Z	  e	e
«      ZdZedz
  ZdZdd„Zdd	„Zdd
„Zdd„Zy)z:Native Delayed Delivery API.

Only relevant for RabbitMQ.
é    )Úannotations)Ú
ConnectionÚExchangeÚQueueÚbinding)Ú
get_loggeré   é   Úcelery_delayed_deliveryc                ó,   — | dk  rt        d«      ‚d| › �S )z=Generates the delayed queue/exchange name based on the level.r   z#level must be a non-negative numberÚcelery_delayed_)Ú
ValueError)Úlevels    úiC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\site-packages\kombu/transport/native_delayed_delivery.pyÚ
level_namer      s"   € àˆq‚yÜÐ>Ó?Ð?à˜U˜GÐ$Ð$ó    c                óJ  — |dk7  r|dk7  rt        d«      ‚| j                  «       }d}t        ddd«      D ]º  }t        |«      }|dkD  rt        |dz
  «      nd	}t	        |d
¬«      j                  |«      }|j                  «        |dt        d|«      dz  |dkD  r|nt        dœ}|dk(  rd|d<   t        ||¬«      j                  |«      }	|	j                  «        |	j                  ||«       d|z   }Œ¼ d}t        ddd«      D ]U  }t        |«      }|dkD  rt        |dz
  «      nd	}t	        |d
¬«      j                  |«      }
|
j                  ||«       d|z   }ŒW t	        t        d
¬«      j                  |«      }|j                  «        |j                  t        d«      |«       y	)z:Declares all native delayed delivery exchanges and queues.ÚclassicÚquorumz+queue_type must be either classic or quorumz1.#é   éÿÿÿÿr   r
   NÚtopic)Útypezreject-publishé   iè  )zx-queue-typez
x-overflowzx-message-ttlzx-dead-letter-exchangezat-least-oncezx-dead-letter-strategy)Úqueue_argumentsz*.z0.#)r   ÚchannelÚranger   r   ÚbindÚdeclareÚpowÚ CELERY_DELAYED_DELIVERY_EXCHANGEr   Úbind_to)Ú
connectionÚ
queue_typer   Úrouting_keyr   Úcurrent_levelÚ
next_levelÚdelayed_exchanger   Údelayed_queueÚnext_level_exchangeÚdelivery_exchanges               r   Ú4declare_native_delayed_delivery_exchanges_and_queuesr,      s¼  € à�YÒ :°Ò#9ÜÐFÓGÐGà× Ñ Ó"€Gà€Kä�r˜2˜sÖ#ˆÜ" 5Ó)ˆØ.3°aªi”Z ¨¡	Ô*¸Tˆ
ä%-Ø ô&)ß)-©¨g«ð 	à× Ñ Ô"ð 'Ø*Ü   E›]¨TÑ1Ø49¸A²I¡jÔCcñ	
ˆð ˜Ò!Ø8GˆOÐ4Ñ5ä$ØØ+ô 
÷ ‰$ˆw‹-ð 	ð 	×ÑÔØ×Ñ˜m¨[Ô9à˜[Ñ(‰ð3 $ð6 €KÜ�r˜1˜cÖ"ˆÜ" 5Ó)ˆØ.3°aªi”Z ¨¡	Ô*¸Tˆ
ä(0Ø˜Wô)&ß&*¡d¨7£mð 	ð 	×#Ñ# M°;Ô?à˜[Ñ(‰ð #ô #+Ü(¨wô#8ß8<¹¸W»ð à×ÑÔØ×Ñœj¨›m¨[Õ9r   c                ó˜  — | j                  «       }|j                  |«      }t        «       }|j                  r<|j	                  t        |j                  |j                  |j                  ¬«      «       n|j                  r|j                  }|D ]º  }|j                  j                  |«      }|j                  dk(  r$t        j                  d|j                  › d�«       ŒQ|j                  j                  d«      r|j                  nd|j                  › �}|j                  t        |¬«       |j                  |j                  |¬«       Œ¼ y)	aÊ  Bind a queue to the native delayed delivery exchange.

    When a message arrives at the delivery exchange, it must be forwarded to
    the original exchange and queue. To accomplish this, the function retrieves
    the exchange or binding objects associated with the queue and binds them to
    the delivery exchange.


    :param connection: The connection object used to create and manage the channel.
    :type connection: Connection
    :param queue: The queue to be bound to the native delayed delivery exchange.
    :type queue: Queue

    Warning:
    -------
        If a direct exchange is detected, a warning will be logged because
        native delayed delivery does not support direct exchanges.
    )r%   Ú	argumentsÚdirectz	Exchange z¤ is a direct exchange and native delayed delivery do not support direct exchanges.
ETA tasks published to this exchange will block the worker until the ETA arrives.Ú#z#.)r%   N)r   r   ÚsetÚexchangeÚaddr   r%   Úbinding_argumentsÚbindingsr   ÚloggerÚwarningÚnameÚ
startswithr"   r!   )r#   Úqueuer   r5   Úbinding_entryr2   r%   s          r   Ú.bind_queue_to_native_delayed_delivery_exchanger<   O   s  € ð& × Ñ Ó"€GØ�J‰J�wÓ€Eä ›U€Hà‡~‚~Ø�‰”WØ�N‰NØ×)Ñ)Ø×-Ñ-ô
õ 	ð
 
�ŠØ—>‘>ˆã!ˆØ*×3Ñ3×8Ñ8¸ÓAˆØ�=‰=˜HÒ$Ü�N‰N˜Y x§}¡} oð 6oð pô qð à3@×3LÑ3L×3WÑ3WØô4�m×/Ò/Ø˜=×4Ñ4Ð5Ð6ð 	à×ÑÔ9À{ÐÔSØ�‰�h—m‘m°ˆÕ=ñ "r   c                ó€   — | dk  rt        d«      ‚|st        d«      ‚dj                  t        | d›«      «      d|› �z   S )zRCalculate the routing key for publishing a delayed message based on the countdown.r
   z#countdown must be a positive numberzrouting_key must be non-emptyÚ.Ú028b)r   ÚjoinÚlist)Ú	countdownr%   s     r   Úcalculate_routing_keyrC   ~   sI   € à�1‚}ÜÐ>Ó?Ð?áÜÐ8Ó9Ð9à�8‰8”D˜I dÐ+Ó-Ó.°1°[°MÐ1BÑBÐBr   N)r   ÚintÚreturnÚstr)r#   r   r$   rF   rE   ÚNone)r#   r   r:   r   rE   rG   )rB   rD   r%   rF   rE   rF   )Ú__doc__Ú
__future__r   Úkombur   r   r   r   Ú	kombu.logr   Ú__name__r6   ÚMAX_NUMBER_OF_BITS_TO_USEÚ	MAX_LEVELr!   r   r,   r<   rC   © r   r   Ú<module>rP      sO   ðñõ #ç 6Ó 6Ý  á	�HÓ	€àÐ Ø%¨Ñ)€	Ø#<Ð  ó%ó3:ól,>ô^Cr   