1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
U
Z±dã@sddlZddlZddlZddlmZddlZddlZddlmZdZ dd„Zdd    „Zd
d „Zed ƒZd e_edƒZde_ejGdd„dƒƒZdS)éN)Úwrapsé)Úis_main_threadz@TRIO_KI_PROTECTION_ENABLEDcCs8|dk    r4t|jkr|jtS|jjdkr,dS|j}qdS)NÚ__del__T)Ú LOCALS_KEY_KI_PROTECTION_ENABLEDÚf_localsÚf_codeÚco_nameÚf_back)Úframe©r úEd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\trio/_core/_ki.pyÚki_protection_enabledVs
 
 rcCs tt ¡ƒS)aŸCheck whether the calling code has :exc:`KeyboardInterrupt` protection
    enabled.
 
    It's surprisingly easy to think that one's :exc:`KeyboardInterrupt`
    protection is enabled when it isn't, or vice-versa. This function tells
    you what Trio thinks of the matter, which makes it useful for ``assert``\s
    and unit tests.
 
    Returns:
      bool: True if protection is enabled, and False otherwise.
 
    )rÚsysÚ    _getframer r r r Úcurrently_ki_protected`s rcs‡fdd„}|S)NcsŠt ˆ¡r$tˆƒ‡‡fdd„ƒ}|St ˆ¡rHtˆƒ‡‡fdd„ƒ}|St ˆ¡rltˆƒ‡‡fdd„ƒ}|Stˆƒ‡‡fdd„ƒ}|SdS)Ncsˆ||Ž}ˆ|jjt<|S©N)Úcr_framerr)ÚargsÚkwargsÚcoro©ÚenabledÚfnr r Úwrapperws
 z<_ki_protection_decorator.<locals>.decorator.<locals>.wrappercsˆ||Ž}ˆ|jjt<|Sr)Úgi_framerr)rrÚgenrr r rs
 
 csˆ||Ž}ˆ|jjt<|Sr)Úag_framerr)rrZagenrr r r’s
 csˆtƒt<ˆ||ŽSr)Úlocalsr)rrrr r rœs
)ÚinspectÚiscoroutinefunctionrÚisgeneratorfunctionÚasync_generatorÚisasyncgenfunction)rr©r)rr Ú    decoratorqs
 
 
z+_ki_protection_decorator.<locals>.decoratorr )rr%r r$r Ú_ki_protection_decoratorps 2r&TÚenable_ki_protectionFÚdisable_ki_protectionc@s(eZdZejddZdd„Zdd„ZdS)Ú    KIManagerN)ÚdefaultcsP|jdkst‚tƒr&t tj¡tjkr*dS‡‡fdd„}||_t tj|¡dS)Ncs.|tjkst‚t|ƒ}|sˆr&ˆƒnt‚dSr)ÚsignalÚSIGINTÚAssertionErrorrÚKeyboardInterrupt)Úsignumr Zprotection_enabled©Ú
deliver_cbÚ*restrict_keyboard_interrupt_to_checkpointsr r Úhandler¹s
z"KIManager.install.<locals>.handler)r3r-rr+Ú    getsignalr,Údefault_int_handler)Úselfr1r2r3r r0r Úinstall±sÿþzKIManager.installcCs6|jdk    r2t tj¡|jkr,t tjtj¡d|_dSr)r3r+r4r,r5)r6r r r ÚcloseÄs
zKIManager.close)Ú__name__Ú
__module__Ú __qualname__ÚattrÚibr3r7r8r r r r r)­s r))rr+rÚ    functoolsrr<r"Z_utilrÚAnyÚTypeVarÚCallableÚFrrrr&r'r9r(Úsr)r r r r Ú<module>s   H
6