3 ]ddlmZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl mZejdkrddlmZnddlZejdd Zej dd d Zd!dZdZeeeZejdZdZejejfdZejddefdZdZGddZGddejej ZGddej Z!dS)") annotationsN)Iterator) )tarfiledirstr | os.PathLikereturnIterator[str | os.PathLike]c#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)rorigs s/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib/python3.11/site-packages/setuptools/_vendor/jaraco/context.pypushdrsQ 9;;DHSMMM  s AA target_dirstr | os.PathLike | Nonec#K|Gtj|dddd}tj| t j|}tj |d5}| |tdddn #1swxYwY|Vtj |dS#tj |wxYw)a Get a tarball, extract it, yield, then clean up. >>> import urllib.request >>> url = getfixture('tarfile_served') >>> target = getfixture('tmp_path') / 'out' >>> tb = tarball(url, target_dir=target) >>> import pathlib >>> with tb as extracted: ... contents = pathlib.Path(extracted, 'contents.txt').read_text(encoding='utf-8') >>> assert not os.path.exists(extracted) Nz.tar.gzz.tgzzr|*)fileobjmode)pathfilter)r rbasenamereplacemkdirurllibrequesturlopenropen extractallstrip_first_componentshutilrmtree)urlrreqtfs rtarballr)'s6 W%%c**229bAAII&RTUU HZ"n$$S)) \#E 2 2 2 Ib MMz2GM H H H I I I I I I I I I I I I I I I j!!!!! j!!!!s0!5C$B?3 C$?CC$CC$$C:membertarfile.TarInfocL|jdd\}|_|S)N/)namesplit)r*r_s rr#r#Gs&[&&sA..NAv{ McLd}tj|t|S)a Compose any number of dependent context managers into a single one. The last, innermost context manager may take arbitrary arguments, but each successive context manager should accept the result from the previous as a single parameter. Like :func:`jaraco.functools.compose`, behavior works from right to left, so the context manager should be indicated from outermost to innermost. Example, to create a context manager to change to a temporary directory: >>> temp_dir_as_cwd = _compose(pushd, temp_dir) >>> with temp_dir_as_cwd() as dir: ... assert os.path.samefile(os.getcwd(), dir) c:fd}tj|S)Nc?K|i|5}|5}|Vdddn #1swxYwYddddS#1swxYwYdSN)argskwargssavedresinnerouters rcomposedz/_compose..compose_two..composedds''' 5%%,, #                                  s, A) A- A- AAA) contextlibcontextmanager)r<r=r>s`` r compose_twoz_compose..compose_twocs5      (222r2) functoolsreducereversed)cmgrsrAs r_composerFOs,(333  K% 9 99r2c/Ktjdtd|dt}t |i|5}||5}|Vdddn #1swxYwYddddS#1swxYwYdS)NzBtarball_context is deprecated. Use tarball or tarball_cwd instead. stacklevelr)warningswarnDeprecationWarningpoprr))r8r9 pushd_ctxtballrs rtarball_contextrQps ML  7E**I $ !& ! !UIIe,<,< s6 A;A# A;#A' 'A;*A' +A;;A?A?ctjdtd|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' z3infer_compression is deprecated with no replacementrHrINzjJ)gzbzxz)rKrLrMdictget)r&compression_indicatormappings rinfer_compressionr^|s_ M=  Hccc***G ;;,c 2 22r2c#pKtj} |V||dS#||wxYw)a` 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', encoding='utf-8') >>> assert not os.path.exists(the_dir) N)tempfilemkdtemp)removertemp_dirs rrcrcsP!!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)extendr!r rdevnull subprocess check_call) r&branchquietdest_ctxexerepo_dircmdrkris r repo_contextrtsC<<%%TC xGS(+  - JJ F+ , , ,rw,,!+tc&1111sABBBc`tjdtdtjS)aD A null context suitable to stand in for a meaningful context. >>> with null() as value: ... assert value is None This context is most useful when dealing with two or more code branches but only some need a context. Wrap the others in a null context to provide symmetry across all options. z.null is deprecated. Use contextlib.nullcontextrHrI)rKrLrMr? nullcontextr7r2rnullrws7 M8  ! # ##r2ceZdZdZdZeffdZdZedZ 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||_dSr6) exceptions)selfr{s r__init__zExceptionTrap.__init__s $r2c|Sr6r7r|s r __enter__zExceptionTrap.__enter__ r2c|jdSNrexc_infors rtypezExceptionTrap.type}Qr2c|jdS)Nr.rrs rvaluezExceptionTrap.valuerr2c|jdS)NrHrrs rtbzExceptionTrap.tbrr2cV|d}|ot||j}|r||_|Sr) issubclassr{r)r|rrmatchess r__exit__zExceptionTrap.__exit__s5{<:dDO<<  %$DMr2c*t|jSr6)boolrrs r__bool__zExceptionTrap.__bool__ sDIr2_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|Sr6)ryr{)r8r9traprfuncr|s rwrapperz%ExceptionTrap.raises..wrapper!st// &4d%f%%% & & & & & & & & & & & & & & &5;; s +//)rBwraps)r|rrrs``` rraiseszExceptionTrap.raisessF&             r2cD||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 r)roperatornot_)r|rs rpasseszExceptionTrap.passes)s&{{4x}{555r2N)__name__ __module__ __qualname____doc__r Exceptionr}rpropertyrrrrrrrrr7r2rryrysB H#,,%%%%  X   X   X %)666666r2ryceZdZdZdS)suppressz A version of contextlib.suppress with decorator support. >>> @suppress(KeyError) ... def key_error(): ... {}[''] >>> key_error() N)rrrrr7r2rrr?sr2rc&eZdZdZddZdZdZdS) 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.c"||_||_dSr6)actioncode)r|rrs rr}zon_interrupt.__init__]s  r2c|Sr6r7rs rrzon_interrupt.__enter__arr2c|tus |jdkrdS|jdkrt|j||jdkS)Nignorerr)KeyboardInterruptr SystemExitr)r|exctypeexcinstexctbs rrzon_interrupt.__exit__dsK + + +t{h/F/F F [G # #TY''W 4{j((r2N)rr.)rrrrr}rrr7r2rrrJsP$)))))r2r)rr r r r6)rrr r )r*r+r r+)" __future__rr?rBrr r$rlsysr`urllib.requestrrKtypingr version_info backportsrr@rr)r#rF tarball_cwdrQr^r%rcrtrwryrContextDecoratorrr7r2rrsn""""""  g!!!!!!!NNN       04""""">:::<hug&&  3332 ]$ !$$$$&n6n6n6n6n6n6n6n6bz"J$?))))):.)))))r2