
    i                       U d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	m
Z
mZmZ ddlmZmZ  ej                   d      Z ed      Zej&                  Zej(                  Zej*                  Zej,                  Zej0                  Zej2                  Zd	ed
<   dZd	ed<   er#ej:                  Zd	ed<   ej:                  Zd	ed<   n9 G d de       Z! G d dej:                  e!      Z G d dej:                  e!      Zd%dZ"d%dZ# G d dee         Z G d dej&                        Z$ G d dej(                        Z% G d dee         Z&	 	 d&	 	 	 	 	 	 	 d'dZ'	 	 d&	 	 	 	 	 	 	 d(dZ(dd d!	 	 	 	 	 	 	 d)d"Z)dd d!	 	 	 	 	 	 	 d*d#Z*d+d$Z+y),z
Utilities to ease the differences between async and sync code.

These object offer a similar interface between sync and async versions; the
script async_to_sync.py will replace the async names with the sync names
when generating the sync version.
    )annotationsN)AnyCallable	CoroutineTYPE_CHECKING   )	TypeAliasTypeVarzpsycopg.poolTr	   Workerasyncio.Task[None]AWorker_GQueue_AGQueuec                      e Zd Zd Zy)FakeGenericMetac                    | S N )selfitems     u/var/www/html/hwPaymentPortal-be-dev/hw-payment-portal-api/venv/lib/python3.12/site-packages/psycopg_pool/_acompat.py__getitem__zFakeGenericMeta.__getitem__,   s    K    N)__name__
__module____qualname__r   r   r   r   r   r   +   s    	r   r   c                      e Zd Zy)r   Nr   r   r   r   r   r   r   r   /       r   )	metaclassc                      e Zd Zy)r   Nr   r   r   r   r   r   2   r    r   c                 >    t        j                         j                  S r   )	threadingcurrent_threadnamer   r   r   current_thread_namer'   6   s    ##%***r   c                 R    t        j                         } | r| j                         S dS )Nz	<no task>)asynciocurrent_taskget_name)ts    r   current_task_namer-   :   s#    A1::<-+-r   c                  &     e Zd ZdZdd fdZ xZS )Queuez>
    A Queue subclass with an interruptible get() method.
    c                ,    |d}t         |   ||      S )Ng     @)superget)r   blocktimeout	__class__s      r   r2   z	Queue.getD   s    ?(Gw{5'**r   )TN)r3   boolr4   float | Nonereturnr   )r   r   r   __doc__r2   __classcell__)r5   s   @r   r/   r/   ?   s    + +r   r/   c                      e Zd ZdZddZy)AEventz
    Subclass of asyncio.Event adding a wait with timeout like threading.Event.

    wait_timeout() is converted to wait() by async_to_sync.
    c                   K   	 t        j                  | j                         |       d {    y7 # t         j                  $ r Y yw xY wwNTFr)   wait_forwaitTimeoutErrorr   r4   s     r   wait_timeoutzAEvent.wait_timeoutR   F     	""499;888 9## 		1   A'3 13 A3 A	AA		ANr4   floatr8   r6   r   r   r   r9   rD   r   r   r   r<   r<   K       r   r<   c                      e Zd ZdZddZy)
AConditionz
    Subclass of asyncio.Condition adding a wait with timeout like threading.Condition.

    wait_timeout() is converted to wait() by async_to_sync.
    c                   K   	 t        j                  | j                         |       d {    y7 # t         j                  $ r Y yw xY wwr>   r?   rC   s     r   rD   zACondition.wait_timeouta   rE   rF   NrG   rI   r   r   r   rL   rL   Z   rJ   r   rL   c                      e Zd Zy)AQueueNr   r   r   r   rO   rO   i   s    r   rO   c                6    t        j                   | | |      S )z,
    Equivalent to asyncio.create_task.
    )r&   )r)   create_task)fargsr&   s      r   aspawnrT   m   s     q$xd33r   c                X    t        j                  | ||d      }|j                          |S )z=
    Equivalent to creating and running a daemon thread.
    T)targetrS   r&   daemon)r$   Threadstart)rR   rS   r&   r,   s       r   spawnrZ   x   s(     	4EAGGIHr    )r4   timeout_hintc                  K   t        j                  | }	 | 3t        j                  t        j                  |      |        d{    y| d{    	 y7 7 # t         j                  $ r Y nw xY w|D ]Q  }|j                         rt        j                  d|j                         |        |s<t        j                  d|       S yw)7
    Equivalent to asyncio.gather or Thread.join()
    N)r4   z'couldn't stop task %r within %s secondshint: %s)	r)   gatherr@   shieldrB   doneloggerwarningr+   )r4   r\   tasksrA   r,   s        r   agatherrf      s      >>5!D""7>>$#7III 		 JJ 	 J 
  5668@!**,PWXNN:|45s_   C/A AA 
CA AA CA A A1.C0A11A C2Cc                    |D ]o  }|j                         s|j                  |        |j                         s6t        j                  d|j                  |        |sZt        j                  d|       q y)r^   z)couldn't stop thread %r within %s secondsr_   N)is_alivejoinrc   rd   r&   )r4   r\   re   r,   s       r   r`   r`      s\      5zz|	wzz|BAFFGTNN:|45r   c                ,    t        j                  |       S )zT
    Equivalent to asyncio.sleep(), converted to time.sleep() by async_to_sync.
    )r)   sleep)secondss    r   asleeprm      s     ==!!r   )r8   str)r   N)rR   z(Callable[..., Coroutine[Any, Any, None]]rS   tuple[Any, ...]r&   
str | Noner8   r   )rR   zCallable[..., Any]rS   ro   r&   rp   r8   threading.Thread)re   zasyncio.Task[Any]r4   r7   r\   rn   r8   None)re   rq   r4   r7   r\   rn   r8   rr   )rl   rH   r8   zCoroutine[Any, Any, None]),r9   
__future__r   timequeuer)   loggingr$   typingr   r   r   r   _compatr	   r
   	getLoggerrc   r   Event	ConditionRLockLockALockrk   rX   r   __annotations__r   r/   r   r   typer   r'   r-   r<   rL   rO   rT   rZ   rf   r`   rm   r   r   r   <module>r      s   #      : : '			>	*CL 		

$$	 $) ) GY$!--Hi'$ %++ 7==O +.
	+GAJ 	+W]] "" 	Xa[ 	 4/4
4 4 	4 



 
 	
 8<QS55(45KN5	54 7;PR55'35JM5	5""r   