Ë
    3ýjÅ  ã                  óÜ   — d Z ddlmZ ddl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 ej                   d	ez  «      Zddd
„Zddd„Z	 d	 	 	 	 	 	 	 dd„Z	 d	 	 	 	 	 	 	 dd„Zdd„Zy)z:Native Delayed Delivery API.

Only relevant for RabbitMQ.
é    )ÚannotationsN)Ú
ConnectionÚExchangeÚQueueÚbinding)Ú
get_loggeré   é   Úcelery_delayed_deliveryz^(?:[01]\.){%d}c                ó>   — | dk  rt        d«      ‚|r|› d| › �S d| › �S )z=Generates the delayed queue/exchange name based on the level.r   z#level must be a non-negative numberÚ_celery_delayed_Úcelery_delayed_)Ú
ValueError)ÚlevelÚprefixs     úa/root/telegram-saas/.venv/lib/python3.12/site-packages/kombu/transport/native_delayed_delivery.pyÚ
level_namer      s7   € àˆq‚yÜÐ>Ó?Ð?áØ�Ð)¨%¨Ð1Ð1Ø˜U˜GÐ$Ð$ó    c                ó(   — | r| › dt         › �S t         S )NÚ_)Ú CELERY_DELAYED_DELIVERY_EXCHANGE)r   s    r   Ú!_celery_delayed_delivery_exchanger      s   € ÙØ�˜Ô;Ð<Ð=Ð=Ü+Ð+r   c                óh  — |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 ]W  }t        ||«      }|dkD  rt        |dz
  |«      nd	}t	        |d
¬«      j                  |«      }|j                  ||«       d|z   }ŒY t	        t        |«      d
¬«      j                  |«      }|j                  «        |j                  t        d|«      |«       y	)aì  Declare all native delayed delivery exchanges and queues.

    The generated delayed exchange/queue names use ``prefix`` when it is a
    non-empty string. In that case, level names are created as
    ``"{prefix}_celery_delayed_{level}"`` and the delivery exchange is named
    ``"{prefix}_celery_delayed_delivery"``. If ``prefix`` is ``None`` or an
    empty string, no prefix is applied and the default names
    ``"celery_delayed_{level}"`` and ``"celery_delayed_delivery"`` are used.
    Ú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Úpowr   r   Úbind_to)Ú
connectionÚ
queue_typer   r"   Úrouting_keyr   Úcurrent_levelÚ
next_levelÚdelayed_exchanger!   Údelayed_queueÚnext_level_exchangeÚdelivery_exchanges                r   Ú4declare_native_delayed_delivery_exchanges_and_queuesr1   %   sß  € ð �YÒ :°Ò#9ÜÐFÓGÐGà× Ñ Ó"€Gà€Kä�r˜2˜sÓ#ò )ˆÜ" 5¨&Ó1ˆØ6;¸a²i”Z ¨¡	¨6Ô2ÀTˆ
ä%-Ø ô&)ß)-©¨g«ð 	à× Ñ Ô"ð 'Ø*Ü   E›]¨TÑ1Ø49¸A²I¡jÔCdÐekÓClñ	
ˆð ˜Ò!Ø8GˆOÐ4Ñ5ä$ØØ+ô 
÷ ‰$ˆw‹-ð 	ð 	×ÑÔØ×Ñ˜m¨[Ô9à˜[Ñ(‰ð3)ð6 €KÜ�r˜1˜cÓ"ò 	)ˆÜ" 5¨&Ó1ˆØ6;¸a²i”Z ¨¡	¨6Ô2ÀTˆ
ä(0Ø˜Wô)&ß&*¡d¨7£mð 	ð 	×#Ñ# M°;Ô?à˜[Ñ(‰ð	)ô #+Ü)¨&Ó1¸ô#AßAEÁÀgÃð à×ÑÔØ×Ñœj¨¨FÓ3°[ÕAr   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)	ap  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
    :param prefix: Optional prefix for delayed delivery exchange and queue names;
        ``None`` or ``""`` means no prefix is applied.
    :type prefix: str | None

    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   r"   r:   Úbinding_entryr7   r*   s           r   Ú.bind_queue_to_native_delayed_delivery_exchangerA   e   s(  € ð0 × Ñ Ó"€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ð 	à×ÑÔ:¸6ÓBÐP[ÐÔ\Ø�‰�h—m‘m°ˆÕ=ñ>r   c                ó®   — | dk  rt        d«      ‚|st        d«      ‚t        j                  d|d¬«      }dj                  | d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Ú )Úcountú.Ú0Úb)r   Ú_delay_prefix_reÚsubÚjoinÚMAX_NUMBER_OF_BITS_TO_USE)Ú	countdownr*   s     r   Úcalculate_routing_keyrM   ™   sh   € à�1‚}ÜÐ>Ó?Ð?áÜÐ8Ó9Ð9ô #×&Ñ& r¨;¸aÐ&Ó@€Kà�8‰8�y Ô#<Ð"=¸QÐ >Ð?ÓAÀaÈÀ}ÐDUÑUÐUr   )N)r   Úintr   ú
str | NoneÚreturnÚstr)r   rO   rP   rQ   )r(   r   r)   rQ   r   rO   rP   ÚNone)r(   r   r?   r   r   rO   rP   rR   )rL   rN   r*   rQ   rP   rQ   )Ú__doc__Ú
__future__r   ÚreÚkombur   r   r   r   Ú	kombu.logr   Ú__name__r;   rK   Ú	MAX_LEVELr   ÚcompilerH   r   r   r1   rA   rM   © r   r   ú<module>r\      sÂ   ðñõ #ã 	ç 6Ó 6Ý  á	�HÓ	€àÐ Ø%¨Ñ)€	Ø#<Ð  à�2—:‘:Ð0Ð3LÑLÓMÐ ô%ô,ð CGð=BØð=BØ(+ð=BØ5?ð=Bà	ó=BðB @Dð1>Øð1>Ø#(ð1>Ø2<ð1>à	ó1>ôhVr   