+
    ÁFñj31  ã                   óò   € R t ^ RIt^ RIt^ RIHtHt ^ RIHt  ^ RIH	t	 Rt
^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ]P,                  t]! ]RR7      t ! R R]],          4      tR#   ] d    Rt
 LSi ; i)zeThis module contains an implementation of the BaseRateLimiter class based on the aiolimiter
library.
N)ÚCallableÚ	Coroutine)ÚAny)ÚAsyncLimiterTF)Ú	constants)Ú
get_logger)ÚJSONDict)Ú
RetryAfter)ÚBaseRateLimiterÚAIORateLimiter)Ú
class_namec                   óò   a € ] tR t^2t o RtRt]P                  P                  ^]P                  P                  ^<^ 3V 3R lR llt
V 3R lR ltV 3R lR ltV 3R lR	 ltV 3R
 lR ltV 3R lR ltRtV tR# )r   ao  
Implementation of :class:`~telegram.ext.BaseRateLimiter` using the library
`aiolimiter <https://aiolimiter.readthedocs.io/en/stable>`_.

Important:
    If you want to use this class, you must install PTB with the optional requirement
    ``rate-limiter``, i.e.

    .. code-block:: bash

       pip install "python-telegram-bot[rate-limiter]"

The rate limiting is applied by combining two levels of throttling and :meth:`process_request`
roughly boils down to::

    async with group_limiter(group_id):
        async with overall_limiter:
            await callback(*args, **kwargs)

Here, ``group_id`` is determined by checking if there is a ``chat_id`` parameter in the
:paramref:`~telegram.ext.BaseRateLimiter.process_request.data`.
The ``overall_limiter`` is applied only if a ``chat_id`` argument is present at all.

Attention:
    * Some bot methods accept a ``chat_id`` parameter in form of a ``@username`` for
      supergroups and channels. As we can't know which ``@username`` corresponds to which
      integer ``chat_id``, these will be treated as different groups, which may lead to
      exceeding the rate limit.
    * As channels can't be differentiated from supergroups by the ``@username`` or integer
      ``chat_id``, this also applies the group related rate limits to channels.
    * A :exc:`~telegram.error.RetryAfter` exception will halt *all* requests for
      :attr:`~telegram.error.RetryAfter.retry_after` + 0.1 seconds. This may be stricter than
      necessary in some cases, e.g. the bot may hit a rate limit in one group but might still
      be allowed to send messages in another group or with
      :paramref:`~telegram.Bot.send_message.allow_paid_broadcast` set to :obj:`True`.

Tip:
    With `Bot API 7.1 <https://core.telegram.org/bots/api-changelog#october-31-2024>`_
    (PTB v27.1), Telegram introduced the parameter
    :paramref:`~telegram.Bot.send_message.allow_paid_broadcast`.
    This allows bots to send up to
    :tg-const:`telegram.constants.FloodLimit.PAID_MESSAGES_PER_SECOND` messages per second by
    paying a fee in Telegram Stars.

    .. versionchanged:: 21.11
        This class automatically takes the
        :paramref:`~telegram.Bot.send_message.allow_paid_broadcast` parameter into account and
        throttles the requests accordingly.

Note:
    This class is to be understood as minimal effort reference implementation.
    If you would like to handle rate limiting in a more sophisticated, fine-tuned way, we
    welcome you to implement your own subclass of :class:`~telegram.ext.BaseRateLimiter`.
    Feel free to check out the source code of this class for inspiration.

.. seealso:: :wiki:`Avoiding Flood Limits <Avoiding-flood-limits>`

.. versionadded:: 20.0

Args:
    overall_max_rate (:obj:`float`): The maximum number of requests allowed for the entire bot
        per :paramref:`overall_time_period`. When set to 0, no rate limiting will be applied.
        Defaults to :tg-const:`telegram.constants.FloodLimit.MESSAGES_PER_SECOND`.
    overall_time_period (:obj:`float`): The time period (in seconds) during which the
        :paramref:`overall_max_rate` is enforced.  When set to 0, no rate limiting will be
        applied. Defaults to ``1``.
    group_max_rate (:obj:`float`): The maximum number of requests allowed for requests related
        to groups and channels per :paramref:`group_time_period`.  When set to 0, no rate
        limiting will be applied. Defaults to
        :tg-const:`telegram.constants.FloodLimit.MESSAGES_PER_MINUTE_PER_GROUP`.
    group_time_period (:obj:`float`): The time period (in seconds) during which the
        :paramref:`group_max_rate` is enforced.  When set to 0, no rate limiting will be
        applied. Defaults to ``60``.
    max_retries (:obj:`int`): The maximum number of retries to be made in case of a
        :exc:`~telegram.error.RetryAfter` exception.
        If set to 0, no retries will be made. Defaults to ``0``.

