
    Yi                         S r SSKJrJr  SSKJr  SSKJr  SSKJ	r	  SSK
JrJrJrJrJr  \(       a  SSKJr  \" SS	S
9r " S S	\S	   \5      r " S S\5      rg)z-This module contains the BaseProcessor class.    )ABCabstractmethod)BoundedSemaphore)AbstractAsyncContextManager)TracebackType)TYPE_CHECKINGAnyOptionalTypeVarfinal)	Awaitable_BUPTBaseUpdateProcessor)boundc                       \ rS rSrSrSrS\4S jrS\S\4S jr	S	\
\\      S
\
\   S\
\   SS4S jr\S\4S j5       r\S\SSSS4S j5       r\SS j5       r\SS j5       r\S\SSSS4S j5       rSrg)r       aL  An 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
_semaphoremax_concurrent_updatesc                 z    Xl         U R                  S:  a  [        S5      e[        U R                  5      U l        g )N   z4`max_concurrent_updates` must be a positive integer!)r   r   
ValueErrorr   r   )selfr   s     L/app/.venv/lib/python3.13/site-packages/telegram/ext/_baseupdateprocessor.py__init__BaseUpdateProcessor.__init__F   s4    '=$&&*STT*4+F+FG    r   returnc                    #     U R                  5       I Sh  vN   U $  N! [         a    U R                  5       I Sh  vN    e f = f7f)z|async_context_manager| :meth:`initializes <initialize>` 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	Exceptionshutdownr   s    r   
__aenter__BaseUpdateProcessor.__aenter__L   sF     	//### 	 $ 	--/!!	s/   A    A  AA AAexc_typeexc_valexc_tbNc                 @   #    U R                  5       I Sh  vN   g N7f)zD|async_context_manager| :meth:`shuts down <shutdown>` the Processor.N)r"   )r   r&   r'   r(   s       r   	__aexit__BaseUpdateProcessor.__aexit__]   s      mmos   c                     U R                   $ )zM:obj:`int`: The maximum number of updates that can be processed concurrently.)r   r#   s    r   r   *BaseUpdateProcessor.max_concurrent_updatesf   s     +++r   update	coroutineAwaitable[Any]c                    #    g7f)af  Custom 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.
N r   r.   r/   s      r   do_process_update%BaseUpdateProcessor.do_process_updatek           c                    #    g7f)zInitializes the processor so resources can be allocated. Must be implemented by a
subclass.

.. seealso::
    :meth:`shutdown`
Nr2   r#   s    r   r    BaseUpdateProcessor.initialize}   r6   r7   c                    #    g7f)zzShutdown the processor so resources can be freed. Must be implemented by a subclass.

.. seealso::
    :meth:`initialize`
Nr2   r#   s    r   r"   BaseUpdateProcessor.shutdown   r6   r7   c                    #    U R                    ISh  vN   U R                  X5      I Sh  vN   SSS5      ISh  vN   g N. N N	! , ISh  vN  (       d  f       g= f7f)a   Calls :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)r   r4   r3   s      r   process_update"BaseUpdateProcessor.process_update   s;      ???((;;; #??; #???sQ   A"AA"AAAA"AA"AA"AAAA"r   N)__name__
__module____qualname____firstlineno____doc__	__slots__intr   r   r$   r
   typeBaseExceptionr   r*   propertyr   r   objectr4   r    r"   r   r=   __static_attributes__r2   r   r   r   r       s   !F :IHs Hu  "4./ -( '	
 
 , , ,  $ 
	 "     << $< 
	< <r   c                   F    \ rS rSrSrSrS\SSSS4S	 jrSS
 jrSS jr	Sr
g)SimpleUpdateProcessor   a  Instance of :class:`telegram.ext.BaseUpdateProcessor` that immediately awaits the
coroutine, i.e. does not apply any additional processing. This is used by default when
:attr:`telegram.ext.ApplicationBuilder.concurrent_updates` is :obj:`int`.

.. versionadded:: 20.4
r2   r.   r/   r0   r   Nc                 $   #    UI Sh  vN   g N7f)zImmediately awaits the coroutine, i.e. does not apply any additional processing.

Args:
    update (:obj:`object`): The update to be processed.
    coroutine (:term:`Awaitable`): The coroutine that will be awaited to process the
        update.
Nr2   r3   s      r   r4   'SimpleUpdateProcessor.do_process_update   s      s   c                    #    g7fzDoes nothing.Nr2   r#   s    r   r     SimpleUpdateProcessor.initialize   r6   r7   c                    #    g7frR   r2   r#   s    r   r"   SimpleUpdateProcessor.shutdown   r6   r7   r?   )r@   rA   rB   rC   rD   rE   rJ   r4   r    r"   rK   r2   r   r   rM   rM      s9     I $ 
	r   rM   N)rD   abcr   r   asyncior   
contextlibr   typesr   typingr   r	   r
   r   r   collections.abcr   r   r   rM   r2   r   r   <module>r\      sT   & 4 # $ 2  ? ?)45}<56KLc }<@/ r   