
    3fi                       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mZ ddlmZ ddlmZmZ ddlmZ  ej*                  d	      Z ed
      Z ed      Zej2                  Zej4                  Zej6                  Zej8                  Zej<                  Zej>                  Z de!d<   ejD                  d   Z#de!d<   d#dZ$d#dZ% G d dejL                  e         Z& G d dej2                        Z' G d dej4                        Z( G d dejL                  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.e	 	 	 	 	 	 	 	 d*d        Z/e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	Awaitable	ParamSpec	TypeAliasoverloadisawaitable)Callable	Coroutine   )TypeVarzpsycopg.poolTPr   WorkerAWorkerc                 >    t        j                         j                  S N)	threadingcurrent_threadname     S/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/psycopg_pool/_acompat.pycurrent_thread_namer   '   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)selfblocktimeout	__class__s      r   r&   z	Queue.get5   s    ?(Gw{5'**r   )TN)r(   boolr)   float | Nonereturnr   )__name__
__module____qualname____doc__r&   __classcell__)r*   s   @r   r#   r#   0   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'   r)   s     r   wait_timeoutzAEvent.wait_timeoutC   F     	""499;888 9## 		1   A'3 13 A3 A	AA		ANr)   floatr-   r+   r.   r/   r0   r1   r<   r   r   r   r4   r4   <       r   r4   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r6   r7   r;   s     r   r<   zACondition.wait_timeoutR   r=   r>   Nr?   rA   r   r   r   rD   rD   K   rB   r   rD   c                      e Zd Zy)AQueueN)r.   r/   r0   r   r   r   rG   rG   Z   s    r   rG   c                6    t        j                   | | |      S )z,
    Equivalent to asyncio.create_task.
    )r   )r   create_task)fargsr   s      r   aspawnrL   ^   s     q$xd33r   c                X    t        j                  | ||d      }|j                          |S )z=
    Equivalent to creating and running a daemon thread.
    T)targetrK   r   daemon)r   Threadstart)rJ   rK   r   r    s       r   spawnrR   i   s(     	4EAGGIHr    )r)   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)r)   z'couldn't stop task %r within %s secondshint: %s)	r   gatherr8   shieldr:   doneloggerwarningr   )r)   rT   tasksr9   r    s        r   agatherr^   v   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)rV   z)couldn't stop thread %r within %s secondsrW   N)is_alivejoinr[   r\   r   )r)   rT   r]   r    s       r   rX   rX      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   asleepre      s     ==!!r   c                   K   y wr   r   rJ   rK   kwargss      r   ensure_asyncri      s      	   c                   K   y wr   r   rg   s      r   ri   ri      s	     SVrj   c                L   K    | |i |}t        |      r
| d {   }|S 7 wr   r	   )rJ   rK   rh   rvs       r   ri   ri      s/     
 
D	F	B2XI s   $"$)r-   str)r   N)rJ   z(Callable[..., Coroutine[Any, Any, None]]rK   tuple[Any, ...]r   
str | Noner-   zasyncio.Task[None])rJ   zCallable[..., Any]rK   ro   r   rp   r-   threading.Thread)r]   zasyncio.Task[Any]r)   r,   rT   rn   r-   None)r]   rq   r)   r,   rT   rn   r-   rr   )rd   r@   r-   zCoroutine[Any, Any, None])rJ   zCallable[P, Awaitable[T]]rK   P.argsrh   P.kwargsr-   r   )rJ   zCallable[P, T]rK   rs   rh   rt   r-   r   )rJ   z4Callable[P, T] | Callable[P, Coroutine[Any, Any, T]]rK   rs   rh   rt   r-   r   )0r1   
__future__r   timequeuer   loggingr   typingr   r   r   r   r   inspectr
   collections.abcr   r   _compatr   	getLoggerr[   r   r   Event	ConditionRLockLockALockrc   rP   r   __annotations__Taskr   r   r!   r#   r4   rD   rG   rL   rR   r^   rX   re   ri   r   r   r   <module>r      s(   #      A A  / 			>	*CLcN 		

$$	 $\\$' '+.
	+EKKN 	+W]] "" 	W]]1 	 4/4
4 4 	4 



 
 	
 8<QS55(45KN5	54 7;PR55'35JM5	5"" 
 )/;C 

 
 V 
 V;  	r   