bg3ddlZddlZddlZddlmZddlmZddlmZddl m Z m Z m Z m Z mZddlmZddlmZdd lmZe ee efZe rddlZGd d Zd eegeffd ZdS)N)Path)compile)mkdtemp)UnionSequence TYPE_CHECKINGTupleCallable)compare)wrap)rmtreec eZdZdZeZdZdZ d%dddddee e dfde e d e d e fd Z ed Zd&dZd'dZed'dZ d(dede de de fdZd)dede fdZ d*de e dede de de f dZdZdefdZd%dedeee fd e fdZd%dee e e fd e fdZeZd%ded e fd Zd%ded dfd!Zd%ded e d eee ffd"Zd#Z d$Z!dS)+ TempDirectoryad A class representing a temporary directory on disk. :param ignore: A sequence of strings containing regular expression patterns that match filenames that should be ignored by the :class:`TempDirectory` listing and checking methods. :param create: If `True`, the temporary directory will be created as part of class instantiation. :param path: If passed, this should be a string containing an absolute path to use as the temporary directory. When passed, :class:`TempDirectory` will not create a new directory to use. :param encoding: A default encoding to use for :meth:`read` and :meth:`write` operations when the ``encoding`` parameter is not passed to those methods. FN)ignorecreateencodingpathz py.path.localrrrcg|_|D])}|jt|*|rt|nd|_||_t ||_|s|||dSdSdSN) rappendrstrrrbool dont_remover)selfrrrrregexs k/builddir/build/BUILD/cloudlinux-venv-1.0.7/venv/lib/python3.11/site-packages/testfixtures/tempdirectory.py__init__zTempDirectory.__init__3s  / /E K  wu~~ . . . .!%/CIII4   ::  dlv~ KKMMMMM#l~~c|jr;tjddd|jDzdSdS)Nz6TempDirectory instances not cleaned up by shutdown: %s c3$K|] }|jV dSr)r).0is r z'TempDirectory.atexit..Is$!@!@Q!&!@!@!@!@!@!@r ) instanceswarningswarnjoin)clss ratexitzTempDirectory.atexitDs_ =  M !@!@#-!@!@!@@@B       r returnc|jr|St|_|j||jjs%t j|jd|j_|S)zt Create a temporary directory for this instance to use if one has not already been created. T)rrr'add __class__ atexit_setupr,registerrs rrzTempDirectory.createLsb 9 KII  4   ~* / ODK ( ( (*.DN ' r c|jrAtj|jr|jst |j|`||jvr|j|dSdS)z Delete the temporary directory and anything in it. This :class:`TempDirectory` cannot be used again unless :meth:`create` is called. N)rosexistsrrr'remover3s rcleanupzTempDirectory.cleanupZsu 9  22 4;K  49    4> ! ! N ! !$ ' ' ' ' ' " !r c\t|jD]}|dS)zn Delete all temporary directories associated with all :class:`TempDirectory` objects. N)tupler'r8)r+r%s r cleanup_allzTempDirectory.cleanup_allfs6 s}%%  A IIKKKK  r recursive files_only followlinksc|r||n|j}g}|rtj||D]\}}}d|t |dzdtj}|r|dz }|D]} |s||| zdz t|D]} ||| zn,tj |D]} || g} t|D]?}d} |j D]}| |rd} n| r*| |@| S)N)r>/r FT) _joinrr5walkr*lensplitseprsortedlistdirrsearch)rrr<r=r>resultdirpathdirnames filenamesdirnamenamenfilteredrrs ractualzTempDirectory.actualos$(6tzz$TY  !02k111 0 0,9((73t99Q;<<#8#>#>rv#F#FGG#sNG';;G%; ggoc&9:::"9--00DMM'$,////0 0Z%% ! ! a    6NN " "DF  <<%%!FE  OOD ! ! ! !r c||||}|std|D]}t|dS)a Print the contents of the specified directory. :param path: The path to list, which can be: * `None`, indicating the root of the temporary directory should be listed. * A tuple of strings, indicating that the elements of the tuple should be used as directory names to traverse from the root of the temporary directory to find the directory to be listed. * A forward-slash separated string, indicating the directory or subdirectory that should be traversed to from the temporary directory and listed. :param recursive: If `True`, the directory specified will have its subdirectories recursively listed too. zNo files or directories found.N)rQprint)rrr<rQrOs rrGzTempDirectory.listdirsT.T9-- 4 2 3 3 3  A !HHHH  r Texpectedc d}tt|t|||||ddS)a Compare the expected contents with the actual contents of the temporary directory. An :class:`AssertionError` will be raised if they are not the same. :param expected: A sequence of strings containing the paths expected in the directory. These paths should be forward-slash separated and relative to the root of the temporary directory. :param path: The path to use as the root for the comparison, relative to the root of the temporary directory. This can either be: * A tuple of strings, making up the relative path. * A forward-slash separated string. If it is not provided, the root of the temporary directory will be used. :param files_only: If specified, directories will be excluded from the list of actual paths used in the comparison. :param recursive: If ``False``, only the direct contents of the directory specified by ``path`` will be included in the actual contents used for comparison. :param followlinks: If ``True``, symlinks and hard links will be followed when recursively building up the actual list of directory contents. TF)rTrQr<N)r rFr:rQ)rrTrr=r<r>__tracebackhide__s rr zTempDirectory.comparesaR!))T[[)Z  ! ! ! ! ! !r ct|tr|d}tj|tj}|tjr+||jr|Stdtj|j|S)Nr@z8Attempt to read or write outside the temporary Directory) isinstancerrDr5rEr*rstrip startswithr ValueError)rrNrelatives rrAzTempDirectory._joins dC  #::c??D6;;t$$++BF33   rv & & ""49-- J w||DIx000r rJcX||}tj||S)a Make an empty directory at the specified path within the temporary directory. Any intermediate subdirectories that do not exist will also be created. :param dirpath: The directory to create, which can be: * A tuple of strings. * A forward-slash separated string. :returns: The absolute path of the created directory. )rAr5makedirs)rrJthepaths rmakedirzTempDirectory.makedirs***W%% Gr filepathdatact|tr|d}t|dkrP||dd}t j|st j|||}|p|j }|| |}t|d5}| |dddn #1swxYwY|S)a Write the supplied data to a file at the specified path within the temporary directory. Any subdirectories specified that do not exist will also be created. The file will always be written in binary mode. The data supplied must either be bytes or an encoding must be supplied to convert the string into bytes. :param filepath: The path to the file to create, which can be: * A tuple of strings. * A forward-slash separated string. :param data: :class:`bytes` containing the data to be written, or a :class:`str` if ``encoding`` has been supplied. :param encoding: The encoding to be used if data is not bytes. Should not be passed if data is already bytes. :returns: The absolute path of the file written. r@r Nwb) rXrrDrCrAr5rr6r^rencodeopenwrite)rrarbrrJr_fs rrhzTempDirectory.writes!4 h $ $ +~~c**H x==1  jj#2#//G7>>'** % G$$$**X&&,t}  ;;x((D '4  A GGDMMM               sC55C9<C9c>||jn||S)ao Return the full path on disk that corresponds to the path relative to the temporary directory that is passed in. :param path: The path to the file to create, which can be: * A tuple of strings. * A forward-slash separated string. :returns: A string containing the absolute path. )rrArrs r as_stringzTempDirectory.as_string,s !Ltyydjj.>.>>r cXt||jn||S)a9 Return the :class:`~pathlib.Path` that corresponds to the path relative to the temporary directory that is passed in. :param path: The path to the file to create, which can be: * A tuple of strings. * A forward-slash separated string. )rrrArks ras_pathzTempDirectory.as_pathAs(DII4::d3C3CDDDr c\ddlm}|||jn||S)a9 Return the :class:`py.path.local` that corresponds to the path relative to the temporary directory that is passed in. :param path: The path to the file to create, which can be: * A tuple of strings. * A forward-slash separated string. r)local)py.pathrprrA)rrrps ras_localzTempDirectory.as_localNs< "!!!!!u$,TYYDJJt4D4DEEEr ct||d5}|}dddn #1swxYwY|p|j}|||S|S)a Reads the file at the specified path within the temporary directory. The file is always read in binary mode. Bytes will be returned unless an encoding is supplied, in which case a unicode string of the decoded data will be returned. :param filepath: The path to the file to read, which can be: * A tuple of strings. * A forward-slash separated string. :param encoding: The encoding used to decode the data in the file. :returns: The contents of the file as a :class:`str` or :class:`bytes`, if ``encoding`` is not specified. rbN)rgrAreadrdecode)rrarrirbs rruzTempDirectory.read\s,$**X&& - - 6688D               ,t}  ;;x(( ( sAA  A c|Srrr3s r __enter__zTempDirectory.__enter__ys r c.|dSr)r8)rtypevalue tracebacks r__exit__zTempDirectory.__exit__|s r r)r-r)r-N)NFFF)NF)NFTF)"__name__ __module__ __qualname____doc__setr'r1rrrrrrr classmethodr,rr8r; PathStringsrQrGr rAr`bytesrhrlgetpathrnrrrurxr}rr rrrs%*IL D7;%' T?23SM     "[     ( ( ( ([!%#$ % &&&& &  &&&&PK4@!%$" % /!/!sm/!/! /!  /!  /!/!/!/!b 1 1 1{$&&k&ucz1B&c&&&&P??eC#$67?3????&G E EK E4 E E E E F F[ FO F F F F[C5PSCT:r rr-cXd|d<t|i|}t|j|jS)z A decorator for making a :class:`TempDirectory` available for the duration of a test function. All arguments and parameters are passed through to the :class:`TempDirectory` constructor. Fr)rr rr8)argskwls rtempdirrs3BxLt"r""A !) $ $$r )r,r5r(pathlibrrertempfilertypingrrrr r testfixtures.comparisonr testfixtures.utilsr rrrrqpyrrrr rrs? BBBBBBBBBBBBBB++++++######CsO$ NNNffffffffR %HhZ%9: % % % % % %r