
    e?1i                        d dl mZ d dlZd dlmZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dlm
Z
 d dlmZ d d	lmZ d d
lmZ ddlmZ ddlmZ ddlmZ ddlmZ  ed      Zej                  r G d de      Zd*dZnd dlmZ d dlmZ  e e       d      Zd+dZ G d de      Z edd      Zer		 	 	 	 d,dZnej:                  Zd-dZd.d Zd.d!Z d"d#	 	 	 	 	 	 	 	 	 d/d$Z! G d% d&      Z"	 	 	 	 	 	 	 	 d0d'Z#	 	 	 	 	 	 	 	 d0d(Z$d1d)Z%y)2    )annotationsN)Context)Any)	Awaitable)Callable)	Coroutine)Optional)TYPE_CHECKING)TypeVar   )memoized_property   )exc)Protocol)	TypeGuard_Tc                  :    e Zd ZU ded<   ded<   d	dZd
dZddZy)greenletbooldeadzOptional[Context]
gr_contextc                     y N selffndrivers      k/home/www/therecruiter.miabetepe.com/venv/lib/python3.12/site-packages/sqlalchemy/util/_concurrency_py3k.py__init__zgreenlet.__init__$   s        c                     y r   r   )r   args     r   throwzgreenlet.throw'       r!   c                     y r   r   )r   values     r   switchzgreenlet.switch*   r%   r!   Nr   zCallable[..., Any]r   r   )r#   r   returnr   )r'   r   r*   r   )__name__
__module____qualname____annotations__r    r$   r(   r   r!   r   r   r       s    
%%			r!   r   c                      y r   r   r   r!   r   
getcurrentr0   -   s    r!   )r0   )r   r   c                |    t        | t               xs* t        | t        j                  t        j                  f      S r   )
isinstance	ExceptionasyncioTimeoutErrorCancelledError)es    r   is_exit_exceptionr8   ;   s8     !Y'' :	G  '"8"89, r!   c                       e Zd ZU ded<   ddZy)_AsyncIoGreenletr   r   c                p    t        j                  | ||       || _        t        r|j                  | _        y y r   )r   r    r   _has_gr_contextr   r   s      r   r    z_AsyncIoGreenlet.__init__K   s0    $F+$//DO r!   Nr)   )r+   r,   r-   r.   r    r   r!   r   r:   r:   H   s    
J0r!   r:   _T_coT)	covariantc                     y r   r   	awaitables    r   iscoroutinerB   V   s     	r!   c                <    t        |       r| j                          y y r   )rB   closer@   s    r   _safe_cancel_awaitablerE   _   s     9 r!   c                    t               }t        |t              s t        |        t	        j
                  d      |j                  j                  |       S )zAwaits an async function in a sync method.

    The sync method must be inside a :func:`greenlet_spawn` context.
    :func:`await_only` calls cannot be nested.

    :param awaitable: The coroutine to call.

    zjgreenlet_spawn has not been called; can't call await_only() here. Was IO attempted in an unexpected place?)r0   r2   r:   rE   r   MissingGreenletr   r(   )rA   currents     r   
await_onlyrI   f   sM     lGg/0y)!!=
 	
 >>  ++r!   c                   t               }t        |t              sKt               }|j	                         r t        |        t        j                  d      |j                  |       S |j                  j                  |       S )zAwaits an async function in a sync method.

    The sync method must be inside a :func:`greenlet_spawn` context.
    :func:`await_fallback` calls cannot be nested.

    :param awaitable: The coroutine to call.

    zgreenlet_spawn has not been called and asyncio event loop is already running; can't call await_fallback() here. Was IO attempted in an unexpected place?)r0   r2   r:   get_event_loop
