Files
952-11/env/python/dll/Python312/Lib/__pycache__/contextlib.cpython-312.pyc
T

232 lines
30 KiB
Plaintext
Raw Normal View History

2024-08-19 17:05:14 +08:00
Ë
*åfoãó"—dZddlZddlZddlZddlZddlmZddlmZddl m
Z
m Z gd¢Z Gd„dej«ZGd „d
ej«ZGd „d e«ZGd
„de«ZGd„d«ZGd„deee«ZGd„deee«Zd„Zd„ZGd„de«ZGd„de«ZGd„de«ZGd„de«ZGd„d e«ZGd!„d"e«ZGd#„d$«ZGd%„d&ee«ZGd'„d(ee«Z Gd)„d*ee«Z!Gd+„d,e«Z"y)-z4Utilities for with-statement contexts. See PEP 343.éN)Údeque©Úwraps)Ú
MethodTypeÚ GenericAlias)ÚasynccontextmanagerÚcontextmanagerÚclosingÚ nullcontextÚAbstractContextManagerÚAbstractAsyncContextManagerÚAsyncExitStackÚContextDecoratorÚ ExitStackÚredirect_stdoutÚredirect_stderrÚsuppressÚaclosingÚchdircóZ—eZdZdZee«Zd„Zejd„«Z
ed„«Z y)r z,An abstract base class for context managers.có—|S©z0Return `self` upon entering the runtime context.©©Úselfs úFC:\Users\RCi\AppData\Local\Programs\Python\Python312\Lib\contextlib.pyÚ __enter__z AbstractContextManager.__enter__s€àˆ ócó—y©z9Raise any exception triggered within the runtime context.Nr©rÚexc_typeÚ exc_valueÚ tracebacks rÚ__exit__zAbstractContextManager.__exit__s€ðrcóL—|turtj|dd«StS)Nrr%)r Ú_collections_abcÚ_check_methodsÚNotImplemented©ÚclsÚCs rÚ__subclasshook__z'AbstractContextManager.__subclasshook__ s&€à Ô(Ñ (Ü#×2Ñ2°1°kÀ:ÓNÐ NÜÐrN) Ú__name__Ú
__module__Ú __qualname__Ú__doc__Ú classmethodrÚ__class_getitem__rÚabcÚabstractmethodr%r-rrrr r sC„á6á# LÓ1Ðòð ×Ññóððñóñrr cóZ—eZdZdZee«Zd„Zejd„«Z
ed„«Z y)r
z9An abstract base class for asynchronous context managers.cƒóK—|S­wrrrs rÚ
__aenter__z&AbstractAsyncContextManager.__aenter__-s èø€àˆ ùó‚cƒó K—y­wr rr!s rÚ __aexit__z%AbstractAsyncContextManager.__aexit__1s èø€ðùó‚cóL—|turtj|dd«StS)Nr8r;)r
r'r(r)r*s rr-z,AbstractAsyncContextManager.__subclasshook__6s-€à Ô-Ñ -Ü#×2Ñ2°1°lØ3>ó@ð
@äÐrN) r.r/r0r1r2rr3r8r4r5r;r-rrrr
r
'sC„áCá# LÓ1Ðòð ×Ññóððñóñrr
có—eZdZdZd„Zd„Zy)rzJA base class or mixin that enables context managers to work as decorators.có—|S)a6Return 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_cmzContextDecorator._recreate_cmAs €ðˆ rcó2‡‡—t‰«ˆˆfd„«}|S)Ncó`•—‰j«5‰|i|¤Žcddd«S#1swYyxYw©N©r@©ÚargsÚkwdsÚfuncrs €€rÚinnerz(ContextDecorator.__call__.<locals>.innerNs1ø€à×"Ñ"Ó$ñ
+Ù˜TÐ* TÑ*÷
+÷
+ò
+ús’$¤-r©rrHrIs`` rÚ__call__zContextDecorator.__call__Ms ù€Ü ˆt‹ô +ó
ð +ðˆ rN©r.r/r0r1r@rKrrrrr>s„ÙPò
órrcó—eZdZdZd„Zd„Zy)ÚAsyncContextDecoratorzPA base class or mixin that enables async context managers to work as decorators.có—|S)z-Return a recreated instance of self.
rrs rr@z"AsyncContextDecorator._recreate_cmXs €ðˆ rcó2‡‡—t‰«ˆˆfd„«}|S)NcŸó¶•K—‰j«4ƒd{–—†‰|i|¤Žƒd{–—†cddd«ƒd{–—†S7Œ%7Œ7Œ #1ƒd{–—†7swYyxYw­wrCrDrEs €€rrIz-AsyncContextDecorator.__call__.<locals>.inner^sVøèø€à×(Ñ(Ó*÷
1ñ
1Ù! 4Ð0¨4Ñ0×0÷
1÷
1ò
1øØ0øð
1ø÷
1÷
1ñ
1üsPƒA˜>™Aœ A¨A©A¬ A¸A¹AÁAÁAÁAÁ
A
Á AÁArrJs`` rrKzAsyncContextDecorator.__call__]s ù€Ü ˆt‹ô 1ó
ð 1ðˆ rNrLrrrrNrNUs„ÙVòó
rrNcó—eZdZdZd„Zd„Zy)Ú_GeneratorContextManagerBasezBShared functionality for @contextmanager and @asynccontextmanager.có —||i|¤Ž|_|||c|_|_|_t |dd«}|€t |«j }||_y)Nr1)ÚgenrHrFrGÚgetattrÚtyper1)rrHrFrGÚdocs rÚ__init__z%_GeneratorContextManagerBase.__init__hsR€Ù˜Ð& Ñ&ˆŒØ*.°°dÐ'ˆŒ �4”9˜dœiä�d˜I tÓ,ˆØ ˆ;Ü�t“*×$Ñ$ˆC؈� rcód—|j|j|j|j«SrC)Ú __class__rHrFrGrs rr@z)_GeneratorContextManagerBase._recreate_cmvs#€ð�~‰~˜dŸi™i¨¯©°D·I±IÓ>Ð>rN)r.r/r0r1rYr@rrrrSrSes„ÙLòó?rrScó—eZdZdZd„Zd„Zy)Ú_GeneratorContextManagerz%Helper for @contextmanager decorator.cól—|`|`|` t|j«S#t
$r
t
d«d‚wxYw©Nzgenerator didn't yield)rFrGrHÚnextrUÚ
StopIterationÚ RuntimeErrorrs rrz"_GeneratorContextManager.__enter__„sD€ð
ˆI�t�y $ )ð CܘŸ™“>Ð !øÜò CÜÐ7Ó8¸dÐ Bð Cúsˆ�3cóB—|€" t|j« td«‚|€|«} |jj |« td«‚#|jj«wxYw#t$rYywxYw#t$r}||ucYd}~Sd}~wt$r@}||ur ||_Yd}~yt|t«r|j|ur ||_Yd}~y‚d}~wt$r}||ur‚||_Yd}~yd}~wwxYw#|jj«wxYw)Núgenerator didn't stopFz#generator didn't stop after throw())
r`rUrbÚcloseraÚthrowÚ
__traceback__Ú
isinstanceÚ __cause__Ú
BaseException©rÚtypÚvaluer$Úexcs rr%z!_GeneratorContextManager.__exit__�s€Ø ˆ;ð
%Ü�T—X‘X”ð%Ü&Ð'>Ó?Ð?ðˆ}ñ›�ð#
Ø—‘—‘˜uÔ%ðF
!Ü"Ð#HÓIÐIøðW—H‘H—N‘NÕ$ûô
!ò
Ùð
ûô!ò
(ð %Ð'Õ'ûÜò
à˜%‘<Ø(1�CÔ%Ü ô˜u¤mÔ4ØŸ
™
¨Ñ.à*3�EÔ'Ü ØûÜ ò
ð˜eÑ#ØØ$-�Ô!Üûð
ûð—‘—‘Õ úsi„A5š A¯BÁ DÁA2Á5 BÂBÂ C?Â
BÂC? C?Â" CÂ2%CÃCà C?Ã) C:Ã:C?ÄDN)r.r/r0r1rr%rrrr]r]}s„ñ
0òCó7!rr]có—eZdZdZd„Zd„Zy)Ú_AsyncGeneratorContextManagerz*Helper for @asynccontextmanager decorator.cƒóˆK—|`|`|` t|j«ƒd{–—†S7Œ#t
$r
t
d«d‚wxYw­wr_)rFrGrHÚanextrUÚStopAsyncIterationrbrs rr8z(_AsyncGeneratorContextManager.__aenter__ÍsMèø€ð
ˆI�t�y $ )ð CܘtŸx™x›×(Ð (Ð(ùÜ!ò CÜÐ7Ó8¸dÐ Bð Cüs#‚AŠ)¢'£)¦A§)©?¿Acƒó¢K—|€* t|j«ƒd{–—† td«‚|€|«} |jj |«ƒd{–—† td«‚7ŒI#|jj«ƒd{–—†7wxYw#t$rYywxYw7ŒI#t$r}||ucYd}~Sd}~wt$rF}||ur ||_Yd}~yt|ttf«r|j|ur ||_Yd}~y‚d}~wt$r}||ur‚||_Yd}~yd}~wwxYw#|jj«ƒd{–—†7wxYw­w)NrdFz$generator didn't stop after athrow()) rrrUrbÚaclosersÚathrowrgrhrarirjrks rr;z'_AsyncGeneratorContextManager.__aexit__Ös@èø€Ø ˆ;ð
,ܘDŸH™H“o×%Ð%ð,Ü&Ð'>Ó?Ð?ðˆ}ñ›�ð#
Ø—h‘h—o‘o eÓ,×,Ð,ðF
(Ü"Ð#IÓJÐJðe&ùðŸ(™(Ÿ/™/Ó+×+Ò+ûô
&ò
Ùð
úð-ùÜ%ò
(ð %Ð'Õ'ûÜò
à˜%‘<Ø(1�CÔ%Ü ô˜u¤}Ô6HÐ&IÔJØŸ
™
¨Ñ.à*3�EÔ'Ü ØûÜ ò
ð˜eÑ#ØØ$-�Ô!Üûð
ûð—h‘h—o‘oÓ'×'Ò'üsã‚E†BžA(ŸB¤ A*¯ E¹B#ÁB!ÁB#Á D'Á(BÁ*BÂB  BÂE BÂEÂBÂEÂ!B#Â# D$Â,B5Â/D$Â0EÂ5 D$à Dà EÃ+DÃ<EÄDÄ D$Ä DÄEÄD$Ä$EÄ'E ÅEÅE Å EN)r.r/r0r1r8r;rrrrprpÆs„ñ
5òCó7(rrpcó.‡—t‰«ˆfd„«}|S)aÛ@contextmanager decorator.
Typical usage:
@contextmanager
def some_generator(<arguments>):
<setup>
try:
yield <value>
finally:
<cleanup>
This makes this:
with some_generator(<arguments>) as <variable>:
<body>
equivalent to this:
<setup>
try:
<variable> = <value>
<body>
finally:
<cleanup>
có•—t‰||«SrC)r]©rFrGrHs €rÚhelperzcontextmanager.<locals>.helper+sø€ä'¨¨d°DÓ9Ð9rr©rHrzs` rr r s ø€ô6 ˆ4ƒ[ó:óð:à €Mrcó.‡—t‰«ˆfd„«}|S)aý@asynccontextmanager decorator.
Typical usage:
@asynccontextmanager
async def some_async_generator(<arguments>):
<setup>
try:
yield <value>
finally:
<cleanup>
This makes this:
async with some_async_generator(<arguments>) as <variable>:
<body>
equivalent to this:
<setup>
try:
<variable> = <value>
<body>
finally:
<cleanup>
có•—t‰||«SrC)rprys €rrzz#asynccontextmanager.<locals>.helperLsø€ä,¨T°4¸Ó>Ð>rrr{s` rrr1s ø€ô6 ˆ4ƒ[ó?óð?à €Mrcó"—eZdZdZd„Zd„Zd„Zy)r
a2Context to automatically close something at the end of a block.
Code like this:
with closing(<module>.open(<arguments>)) as f:
<block>
is equivalent to this:
f = <module>.open(<arguments>)
try:
<block>
finally:
f.close()
có—||_yrC©Úthing©rr�s rrYzclosing.__init__có €Øˆ�
rcó—|jSrCr€rs rrzclosing.__enter__es €Ø�z‰zÐrcó8—|jj«yrC)r�re©rÚexc_infos rr%zclosing.__exit__gs€Ø �
‰
×ÑÕrN©r.r/r0r1rYrr%rrrr
r
Rs„ñò òórr
có"—eZdZdZd„Zd„Zd„Zy)ražAsync 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(<module>.fetch(<arguments>)) as agen:
<block>
is equivalent to this:
agen = <module>.fetch(<arguments>)
try:
<block>
finally:
await agen.aclose()
có—||_yrCr€r‚s rrYzaclosing.__init__}rƒrcƒó"K—|jS­wrCr€rs rr8zaclosing.__aenter__sèø€Ø�z‰zÐùó‚
c‡óTK—|jj«ƒd{–—†y7Œ­wrC)r�rur†s rr;zaclosing.__aexit__�sèø€Ø�j‰j×ÑÓ!×!Ò!ús ‚( &¡(N)r.r/r0r1rYr8r;rrrrrks„ñò"òó"rrcó"—eZdZdZd„Zd„Zd„Zy)Ú_RedirectStreamNcó —||_g|_yrC)Ú _new_targetÚ _old_targets)rÚ
new_targets rrYz_RedirectStream.__init__‰s€Ø%ˆÔàˆÕrcóÊ—|jjtt|j««t t|j|j «|j SrC)r’ÚappendrVÚsysÚ_streamÚsetattrr‘rs rrz_RedirectStream.__enter__ŽsC€Ø ×Ñ× Ñ ¤¬¨d¯l©lÓ!;Ô<Ü”�T—\‘\ 4×#3Ñ#3Ô4Ø×ÑÐrcój—tt|j|jj ««yrC)r˜r–r—r’Úpop)rÚexctypeÚexcinstÚexctbs rr%z_RedirectStream.__exit__“s!€Ü”�T—\‘\ 4×#4Ñ#4×#8Ñ#8Ó#:Õ;r)r.r/r0r—rYrr%rrrr�r�…s„à€Gòò
 ó
