o
    E6d`!                     @  s  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roG dd deZdFddZnd dlmZ d dlmZ ee dZdGddZG dd  d eZed!d"d#ZerdHd'd(ZnejZdId+d,ZdJd.d/ZdJd0d1Z d2d3dKd:d;Z!G d<d= d=Z"dLd?d@Z#dLdAdBZ$dMdDdEZ%dS )N    )annotationsN)Context)Any)	Awaitable)Callable)	Coroutine)Optional)TYPE_CHECKING)TypeVar   )memoized_property   )exc)Protocol)	TypeGuard_Tc                   @  s<   e Zd ZU ded< ded< ddd	ZdddZdddZdS )greenletbooldeadzOptional[Context]
gr_contextfnCallable[..., Any]driverc                 C     d S N selfr   r   r   r   xC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\sqlalchemy/util/_concurrency_py3k.py__init__$      zgreenlet.__init__argr   returnc                 G  r   r   r   )r   r!   r   r   r   throw'   r    zgreenlet.throwvaluec                 C  r   r   r   )r   r$   r   r   r   switch*   r    zgreenlet.switchNr   r   r   r   )r!   r   r"   r   )r$   r   r"   r   )__name__
__module____qualname____annotations__r   r#   r%   r   r   r   r   r       s   
 

r   r"   c                   C  r   r   r   r   r   r   r   
getcurrent-   r    r+   )r+   )r   r   eBaseExceptionr   c                 C  s   t | t pt | tjtjfS r   )
isinstance	ExceptionasyncioTimeoutErrorCancelledError)r,   r   r   r   is_exit_exception;   s   r3   c                   @  s    e Zd ZU ded< d
ddZd	S )_AsyncIoGreenletr   r   r   r   r   r   c                 C  s(   t | || || _tr|j| _d S d S r   )r   r   r   _has_gr_contextr   r   r   r   r   r   K   s
   z_AsyncIoGreenlet.__init__Nr&   )r'   r(   r)   r*   r   r   r   r   r   r4   H   s   
 r4   _T_coT)	covariant	awaitableAwaitable[_T_co]%TypeGuard[Coroutine[Any, Any, _T_co]]c                 C  r   r   r   r8   r   r   r   iscoroutineV   s   r<   Awaitable[Any]Nonec                 C  s   t | r
|   d S d S r   )r<   closer;   r   r   r   _safe_cancel_awaitable_   s   r@   Awaitable[_T]c                 C  s.   t  }t|tst|  t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?)r+   r.   r4   r@   r   MissingGreenletr   r%   )r8   currentr   r   r   
await_onlyf   s   

	rD   c                 C  sF   t  }t|tst }| rt|  t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?)r+   r.   r4   get_event_loop
is_runningr@   r   rB   run_until_completer   r%   )r8   rC   loopr   r   r   await_fallback   s   

rI   F)_require_awaitr   Callable[..., _T]argsr   rJ   kwargsc                  s   t | t }d}z1|j|i |}|js7d}z|I dH }W n ty.   |jt  }Y nw ||}|jrW |`n|`w |rG|sGt	
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.)r4   r+   r%   r   r-   r#   sysexc_infor   r   ZAwaitRequired)r   rJ   rL   rM   contextZswitch_occurredresultr$   r   r   r   greenlet_spawn   s*   
rR   c                   @  s.   e Zd ZedddZdddZdddZdS )AsyncAdaptedLockr"   asyncio.Lockc                 C  s   t  S r   )r0   Lockr   r   r   r   mutex   s   zAsyncAdaptedLock.mutexr   c                 C  s   t | j S r   )rI   rW   acquirerV   r   r   r   	__enter__   s   zAsyncAdaptedLock.__enter__r!   r   kwr>   c                 O  s   | j   d S r   )rW   release)r   r!   rZ   r   r   r   __exit__   s   zAsyncAdaptedLock.__exit__N)r"   rT   )r"   r   )r!   r   rZ   r   r"   r>   )r'   r(   r)   r   rW   rY   r\   r   r   r   r   rS      s
    
rS   'Callable[..., Coroutine[Any, Any, Any]]c                 O  s*   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)rE   rF   r/   rG   r   rL   rM   rH   r   r   r   "_util_async_run_coroutine_function   s   r`   c                 O  sH   t  }| s|t| g|R i |S tt tsJ | |i |S )r^   )rE   rF   rG   rR   r.   r+   r4   r_   r   r   r   _util_async_run   s
   ra   asyncio.AbstractEventLoopc                   C  s*   zt  W S  ty   Y nw t   S )z}vendor asyncio.get_event_loop() for python 3.7 and above.

    Python 3.10 deprecates get_event_loop() as a standalone.

    )r0   get_running_loopRuntimeErrorget_event_loop_policyrE   r   r   r   r   rE      s   
rE   )r"   r   )r,   r-   r"   r   )r8   r9   r"   r:   )r8   r=   r"   r>   )r8   rA   r"   r   )
r   rK   rL   r   rJ   r   rM   r   r"   r   )r   r]   rL   r   rM   r   r"   r   )r"   rb   )&
__future__r   r0   contextvarsr   rN   typingr   r   r   r   r   r	   r
   Zlanghelpersr    r   Zutil.typingr   r   r   r   r+   hasattrr5   r3   r4   r6   r<   r@   rD   rI   rR   rS   r`   ra   rE   r   r   r   r   <module>   sL   




2