is_runningrE   r   rG   run_until_completer   r(   )rA   rH   loops      r   await_fallbackrO      sp     lGg/0??"9-%%; 
 &&y11>>  ++r!   F)_require_awaitc               v  K   t        | t                     }d}	  |j                  |i |}|j                  s+d}	 | d{   }|j                  |      }|j                  s+|`|r|st        j                  d      |S 7 ?# t        $ r$  |j
                  t        j                          }Y Xw xY w# |`w xY ww)aG  Runs a sync function ``fn`` in a new greenlet.

    The sync function can then use :func:`await_only` to wait for async
    functions.

    :param fn: The sync callable to call.
    :param \*args: Positional arguments to pass to the ``fn`` callable.
    :param \*\*kwargs: Keyword arguments to pass to the ``fn`` callable.
    FTNzThe current operation required an async execution but none was detected. This will usually happen when using a non compatible DBAPI driver. Please ensure that an async DBAPI is used.)r:   r0   r(   r   BaseExceptionr$   sysexc_infor   r   AwaitRequired)r   rP   argskwargscontextswitch_occurredresultr'   s           r   greenlet_spawnr[      s     " r:<0G
 O00,,"O
/ % !. ,, NoG
 	

 M# %  8 '7	8 NsQ   B9 B2 B  B B B2 #B9 B *B/,B2 .B//B2 2B66B9c                  .    e Zd Zedd       ZddZddZy)AsyncAdaptedLockc                *    t        j                         S r   )r4   Lockr   s    r   mutexzAsyncAdaptedLock.mutex   s     ||~r!   c                H    t        | j                  j                               S r   )rO   ra   acquirer`   s    r   	__enter__zAsyncAdaptedLock.__enter__   s     djj00233r!   c                8    | j                   j                          y r   )ra   release)r   r#   kws      r   __exit__zAsyncAdaptedLock.__exit__   s    

r!   N)r*   zasyncio.Lock)r*   r   )r#   r   rg   r   r*   None)r+   r,   r-   r   ra   rd   rh   r   r!   r   r]   r]      s     
4
r!   r]   c                z    t               }|j                         rt        d      |j                   | |i |      S )for test suite/ util onlyz]for async run coroutine we expect that no greenlet or event loop is running when we start out)rK   rL   r3   rM   r   rV   rW   rN   s       r   "_util_async_run_coroutine_functionrm      sE    
 D0
 	
 ""2t#6v#677r!   c                    t               }|j                         s|j                  t        | g|i |      S t	        t               t              sJ  | |i |S )rk   )rK   rL   rM   r[   r2   r0   r:   rl   s       r   _util_async_runro      s[    
 D??&&~b'J4'J6'JKK *,(89994"6""r!   c                     	 t        j                         S # t        $ r Y nw xY wt        j                         j	                         S )z}vendor asyncio.get_event_loop() for python 3.7 and above.

    Python 3.10 deprecates get_event_loop() as a standalone.

    )r4   get_running_loopRuntimeErrorget_event_loop_policyrK   r   r!   r   rK   rK      sB    ''))  ((*99;;s    	"")r*   r   )r7   rR   r*   r   )rA   zAwaitable[_T_co]r*   z%TypeGuard[Coroutine[Any, Any, _T_co]])rA   zAwaitable[Any]r*   ri   )rA   zAwaitable[_T]r*   r   )
r   zCallable[..., _T]rV   r   rP   r   rW   r   r*   r   )r   z'Callable[..., Coroutine[Any, Any, Any]]rV   r   rW   r   r*   r   )r*   zasyncio.AbstractEventLoop)&
__future__r   r4   contextvarsr   rS   typingr   r   r   r   r	   r
   r   langhelpersr    r   util.typingr   r   r   r   r0   hasattrr<   r8   r:   r=   rB   rE   rI   rO   r[   r]   rm   ro   rK   r   r!   r   <module>r{      sW   #   
          *  " #T]	8  $! *,50x 0 	4(#	. %%K,4,< !/// / 	/
 /d  8/88;8GJ88#/#8;#GJ##<r!   