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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
U
H=®dBã    @s¸dZddlZddlZddlZddlmZddlmZddddd    d
d d d g    Zedg7Zej    dd…dkrnej
Z ne  de fddi¡Z dd„Zdd„ZGdd„de ƒZGdd    „d    e ƒZGdd„deƒZdd„ZGdd„de ƒZGdd„de ƒZGd d „d eƒZGd!d „d eƒZGd"d „d e ƒZej    dd#kZer@d$d%„Zd&d'„Znd(d%„Zd)d'„Zzdd*lmZWnek
rzeZ Yn
Xd+d,„Z Gd-d
„d
e ƒZ!Gd.d„de!ƒZ"Gd/d„deƒZ#dS)0zAcontextlib2 - backports and enhancements to the contextlib moduleéN)Údeque©ÚwrapsÚcontextmanagerÚclosingÚ nullcontextÚAbstractContextManagerÚContextDecoratorÚ    ExitStackÚredirect_stdoutÚredirect_stderrÚsuppressÚ ContextStacké)ééÚABCÚ    __slots__©cCs0||kr dS| |¡|jD]}t||ƒq|S©N)ÚappendÚ    __bases__Ú _classic_mro)ÚCÚresultÚBrrúND:\z\workplace\VsCode\pyvenv\venv\Lib\site-packages\pip/_vendor/contextlib2.pyrs 
 
 rcGsvz
|j}Wn"tk
r,tt|gƒƒ}YnX|D]>}|D],}||jkr:|j|dkrbtSq2q:tSq2dS)NT)Ú__mro__ÚAttributeErrorÚtuplerÚ__dict__ÚNotImplemented)rÚmethodsÚmroÚmethodrrrrÚ_check_methods$s
 
 
r%c@s2eZdZdZdd„Zejdd„ƒZedd„ƒZ    dS)    rz,An abstract base class for context managers.cCs|S)z0Return `self` upon entering the runtime context.r©ÚselfrrrÚ    __enter__8sz AbstractContextManager.__enter__cCsdS)z9Raise any exception triggered within the runtime context.Nr)r'Úexc_typeÚ    exc_valueÚ    tracebackrrrÚ__exit__<szAbstractContextManager.__exit__cCs|tkrt|ddƒStS)z<Check whether subclass is considered a subclass of this ABC.r(r,)rr%r!)ÚclsrrrrÚ__subclasshook__As z'AbstractContextManager.__subclasshook__N)
Ú__name__Ú
__module__Ú __qualname__Ú__doc__r(ÚabcÚabstractmethodr,Ú classmethodr.rrrrr5s 
c@s(eZdZdZdd„Zdd„Zdd„ZdS)    r    zJA base class or mixin that enables context managers to work as decorators.cCst dt¡| ¡S)aÁReturns the context manager used to actually wrap the call to the
        decorated function.
 
        The default implementation just returns *self*.
 
        Overriding this method allows otherwise one-shot context managers
        like _GeneratorContextManager to support use as decorators via
        implicit recreation.
 
        DEPRECATED: refresh_cm was never added to the standard library's
                    ContextDecorator API
        z2refresh_cm was never added to the standard library)ÚwarningsÚwarnÚDeprecationWarningÚ _recreate_cmr&rrrÚ
refresh_cmLs ÿzContextDecorator.refresh_cmcCs|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.
        rr&rrrr9]s