c                ó<   <€ V ^8„  d   QhRS[ RS[ RS[ RS[ RS[RR/# )é   Úoverall_max_rateÚoverall_time_periodÚgroup_max_rateÚgroup_time_periodÚmax_retriesÚreturnN)ÚfloatÚint)ÚformatÚ__classdict__s   "€ÚR/opt/hermes-site/venv/lib/python3.14/site-packages/telegram/ext/_aioratelimiter.pyÚ__annotate__ÚAIORateLimiter.__annotate__Œ   sG   ø€ ÷ !&ñ !&áð!&ñ #ð!&ñ ð	!&ñ
 !ð!&ñ ð!&ð 
ñ!&ó    c                ó²  € \         '       g   \        R 4      hV'       d   V'       d   \        WR7      V n        MRV n        V'       d   V'       d   W0n        W@n        M^ V n        ^ V n        / V n        \        \        P                  P                  ^R7      V n
        WPn        \        P                  ! 4       V n        V P                  P                  4        R# )zeTo use `AIORateLimiter`, PTB must be installed via `pip install "python-telegram-bot[rate-limiter]"`.©Úmax_rateÚtime_periodN)ÚAIO_LIMITER_AVAILABLEÚRuntimeErrorr   Ú_base_limiterÚ_group_max_rateÚ_group_time_periodÚ_group_limitersr   Ú
FloodLimitÚPAID_MESSAGES_PER_SECONDÚ_apb_limiterÚ_max_retriesÚasyncioÚEventÚ_retry_after_eventÚset)Úselfr   r   r   r   r   s   &&&&&&r   Ú__init__ÚAIORateLimiter.__init__Œ   s¯   € ÷ %Ó$Üð8óð ÷ × 3Ü6BØ)ô7ˆDÕð "&ˆDÔç×/Ø*8Ô Ø->Õ#à#$ˆDÔ Ø&'ˆDÔ#à>@ˆÔÜ*6Ü×)Ñ)×BÑBÐPQô+
ˆÔð "-ÔÜ")§-¢-£/ˆÔØ×Ñ×#Ñ#Ö%r   c                ó   <€ V ^8„  d   QhRR/# ©r   r   N© )r   r   s   "€r   r   r   ¯   s   ø€ ÷ ñ  $ñ r   c              ƒ  ó   "  € R# 5i©zDoes nothing.Nr5   ©r0   s   &r   Ú
initializeÚAIORateLimiter.initialize¯   ó   é ‚ ùó   ‚c                ó   <€ V ^8„  d   QhRR/# r4   r5   )r   r   s   "€r   r   r   ²   s   ø€ ÷ ñ  ñ r   c              ƒ  ó   "  € R# 5ir7   r5   r8   s   &r   ÚshutdownÚAIORateLimiter.shutdown²   r;   r<   c                óD   <€ V ^8„  d   QhRS[ S[,          S[,          RR/# )r   Úgroup_idr   r   )Ústrr   Úbool)r   r   s   "€r   r   r   µ   s$   ø€ ÷ .ñ .©3±­9±tÕ+;ð .Àñ .r   c                óª  € \        V P                  4      R 8”  dj   V P                  P                  4       P                  4        F=  w  r#W!8X  d   K  VP	                  VP
                  4      '       g   K0  V P                  V K?  	  WP                  9  d/   \        V P                  V P                  R7      V P                  V&   V P                  V,          # )i   r   )	Úlenr'   ÚcopyÚitemsÚhas_capacityr    r   r%   r&   )r0   rB   ÚkeyÚlimiters   &&  r   Ú_get_group_limiterÚ!AIORateLimiter._get_group_limiterµ   s±   € ô
 ˆt×#Ñ#Ó$ sÔ*à $× 4Ñ 4× 9Ñ 9Ó ;× AÑ AÖ C‘�Ø”?ÙØ×'Ñ'¨×(8Ñ(8×9Ô9Ø×,Ñ,¨SÒ1ñ	 !Dð ×/Ñ/Ô/Ü-9Ø×-Ñ-Ø ×3Ñ3ô.ˆD× Ñ  Ñ*ð ×#Ñ# HÕ-Ð-r   c                ó  <€ V ^8„  d   QhRS[ RS[S[,          S[ ,          RS[ RS[RS[S[S[S[ S[,          S[S[,          ,          3,          3,          RS[RS[S[S[3,          RS[ S[,          S[S[,          ,          /# )	r   ÚchatÚgroupÚallow_paid_broadcastÚcallback.ÚargsÚkwargsr   )	rD   rC   r   r   r   r   r   ÚlistÚdict)r   r   s   "€r   r   r   É   s’   ø€ ÷ %ñ %áð%ñ ‘S�y™4Õð%ñ #ð	%ñ
 ˜3¡	©#©s±D¹8µOÁdÉ8ÅnÕ4TÐ*TÕ UÐUÕVð%ñ ð%ñ ‘S™#�X•ð%ñ 
‘�™4¡�>Õ	)ñ%r   c           
   ƒ  ó$  a aaa"  € R  VVVV 3R llpV'       d?   S P                   ;_uu_4       GRj  x€L
  V! 4       G Rj  x€L
 uuRRR4      GRj  x€L
  # V'       d   S P                  '       d   S P                  M	\        4       pV'       d$   S P                  '       d   S P	                  V4      M	\        4       p	T	;_uu_4       GRj  x€L
  T;_uu_4       GRj  x€L
  V! 4       G Rj  x€L
 uuRRR4      GRj  x€L
  uuRRR4      GRj  x€L
  #  Lã LÖ LÇ  + GRj  x€L 
 '       g   i     R# ; i Lm L\ LO L@ L0  + GRj  x€L 
 '       g   i     M; iRRR4      GRj  x€L 
  R#   + GRj  x€L 
 '       g   i     R# ; i5i)c                óf   € V ^8„  d   QhR\         \        ,          \        \        ,          ,          /# )r   r   )rD   r   rU   )r   s   "r   r   Ú1AIORateLimiter._run_request.<locals>.__annotate__Ò   s    € ÷ 	3ñ 	3œT¤H�_¬t´H­~Õ=ñ 	3r   c               “   óx   <"  € SP                   P                  4       G R j  x€L
  S! S / SB G R j  x€L
 #  L L5i)N)r.   Úwait)rS   rR   rT   r0   s   €€€€r   ÚinnerÚ*AIORateLimiter._run_request.<locals>.innerÒ   s9   øé € à×)Ñ)×.Ñ.Ó0×0Ð0Ù! 4Ð2¨6Ñ2×2Ð2ñ 1Ù2ùs   ƒ:¡6¢:±8²:¸:N)r*   r$   Únull_contextr%   rL   )
