
    ^f                        d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	 ej
        dk     rddlmZ nddlmZ erddlmZ d	Z ed
          Z G d d          Z G d d          ZdS )z&Semaphores and concurrency primitives.    )annotationsN)deque)TYPE_CHECKINGCallableDeque)   
   )	ParamSpec)TracebackType)	DummyLockLaxBoundedSemaphorePc                  N    e Zd ZdZddZddZddZdddZdddZddZ	ddZ
dS )r   a  Asynchronous Bounded Semaphore.

    Lax means that the value will stay within the specified
    range even if released more times than it was acquired.

    Example:
    -------
        >>> x = LaxBoundedSemaphore(2)

        >>> x.acquire(print, 'HELLO 1')
        HELLO 1

        >>> x.acquire(print, 'HELLO 2')
        HELLO 2

        >>> x.acquire(print, 'HELLO 3')
        >>> x._waiters   # private, do not access directly
        [print, ('HELLO 3',)]

        >>> x.release()
        HELLO 3
    valueintreturnNonec                    |x| _         | _        t                      | _        | j        j        | _        | j        j        | _        d S N)initial_valuer   r   _waitingappend_add_waiterpopleft_pop_waiter)selfr   s     N/var/www/html/env/lib/python3.11/site-packages/kombu/asynchronous/semaphore.py__init__zLaxBoundedSemaphore.__init__.   s<    *//TZ&+gg=/=0    callbackCallable[P, None]partial_argsP.argspartial_kwargsP.kwargsboolc                    | j         }|dk    r|                     |||f           dS t          |dz
  d          | _          ||i | dS )a^  Acquire semaphore.

        This will immediately apply ``callback`` if
        the resource is available, otherwise the callback is suspended
        until the semaphore is released.

        Arguments:
        ---------
            callback (Callable): The callback to apply.
            *partial_args (Any): partial arguments to callback.
        r   F   T)r   r   max)r   r    r"   r$   r   s        r   acquirezLaxBoundedSemaphore.acquire4   sc    " 
A::hnEFFF5UQY**DJHl5n5554r   c                    	 |                                  \  }}} ||i | dS # t          $ r& t          | j        dz   | j                  | _        Y dS w xY w)zRelease semaphore.

        Note:
        ----
            If there are any waiters this will apply the first waiter
            that is waiting for the resource (FIFO order).
        r(   N)r   
IndexErrorminr   r   )r   waiterargskwargss       r   releasezLaxBoundedSemaphore.releaseN   s}    	$#'#3#3#5#5 FD& FD#F#####  	A 	A 	ATZ!^T-?@@DJJJJ	As   $ ,AAr(   nc                    | xj         |z  c_         | xj        |z  c_        t          |          D ]}|                                  dS )z6Change the size of the semaphore to accept more users.N)r   r   ranger1   )r   r2   _s      r   growzLaxBoundedSemaphore.grow]   sS    a

a

q 	 	ALLNNNN	 	r   c                z    t          | j        |z
  d          | _        t          | j        |z
  d          | _        dS )z6Change the size of the semaphore to accept less users.r   N)r)   r   r   )r   r2   s     r   shrinkzLaxBoundedSemaphore.shrinkd   s7     !3a!7;;a++


r   c                P    | j                                          | j        | _        dS )z@Reset the semaphore, which also wipes out any waiting callbacks.N)r   clearr   r   r   s    r   r:   zLaxBoundedSemaphore.cleari   s$    '


r   strc                    d                     | j        j        t          |           | j        t          | j                            S )Nz!<{} at {:#x} value:{} waiting:{}>)format	__class____name__idr   lenr   r;   s    r   __repr__zLaxBoundedSemaphore.__repr__n   s:    299N#RXXtz3t};M;M
 
 	
r   N)r   r   r   r   )r    r!   r"   r#   r$   r%   r   r&   )r   r   )r(   )r2   r   r   r   )r   r<   )r@   
__module____qualname____doc__r   r*   r1   r6   r8   r:   rC    r   r   r   r      s         .1 1 1 1   4$ $ $ $    , , , , ,
( ( ( (

 
 
 
 
 
r   r   c                  "    e Zd ZdZddZddZdS )r   zPretending to be a lock.r   c                    | S r   rG   r;   s    r   	__enter__zDummyLock.__enter__w   s    r   exc_typetype[BaseException] | Noneexc_valBaseException | Noneexc_tbTracebackType | Noner   c                    d S r   rG   )r   rK   rM   rO   s       r   __exit__zDummyLock.__exit__z   s	     	r   N)r   r   )rK   rL   rM   rN   rO   rP   r   r   )r@   rD   rE   rF   rJ   rR   rG   r   r   r   r   t   sB        ""        r   r   )rF   
__future__r   syscollectionsr   typingr   r   r   version_infotyping_extensionsr
   typesr   __all__r   r   r   rG   r   r   <module>r[      s   , , " " " " " " 



       1 1 1 1 1 1 1 1 1 1g+++++++       $###### /IcNN[
 [
 [
 [
 [
 [
 [
 [
|         r   