_d$ddlZddlZddlZddlZddlZddlZddlZddlZejdZ ejdde fdZ dZ ejejfdZ ejdde fdZejdZGd d ZGd d ej"ej$ZGd dej$Zy)Nc#Ktj}tj| |tj|y#tj|wxYww)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)osgetcwdchdir)dirorigs C/usr/lib/python3/dist-packages/setuptools/_vendor/jaraco/context.pypushdr s> 99;DHHSM  s*A!AA!AA!c #K|?tjj|jddjdd}|&t j t jd}ntjdt|djdit d }d }d j||f}||jdd t|it||5|ddd|d jdity#1swY*xYw#|d jditwxYww)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.gzz.tgzT)shellzrunner parameter is deprecatedzmkdir {target_dir}zwget {url} -O -z7tar x{compression} --strip-components=1 -C {target_dir}z | compressionzrm -Rf {target_dir})rpathbasenamereplace functoolspartial subprocess check_callwarningswarnDeprecationWarningformatvarsjoininfer_compression)url target_dirrunnerr getterextractcmds r tarball_contextr$s,WW%%c*229bAII&RTU  ~"":#8#8E 68JK  &  & & 0 017"Kjj&'*+zszzG&7&<GGH :     +$++5df56   +$++5df56s7B$E'A D+1D6D+>!ED($D++"E  EcL|dd}tddd}|j|dS)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' NzjJ)gzbzxz)dictget)rcompression_indicatormappings r rr:s0 Hccc*G ;;,c 22c#hKtj} |||y#||wxYww)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)tempfilemkdtemp)removertemp_dirs r r6r6Ns0!Hs2% 2 /2Tc#Kd|vrdnd}|5}|d||g}|r|jd|gttjjd}|r|nd}t j |||dddy#1swYyxYww)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. githgclonez--branchwN)stdout)extendopenrrdevnullrr) rbranchquietdest_ctxexerepo_dirr#r?r<s r repo_contextrEasC<%TC xGS(+  JJ F+ ,rww,!tc&1sBA!A<3 B<BBc#Kdyw)z A null context suitable to stand in for a meaningful context. >>> with null() as value: ... assert value is None Nrrr1r nullrGts  scteZdZdZdZeffdZdZedZ edZ edZ dZ d Z ed d Zd Zy ) 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 )NNNc||_yN) exceptions)selfrLs r __init__zExceptionTrap.__init__s $r1c|SrKrrMs r __enter__zExceptionTrap.__enter__ r1c |jdSNrexc_inforPs r typezExceptionTrap.type}}Qr1c |jdS)NrUrPs r valuezExceptionTrap.valuerXr1c |jdS)NrUrPs r tbzExceptionTrap.tbrXr1cV|d}|xrt||j}|r||_|SrT) issubclassrLrV)rMrVrWmatchess r __exit__zExceptionTrap.__exit__s/{<:dDOO< $DMr1c,t|jSrK)boolrWrPs r __bool__zExceptionTrap.__bool__sDIIr1_testcJtjfd}|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 cxtj5}|i|dddS#1swYxYwrK)rIrL)argskwargstraprgfuncrMs r wrapperz%ExceptionTrap.raises..wrappers=t/ &4d%f% &;  & &s 09)rwraps)rMrmrgrns``` r raiseszExceptionTrap.raisess'&      r1cD|j|tjS)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 rf)rpoperatornot_)rMrms r passeszExceptionTrap.passess&{{4x}}{55r1N)__name__ __module__ __qualname____doc__rV ExceptionrNrQpropertyrWr[r^rbrerdrprtrr1r rIrIssB H#,,%      %)66r1rIceZdZdZy)suppressz A version of contextlib.suppress with decorator support. >>> @suppress(KeyError) ... def key_error(): ... {}[''] >>> key_error() N)rurvrwrxrr1r r|r|sr1r|c(eZdZdZ ddZdZdZy) 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)() c ||_||_yrK)actioncode)rMrrs r rNzon_interrupt.__init__s  r1c|SrKrrPs r rQzon_interrupt.__enter__rRr1c|tus|jdk(ry|jdk(rt|j||jdk(S)Nignoreerrorr|)KeyboardInterruptr SystemExitr)rMexctypeexcinstexctbs r rbzon_interrupt.__exit__sE + +t{{h/F  [[G #TYY'W 4{{j((r1N)rrZ)rurvrwrxrNrQrbrr1r r~r~s ( )r1r~)rr contextlibrr3shutilrrrcontextmanagerr r$rrmtreer6rErGrIr|ContextDecoratorr~rr1r rs       $(U77:3( ]]$ !$   n6n6bz""J$?$?%):..%)r1