
    
 @g                        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-dAd4Z! G d5 d6          Z"dBd8Z#dBd9Z$dCd;Z%dS )D    )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dS )greenletbooldeadzOptional[Context]
gr_contextfnCallable[..., Any]driverc                    d S N selfr   r   s      U/var/www/piapp/venv/lib/python3.11/site-packages/sqlalchemy/util/_concurrency_py3k.py__init__zgreenlet.__init__$   s    C    argr   returnc                    d S r   r   )r   r#   s     r    throwzgreenlet.throw'       4r"   valuec                    d S r   r   )r   r(   s     r    switchzgreenlet.switch*   r'   r"   Nr   r   r   r   )r#   r   r$   r   )r(   r   r$   r   )__name__
__module____qualname____annotations__r!   r&   r*   r   r"   r    r   r       sg         


%%%%	 	 	 		 	 	 		 	 	 	 	 	r"   r   r$   c                     d S r   r   r   r"   r    
getcurrentr1   -   s    r"   )r1   )r   r   eBaseExceptionr   c                z    t          | t                     p%t          | t          j        t          j        f          S r   )
isinstance	ExceptionasyncioTimeoutErrorCancelledError)r2   s    r    is_exit_exceptionr:   ;   s:     !Y''' :	G '"89, , r"   c                  "    e Zd ZU ded<   d	dZdS )
_AsyncIoGreenletr   r   r   r   r   r   c                j    t          j        | ||           || _        t          r|j        | _        d S d S r   )r   r!   r   _has_gr_contextr   r   s      r    r!   z_AsyncIoGreenlet.__init__K   s>    $F+++ 	0$/DOOO	0 	0r"   Nr+   )r,   r-   r.   r/   r!   r   r"   r    r<   r<   H   s3         JJJ0 0 0 0 0 0r"   r<   _T_coT)	covariant	awaitableAwaitable[_T_co]%TypeGuard[Coroutine[Any, Any, _T_co]]c                    d S r   r   rA   s    r    iscoroutinerF   V   s	     	r"   Awaitable[Any]Nonec                P    t          |           r|                                  d S d S r   )rF   closerE   s    r    _safe_cancel_awaitablerK   _   s4     9  r"   Awaitable[_T]c                    t                      }t          |t                    s#t          |            t	          j        d          |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?)r1   r5   r<   rK   r   MissingGreenletr   r*   )rA   currents     r    
await_onlyrP   f   s`     llGg/00 
y)))!=
 
 	
 >  +++r"   c                0   t                      }t          |t                    sZt                      }|                                r#t          |            t          j        d          |                    |           S |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?)r1   r5   r<   get_event_loop
is_runningrK   r   rN   run_until_completer   r*   )rA   rO   loops      r    await_fallbackrV      s     llGg/00 
2?? 	"9---%;  
 &&y111>  +++r"   F)_require_awaitr   Callable[..., _T]argsr   rW   kwargsc               Z  K   t          | t                                }d}	  |j        |i |}|j        sSd}	 | d{V }|                    |          }n+# t          $ r  |j        t          j                     }Y nw xY w|j        S|`n# |`w xY w|r|st          j
        d          |S )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<   r1   r*   r   r3   r&   sysexc_infor   r   AwaitRequired)r   rW   rY   rZ   contextswitch_occurredresultr(   s           r    greenlet_spawnrb      s     " r:<<00G
 O000, 	/"O
/ % !.. ! 8 8 8 '7	8 , 	/ NNGN 
o 
G
 
 	

 Ms.   B A B %A?<B >A??
B Bc                  6    e Zd Zedd            ZddZdd
ZdS )AsyncAdaptedLockr$   asyncio.Lockc                (    t          j                    S r   )r7   Lockr   s    r    mutexzAsyncAdaptedLock.mutex   s     |~~r"   r   c                N    t          | j                                                  S r   )rV   ri   acquirerh   s    r    	__enter__zAsyncAdaptedLock.__enter__   s      dj0022333r"   r#   r   kwrH   c                8    | j                                          d S r   )ri   release)r   r#   rm   s      r    __exit__zAsyncAdaptedLock.__exit__   s    
r"   N)r$   re   )r$   r   )r#   r   rm   r   r$   rH   )r,   r-   r.   r   ri   rl   rp   r   r"   r    rd   rd      s[           
4 4 4 4
     r"   rd   'Callable[..., Coroutine[Any, Any, Any]]c                    t                      }|                                rt          d          |                     | |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)rR   rS   r6   rT   r   rY   rZ   rU   s       r    "_util_async_run_coroutine_functionru      s]    
 D 
0
 
 	
 ""22t#6v#6#6777r"   c                    t                      }|                                s#|                    t          | g|R i |          S t	          t                      t                    sJ  | |i |S )rs   )rR   rS   rT   rb   r5   r1   r<   rt   s       r    _util_async_runrw      s    
 D?? #&&~b'J4'J'J'J6'J'JKKK *,,(899999r4"6"""r"   asyncio.AbstractEventLoopc                     	 t          j                    S # t          $ r Y nw xY wt          j                                                    S )z}vendor asyncio.get_event_loop() for python 3.7 and above.

    Python 3.10 deprecates get_event_loop() as a standalone.

    )r7   get_running_loopRuntimeErrorget_event_loop_policyrR   r   r"   r    rR   rR      sS    ')))    (**99;;;s    
"")r$   r   )r2   r3   r$   r   )rA   rB   r$   rC   )rA   rG   r$   rH   )rA   rL   r$   r   )
r   rX   rY   r   rW   r   rZ   r   r$   r   )r   rq   rY   r   rZ   r   r$   r   )r$   rx   )&
__future__r   r7   contextvarsr   r\   typingr   r   r   r   r	   r
   r   langhelpersr    r   util.typingr   r   r   r   r1   hasattrr>   r:   r<   r?   rF   rK   rP   rV   rb   rd   ru   rw   rR   r   r"   r    <module>r      s   # " " " " "        



                                                  * * * * * *       " " " " " " # # # # # #WT]]	 "    8        $#####!!!!!! '**,,55   0 0 0 0 0x 0 0 0 	4((( &     %K   , , , ,4, , , ,< !/ / / / / /d        8 8 8 8# # # #< < < < < <r"   