
    g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j        Zej        Zd	ed
<   dZd	ed<   e	rej        Zd	ed<   ej        Zd	ed<   n8 G d de           Z! G d dej        e!          Z G d dej        e!          Zd9dZ"d9d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=d3Z)dd+d,d>d4Z*d?d8Z+dS )@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)TYPE_CHECKINGAnyCallable	Coroutine   )	TypeAliasTypeVarzpsycopg.poolTr	   Workerasyncio.Task[None]AWorker_GQueue_AGQueuec                      e Zd Zd ZdS )FakeGenericMetac                    | S N )selfitems     e/var/www/html/Pagina-Ingenieria-Requisitos/venv/lib/python3.11/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dS )r   Nr   r   r   r   r   r   r   r   /           r   )	metaclassc                      e Zd ZdS )r   Nr   r   r   r   r   r   2   r    r   returnstrc                 2    t          j                    j        S r   )	threadingcurrent_threadnamer   r   r   current_thread_namer)   6   s    #%%**r   c                 X    t          j                    } | r|                                 n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.
    TNblockbooltimeoutfloat | Noner#   r   c                P    |d}t                                          ||          S )Ng     @)superget)r   r2   r4   	__class__s      r   r8   z	Queue.getD   s%    ?(Gww{{5'***r   )TN)r2   r3   r4   r5   r#   r   )r   r   r   __doc__r8   __classcell__)r9   s   @r   r1   r1   ?   sL         + + + + + + + + + + +r   r1   c                      e Zd ZdZddZdS )	AEventz
    Subclass of asyncio.Event adding a wait with timeout like threading.Event.

    wait_timeout() is converted to wait() by async_to_sync.
    r4   floatr#   r3   c                   K   	 t          j        |                                 |           d {V  dS # t           j        $ r Y dS w xY wNTFr+   wait_forwaitTimeoutErrorr   r4   s     r   wait_timeoutzAEvent.wait_timeoutR   b      	"499;;8888888884# 	 	 	55	   -3 AANr4   r>   r#   r3   r   r   r   r:   rF   r   r   r   r=   r=   K   2              r   r=   c                      e Zd ZdZddZdS )	
AConditionz
    Subclass of asyncio.Condition adding a wait with timeout like threading.Condition.

    wait_timeout() is converted to wait() by async_to_sync.
    r4   r>   r#   r3   c                   K   	 t          j        |                                 |           d {V  dS # t           j        $ r Y dS w xY wr@   rA   rE   s     r   rF   zACondition.wait_timeouta   rG   rH   NrI   rJ   r   r   r   rM   rM   Z   rK   r   rM   c                      e Zd ZdS )AQueueNr   r   r   r   rP   rP   i   s        Dr   rP   r   f(Callable[..., Coroutine[Any, Any, None]]argstuple[Any, ...]r(   
str | Nonec                4    t          j         | | |          S )z,
    Equivalent to asyncio.create_task.
    )r(   )r+   create_task)rQ   rS   r(   s      r   aspawnrX   m   s      qq$xd3333r   Callable[..., Any]threading.Threadc                ^    t          j        | ||d          }|                                 |S )z=
    Equivalent to creating and running a daemon thread.
    T)targetrS   r(   daemon)r&   Threadstart)rQ   rS   r(   r.   s       r   spawnr`   x   s/     	4EEEAGGIIIHr    )r4   timeout_hinttasksasyncio.Task[Any]r4   r5   rb   Nonec                  K   t          j        | }	 | /t          j        t          j        |          |            d{V  n| d{V  dS # t           j        $ r Y nw xY w|D ]b}|                                rt                              d|                                |            |rt                              d|           cdS )7
    Equivalent to asyncio.gather or Thread.join()
    N)r4   z'couldn't stop task %r within %s secondshint: %s)	r+   gatherrB   shieldrD   doneloggerwarningr-   )r4   rb   rc   rC   r.   s        r   agatherrn      s       >5!D"7>$#7#7IIIIIIIIIIIJJJJJJJ 	    
  5 56688 	@!**,,PWXXX 	5NN:|4445 5s   9A AAc                
   |D ]}|                                 s|                    |            |                                 sAt                              d|j        |            |rt                              d|           dS )rg   z)couldn't stop thread %r within %s secondsrh   N)is_alivejoinrl   rm   r(   )r4   rb   rc   r.   s       r   ri   ri      s      5 5zz|| 		wzz|| 	BAFGTTT 	5NN:|4445 5r   secondsr>   Coroutine[Any, Any, None]c                *    t          j        |           S )zT
    Equivalent to asyncio.sleep(), converted to time.sleep() by async_to_sync.
    )r+   sleep)rr   s    r   asleeprv      s     =!!!r   )r#   r$   )r   N)rQ   rR   rS   rT   r(   rU   r#   r   )rQ   rY   rS   rT   r(   rU   r#   rZ   )rc   rd   r4   r5   rb   r$   r#   re   )rc   rZ   r4   r5   rb   r$   r#   re   )rr   r>   r#   rs   ),r:   
__future__r   timequeuer+   loggingr&   typingr   r   r   r   _compatr	   r
   	getLoggerrl   r   Event	ConditionRLockLockALockru   r^   r   __annotations__r   r1   r   r   typer   r)   r/   r=   rM   rP   rX   r`   rn   ri   rv   r   r   r   <module>r      sJ     # " " " " "         : : : : : : : : : : : : ' ' ' ' ' ' ' '		>	*	*GCLL 		
$ $ $ $ $) ) ) ) )  G$$$$!-H'''''    $       %+        7=O    + + + +. . . .
	+ 	+ 	+ 	+ 	+GAJ 	+ 	+ 	+    W]       "   	 	 	 	 	Xa[ 	 	 	 4 4 4 4 4 
 
 
 
 
 8<QS5 5 5 5 5 54 7;PR5 5 5 5 5 5"" " " " " "r   