zContextDecorator._recreate_cmcstˆƒ‡‡fdd„ƒ}|S)Nc
s*ˆ ¡ˆ||ŽW5QR£SQRXdSr)r9©ÚargsÚkwds©Úfuncr'rrÚinnerjs
z(ContextDecorator.__call__.<locals>.innerr)r'r?r@rr>rÚ__call__iszContextDecorator.__call__N)r/r0r1r2r:r9rArrrrr    Is c@s0eZdZdZdd„Zdd„Zdd„Zdd    „Zd
S) Ú_GeneratorContextManagerz%Helper for @contextmanager decorator.cCsJ|||Ž|_||||_|_|_t|ddƒ}|dkr@t|ƒj}||_dS)Nr2)Úgenr?r<r=ÚgetattrÚtyper2)r'r?r<r=ÚdocrrrÚ__init__ts   
z!_GeneratorContextManager.__init__cCs| |j|j|j¡Sr)Ú    __class__r?r<r=r&rrrr9‚sz%_GeneratorContextManager._recreate_cmcCs.z t|jƒWStk
r(tdƒ‚YnXdS)Nzgenerator didn't yield)ÚnextrCÚ StopIterationÚ RuntimeErrorr&rrrr(ˆs z"_GeneratorContextManager.__enter__c
Csþ|dkr8zt|jƒWntk
r,YdSXtdƒ‚nÂ|dkrF|ƒ}z|j |||¡tdƒ‚Wn–tk
r}z||k    WY¢Sd}~XYnjtk
rÜ}z0||kr²WY¢"dStrÊ|j|krÊWY¢
dS‚W5d}~XYnt ¡d|k    rô‚YnXdS)Nzgenerator didn't stopz#generator didn't stop after throw()Fé)    rIrCrJrKÚthrowÚ_HAVE_EXCEPTION_CHAININGÚ    __cause__ÚsysÚexc_info)r'rEÚvaluer+Úexcrrrr,Žs,
 
 
z!_GeneratorContextManager.__exit__N)r/r0r1r2rGr9r(r,rrrrrBqs
rBcstˆƒ‡fdd„ƒ}|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>
 
    cs tˆ||ƒSr)rBr;©r?rrÚhelperÕszcontextmanager.<locals>.helperr)r?rUrrTrr¹sc@s(eZdZdZdd„Zdd„Zdd„ZdS)    ra2Context 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()
 
    cCs
||_dSr©Úthing)r'rWrrrrGìszclosing.__init__cCs|jSrrVr&rrrr(ïszclosing.__enter__cGs|j ¡dSr)rWÚclose)r'rQrrrr,òszclosing.__exit__N©r/r0r1r2rGr(r,rrrrrÛsc@s(eZdZdZdd„Zdd„Zdd„ZdS)Ú_RedirectStreamNcCs||_g|_dSr)Ú _new_targetÚ _old_targets)r'Ú
new_targetrrrrGúsz_RedirectStream.__init__cCs*|j tt|jƒ¡tt|j|jƒ|jSr)r\rrDrPÚ_streamÚsetattrr[r&rrrr(ÿsz_RedirectStream.__enter__cCstt|j|j ¡ƒdSr)r_rPr^r\Úpop©r'ÚexctypeÚexcinstÚexctbrrrr,sz_RedirectStream.__exit__)r/r0r1r^rGr(r,rrrrrZösrZc@seZdZdZdZdS)r aAContext 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/r0r1r2r^rrrrr s c@seZdZdZdZdS)r zCContext manager for temporarily redirecting stderr to another file.ÚstderrNrfrrrrr sc@s(eZdZdZdd„Zdd„Zdd„ZdS)    r a?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
    cGs
||_dSr)Ú _exceptions)r'Ú
exceptionsrrrrG)szsuppress.__init__cCsdSrrr&rrrr(,szsuppress.__enter__cCs|dk    ot||jƒSr)Ú
issubclassrhrarrrr,/s
zsuppress.__exit__NrYrrrrr s
rcs‡fdd„}|S)Ncs4|j}||krdS|dks*|ˆkr$q*|}q||_dSr)Ú __context__)Únew_excÚold_excÚ exc_context©Ú    frame_excrrÚ_fix_exception_context@sz3_make_context_fixer.<locals>._fix_exception_contextr)rprqrrorÚ_make_context_fixer?s rrcCs<z|dj}|d‚Wn tk
r6||d_‚YnXdS)NrL)rkÚ BaseException)Ú exc_detailsÚ    fixed_ctxrrrÚ_reraise_with_existing_contextOs 
 
rvcCsdd„S)NcSsdSrr)rlrmrrrÚ<lambda>[óz%_make_context_fixer.<locals>.<lambda>rrorrrrrZscCs|\}}}tdƒdS)Nz!raise exc_type, exc_value, exc_tb)Úexec)rtr)r*Úexc_tbrrrrv_s
)Ú InstanceTypecCst|ƒ}|tkr|jS|Sr)rEr{rH)ÚobjZobj_typerrrÚ    _get_typeksr}c@sXeZdZdZdd„Zdd„Zdd„Zdd    „Zd
d „Zd d „Z    dd„Z
dd„Z dd„Z dS)r
a‹Context 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
 
    cCs tƒ|_dSr)rÚ_exit_callbacksr&rrrrGszExitStack.__init__cCst|ƒƒ}|j|_tƒ|_|S)z?Preserve the context stack by transferring it to a new instance)rEr~r)r'Ú    new_stackrrrÚpop_all‚s