r0   rO   rP   rQ   rR   rS   rT   r\   Úbase_contextÚgroup_contexts
   f&&&fff   r   Ú_run_requestÚAIORateLimiter._run_requestÉ   sâ   ûé € ÷	3ó 	3÷
  Ø×(×(×(Ó(Ù"›W—}÷ )×(Ò(÷ 37¸4×;M×;MÐ;M˜4×-Ò-ÔT`ÓTbˆL÷ ˜T×1×1Ð1ð ×'Ñ'¨Ô.ä!“^ð ÷ %—}’}§l§l¢lÙ"›W—}÷ '3§l¡l—}—}’}ñ )Ù$÷ )×(×(Ó(úñ %¡lÙ$ñ '3‘}§l§l§l lú—}—}—}—}—}”}üs.  †-F³D´F·DÁDÁDÁFÁDÁFÁ!FÁ3FÂFÂ#)FÃD:ÃFÃE3ÃD<Ã E3Ã#E	Ã.D>Ã/E	Ã2E3Ã?E 
Ä E3ÄFÄEÄFÄDÄFÄD7	Ä#D&Ä$
D7	Ä/D7	Ä1
FÄ<E3Ä>E	Å E3ÅFÅEÅ
EÅ
EÅEÅE3Å FÅ+E.Å,FÅ3F	Å9E<Å:
F	ÆF	Æ	Fc                ó  <€ V ^8„  d   QhRS[ RS[S[S[S[S[,          S[S[,          ,          3,          3,          RS[RS[S[S[3,          RS[RS[S[S[3,          RS[R,          R	S[S[,          S[S[,          ,          /# )
r   rR   .rS   rT   ÚendpointÚdataÚrate_limit_argsNr   )	r   r   r   rD   r   rU   rV   rC   r   )r   r   s   "€r   r   r   æ   s•   ø€ ÷ ?ñ ?á˜3¡	©#©s±D¹8µOÁdÉ8ÅnÕ4TÐ*TÕ UÐUÕVð?ñ ð?ñ ‘S™#�X•ð	?ñ
 ð?ñ ‘3™�8�nð?ñ ˜t�ð?ñ 
‘�™4¡�>Õ	)ñ?r   c           
   ƒ  ó
  "  € T;'       g    V P                   pRpRp	VP                  R4      p
VP                  RR4      pV
e   Rp	\        P                  ! \        \
        4      ;_uu_ 4        \        V
4      p
RRR4       \        V
\        4      '       d   V
^ 8  g   \        V
\        4      '       d   T
p\        V^,           4       F=  p V P                  V	VVVVVR7      G Rj  x€L
 V P                  P                  4        u # 	  R#   + '       g   i     Lš; i L7  \         d™   pYÇ8X  d   \        P                  RY}R7       h TP                   P#                  4       R	,           p\        P%                  R
T4       T P                  P'                  4        \(        P*                  ! T4      G Rj  x€L 
   Rp?MRp?ii ; i T P                  P                  4        EK    T P                  P                  4        i ; i5i)a…  
Processes a request by applying rate limiting.

See :meth:`telegram.ext.BaseRateLimiter.process_request` for detailed information on the
arguments.

Args:
    rate_limit_args (:obj:`None` | :obj:`int`): If set, specifies the maximum number of
        retries to be made in case of a :exc:`~telegram.error.RetryAfter` exception.
        Defaults to :paramref:`AIORateLimiter.max_retries`.
FÚchat_idrQ   NT)rO   rP   rQ   rR   rS   rT   z*Rate limit hit after maximum of %d retries)Úexc_infogš™™™™™¹?z)Rate limit hit. Retrying after %f seconds)r+   ÚgetÚ
contextlibÚsuppressÚ
ValueErrorÚ	TypeErrorr   Ú
isinstancerC   Úrangera   r.   r/   r	   Ú_LOGGERÚ	exceptionÚ_retry_afterÚtotal_secondsÚinfoÚclearr,   Úsleep)r0   rR   rS   rT   rd   re   rf   r   rP   rO   rh   rQ   ÚiÚexcrw   s   &&&&&&&        r   Úprocess_requestÚAIORateLimiter.process_requestæ   s°  é € ð( &×:Ð:¨×):Ñ):ˆà"'ˆØˆØ—(‘(˜9Ó%ˆØ#Ÿx™xÐ(>ÀÓFÐØÒØˆDô × Ò ¤¬Y×7Õ7Ü˜'“lˆG÷ 8ô �w¤×$Ò$¨°1¬¼ÀGÌS×9QÒ9Qð ˆEä�{ Q•Ö'ˆAð.Ø!×.Ñ.ØØØ)=Ø%ØØ!ð /ó ÷ ð, ×'Ñ'×+Ñ+×-ñ1 (ñ2 ÷C 8×7úñøô ô +ØÔ#Ü×%Ñ%ØDÀkð &ô ð à×(Ñ(×6Ñ6Ó8¸3Õ>�Ü—‘ÐHÈ%ÔPà×'Ñ'×-Ñ-Ô/Ü—m’m EÓ*×*Ö*ûð+úð +ð ×'Ñ'×+Ñ+×-ø�×'Ñ'×+Ñ+Õ-üsz   ‚A+HÁ-DÁ9AHÃD Ã&DÃ'D Ã*!HÄD	ÄHÄD Ä GÄ+BF>Æ3F6Æ4F>Æ9G$Æ>GÇG$ÇHÇ$H È H)r*   r$   r'   r%   r&   r+   r.   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú	__slots__r   r(   ÚMESSAGES_PER_SECONDÚMESSAGES_PER_MINUTE_PER_GROUPr1   r9   r?   rL   ra   rz   Ú__static_attributes__Ú__classdictcell__)r   s   @r   r   r   2   sy   ø‡ € ñMð^€Ið #,×"6Ñ"6×"JÑ"JØ%&Ø )× 4Ñ 4× RÑ RØ#%Ø÷!&ò !&÷Fð ÷ð ÷.ð .÷(%ð %÷:?ö ?r   )r€   r,   rk   Úcollections.abcr   r   Útypingr   Ú
aiolimiterr   r"   ÚImportErrorÚtelegramr   Útelegram._utils.loggingr   Útelegram._utils.typesr   Útelegram.errorr	   Útelegram.ext._baseratelimiterr
   Únullcontextr^   r|   rq   r   r   r5   r   r   Ú<module>r�      s}   ðñ&ó Û ß /Ý ð"Ý'à Ðõ Ý .Ý *Ý %Ý 9ð
 ×%Ñ%€ñ �XÐ*:Ô
;€ôs�_ SÕ)ö søð% ô "Ø!Òð"ús   šA* Á*	A6Á5A6