XjtUddlmZdZddlZddlmZddlmZddlm Z m Z m Z m Z m Z mZmZddlmZdd lmZe rdd lmZe d Ze d Zdd ZddZddZeeddGddZddZeZded<Gddej>Z Gdde eZ!Gdde eZ"y) ) annotations)EventLoopToken RunvarTokenRunVar checkpointcheckpoint_if_cancelledcancel_shielded_checkpoint current_tokenN) dataclass) TracebackType) TYPE_CHECKINGAnyGenericLiteralTypeVarfinaloverload)WeakKeyDictionary)get_async_backend) AsyncBackendTDcPKtjd{y7w)z Check for cancellation and allow the scheduler to switch to another task. Equivalent to (but more efficient than):: await checkpoint_if_cancelled() await cancel_shielded_checkpoint() .. versionadded:: 3.0 N)rrb/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/anyio/lowlevel.pyrrs   ( ( *** &$&cPKtjd{y7w)z Enter a checkpoint if the enclosing cancel scope has been cancelled. This does not allow the scheduler to switch to a different task. .. versionadded:: 3.0 N)rrrrrrr+s   5 5 777rcPKtjd{y7w)z Allow the scheduler to switch to another task but without checking for cancellation. Equivalent to (but potentially more efficient than):: with CancelScope(shield=True): await checkpoint() .. versionadded:: 3.0 N)rr rrrr r 7s   8 8 :::rTF)frozenreprc&eZdZUdZded<ded<y)rza An opaque object that holds a reference to an event loop. .. versionadded:: 4.11.0 ztype[AsyncBackend] backend_classobject native_tokenN)__name__ __module__ __qualname____doc____annotations__rrrrrFs &%rrcNt}|j}t||S)z Return a token object that can be used to call code in the current event loop from another thread. :raises NoEventLoopError: if no supported asynchronous event loop is running in the current thread .. versionadded:: 4.11.0 )rr r)r$ raw_tokens rr r Ss'&'M++-I - 33rz1WeakKeyDictionary[object, dict[RunVar[Any], Any]] _run_varsc.eZdZejZy) _NoValueSetN)r'r(r)enumauto NO_VALUE_SETrrrr0r0fs499;Lrr0c<eZdZdZdZddZddZ d dZy) rz A token that can be used to restore a :class:`RunVar` to its previous value. Returned by :meth:`RunVar.set`. Can be used as a context manager to automatically reset the variable on exit, or passed directly to :meth:`RunVar.reset`. _var_value _redeemedc.||_||_d|_y)NFr5)selfvarvalues r__init__zRunvarToken.__init__ts =B rc|SNrr:s r __enter__zRunvarToken.__enter__ys rc:|jj|yr?)r6reset)r:exc_typeexc_valexc_tbs r__exit__zRunvarToken.__exit__|s rN)r;z RunVar[T]r<%T | Literal[_NoValueSet.NO_VALUE_SET])returnRunvarToken[T])rDztype[BaseException] | NonerEzBaseException | NonerFzTracebackType | NonerINone)r'r(r)r* __slots__r=rArGrrrrrjsC.I ,&%   rrceZdZUdZdZej Zded<ef ddZe ddZ e ddZ e ddZ ef dd Z dd Z dd Zdd Zy )ra Like a :class:`~contextvars.ContextVar`, except scoped to the running event loop. Can be used as a context manager, Just like :class:`~contextvars.ContextVar`, that will reset the variable to its previous value when the context block is exited. _name_defaultz!Literal[_NoValueSet.NO_VALUE_SET]r3c ||_||_yr?rN)r:namedefaults rr=zRunVar.__init__s  rcvtj} t|S#t$rix}t|<|cYSwxYwr?)r r&r.KeyError)r:r&run_varss r _current_varszRunVar._current_varssB$33  \* * 13 3Hy.O s 88cyr?rr:rSs rgetz RunVar.gets(+rcyr?rr@s rrZz RunVar.getsrc |j|S#t$rC|tjur|cYS|jtjur|jcYSYnwxYwt d|j d)a2 Return the current value of this run variable. :param default: a fallback value to return if no value has been set :return: the current value, the provided default, or the variable's own default :raises LookupError: if no value is set and no default is available zRun variable "z!" has no value and no default set)rWrUrr3rP LookupErrorrOrYs rrZz RunVar.gets{ %%%d+ + %f111f&9&99}}$: % TZZL(I J  sA(AAc||j}t||j|tj}|||<|S)z Set the value of this run variable for the current event loop. :param value: the new value :return: a token that can be used to restore the previous value )rWrrZrr3)r:r< current_varstokens rsetz RunVar.sets=)) D,"2"249L9L"MN" T rc4|j|ur td|jr td|jtj ur |j |=d|_y|j|j |<d|_y#t$r Yd|_ywxYw)a Restore this run variable to the value it held before the matching :meth:`set`. :param token: the token returned by :meth:`set` :raises ValueError: if the token belongs to a different :class:`RunVar` or the token has already been used z)This token does not belong to this RunVarz This token has already been usedTN)r6 ValueErrorr8r7r0r3rWrU)r:r`s rrCz RunVar.resets ::T !HI I ???@ @ <<;33 3 &&t, (-||D  t $    s B BBc"d|jdS)Nz )rOr@s r__repr__zRunVar.__repr__stzznA..rN)rRstrrSrH)rIzdict[RunVar[T], T])rSrrIT | D)rIr)rSz%D | Literal[_NoValueSet.NO_VALUE_SET]rIrh)r<rrIrJ)r`rJrIrK)rIrg)r'r(r)r*rLr0r3r+r=propertyrWrrZrarCrfrrrrrs$I6A6N6NL3NKW  "G ++ @L <  . 2/rr)rIrK)rIr)# __future__r__all__r1 dataclassesr typesr typingr rrrrrrweakrefr_core._eventlooprabcrrrrrr rr r.r+Enumr0rrrrrrss"  !QQQ%/! CL CL + 8 ; $U#$ 4 @Q?R <R$))'!*6_/WQZ_/r