zExitStack.pop_allcs"‡‡fdd„}ˆ|_| |¡dS)z:Helper to correctly register callbacks to __exit__ methodscsˆˆf|žŽSrr)rt©ÚcmÚcm_exitrrÚ _exit_wrapper‹sz.ExitStack._push_cm_exit.<locals>._exit_wrapperN)Ú__self__Úpush)r'r‚rƒr„rrrÚ _push_cm_exit‰szExitStack._push_cm_exitcCsDt|ƒ}z
|j}Wn tk
r2|j |¡YnX| ||¡|S)aRegisters a callback with the standard __exit__ method signature
 
        Can suppress exceptions the same way __exit__ methods can.
 
        Also accepts any object with an __exit__ method (registering a call
        to the method instead of the object itself)
        )r}r,rr~rr‡)r'ÚexitÚ_cb_typeÚ exit_methodrrrr†s
 
 zExitStack.pushcs$‡‡‡fdd„}ˆ|_| |¡ˆS)z\Registers an arbitrary callback and arguments.
 
        Cannot suppress exceptions.
        csˆˆˆŽdSrr)r)rSÚtb©r<Úcallbackr=rrr„©sz)ExitStack.callback.<locals>._exit_wrapper)Ú __wrapped__r†)r'rr<r=r„rrŒrr¤s
zExitStack.callbackcCs(t|ƒ}|j}| |¡}| ||¡|S)zªEnters the supplied context manager
 
        If successful, also pushes its __exit__ method as a callback and
        returns the result of the __enter__ method.
        )r}r,r(r‡)r'r‚Ú_cm_typeÚ_exitrrrrÚ enter_context±s
 
 zExitStack.enter_contextcCs| ddd¡dS)z$Immediately unwind the context stackN)r,r&rrrrX¾szExitStack.closecCs|Srrr&rrrr(ÂszExitStack.__enter__c    Gs–|ddk    }t ¡d}t|ƒ}d}d}|jr‚|j ¡}z||ŽrNd}d}d}Wq(t ¡}||d|dƒd}|}Yq(Xq(|rŽt|ƒ|o”|S)NrrLFT)NNN)rPrQrrr~r`rv)    r'rtÚ received_excrprqÚsuppressed_excÚ pending_raiseÚcbÚnew_exc_detailsrrrr,Ås(  
 zExitStack.__exit__N) r/r0r1r2rGr€r‡r†rr‘rXr(r,rrrrr
ss   cs8eZdZdZ‡fdd„Zdd„Zdd„Zdd    „Z‡ZS)
rz+Backwards compatibility alias for ExitStackcst dt¡tt|ƒ ¡dS)Nz*ContextStack has been renamed to ExitStack)r6r7r8ÚsuperrrGr&©rHrrrGçsÿzContextStack.__init__cCs
| |¡Sr)r†)r'rrrrÚ register_exitìszContextStack.register_exitcOs|j|f|ž|ŽSr)r)r'rr<r=rrrÚregisterïszContextStack.registercCs| ¡Sr)r€r&rrrÚpreserveòszContextStack.preserve)    r/r0r1r2rGr™ršr›Ú __classcell__rrr˜rräs
 c@s*eZdZdZd    dd„Zdd„Zdd„ZdS)
raMContext 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
    NcCs
||_dSr©Ú enter_result)r'ržrrrrGÿsznullcontext.__init__cCs|jSrrr&rrrr(sznullcontext.__enter__cGsdSrr)r'Úexcinforrrr,sznullcontext.__exit__)NrYrrrrrös
)$r2r3rPr6Ú collectionsrÚ    functoolsrÚ__all__Ú version_inforÚ_abc_ABCÚABCMetaÚobjectrr%rr    rBrrrZr r r rNrrrvÚtypesr{Ú ImportErrorrEr}r
rrrrrrÚ<module>sT  ý
 
(H"
 
q