
    ,hw1                       % S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKJ	r	J
r
JrJr  SSKJr  SSKJr  SSKJrJrJrJr  SS	KJr  SS
KJr  SSKJr  \R6                  r\R:                  r\R>                  r \RB                  r"\R6                  r#\R:                  r$\R>                  r%\RL                  " \'5      r(SSS jjr)SSS jjr*SSS jjr+SSS jjr,SSS jjr-\." \S5      (       a  \\R^                  \R`                  -  \Rb                  -  \\R^                  \Rd                  -  \Rb                  -  \ \R^                  \R`                  \Rd                  -  \Rb                  -  -  0r3O0 r3SSS jjr4\." \S5      (       a4  \\Rj                  \\Rl                  \ \Rj                  \Rl                  -  0r7O0 r7SSS jjr8S S jr9\(       a  \Rt                  r:S\;S'   S\Rx                  ;   aG  \Rx                  S   r=\=R}                  S5      (       a  \=\?" 5       ;  a  \@" S\=< 35      e\?" 5       \=   rAg\(       a  \R                  S:w  a  \9" 5       (       d  \:rAg\R                  \C" \SS5      L a  \-rAg\." \S5      (       a  \8rAg\)rAg)!z
Code concerned with waiting in different contexts (blocking, async, etc).

These functions are designed to consume the generators returned by the
`generators` module function and to return their final value.

    )annotationsN)EventTimeoutErrorget_event_loopwait_for)DefaultSelector   )errors)RVPQGen	PQGenConnWaitFunc)Ready)Wait)_psycopgc                    [        U 5      n[        5        nUR                  X5         UR                  US9=n(       d  U R	                  [
        5        M.  UR                  U5        US   S   nU R	                  U5      nUR                  X5        Mj  ! , (       d  f       g= f! [         a  nUR                  nUs SnA$ SnAff = f)a  
Wait for a generator using the best strategy available.

:param gen: a generator performing database operations and yielding
    `Ready` values when it would block.
:param fileno: the file descriptor to wait on.
:param interval: interval (in seconds) to check for other interrupt, e.g.
    to allow Ctrl-C. If zero or None, wait indefinitely.
:return: whatever `!gen` returns on completion.

Consume `!gen`, scheduling `fileno` for completion when it is reported to
block. Once ready again send the ready state back to `!gen`.
timeoutr   r	   N	nextr   registerselectsend
READY_NONE
unregisterStopIterationvalue)	genfilenointervalsselrlistreadyexrvs	            J/var/www/html/Ai_home/venv/lib/python3.13/site-packages/psycopg/waiting.pywait_selectorr(   &   s    I#LL#!$H!===HHZ(v&aHHUOV'    	s5   B% A=B
B"B% "B% %
C/C<CCc                    [        U 5      u  p#U(       d  Sn[        5        nUR                  X#5         UR                  US9=n(       d  U R	                  [
        5        M.  UR                  U5        US   S   nU R	                  U5      u  p#UR                  X#5        Ml  ! , (       d  f       g= f! [         a  nUR                  nUs SnA$ SnAff = f)a  
Wait for a connection generator using the best strategy available.

:param gen: a generator performing database operations and yielding
    (fd, `Ready`) pairs when it would block.
:param interval: interval (in seconds) to check for other interrupt, e.g.
    to allow Ctrl-C. If zero or None, wait indefinitely.
:return: whatever `!gen` returns on completion.

Behave like in `wait()`, but take the fileno to wait from the generator
itself, which might change during processing.
Nr   r   r	   r   )	r   r    r   r!   r"   r#   r$   r%   r&   s	            r'   	wait_connr*   G   s    I	H#LL#!$H!===HHZ(v&aHHUO	V'    	s5    B2 A?B!!
B/+B2 /B2 2
C<C	CCc                  ^
^#    [        5       m
[        5       nSU
U4S jjn [        U 5      n U[        -  nU[        -  nU(       d   U(       d  [
        R                  " SU 35      eT
R                  5         SmU(       a  UR                  X[        5        U(       a  UR                  X[        5         Ub$   [        T
R                  5       U5      I Sh  vN   OT
R                  5       I Sh  vN   U(       a  UR                  U5        U(       a  UR!                  U5        U R#                  T5      nGM	   Na! [         a     NRf = f NZ! U(       a  UR                  U5        U(       a  UR!                  U5        f f = f! [$         a$  n[
        R&                  " [)        U5      5      eSnAf[*         a  nUR,                  n	U	s SnA$ SnAff = f7f)a  
Coroutine waiting for a generator to complete.

:param gen: a generator performing database operations and yielding
    `Ready` values when it would block.
:param fileno: the file descriptor to wait on.
:param interval: interval (in seconds) to check for other interrupt, e.g.
    to allow Ctrl-C. If None, wait indefinitely.
:return: whatever `!gen` returns on completion.

Behave like in `wait()`, but exposing an `asyncio` interface.
c                0   > TU -  mTR                  5         g Nsetstateevr$   s    r'   wakeupwait_async.<locals>.wakeup}   s    
    bad poll status: r   Nr1   r   returnNone)r   r   r   WAIT_RWAIT_WeInternalErrorclear
add_readerREADY_R
add_writerREADY_Wr   waitr   remove_readerremove_writerr   OSErrorOperationalErrorstrr   r   )r   r   r    loopr3   r!   readerwriterr%   r&   r2   r$   s             @@r'   
wait_asyncrL   i   sz     
BD 
!IZFZFfoo(9!&=>>HHJE88/'&rwwy(;;; '')OO&&v.&&v.A1  <'  $&&v.&&v.   *  R)) 	s   GBF 5E 9D: D8D: E /E
0E 4AF 8D: :
EE EE 3E??F 
GF++G8GGGGGc                b  ^
^#    [        5       m
[        5       nSU
U4S jjn [        U 5      u  pE U[        -  nU[        -  nU(       d   U(       d  [
        R                  " SU 35      eT
R                  5         SmU(       a  UR                  XC[        5        U(       a  UR                  XC[        5         U(       a$   [        T
R                  5       U5      I Sh  vN   OT
R                  5       I Sh  vN   U(       a  UR                  U5        U(       a  UR!                  U5        U R#                  T5      u  pEGM   Nc! [         a     NTf = f N\! U(       a  UR                  U5        U(       a  UR!                  U5        f f = f! [$         a  nUR&                  n	U	s SnA$ SnAff = f7f)a  
Coroutine waiting for a connection generator to complete.

:param gen: a generator performing database operations and yielding
    (fd, `Ready`) pairs when it would block.
:param interval: interval (in seconds) to check for other interrupt, e.g.
    to allow Ctrl-C. If zero or None, wait indefinitely.
:return: whatever `!gen` returns on completion.

Behave like in `wait()`, but take the fileno to wait from the generator
itself, which might change during processing.
c                *   > U mTR                  5         g r-   r.   r0   s    r'   r3   wait_conn_async.<locals>.wakeup   s    
r5   r6   r   Nr7   )r   r   r   r:   r;   r<   r=   r>   r?   r@   rA   rB   r   rC   r   rD   rE   r   r   r   )r   r    rI   r3   r   r!   rJ   rK   r%   r&   r2   r$   s             @@r'   wait_conn_asyncrP      s]     
BD 
I	ZFZFfoo(9!&=>>HHJE88/&rwwy(;;; '')OO&&v.&&v.IF1  <'  $&&v.&&v.   	s   F/BF
 7E ?E E E !E 5E6E :AF
  E 
EE EE 3FF
 

F,F'!F,"F/'F,,F/c                    [        U 5      nSnU4n [        R                  " U[        -  (       a  UOUU[        -  (       a  UOUUU5      u  pgnSn	U(       a  [        n	U(       a	  U	[
        -  n	U	(       d  U R                  [        5        Mz  U R                  U	5      nM  ! [         a  n
U
R                  nUs Sn
A
$ Sn
A
ff = f)zv
Wait for a generator using select where supported.

BUG: on Linux, can't select on FD >= 1024. On Windows it's fine.
 r   N)
r   r   r:   r;   r@   rB   r   r   r   r   )r   r   r    r!   emptyfnlistrlwlxlr$   r%   r&   s               r'   wait_selectrX      s    If*%f*%	JBB E $A! $  	s   BB 
C)B<6C<CEpollSelectorc                L    [        U 5      nUb  US:  a  Sn[        R                  " 5        n[        U   nUR	                  X5         UR                  U5      =n(       d  U R                  [        5        M0  US   S   nSnU[        R                  ) -  (       a  [        nU[        R                  ) -  (       a	  U[        -  nU R                  U5      n[        U   nUR                  X5        M  ! , (       d  f       g= f! [         a  n	U	R                  n
U
s Sn	A	$ Sn	A	ff = f)a  
Wait for a generator using epoll where supported.

Parameters are like for `wait()`. If it is detected that the best selector
strategy is `epoll` then this function will be used instead of `wait`.

See also: https://linux.die.net/man/2/epoll_ctl

BUG: if the connection FD is closed, `epoll.poll()` hangs. Same for
EpollSelector. For this reason, wait_poll() is currently preferable.
To reproduce the bug:

    export PSYCOPG_WAIT_FUNC=wait_epoll
    pytest tests/test_concurrency.py::test_concurrent_close
Nr   g        r	   )r   r   epoll_epoll_evmasksr   pollr   r   EPOLLOUTr@   EPOLLINrB   modifyr   r   )r   r   r    r!   r[   evmaskfileevsr2   r$   r%   r&   s              r'   
wait_epollrc     s     Ix!|H\\^u#A&FNN6*#(::h#777HHZ(QZ]((#E'W$EHHUO'*V,  ^"  	s5   +D CC00
C>:D >D 
D#DD#D#PollSelectorc                F    [        U 5      nUb  US:  a  SnO[        US-  5      n[        R                  " 5       n[        U   nUR                  X5         UR                  U5      =n(       d  U R                  [        5        M0  US   S   nSnU[        R                  ) -  (       a  [        nU[        R                  ) -  (       a	  U[        -  nU R                  U5      n[        U   nUR                  X5        M  ! [         a  n	U	R                  n
U
s Sn	A	$ Sn	A	ff = f)zU
Wait for a generator using poll where supported.

Parameters are like for `wait()`.
Nr   g     @@r	   )r   intr   r]   _poll_evmasksr   r   r   POLLOUTr@   POLLINrB   r`   r   r   )r   r   r    r!   r]   ra   rb   r2   r$   r%   r&   s              r'   	wait_pollrj   F  s    Ix!|H8f,-H{{}q!f%#yy22G2$ABEV^^O#V]]N" A"1%FKK'   	s   C<C> >
D DD D c                     [         R                  R                  S5      =n (       a   U R                  S5      (       a  g gg! [         a   n[
        R                  SU5         SnAgSnAff = f)z
Detect if some greenlet library has patched the select library.

If this is the case, avoid to use the wait_c function as it doesn't behave
in a collaborative way.

Currently supported: gevent.
zgevent.monkeyr   Tz+failed to detect gevent monkey-patching: %sNF)sysmodulesgetis_module_patched	Exceptionloggerwarning)mr%   s     r'   _is_select_patchedrt   k  si     KKOOO,,q,	N""8,, -
   	NNNH"MM	Ns   A 
A,A''A,r   rC   PSYCOPG_WAIT_FUNCwait_zHPSYCOPG_WAIT_FUNC should be the name of an available wait function; got win32SelectSelectorr-   )r   z	PQGen[RV]r   rf   r    float | Noner8   r   )r   zPQGenConn[RV]r    ry   r8   r   )r8   bool)D__doc__
__future__r   osrl   r   logging	selectorsasyncior   r   r   r   r    r
   r<   abcr   r   r   r   _enumsr   r   _cmoduler   Rr:   Wr;   RWWAIT_RWNONEr   r@   rB   READY_RW	getLogger__name__rq   r(   r*   rL   rP   rX   hasattrEPOLLONESHOTr_   EPOLLERRr^   r\   rc   ri   rh   rg   rj   rt   wait_c__annotations__environfname
startswithglobalsImportErrorrC   platformgetattrrR   r5   r'   <module>r      sD   # 	 
    A A %  / / "   		
''ZZ

''
''88			8	$BD:z7zD 9o&&##fnn4vF##foo5G$$>>FOO+foo=?N N)X 9n%%/M M"J( __F  "**$JJ*+EG$$WY(>9
 	
 9UD
 #,,')2D2F2FD')5Et"LLDY'' D Dr5   