<rr�có—eZdZdZdZy)raAContext manager for temporarily redirecting stdout to another file.
# How to send help() to stderr
with redirect_stdout(sys.stderr):
help(dir)
# How to write help() to a file
with open('help.txt', 'w') as f:
with redirect_stdout(f):
help(pow)
ÚstdoutN©r.r/r0r1r—rrrrr—s„ñ
ð�Grrcó—eZdZdZdZy)rzCContext manager for temporarily redirecting stderr to another file.ÚstderrNr rrrrr§s
„ÙMà�Grrcó"—eZdZdZd„Zd„Zd„Zy)ra?Context manager to suppress specified exceptions
After the exception is suppressed, execution proceeds with the next
statement following the with statement.
with suppress(FileNotFoundError):
os.remove(somefile)
# Execution still resumes here if the file was already removed
có—||_yrC)Ú _exceptions)rÚ
exceptionss rrYzsuppress.__init__¸s
€Ø%ˆÕrcó—yrCrrs rrzsuppress.__enter__»ó€Ø rcóž—|€yt||j«ryt|t«r#|j|j«\}}|€y|‚y)NTF)Ú
issubclassr¥ÚBaseExceptionGroupÚsplit)rr›rœr�ÚmatchÚrests rr%zsuppress.__exit__¾sR€ð ˆ?Ø Ü �g˜t×/Ñ/Ô 0ØÜ �gÔ1Ô 2Ø!Ÿ-™-¨×(8Ñ(8Ó9‰KˆE�4؈|ØØˆJØrNrˆrrrrr­s„ñò&ò
órrcó\—eZdZdZed„«Zed„«Zd„Zd„Zd„Z d„Z
d„Z d „Z d d
„Z
y )
Ú_BaseExitStackz.A base class for ExitStack and AsyncExitStack.có—t||«SrC©r©ÚcmÚcm_exits rÚ_create_exit_wrapperz#_BaseExitStack._create_exit_wrapper×ó€ä˜' 2Ó&Ð&rc󇇇—ˆˆˆfd„}|S)Ncó•—‰‰i‰¤ŽyrCr©r"rnÚtbrFÚcallbackrGs €€€rÚ
_exit_wrapperz8_BaseExitStack._create_cb_wrapper.<locals>._exit_wrapperÝsø€Ù �dÐ #˜dÓ #rr©r¼rFrGr½s``` rÚ_create_cb_wrapperz!_BaseExitStack._create_cb_wrapperÛsú€ö $àÐrcó"—t«|_yrC)rÚ_exit_callbacksrs rrYz_BaseExitStack.__init__ás €Ü$›wˆÕrcóf—t|««}|j|_t«|_|S)z@Preserve the context stack by transferring it to a new instance.)rWrÁr)rÚ new_stacks rÚpop_allz_BaseExitStack.pop_alläs-€à”D˜“J“Lˆ Ø$(×$8Ñ$8ˆ Ô!Ü$›wˆÔØÐrcóœ—t|«} |j}|j||«|S#t$r|j |«Y|SwxYw)aRegisters 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).
)rWr%Ú
_push_cm_exitÚAttributeErrorÚ_push_exit_callback©rÚexitÚ_cb_typeÚ exit_methods rÚpushz_BaseExitStack.pushësZ€ô˜“:ˆð 2Ø"×+Ñ+ˆKð
× Ñ ˜t [Ô 1؈ øô ò +à × $Ñ $ TÕ *ðˆ ð  +ús� -­A Á
A cóê—t|«} |j}|j}||«}|j||«|S#t$r(t d|j
›d|j ›d�«d‚wxYw)z«Enters 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)rWrr%rÇÚ TypeErrorr/r0rÆ©rr´r+Ú_enterÚ_exitÚresults rÚ
enter_contextz_BaseExitStack.enter_contextÿs�€ô�2‹hˆð SØ—]‘]ˆFØ—L‘LˆEñ˜“ˆØ ×ј2˜uÔ%؈
øô ò Sܘa §¡Ð/¨q°×1AÑ1AÐ0BðCGðHóIØNRð
Sð Sús �AÁ1A2cób—|j|g|¢­i|¤Ž}||_|j|«|S)z\Registers an arbitrary callback and arguments.
Cannot suppress exceptions.
)r¿Ú __wrapped__rÈ©rr¼rFrGr½s rr¼z_BaseExitStack.callbacks=€ð
0˜×/Ñ/°ÐH¸4ÒHÀ4ÑHˆ
ð%-ˆ