L idZddlmZmZddlmZddlmZddlm Z m Z m Z m Z m Z ddlmZe rddlmZe dd ZGd d ed eZGd d eZy)z-This module contains the BaseProcessor class.)ABCabstractmethod)AbstractAsyncContextManager) TracebackType) TYPE_CHECKINGAnyOptionalTypeVarfinal)TrackedBoundedSemaphore) Awaitable_BUPTBaseUpdateProcessor)boundceZdZdZdZdefdZdedefdZde e e d e e d e e dd fd Z edefd ZedefdZededddd fdZeddZeddZededddd fdZy )raAn abstract base class for update processors. You can use this class to implement your own update processor. Instances of this class can be used as asyncio context managers, where .. code:: python async with processor: # code is roughly equivalent to .. code:: python try: await processor.initialize() # code finally: await processor.shutdown() .. seealso:: :meth:`__aenter__` and :meth:`__aexit__`. .. seealso:: :wiki:`Concurrency` .. versionadded:: 20.4 Args: max_concurrent_updates (:obj:`int`): The maximum number of updates to be processed concurrently. If this number is exceeded, new updates will be queued until the number of currently processed updates decreases. Raises: :exc:`ValueError`: If :paramref:`max_concurrent_updates` is a non-positive integer. )_max_concurrent_updates _semaphoremax_concurrent_updatescz||_|jdkr tdt|j|_y)Nz4`max_concurrent_updates` must be a positive integer!)rr ValueErrorr r)selfrs g/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/telegram/ext/_baseupdateprocessor.py__init__zBaseUpdateProcessor.__init__Hs6'=$  & & *ST T1$2M2MNrreturncK |jd{|S7#t$r|jd{7wxYww)a+|async_context_manager| :meth:`initializes ` the Processor. Returns: The initialized Processor instance. Raises: :exc:`Exception`: If an exception is raised during initialization, :meth:`shutdown` is called in this case. N) initialize Exceptionshutdownrs r __aenter__zBaseUpdateProcessor.__aenter__NsG //# # # $ --/ ! !  s.A  A A?AAexc_typeexc_valexc_tbNc@K|jd{y7w)zD|async_context_manager| :meth:`shuts down ` the Processor.N)r )rr#r$r%s r __aexit__zBaseUpdateProcessor.__aexit___smmos c|jS)zM:obj:`int`: The maximum number of updates that can be processed concurrently.)rr!s rrz*BaseUpdateProcessor.max_concurrent_updateshs+++rcH|j|jjz S)a:obj:`int`: The number of updates currently being processed. Caution: This value is a snapshot of the current number of updates being processed. It may change immediately after being read. .. versionadded:: 21.11 )rr current_valuer!s rcurrent_concurrent_updatesz.BaseUpdateProcessor.current_concurrent_updatesms**T__-J-JJJrupdate coroutineAwaitable[Any]c Kyw)aCustom implementation of how to process an update. Must be implemented by a subclass. Warning: This method will be called by :meth:`process_update`. It should *not* be called manually. Args: update (:obj:`object`): The update to be processed. coroutine (:term:`Awaitable`): The coroutine that will be awaited to process the update. Nrr,r-s rdo_process_updatez%BaseUpdateProcessor.do_process_updateyc Kyw)zInitializes the processor so resources can be allocated. Must be implemented by a subclass. .. seealso:: :meth:`shutdown` Nr0r!s rrzBaseUpdateProcessor.initializer3r4c Kyw)zShutdown the processor so resources can be freed. Must be implemented by a subclass. .. seealso:: :meth:`initialize` Nr0r!s rr zBaseUpdateProcessor.shutdownr3r4cK|j4d{|j||d{dddd{y7/77 #1d{7swYyxYww)a0Calls :meth:`do_process_update` with a semaphore to limit the number of concurrent updates. Args: update (:obj:`object`): The update to be processed. coroutine (:term:`Awaitable`): The coroutine that will be awaited to process the update. N)rr2r1s rprocess_updatez"BaseUpdateProcessor.process_updatesX?? < <((; ; ; < < < ; < < < rCr2rr r0rrrErEs9I  $   rrEN)r=abcrr contextlibrtypesrtypingrrr r r telegram.ext._utils.asyncior collections.abcr rrrEr0rrrPsT&4#2???)45I<56KLcI