Jz`fl"SrSSKrSSKrSSKrSSKrSSKJr SSKJr SSK J r J r /SQr "SS\R5r"S S \R5r"S S \5r"S S\5r"SS5r"SS\\\5r"SS\\\5rSrSr"SS\5r"SS\5r"SS\5r"SS\5r"SS \5r"S!S"\5r"S#S$5r"S%S&\\5r"S'S(\\5r "S)S*\\5r!"S+S,\5r"g)-z4Utilities for with-statement contexts. See PEP 343.N)dequewraps) MethodType GenericAlias)asynccontextmanagercontextmanagerclosing nullcontextAbstractContextManagerAbstractAsyncContextManagerAsyncExitStackContextDecorator ExitStackredirect_stdoutredirect_stderrsuppressaclosingchdircf\rSrSrSr\"\5rSrSr \ RS5r \S5r Srg)r z,An abstract base class for context managers.cU$z0Return `self` upon entering the runtime context.rselfs #/usr/lib64/python3.13/contextlib.py __enter__ AbstractContextManager.__enter__s cgz9Raise any exception triggered within the runtime context.Nrrexc_type exc_value tracebacks r__exit__AbstractContextManager.__exit__sr cPU[La[R"USS5$[$)Nrr')r _collections_abc_check_methodsNotImplementedclsCs r__subclasshook__'AbstractContextManager.__subclasshook__"s& ( (#221k:N Nr N)__name__ __module__ __qualname____firstlineno____doc__ classmethodr__class_getitem__ __slots__rabcabstractmethodr'r0__static_attributes__rr rr r sH6#L1I r r cf\rSrSrSr\"\5rSrSr \ RS5r \S5r Srg)r )z9An abstract base class for asynchronous context managers.rc# U$7frrrs r __aenter__&AbstractAsyncContextManager.__aenter__1s  c # g7fr"rr#s r __aexit__%AbstractAsyncContextManager.__aexit__5s cPU[La[R"USS5$[$)Nr@rD)r r*r+r,r-s rr0,AbstractAsyncContextManager.__subclasshook__:s- - -#221l3>@ @r N)r2r3r4r5r6r7rr8r9r@r:r;rDr0r<rr rr r )sHC#L1I r r c$\rSrSrSrSrSrSrg)rBzJA base class or mixin that enables context managers to work as decorators.cU$)aReturn a recreated instance of self. Allows an otherwise one-shot context manager like _GeneratorContextManager to support use as a decorator via implicit recreation. This is a private interface just for _GeneratorContextManager. See issue #11647 for details. rrs r _recreate_cmContextDecorator._recreate_cmEs  r c4^^[T5UU4Sj5nU$)Ncj>TR5 T"U0UD6sSSS5 $!,(df  g=fNrLargskwdsfuncrs rinner(ContextDecorator.__call__..innerRs1""$ +T*T* + + +s$ 2rrrUrVs`` r__call__ContextDecorator.__call__Qs t +  + r rNr2r3r4r5r6rLrYr<rr rrrBsP r rc$\rSrSrSrSrSrSrg)AsyncContextDecoratorYzPA base class or mixin that enables async context managers to work as decorators.cU$)z-Return a recreated instance of self. rrs rrL"AsyncContextDecorator._recreate_cm\s  r c4^^[T5UU4Sj5nU$)Nc># TR5IShvN T"U0UD6IShvN sSSS5IShvN $N%NN !,IShvN (df  g=f7frPrQrRs rrV-AsyncContextDecorator.__call__..innerbsR((* 1 1!40400 1 1 10 1 1 1 1sPA>A AAA AAAAAA A AArrXs`` rrYAsyncContextDecorator.__call__as t 1  1 r rNr[rr rr]r]YsV r r]c$\rSrSrSrSrSrSrg)_GeneratorContextManagerBaseizBShared functionality for @contextmanager and @asynccontextmanager.cU"U0UD6UlXUsUlUlUl[ USS5nUc[ U5R nX@lg)Nr6)genrUrSrTgetattrtyper6)rrUrSrTdocs r__init__%_GeneratorContextManagerBase.__init__lsN&&*.d' 49didIt, ;t*$$C r cdURURURUR5$rP) __class__rUrSrTrs rrL)_GeneratorContextManagerBase._recreate_cmzs#~~diiDII>>r )rirUrSrTr6N)r2r3r4r5r6rmrLr<rr rrfrfisL?r rfc$\rSrSrSrSrSrSrg)_GeneratorContextManagerz%Helper for @contextmanager decorator.cnU?U?U?[UR5$![ a [ S5Sef=fNzgenerator didn't yield)rSrTrUnextri StopIteration RuntimeErrorrs rr"_GeneratorContextManager.__enter__sD Ity$) C> ! C78d B Cs4cRUc"[UR5 [S5eUcU"5nURR U5 [S5e!URR5 f=f![a gf=f![a nXBLsSnA$SnAf[aDnXBLa X4lSnAg[U[5(aURULa X2lSnAgeSnAf[anXBLaeX4lSnAgSnAff=f!URR5 f=f)Ngenerator didn't stopFz#generator didn't stop after throw()) rwrirycloserxthrow __traceback__ isinstance __cause__ BaseExceptionrtypvaluer&excs rr'!_GeneratorContextManager.__exit__s  ; %TXX%&'>??}# u%F !"#HIIWHHNN$ !  ! ('' <(1% um44 .*3'  #$-!  siA7 AB D A47 BB DBD D& C%5*C%$C%% D2 DD D&rSrUrirTN)r2r3r4r5r6rr'r<rr rrsrss 0C7!r rsc$\rSrSrSrSrSrSrg)_AsyncGeneratorContextManagerz*Helper for @asynccontextmanager decorator.c# U?U?U?[UR5IShvN $N![ a [ S5Sef=f7frv)rSrTrUanextriStopAsyncIterationryrs rr@(_AsyncGeneratorContextManager.__aenter__sL Ity$) Ctxx( ((! C78d B Cs%A)')A)AAc# Uc*[UR5IShvN [S5eUcU"5nURR U5IShvN [S5eNJ!URR5IShvN f=f![a gf=fNJ![a nXBLsSnA$SnAf[aJnXBLa X4lSnAg[U[[45(aURULa X2lSnAgeSnAf[anXBLaeX4lSnAgSnAff=f!URR5IShvN f=f7f)Nr|Fz$generator didn't stop after athrow()) rriryacloserathrowrrrxrrrs rrD'_AsyncGeneratorContextManager.__aexit__s6 ; ,DHHo%%,&'>??}# hhooe,,,F ("#IJJe&((//+++ &  -% ('' <(1% u}6H&IJJ .*3'  #$-! hhoo'''sEBA*B A, EB&B$B& D/*B,B B  BE B!E B!!E$B&& D,0B82D,3E8 D, D E0D E D  D, D'"E'D,,E/E EEErN)r2r3r4r5r6r@rDr<rr rrrs 5C7(r rc0^[T5U4Sj5nU$)a@contextmanager decorator. Typical usage: @contextmanager def some_generator(): try: yield finally: This makes this: with some_generator() as : equivalent to this: try: = finally: c>[TX5$rP)rsrSrTrUs rhelpercontextmanager..helper/s'd99r rrUrs` rr r s 6 4[:: Mr c0^[T5U4Sj5nU$)a@asynccontextmanager decorator. Typical usage: @asynccontextmanager async def some_async_generator(): try: yield finally: This makes this: async with some_async_generator() as : equivalent to this: try: = finally: c>[TX5$rP)rrs rr#asynccontextmanager..helperPs,T4>>r rrs` rrr5s 6 4[?? Mr c*\rSrSrSrSrSrSrSrg)r iVa Context to automatically close something at the end of a block. Code like this: with closing(.open()) as f: is equivalent to this: f = .open() try: finally: f.close() cXlgrPthingrrs rrmclosing.__init__g r cUR$rPrrs rrclosing.__enter__is zzr c8URR5 grP)rr}rexc_infos rr'closing.__exit__ks r rN r2r3r4r5r6rmrr'r<rr rr r Vs r r c*\rSrSrSrSrSrSrSrg)rioarAsync context manager for safely finalizing an asynchronously cleaned-up resource such as an async generator, calling its ``aclose()`` method. Code like this: async with aclosing(.fetch()) as agen: is equivalent to this: agen = .fetch() try: finally: await agen.aclose() cXlgrPrrs rrmaclosing.__init__rr c"# UR$7frPrrs rr@aclosing.__aenter__szz cT# URR5IShvN gN7frP)rrrs rrDaclosing.__aexit__sjj!!!s (&(rN) r2r3r4r5r6rmr@rDr<rr rrros""r rc*\rSrSrSrSrSrSrSrg)_RedirectStreamiNcXl/UlgrP) _new_target _old_targets)r new_targets rrm_RedirectStream.__init__s%r cURR[[UR55 [ [URUR 5 UR $rP)rappendrjsys_streamsetattrrrs rr_RedirectStream.__enter__sC   dll!;<T\\4#3#34r cj[[URURR 55 grP)rrrrpop)rexctypeexcinstexctbs rr'_RedirectStream.__exit__s!T\\4#4#4#8#8#:;r )rrr) r2r3r4r5rrmrr'r<rr rrrsG  T"T0TD6 grPrr$rtbrScallbackrTs r _exit_wrapper8_BaseExitStack._create_cb_wrapper.._exit_wrappers d #d #r rrrSrTrs``` r_create_cb_wrapper!_BaseExitStack._create_cb_wrappers $r c"[5UlgrP)r_exit_callbacksrs rrm_BaseExitStack.__init__s $wr cf[U5"5nURUl[5UlU$)z@Preserve the context stack by transferring it to a new instance.)rkrr)r new_stacks rpop_all_BaseExitStack.pop_alls+JL $($8$8 !$wr c[U5nURnURX5 U$![a UR U5 U$f=f)zRegisters a callback with the standard __exit__ method signature. Can suppress exceptions the same way __exit__ method can. Also accepts any object with an __exit__ method (registering a call to the method instead of the object itself). )rkr' _push_cm_exitAttributeError_push_exit_callbackrexit_cb_type exit_methods rpush_BaseExitStack.pushsX: 2"++K   t 1  +  $ $T *  +s ,A  A c[U5nURnURnU"U5nURX5 U$![a( [ SUR SUR S35Sef=f)zEnters the supplied context manager. If successful, also pushes its __exit__ method as a callback and returns the result of the __enter__ method. '.z6' object does not support the context manager protocolN)rkrr'r TypeErrorr3r4rrrr._enter_exitresults r enter_context_BaseExitStack.enter_contexts2h S]]FLLE 2%  Sa/q1A1A0BCGHINR S Ss A2A2c`UR"U/UQ70UD6nXlURU5 U$)zLRegisters an arbitrary callback and arguments. Cannot suppress exceptions. )r __wrapped__rrrrSrTrs rr_BaseExitStack.callbacks9 //H4H4H %-!   /r cJURX5nURUS5 g)z;Helper to correctly register callbacks to __exit__ methods.TN)rrrrrrs rr_BaseExitStack._push_cm_exit#s"11">    5r c<URRX!45 grP)rr)rris_syncs rr"_BaseExitStack._push_exit_callback(s ##W$78r )rrN)T)r2r3r4r5r6 staticmethodrrrmrrrrrrr<rr rrrsN8'' '(& 6 9r rc*\rSrSrSrSrSrSrSrg)ri-aoContext manager for dynamic management of a stack of exit callbacks. For example: with ExitStack() as stack: files = [stack.enter_context(open(fname)) for fname in filenames] # All opened files will automatically be closed at the end of # the with statement, even if attempts to open files later # in the list raise an exception. cU$rPrrs rrExitStack.__enter__8s r c^ USnUSLn[R"5m U 4SjnSnSnUR(afURR5upxU(deUcSnO[ U5X"R 4nU"U6(aSnSnSnUR(aMfU(aURn UeU=(a U$![ an U"X5 SnU nSn A NOSn A ff=f![ a W Ulef=f)NcP>URnUbX!LagUTLaOUnMXlgrP __context__new_excold_exc exc_context frame_excs r_fix_exception_context2ExitStack.__exit__.._fix_exception_contextB<%11 &+*@)+%#* r FNNNTr exceptionrrrkrrr) r exc_detailsr received_excr"suppressed_exc pending_raisercbr fixed_ctxr!s @rr'ExitStack.__exit__;s!n$ MMO  *  ""..224KGN7 ;"2K"&s)S2C2C"CK{#%)N$)MC"""$   OO  ..! &w4 $   ! "+ s$!-C)C% C" CC"%C8c*URSSS5 gz%Immediately unwind the context stack.N)r'rs rr}ExitStack.closeqs dD$'r )rN) r2r3r4r5r6rr'r}r<rr rrr-s4/l(r rcb\rSrSrSr\S5r\S5rSrSr Sr Sr S r S r S rS rg )riwaAsync context manager for dynamic management of a stack of exit callbacks. For example: async with AsyncExitStack() as stack: connections = [await stack.enter_async_context(get_connection()) for i in range(5)] # All opened connections will automatically be released at the # end of the async with statement, even if attempts to open a # connection later in the list raise an exception. c[X5$rPrrs r_create_async_exit_wrapper)AsyncExitStack._create_async_exit_wrapperrr c^^^UUU4SjnU$)Nc2># T"T0TD6IShvN gN7frPrrs rr>AsyncExitStack._create_async_cb_wrapper.._exit_wrappersD)D) ) )s rrs``` r_create_async_cb_wrapper'AsyncExitStack._create_async_cb_wrappers *r c# [U5nURnURnU"U5IShvN nURX5 U$![a( [ SUR SUR S35Sef=fNL7f)zEnters the supplied async context manager. If successful, also pushes its __aexit__ method as a callback and returns the result of the __aenter__ method. rrzC' object does not support the asynchronous context manager protocolN)rkr@rDrrr3r4_push_async_cm_exitrs renter_async_context"AsyncExitStack.enter_async_contexts 2h '^^FMME bz!   +  'a/q1A1A0BCTU"& ' '"s% BA BA?B 2A<<Bc[U5nURnURX5 U$![a UR US5 U$f=f)zRegisters a coroutine function with the standard __aexit__ method signature. Can suppress exceptions the same way __aexit__ method can. Also accepts any object with an __aexit__ method (registering a call to the method instead of the object itself). F)rkrDr<rrrs rpush_async_exitAsyncExitStack.push_async_exitsZ: 8",,K  $ $T 7  2  $ $T5 1  2s ,A  A cbUR"U/UQ70UD6nXlURUS5 U$)zVRegisters an arbitrary coroutine function and arguments. Cannot suppress exceptions. F)r9r rr s rpush_async_callback"AsyncExitStack.push_async_callbacks; 55hNNN %-!   6r cF# URSSS5IShvN gN7fr0)rDrs rrAsyncExitStack.aclosesnnT4...s !!cJURX5nURUS5 g)zDHelper to correctly register coroutine function to __aexit__ method.FN)r4rrs rr<"AsyncExitStack._push_async_cm_exits$77D    6r c# U$7frPrrs rr@AsyncExitStack.__aenter__s  rBc^ # USnUSLn[R"5m U 4SjnSnSnUR(atURR5upxUcSnO[ U5X"R 4nU(aU"U6n O U"U6IShvN n U (aSnSnSnUR(aMtU(aURn UeU=(a U$NE![ an U"X5 SnU nSn A NQSn A ff=f![ a W Ulef=f7f)NrcP>URnUbX!LagUTLaOUnMXlgrPrrs rr"8AsyncExitStack.__aexit__.._fix_exception_contextr$r Fr%Tr&) rr(rr)r"r*r+rr, cb_suppressrr-r!s @rrDAsyncExitStack.__aexit__s!n$ MMO  *  ""..224KG ;"2K"&s)S2C2C"CK"$k"2K(*K(8"8K%)N$)MC""",   OO  ..+#9 ! &w4 $   ! "+ s`AD 2C C CD 1D 9C7 D C C4 C/*D /C44D 7D  D )rr9N)r2r3r4r5r6rr4r9r=r@rCrr<r@rDr<rr rrrwsR '' $$ /7 8/r rc:\rSrSrSrS SjrSrSrSrSr S r g) r ia7Context manager that does no additional processing. Used as a stand-in for a normal context manager, when a particular block of code is only sometimes used with a normal context manager: cm = optional_cm if condition else nullcontext() with cm: # Perform operation, using optional_cm if condition is True NcXlgrP enter_result)rrSs rrmnullcontext.__init__s(r cUR$rPrRrs rrnullcontext.__enter__s   r cgrPrrexcinfos rr'nullcontext.__exit__rr c"# UR$7frPrRrs rr@nullcontext.__aenter__s   rc # g7frPrrXs rrDnullcontext.__aexit__s rFrRrP) r2r3r4r5r6rmrr'r@rDr<rr rr r s )! ! r r c*\rSrSrSrSrSrSrSrg)ri"zHNon thread-safe context manager to change the current working directory.cXl/UlgrPpath_old_cwd)rrbs rrmchdir.__init__%s  r cURR[R"55 [R"UR 5 grP)rcrosgetcwdrrbrs rrchdir.__enter__)s* RYY[) r c`[R"URR55 grP)rfrrcrrXs rr'chdir.__exit__-s ""$%r raNrrr rrr"sR&r r)#r6r:rfrr* collectionsr functoolsrtypesrr__all__ABCr r objectrr]rfrsrr rr rrrrrrrrr rrr rrqs9: * SWW0#''2v. F  ??0G! G!RG( G(TBB$2"*"4<,<$ o  o $%$NQ9Q9jF( 6F(TM/^%@M/` (*E 6 & " &r