id$|ddlZddlZddlZddlZddlZddlZddlZddlZejdZ ejdde fdZ dZ ejej fdZ ejdde fdZejdZGd d ZGd d ejejZGd dejZdS)Nc#Ktj}tj| |Vtj|dS#tj|wxYw)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 Y/opt/cloudlinux/venv/lib/python3.11/site-packages/pkg_resources/_vendor/jaraco/context.pypushdr sQ 9;;DHSMMM  s AAc #K|Gtj|dddd}|!t jt jd}ntj dt|dj dit d }d }d ||f}||j dd t|it||5|Vdddn #1swxYwY|d j ditdS#|d j ditwxYw)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$sW%%c**229bAAII&RTUU  ~":#8EEE 68JKKK  F &  & 0 0 0 01117"Kjj&'*++zszGG&7&<&<GGGHHH U:                       +$+55dff5566666+$+55dff556666s1,AED EDEDE$E'cf|dd}tddd}||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:s; Hccc***G ;;,c 2 22c#pKtj} |V||dS#||wxYw)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 r6r6NsP!!Hs( 5Tc#Kd|vrdnd}|5}|d||g}|r|d|gttjjd}|r|nd}t j|||VddddS#1swxYwYdS)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+ , , ,rw,,!+tc&1111sABBBc#KdVdS)z A null context suitable to stand in for a meaningful context. >>> with null() as value: ... assert value is None Nrrr1r nullrGts EEEEEr1ceZdZdZdZeffdZdZedZ edZ edZ dZ d Z ed d Zd Zd S) 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||_dSN) 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}|ot||j}|r||_|SrT) issubclassrLrV)rMrVrWmatchess r __exit__zExceptionTrap.__exit__s5{<:dDO<<  %$DMr1c*t|jSrK)boolrWrPs r __bool__zExceptionTrap.__bool__sDIr1_testcNtjfd}|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 ctj5}|i|dddn #1swxYwY|SrK)rIrL)argskwargstraprgfuncrMs r wrapperz%ExceptionTrap.raises..wrapperst// &4d%f%%% & & & & & & & & & & & & & & &5;; s +//)rwraps)rMrmrgrns``` r raiseszExceptionTrap.raisessF&             r1cD||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}{555r1N)__name__ __module__ __qualname____doc__rV ExceptionrNrQpropertyrWr[r^rbrerdrprtrr1r rIrIsB H#,,%%%%  X   X   X %)666666r1rIceZdZdZdS)suppressz A version of contextlib.suppress with decorator support. >>> @suppress(KeyError) ... def key_error(): ... {}[''] >>> key_error() N)rurvrwrxrr1r r|r|sr1r|c*eZdZdZ ddZdZdZdS) 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)() errorrZc"||_||_dSrK)actioncode)rMrrs r rNzon_interrupt.__init__s  r1c|SrKrrPs r rQzon_interrupt.__enter__rRr1c|tus |jdkrdS|jdkrt|j||jdkS)Nignorerr|)KeyboardInterruptr SystemExitr)rMexctypeexcinstexctbs r rbzon_interrupt.__exit__sK + + +t{h/F/F F [G # #TY''W 4{j((r1N)rrZ)rurvrwrxrNrQrbrr1r r~r~sZ( )))))r1r~)rr contextlibrr3shutilrrrcontextmanagerr r$rrmtreer6rErGrIr|ContextDecoratorr~rr1r rs        $(U7777:333( ]$ !$    n6n6n6n6n6n6n6n6bz"J$?%)%)%)%)%):.%)%)%)%)%)r1