L iavdZddlmZmZddlmZddlmZmZm Z m Z m Z ddl m Z ddlmZGddee eZy ) zOThis module contains a class that allows to rate limit requests to the Bot API.)ABCabstractmethod) Coroutine)AnyCallableGenericOptionalUnion)JSONDict)RLARGSceZdZdZdZeddZeddZedede e e e e e ee fffd e d eee fd ed eee fd eede e e ee ffdZy)BaseRateLimitera Abstract interface class that allows to rate limit the requests that python-telegram-bot sends to the Telegram Bot API. An implementation of this class must implement all abstract methods and properties. This class is a :class:`~typing.Generic` class and accepts one type variable that specifies the type of the argument :paramref:`~process_request.rate_limit_args` of :meth:`process_request` and the methods of :class:`~telegram.ext.ExtBot`. Hint: Requests to :meth:`~telegram.Bot.get_updates` are never rate limited. .. seealso:: :wiki:`Architecture Overview `, :wiki:`Avoiding Flood Limits ` .. versionadded:: 20.0 returnNc Kyw)zKInitialize resources used by this class. Must be implemented by a subclass.Nrselfs c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/telegram/ext/_baseratelimiter.py initializezBaseRateLimiter.initialize2c Kyw)zMStop & clear resources used by this class. Must be implemented by a subclass.Nrrs rshutdownzBaseRateLimiter.shutdown6rrcallback.argskwargsendpointdatarate_limit_argsc Kyw)a; Process a request. Must be implemented by a subclass. This method must call :paramref:`callback` and return the result of the call. `When` the callback is called is up to the implementation. Important: This method must only return once the result of :paramref:`callback` is known! If a :exc:`~telegram.error.RetryAfter` error is raised, this method may try to make a new request by calling the callback again. Warning: This method *should not* handle any other exception raised by :paramref:`callback`! There are basically two different approaches how a rate limiter can be implemented: 1. React only if necessary. In this case, the :paramref:`callback` is called without any precautions. If a :exc:`~telegram.error.RetryAfter` error is raised, processing requests is halted for the :attr:`~telegram.error.RetryAfter.retry_after` and finally the :paramref:`callback` is called again. This approach is often amendable for bots that don't have a large user base and/or don't send more messages than they get updates. 2. Throttle all outgoing requests. In this case the implementation makes sure that the requests are spread out over a longer time interval in order to stay below the rate limits. This approach is often amendable for bots that have a large user base and/or send more messages than they get updates. An implementation can use the information provided by :paramref:`data`, :paramref:`endpoint` and :paramref:`rate_limit_args` to handle each request differently. Examples: * It is usually desirable to call :meth:`telegram.Bot.answer_inline_query` as quickly as possible, while delaying :meth:`telegram.Bot.send_message` is acceptable. * There are `different `_ rate limits for group chats and private chats. * When sending broadcast messages to a large number of users, these requests can typically be delayed for a longer time than messages that are direct replies to a user input. Args: callback (Callable[..., :term:`coroutine`]): The coroutine function that must be called to make the request. args (tuple[:obj:`object`]): The positional arguments for the :paramref:`callback` function. kwargs (dict[:obj:`str`, :obj:`object`]): The keyword arguments for the :paramref:`callback` function. endpoint (:obj:`str`): The endpoint that the request is made for, e.g. ``"sendMessage"``. data (dict[:obj:`str`, :obj:`object`]): The parameters that were passed to the method of :class:`~telegram.ext.ExtBot`. Any ``api_kwargs`` are included in this and any :paramref:`~telegram.ext.ExtBot.defaults` are already applied. Example: When calling:: await ext_bot.send_message( chat_id=1, text="Hello world!", api_kwargs={"custom": "arg"} ) then :paramref:`data` will be:: {"chat_id": 1, "text": "Hello world!", "custom": "arg"} rate_limit_args (:obj:`None` | :class:`object`): Custom arguments passed to the methods of :class:`~telegram.ext.ExtBot`. Can e.g. be used to specify the priority of the request. Returns: :obj:`bool` | dict[:obj:`str`, :obj:`object`] | :obj:`None`: The result of the callback function. Nr)rrrrrrrs rprocess_requestzBaseRateLimiter.process_request:rr)rN)__name__ __module__ __qualname____doc__ __slots__rrrrrrr boolr listdictstrr r r!rrrrs$IZZ\\T 3 #sE$$x.:X4Y*Y ZZ[T T S#X T  T 38n T "&)T  tXtH~- .T T r+rN)r%abcrrcollections.abcrtypingrrrr r telegram._utils.typesr telegram.ext._utils.typesr rrr+rr1s1&V#%::*,r c76?r r+