U aH @s ddlZddlZddlmZddlmZddlmZddlZddlmZddl m Z dd lm Z ej rzdd l mZeejd Wqeefk rdZYqXndZd d ZGdddejZeedddZeedddZddeedddZGdddZddZddZd d!ZdS)"N)Any)Callable) Coroutine)compat)memoized_property)exc) copy_context gr_contextcCst|t pt|tjtjfSN) isinstance Exceptionasyncio TimeoutErrorZCancelledError)erbC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\util\_concurrency_py3k.pyis_exit_exceptions rc@seZdZddZdS)_AsyncIoGreenletcCs*tj|||||_tdk r&t|_dSr )greenlet__init__driver _copy_contextr )selffnrrrrr)sz_AsyncIoGreenlet.__init__N)__name__ __module__ __qualname__rrrrrr(sr) awaitablereturncCs(t}t|tstd|j|S)Awaits an async function in a sync method. The sync method must be inside a :func:`greenlet_spawn` context. :func:`await_` calls cannot be nested. :param awaitable: The coroutine to call. zfgreenlet_spawn has not been called; can't call await_() here. Was IO attempted in an unexpected place?)r getcurrentr rr MissingGreenletrswitch)rcurrentrrr await_only0s   r&cCs@t}t|ts4t}|r*td||S|j |S)r!zgreenlet_spawn has not been called and asyncio event loop is already running; can't call await_() here. Was IO attempted in an unexpected place?) rr"r rget_event_loop is_runningr r#run_until_completerr$)rr%looprrrawait_fallbackHs   r+F)_require_await)rr cst|t}d}zX|j||}|jshd}z|IdH}Wn"tk rZ|jt }Yq X||}q W5|`X|r|st d|S)aCRuns a sync function ``fn`` in a new greenlet. The sync function can then use :func:`await_` 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.) rrr"rr$Zdead BaseExceptionthrowsysexc_infor Z AwaitRequired)rr,argskwargscontextZswitch_occurredresultvaluerrrgreenlet_spawn`s"  r6c@s(eZdZeddZddZddZdS)AsyncAdaptedLockcCstSr )rLockrrrrmutexszAsyncAdaptedLock.mutexcCst|j|Sr )r+r:acquirer9rrr __enter__szAsyncAdaptedLock.__enter__cOs|jdSr )r:release)rargkwrrr__exit__szAsyncAdaptedLock.__exit__N)rrrrr:r<r@rrrrr7s r7cOs&t}|rtd||||S)for test suite/ util onlyz]for async run coroutine we expect that no greenlet or event loop is running when we start out)r'r(rr)rr1r2r*rrr"_util_async_run_coroutine_functions rCcOsDt}|s$|t|f||Sttts6t|||SdS)rAN) r'r(r)r6r rr"rAssertionErrorrBrrr_util_async_runs rEcCs@tjr4z tWStk r0tYSXntSdS)z}vendor asyncio.get_event_loop() for python 3.7 and above. Python 3.10 deprecates get_event_loop() as a standalone. N)rpy37rZget_running_loop RuntimeErrorZget_event_loop_policyr'rrrrr's  r')rr/typingrrrrrZ langhelpersrr rFZ contextvarsr rgetattr ImportErrorAttributeErrorrrr&r+r6r7rCrEr'rrrrs8          .