a „oe$ã@sÞddlZddlZddlZddlZddlZddlZddlZddlZejdd„ƒZ ejdde fdd„ƒZ dd„Z ejej fdd „ƒZ ejdd e fd d „ƒZejd d„ƒZGdd„dƒZGdd„dejejƒZGdd„dejƒZdS)éNc cs8t ¡}t |¡z|VWt |¡n t |¡0dS)zµ >>> tmp_path = getfixture('tmp_path') >>> with pushd(tmp_path): ... assert os.getcwd() == os.fspath(tmp_path) >>> assert os.getcwd() != os.fspath(tmp_path) N)ÚosÚgetcwdÚchdir)ÚdirZorig©rúBC:\Program Files\Certbot\pkgs\setuptools\_vendor\jaraco\context.pyÚpushd s  rc csú|dur$tj |¡ dd¡ dd¡}|dur>tjtjdd�}n t  dt ¡|dj fit ƒ¤Žƒz|d }d }d   ||f¡}||j fd t|ƒit ƒ¤Žƒ||ƒ�|VWdƒn1sº0YW|d j fit ƒ¤Žƒn|d j fit ƒ¤Žƒ0dS)zÆ Get a tarball, extract it, change to that directory, yield, then clean up. `runner` is the function to invoke commands. `pushd` is a context manager for changing the directory. Nz.tar.gzÚz.tgzT)Úshellzrunner parameter is deprecatedzmkdir {target_dir}zwget {url} -O -z7tar x{compression} --strip-components=1 -C {target_dir}z | Ú compressionzrm -Rf {target_dir})rÚpathÚbasenameÚreplaceÚ functoolsÚpartialÚ subprocessÚ check_callÚwarningsÚwarnÚDeprecationWarningÚformatÚvarsÚjoinÚinfer_compression)ÚurlZ target_dirZrunnerrÚgetterÚextractÚcmdrrrÚtarball_contexts  &rcCs&|dd…}tdddd�}| |d¡S)a Given a URL or filename, infer the compression code for tar. >>> infer_compression('http://foo/bar.tar.gz') 'z' >>> infer_compression('http://foo/bar.tgz') 'z' >>> infer_compression('file.bz') 'j' >>> infer_compression('file.xz') 'J' éþÿÿÿNÚzÚjÚJ)ÚgzZbzÚxz)ÚdictÚget)rZcompression_indicatorÚmappingrrrr:s rccs*t ¡}z|VW||ƒn ||ƒ0dS)aN Create a temporary directory context. Pass a custom remover to override the removal behavior. >>> import pathlib >>> with temp_dir() as the_dir: ... assert os.path.isdir(the_dir) ... _ = pathlib.Path(the_dir).joinpath('somefile').write_text('contents') >>> assert not os.path.exists(the_dir) N)ÚtempfileZmkdtemp)ZremoverÚtemp_dirrrrr)Ns r)Tc cs†d|vr dnd}|ƒ�\}|d||g}|r6| d|g¡ttjjdƒ}|rL|nd}tj||d�|VWdƒn1sx0YdS)z  Check out the repo indicated by url. If dest_ctx is supplied, it should be a context manager to yield the target directory for the check out. ÚgitZhgZclonez--branchÚwN)Ústdout)ÚextendÚopenrr Údevnullrr) rÚbranchÚquietZdest_ctxZexeZrepo_dirrr/r,rrrÚ repo_contextas  r2ccs dVdS)z‡ A null context suitable to stand in for a meaningful context. >>> with null() as value: ... assert value is None NrrrrrÚnulltsr3c@steZdZdZdZeffdd„Zdd„Zedd„ƒZ ed d „ƒZ ed d „ƒZ d d„Z dd„Z edœdd„Zdd„ZdS)Ú ExceptionTrapa© A context manager that will catch certain exceptions and provide an indication they occurred. >>> with ExceptionTrap() as trap: ... raise Exception() >>> bool(trap) True >>> with ExceptionTrap() as trap: ... pass >>> bool(trap) False >>> with ExceptionTrap(ValueError) as trap: ... raise ValueError("1 + 1 is not 3") >>> bool(trap) True >>> trap.value ValueError('1 + 1 is not 3') >>> trap.tb >>> with ExceptionTrap(ValueError) as trap: ... raise Exception() Traceback (most recent call last): ... Exception >>> bool(trap) False )NNNcCs ||_dS©N)Ú exceptions)Úselfr6rrrÚ__init__£szExceptionTrap.__init__cCs|Sr5r©r7rrrÚ __enter__¦szExceptionTrap.__enter__cCs |jdS©Nr©Úexc_infor9rrrÚtype©szExceptionTrap.typecCs |jdS)Nér<r9rrrÚvalue­szExceptionTrap.valuecCs |jdS)Nér<r9rrrÚtb±szExceptionTrap.tbcGs&|d}|ot||jƒ}|r"||_|Sr;)Ú issubclassr6r=)r7r=r>ÚmatchesrrrÚ__exit__µs zExceptionTrap.__exit__cCs t|jƒSr5)Úboolr>r9rrrÚ__bool__¼szExceptionTrap.__bool__©Ú_testcst ˆ¡‡‡‡fdd„ƒ}|S)a± Wrap func and replace the result with the truth value of the trap (True if an exception occurred). First, give the decorator an alias to support Python 3.8 Syntax. >>> raises = ExceptionTrap(ValueError).raises Now decorate a function that always fails. >>> @raises ... def fail(): ... raise ValueError('failed') >>> fail() True cs@tˆjƒ�}ˆ|i|¤ŽWdƒn1s.0Yˆ|ƒSr5)r4r6)ÚargsÚkwargsZtrap©rIÚfuncr7rrÚwrapperÒs ,z%ExceptionTrap.raises..wrapper)rÚwraps)r7rMrIrNrrLrÚraises¿szExceptionTrap.raisescCs|j|tjd�S)aª Wrap func and replace the result with the truth value of the trap (True if no exception). First, give the decorator an alias to support Python 3.8 Syntax. >>> passes = ExceptionTrap(ValueError).passes Now decorate a function that always fails. >>> @passes ... def fail(): ... raise ValueError('failed') >>> fail() False rH)rPÚoperatorÚnot_)r7rMrrrÚpassesÚszExceptionTrap.passesN)Ú__name__Ú __module__Ú __qualname__Ú__doc__r=Ú Exceptionr8r:Úpropertyr>r@rBrErGrFrPrSrrrrr4s!   r4c@seZdZdZdS)ÚsuppresszŸ A version of contextlib.suppress with decorator support. >>> @suppress(KeyError) ... def key_error(): ... {}[''] >>> key_error() N)rTrUrVrWrrrrrZðsrZc@s*eZdZdZd dd„Zdd„Zdd „Zd S) Ú on_interrupta Replace a KeyboardInterrupt with SystemExit(1) >>> def do_interrupt(): ... raise KeyboardInterrupt() >>> on_interrupt('error')(do_interrupt)() Traceback (most recent call last): ... SystemExit: 1 >>> on_interrupt('error', code=255)(do_interrupt)() Traceback (most recent call last): ... SystemExit: 255 >>> on_interrupt('suppress')(do_interrupt)() >>> with __import__('pytest').raises(KeyboardInterrupt): ... on_interrupt('ignore')(do_interrupt)() Úerrorr?cCs||_||_dSr5)ÚactionÚcode)r7r]r^rrrr8szon_interrupt.__init__cCs|Sr5rr9rrrr:szon_interrupt.__enter__cCs6|tus|jdkrdS|jdkr,t|jƒ|‚|jdkS)NÚignorer\rZ)ÚKeyboardInterruptr]Ú SystemExitr^)r7ÚexctypeÚexcinstÚexctbrrrrEs   zon_interrupt.__exit__N)r\r?)rTrUrVrWr8r:rErrrrr[ûs û r[)rrÚ contextlibrr(ÚshutilrQrÚcontextmanagerrrrÚrmtreer)r2r3r4rZÚContextDecoratorr[rrrrÚs*  q