f _Uc@sZdZddlZddlZddlZddlZddlZddlZzddlZ[dZWne y\dZYn0zddl Z [ dZ Wne ydZ Yn0zddl Z [ dZ Wne ydZ Yn0zddlmZWne ydZYn0zddlmZWne ydZYn0ejdkZdZZejdkr,ddlZner:ddlZerDd nd Zeed o^ejd aeoneed ZdZgdZGdddeZGdddeZ GdddeZ!GdddeZ"GdddeZ#Gddde$Z%Gddde$Z&ddZ'd d!Z(efd"d#Z)dd$d%Z*d&d'Z+d(d)Z,d*d+Z-dd,d-d.Z.dd,d/d0Z/eed1rbdd,d2d3Z0nd4d3Z0dd,d5d6Z1dd,d7d8Z2dd,d9d:Z3d;d<Z4dd=d>Z5dde3ddfd?d@Z6eej7dArdBdCZ8dDdEZ9ndFdCZ8dGdEZ9dHdIZ:dJdKZ;ejhej?ko.ej@ejAvo.ejejBvZCddLdMZDeCeD_EdNdOZFe3fdPdQZGdRdSZHdTdUZIdVdWZJddYdZZKdd[d\ZLd]eKd^gd_fiZMereKd`gdafeMdb<eLgdcfeMdd<e reKdegdffeMdg<e reKdhgdifeMdj<dkdlZNddndoZOdpdqZPddrdsZQdtduZRdvdwZSddxdyZTdzd{ZUd|d}ZVd~dZWddZXdgeXgd_fdgeWgdcfdZYervddgeXgdafeYdb<e rddgeXgdffeYdg<e rddgeXgdifeYdj<ddZZdddZ[eedre\de]ddZ^de^j__de^j`_de^ja_ddZbn$er$e\de]ddZ^ddZbdddZcdddZdddZeejfejgBdfddZhdS)zUtility functions for copying and archiving files and directory trees. XXX The functions here don't copy the resource fork or other metadata on Mac. NTF)getpwnam)getgrnamntposixiisendfileZlinux _fcopyfilez%.COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS;.MSC) copyfileobjcopyfilecopymodecopystatcopycopy2copytreemovermtreeErrorSpecialFileError ExecError make_archiveget_archive_formatsregister_archive_formatunregister_archive_formatget_unpack_formatsregister_unpack_formatunregister_unpack_formatunpack_archiveignore_patternschownwhichget_terminal_size SameFileErrorc@s eZdZdS)rN)__name__ __module__ __qualname__r#r#/usr/lib64/python3.10/shutil.pyrErc@eZdZdZdS)rz5Raised when source and destination are the same file.Nr r!r"__doc__r#r#r#r$rHr%rc@r&)rz|Raised when trying to do a kind of operation (e.g. copying) which is not supported on a special file (e.g. a named pipe)Nr'r#r#r#r$rKr%rc@r&)rz+Raised when a command could not be executedNr'r#r#r#r$rOr%rc@r&) ReadErrorz%Raised when an archive cannot be readNr'r#r#r#r$r)Rr%r)c@r&) RegistryErrorzVRaised when a registry operation with the archiving and unpacking registries failsNr'r#r#r#r$r*Ur%r*c@r&)_GiveupOnFastCopyzuRaised as a signal to fallback on using raw read()/write() file copy when fast-copy functions fail to do so. Nr'r#r#r#r$r+Yr%r+c Csz|}|}Wn,ty@}zt|WYd}~n d}~00zt|||WnVty}z>|j|_|j|_|j t j t j hvrt|n|dWYd}~n d}~00dS)zhCopy a regular file content or metadata by using high-performance fcopyfile(3) syscall (macOS). N) fileno Exceptionr+rrOSErrornamefilename filename2errnoEINVALENOTSUP)fsrcfdstZflagsinfdoutfderrr#r#r$_fastcopy_fcopyfile^s  r:c CsFz|}|}Wn,ty@}zt|WYd}~n d}~00ztt|jd}Wntynd}Yn0tj dkrt |d}d}zt ||||}Wnty(}zr|j |_ |j |_|jtjkrdat||jtjkr|d|dkrt|dtjdkrt||WYd}~qd}~00|dkr8qB||7}qdS)zCopy data from one regular mmap-like fd to another by using high-performance sendfile(2) syscall. This should work on Linux >= 2.6.33 only. Niili@rF)r,r-r+Zmaxosfstatst_sizer.sysZmaxsizeminrr/r0r1r2ZENOTSOCK_USE_CP_SENDFILEZENOSPCZlseekZSEEK_CUR)r5r6r7r8r9Z blocksizeZoffsetZsentr#r#r$_fastcopy_sendfilers8         rAc Cs|j}|j}tt|j}||}|s*qtq||krj|d|}||Wdn1s^0Yq||qWdn1s0YdS)zreadinto()/memoryview() based variant of copyfileobj(). *fsrc* must support readinto() method and both files must be open in binary mode. N)ZreadintowriteZ memoryviewZ bytearray)r5r6lengthZ fsrc_readinto fdst_writeZmvZnZsmvr#r#r$_copyfileobj_readintos*rEcCs0|st}|j}|j}||}|s"q,||qdS)z=copy data from file-like object fsrc to file-like object fdstN) COPY_BUFSIZEreadrB)r5r6rCZ fsrc_readrDZbufr#r#r$rsrcCst|tjrHttjdrHztj|t|WStyFYdS0ttjdrzztj||WStyxYdS0tj tj |tj tj |kS)NsamestatFsamefile) isinstancer;DirEntryhasattrpathrHstatr.rInormcaseabspathsrcdstr#r#r$ _samefiles   rTcCst|tjr|St|SN)rJr;rKrNfnr#r#r$_statrXcCs t|tjr|Stj|SrU)rJr;rK is_symlinkrMislinkrVr#r#r$_islinkrYr\follow_symlinksc Cstd||t||r(td||d}t||gD]h\}}z t|}Wnty^Yq80t |j rt |t j r~|jn|}td|tr8|dkr8|j}q8|st|rt t ||n:t|d}t|d}tr*z0t||tj|WWdWdSty(Yn0trrz,t|||WWdWdStypYnD0tr|dkrt||t|t|WdWdSt ||Wdn1s0YWdn1s0Y|S)zCopy data from src to dst in the most efficient way possible. If follow_symlinks is not set and src is a symbolic link, a new symlink will be created instead of copying the file it points to. zshutil.copyfilez{!r} and {!r} are the same filerz`%s` is a named pipeZrbwbN)!r>auditrTrformatZ enumeraterXr.rNZS_ISFIFOst_moderJr;rKrMr_WINDOWSr=r\symlinkreadlinkopen_HAS_FCOPYFILEr:rZ_COPYFILE_DATAr+r@rArEr?rFr) rRrSr^Z file_sizeZirWstr5r6r#r#r$rsD       " " JrcCsntd|||sDt|rDtj|rDttdr@tjtj}}ndSt tj }}||}||t |j dS)zCopy mode bits from src to dst. If follow_symlinks is not set, symlinks aren't followed if and only if both `src` and `dst` are symlinks. If `lchmod` isn't available (e.g. Linux) this method does nothing. zshutil.copymodelchmodN)r>r`r\r;rMr[rLlstatrirXchmodrNS_IMODErb)rRrSr^Z stat_funcZ chmod_funcrhr#r#r$r !s  r listxattrc Csztj||d}Wn>tyP}z&|jtjtjtjfvr:WYd}~dSd}~00|D]j}z&tj|||d}tj||||dWqVty}z(|jtj tjtjtjfvrWYd}~qVd}~00dS)zCopy extended filesystem attributes from `src` to `dst`. Overwrite existing attributes. If `follow_symlinks` is false, symlinks won't be followed. r]N) r;rmr.r2r4ZENODATAr3ZgetxattrZsetxattrZEPERM)rRrSr^namesZer/Zvaluer#r#r$ _copyxattr7s rocOdSrUr#)argskwargsr#r#r$roOrYc s`td||ddddd|p6t|o4tj| }|rJfdd}n fdd}t|tjrp|j|d }n|d ||d }t |j }|d ||j |j f|dt |||d z|d |||d WntyYn0t|d r\z|d||j|d WnXtyZ}z>dD]*}tt|r|jtt|krqFqWYd}~n d}~00dS)aCopy file metadata Copy the permission bits, last access time, last modification time, and flags from `src` to `dst`. On Linux, copystat() also copies the "extended attributes" where possible. The file contents, owner, and group are unaffected. `src` and `dst` are path-like objects or path names given as strings. If the optional flag `follow_symlinks` is not set, symlinks aren't followed if and only if both `src` and `dst` are symlinks. zshutil.copystatN)nsr^cWrprUr#)rsr^rqr#r#r$_nop`rYzcopystat.._nopcs tt|SrU)getattrr;r/rtr#r$lookupgrYzcopystat..lookupcstt|}|tjvr|SSrU)rur;supports_follow_symlinks)r/rWrwr#r$rxls  r]rNZutimerkst_flagsZchflags)Z EOPNOTSUPPr4)r>r`r\r;rMr[rJrKrNrlrbZ st_atime_nsZ st_mtime_nsroZNotImplementedErrorrLrzr.r2ru) rRrSr^Zfollowrxrhmodewhyr9r#rwr$r Rs4       r cCBtj|r"tj|tj|}t|||dt|||d|S)a3Copy data and mode bits ("cp src dst"). Return the file's destination. The destination may be a directory. If follow_symlinks is false, symlinks won't be followed. This resembles GNU's "cp -P src dst". If source and destination are the same file, a SameFileError will be raised. r])r;rMisdirjoinbasenamerr rRrSr^r#r#r$r s r cCr})a0Copy data and metadata. Return the file's destination. Metadata is copied with copystat(). Please see the copystat function for more information. The destination may be a directory. If follow_symlinks is false, symlinks won't be followed. This resembles GNU's "cp -P src dst". r])r;rMr~rrrr rr#r#r$r s r csfdd}|S)zFunction that can be used as copytree() ignore parameter. Patterns is a sequence of glob-style patterns that are used to exclude filescs(g}D]}|t||qt|SrU)extendfnmatchfilterset)rMrn ignored_namesZpatternpatternsr#r$_ignore_patternssz)ignore_patterns.._ignore_patternsr#)rrr#rr$rs rc CsB|dur$|t|dd|D}nt}tj||dg} |tupJ|tu} |D]} | j|vrbqPtj|| j} tj|| j} | r| n| }z| }|rtjdkr| j dd}|j t j krd}|r8t | }|rt|| t|| | dnntj|s |r WqP| r,t|| ||||dn6||| n*| rXt|| ||||dn ||| WqPty}z| |jdWYd}~qPd}~0ty}z | | | t|fWYd}~qPd}~00zt||WnLty.}z2t|d ddur| ||t|fWYd}~n d}~00| r>t| |S) NcSsg|] }|jqSr#rv).0Zxr#r#r$ z_copytree..)Zexist_okrFr]) dirs_exist_okrZwinerror)r;fspathrmakedirsr r r/rMrrZrNst_reparse_tagIO_REPARSE_TAG_MOUNT_POINTrerdr existsis_dirr rrrqr.appendstrru)entriesrRrSsymlinksignore copy_functionignore_dangling_symlinksrrZerrorsZ use_srcentryZsrcentryZsrcnameZdstnameZsrcobjrZrjlinktor9r|r#r#r$ _copytrees^            $**rc CsXtd||t|}t|}Wdn1s60Yt||||||||dS)aeRecursively copy a directory tree and return the destination directory. dirs_exist_ok dictates whether to raise an exception in case dst or any missing parent directory already exists. If exception(s) occur, an Error is raised with a list of reasons. If the optional symlinks flag is true, symbolic links in the source tree result in symbolic links in the destination tree; if it is false, the contents of the files pointed to by symbolic links are copied. If the file pointed by the symlink doesn't exist, an exception will be added in the list of errors raised in an Error exception at the end of the copy process. You can set the optional ignore_dangling_symlinks flag to true if you want to silence this exception. Notice that this has no effect on platforms that don't support os.symlink. The optional ignore argument is a callable. If given, it is called with the `src` parameter, which is the directory being visited by copytree(), and `names` which is the list of `src` contents, as returned by os.listdir(): callable(src, names) -> ignored_names Since copytree() is called recursively, the callable will be called once for each directory that is copied. It returns a list of names relative to the `src` directory that should not be copied. The optional copy_function argument is a callable that will be used to copy each file. It will be called with the source path and the destination path as arguments. By default, copy2() is used, but any function that supports the same signature (like copy()) can be used. zshutil.copytreeN)rrRrSrrrrr)r>r`r;scandirlistr) rRrSrrrrrZitrrr#r#r$r s& & r st_file_attributescCsJz4|jdd}t|jo2|jtj@o0|jtjk WStyHYdS0NFr])rNS_ISDIRrbrFILE_ATTRIBUTE_REPARSE_POINTrrr.)entryrhr#r#r$ _rmtree_isdir6s     rcCsFz0t|}t|jp.|jtj@o.|jtjkWSt yDYdS0)NF) r;rjrNZS_ISLNKrbrrrrr.)rMrhr#r#r$_rmtree_islink?s     rcCs$z|jddWSty"YdS0r)rr.)rr#r#r$rHs cCs tj|SrU)r;rMr[)rMr#r#r$rNrYc Cs0z6t|}t|}Wdn1s*0YWn(ty^|tj|tg}Yn0|D]}|j}t|rz|rtdWn*ty|tjj |tYqdYn0t ||qdzt |Wqdty|tj |tYqd0zt |Wn&ty*|tj |tYn0dS)N%Cannot call rmtree on a symbolic link) r;rrr.r>exc_inforMrrZr[_rmtree_unsafeunlinkrmdir)rMonerror scandir_itrrfullnamer#r#r$rRs0 *       rc Cs>z6t|}t|}Wdn1s*0YWn>tyt}z&||_|tj|tWYd}~dSd}~00|D]}tj||j }z|j dd}Wntyd}YnP0|rz|j dd} t | j }Wn*ty|tj|tYqzYn0|rztj|j tj|d} Wn&tyJ|tj|tYn0ztj| t| rt| ||ztj|j |dWn\ty|tj|tYn80z tdWn(ty|tjj|tYn0Wt| nHt| 0ztj|j |dWqzty6|tj|tYqz0qzdS)NFr])Zdir_fdr)r;rrr.r0r>rrMrr/rrNrrbrjrfO_RDONLYrHr<_rmtree_safe_fdrr[closer) ZtopfdrMrrrr9rrrorig_stZdirfdr#r#r$rqsR *       rc Cstd||rdd}n|dur*dd}tr^t|trDt|}zt|}Wn&tyx|tj|t YdS0zt |tj }Wn&ty|tj|t YdS0ztj |t|rt|||zt|Wn\ty |tj|t Yn80z tdWn(tyB|tj j|t Yn0Wt|nXt|0zt|rrtdWn*ty|tj j|t YdS0t||SdS)aRecursively delete a directory tree. If ignore_errors is set, errors are ignored; otherwise, if onerror is set, it is called to handle the error with arguments (func, path, exc_info) where func is platform and implementation dependent; path is the argument to that function that caused it to fail; and exc_info is a tuple returned by sys.exc_info(). If ignore_errors is false and onerror is None, an exception is raised. z shutil.rmtreecWrprUr#rqr#r#r$rrYzrmtree..onerrorNcWsdSrUr#rr#r#r$rrYr)r>r`_use_fd_functionsrJbytesr;fsdecoderjr-rrfrrMrHr<rrr.r[rrr)rMZ ignore_errorsrrZfdr#r#r$rsJ          rcCs0t|}tjjtjjpd}tj||S)aHA basename() variant which first strips the trailing slash, if present. Thus we always get the last component of the path, even for directories. path: Union[PathLike, str] e.g. >>> os.path.basename('/bar/foo') 'foo' >>> os.path.basename('/bar/foo/') '' >>> _basename('/bar/foo/') 'foo' )r;rrMsepZaltseprZrstrip)rMrr#r#r$ _basenames rc Cstd|||}tj|rbt||r8t||dStj|t|}tj |rbt d|zt||Wnt ytj |rt |}t||t|nTtj|rt||rt d||ft|||ddt|n|||t|Yn0|S)a+Recursively move a file or directory to another location. This is similar to the Unix "mv" command. Return the file or directory's destination. If the destination is a directory or a symlink to a directory, the source is moved inside the directory. The destination path must not already exist. If the destination already exists but is not a directory, it may be overwritten depending on os.rename() semantics. If the destination is on our current filesystem, then rename() is used. Otherwise, src is copied to the destination and then removed. Symlinks are recreated under the new name if os.rename() fails because of cross filesystem renames. The optional `copy_function` argument is a callable that will be used to copy the source or it will be delegated to `copytree`. By default, copy2() is used, but any function that supports the same signature (like copy()) can be used. A lot more could be done here... A look at a mv.c shows a lot of the issues this implementation glosses over. z shutil.moveNz$Destination path '%s' already existsz.Cannot move a directory '%s' into itself '%s'.T)rr)r>r`r;rMr~rTZrenamerrrrr.r[rerdr _destinsrcr r)rRrSrZreal_dstrr#r#r$rs8             rcCsVtj|}tj|}|tjjs2|tjj7}|tjjsL|tjj7}||SrU)r;rMrPendswithr startswithrQr#r#r$r8s    rcCLtdus|durdSz t|}Wnty6d}Yn0|durH|dSdS)z"Returns a gid, given a group name.N)rKeyErrorr/Zresultr#r#r$_get_gidA   rcCr)z"Returns an uid, given a user name.Nr)rrrr#r#r$_get_uidMrrgzipcs(|durd}nDtr |dkr d}n2tr2|dkr2d}n trD|dkrDd}ntd|d dl} |rfd |nd} |d | } tj| } | rtj | s|dur| d | |st | |dur| d t t fdd} |s$| | d|}z|j|| dW|n |0| S)aCreate a (possibly compressed) tar file from all the files under 'base_dir'. 'compress' must be "gzip" (the default), "bzip2", "xz", or None. 'owner' and 'group' can be used to define an owner and a group for the archive that is being built. If not provided, the current owner and group will be used. The output tar file will be named 'base_name' + ".tar", possibly plus the appropriate compression extension (".gz", ".bz2", or ".xz"). Returns the output filename. NrrZgzbzip2bz2xzzCbad value for 'compress', or compression format not supported : {0}rZ..tar creating %szCreating tar archivecs,dur|_|_dur(|_|_|SrU)gidZgnameuidZuname)Ztarinforgroupownerrr#r$ _set_uid_gidsz#_make_tarball.._set_uid_gidzw|%s)r)_ZLIB_SUPPORTED_BZ2_SUPPORTED_LZMA_SUPPORTED ValueErrorratarfiler;rMdirnamerinforrrrfaddr) base_namebase_dircompressverbosedry_runrrloggerZtar_compressionrZ compress_extZ archive_name archive_dirrtarr#rr$ _make_tarballYs>         rc Csddl}|d}tj|}|rNtj|sN|dur@|d||sNt||durd|d|||s|j|d|jd}tj |} | tj kr| | | |dur|d| t |D]\} } } t | D]:} tj tj| | } | | | |dur|d| q| D]L} tj tj| | } tj| r| | | |dur|d| qqWdn1sv0Y|S) zCreate a zip file from all the files under 'base_dir'. The output zip file will be named 'base_name' + ".zip". Returns the name of the output zip file. rN.ziprz#creating '%s' and adding '%s' to itZw)Z compressionz adding '%s')zipfiler;rMrrrrZipFileZ ZIP_DEFLATEDZnormpathcurdirrBZwalkZsortedrZisfile)rrrrrrZ zip_filenamerZzfrMZdirpathZdirnamesZ filenamesr/r#r#r$ _make_zipfilesF           2rr)rNzuncompressed tar file)rrzgzip'ed tar-fileZgztarzZIP filezip)rrzbzip2'ed tar-fileZbztar)rrzxz'ed tar-fileZxztarcCddtD}||S)zReturns a list of supported formats for archiving and unarchiving. Each element of the returned sequence is a tuple (name, description) cSsg|]\}}||dfqS)rr#)rr/Zregistryr#r#r$rrz'get_archive_formats..)_ARCHIVE_FORMATSitemssortZformatsr#r#r$rs rrcCst|dur g}t|s td|t|ttfs6td|D]&}t|ttfrXt|dkr:tdq:|||ft|<dS)auRegisters an archive format. name is the name of the format. function is the callable that will be used to create archives. If provided, extra_args is a sequence of (name, value) tuples that will be passed as arguments to the callable. description can be provided to describe the format, and will be returned by the get_archive_formats() function. NzThe %s object is not callablez!extra_args needs to be a sequencerz+extra_args elements are : (arg_name, value))callable TypeErrorrJZtuplerZlenr)r/function extra_args descriptionZelementr#r#r$rs   rcCs t|=dSrU)rrvr#r#r$rrYrc  CsBtd||||t} |durP|dur6|d|tj|}|sPt||dur^tj}||d} z t |} Wn t yt d|dYn0| d} | dD]\} }|| | <q|dkr|| d <|| d <z@| ||fi| }W|dur>|dur|d | t| n,|dur<|dur2|d | t| 0|S) aCreate an archive file (eg. zip or tar). 'base_name' is the name of the file to create, minus any format-specific extension; 'format' is the archive format: one of "zip", "tar", "gztar", "bztar", or "xztar". Or any other registered format. 'root_dir' is a directory that will be the root directory of the archive; ie. we typically chdir into 'root_dir' before creating the archive. 'base_dir' is the directory where we start archiving from; ie. 'base_dir' will be the common prefix of all files and directories in the archive. 'root_dir' and 'base_dir' both default to the current directory. Returns the name of the archive file. 'owner' and 'group' are used when creating a tar archive. By default, uses the current owner and group. zshutil.make_archiveNzchanging into '%s')rrzunknown archive format '%s'rrrrzchanging back to '%s') r>r`r;getcwdZdebugrMrPZchdirrrrr)rraZroot_dirrrrrrrZsave_cwdrr format_infofuncZargZvalr0r#r#r$rs@              rcCr)zReturns a list of supported formats for unpacking. Each element of the returned sequence is a tuple (name, extensions, description) cSs"g|]\}}||d|dfqS)rir#)rr/rr#r#r$r7rz&get_unpack_formats..)_UNPACK_FORMATSrrrr#r#r$r1s rc Csji}tD]\}}|dD] }|||<qq |D]$}||vr0d}t||||fq0t|sftddS)z+Checks what gets registered as an unpacker.rz!%s is already registered for "%s"z*The registered function must be a callableN)rrr*rr) extensionsrrZexisting_extensionsr/rext extensionZmsgr#r#r$_check_unpack_options<s   rcCs,|dur g}t|||||||ft|<dS)aMRegisters an unpack format. `name` is the name of the format. `extensions` is a list of extensions corresponding to the format. `function` is the callable that will be used to unpack archives. The callable will receive archives to unpack. If it's unable to handle an archive, it needs to raise a ReadError exception. If provided, `extra_args` is a sequence of (name, value) tuples that will be passed as arguments to the callable. description can be provided to describe the format, and will be returned by the get_unpack_formats() function. N)rr)r/rrrrr#r#r$rNs rcCs t|=dS)z*Removes the pack format from the registry.N)rrvr#r#r$rdsrcCs&tj|}tj|s"t|dS)z1Ensure that the parent directory of `path` existsN)r;rMrr~r)rMrr#r#r$_ensure_directoryhs  rc Csddl}||std|||}z|D]}|j}|ds2d|vrPq2tjj |g| dR}|spq2t || ds2| |j}t|d}z||W|~q2|~0W|n |0dS)z+Unpack zip `filename` to `extract_dir` rNz%s is not a zip filez/z..r_)rZ is_zipfiler)rZinfolistr0rr;rMrsplitrrrGrfrBr) r0 extract_dirrrrr/ZtargetZdataZfr#r#r$_unpack_zipfilens.        rcCs^ddl}z||}Wn |jy6td|Yn0z||W|n |0dS)zAUnpack tar/tar.gz/tar.bz2/tar.xz `filename` to `extract_dir` rNz/%s is not a compressed or uncompressed tar file)rrfZTarErrorr)Z extractallr)r0rrZtarobjr#r#r$_unpack_tarfiles  rrr)rrz.tar.gzz.tgzz.tar.bz2z.tbz2z.tar.xzz.txzcCs8tD]*\}}|dD]}||r|SqdS)Nr)rrr)r0r/rrr#r#r$_find_unpack_formats   rcCstd||||dur t}t|}t|}|durz t|}Wn"tyjtd|dYn0|d}|||fit |dnLt |}|durt d|t|d}t t|d}|||fi|dS)a Unpack an archive. `filename` is the name of the archive. `extract_dir` is the name of the target directory, where the archive is unpacked. If not provided, the current working directory is used. `format` is the archive format: one of "zip", "tar", "gztar", "bztar", or "xztar". Or any other registered format. If not provided, unpack_archive will use the filename extension and see if an unpacker was registered for that extension. In case none is found, a ValueError is raised. zshutil.unpack_archiveNzUnknown unpack format '{0}'rrzUnknown archive format '{0}') r>r`r;rrrrrraZdictrr))r0rrarrrrr#r#r$rs$     rstatvfs disk_usageZusageztotal used freezTotal space in byteszUsed space in byteszFree space in bytescCs@t|}|j|j}|j|j}|j|j|j}t|||S)zReturn disk usage statistics about the given path. Returned value is a named tuple with attributes 'total', 'used' and 'free', which are the amount of total, used and free space, in bytes. )r;rZf_bavailZf_frsizeZf_blocksZf_bfree_ntuple_diskusage)rMrhfreetotalusedr#r#r$rs    cCs"t|\}}||}t|||S)zReturn disk usage statistics about the given path. Returned values is a named tuple with attributes 'total', 'used' and 'free', which are the amount of total, used and free space, in bytes. )rZ _getdiskusager)rMrrrr#r#r$rscCstd||||dur(|dur(td|}|}|dur>d}n(t|trft|}|durftd||durtd}n(t|tst |}|durtd|t |||dS)zChange owner user and group of the given path. user and group can be the uid/gid or the user/group names, and in that case, they are converted to their respective uid/gid. z shutil.chownNzuser and/or group must be setizno such user: {!r}zno such group: {!r}) r>r`rrJrrZ LookupErrorraintrr;r)rMZuserrZ_userZ_groupr#r#r$rs$  riPic Cszttjd}Wnttfy,d}Yn0zttjd}WnttfyZd}Yn0|dksl|dkrzttj}Wn"t tt fyt |}Yn0|dkr|j }|dkr|j }t ||fS)aGet the size of the terminal window. For each of the two dimensions, the environment variable, COLUMNS and LINES respectively, is checked. If the variable is defined and the value is a positive integer, it is used. When COLUMNS or LINES is not defined, which is the common case, the terminal connected to sys.__stdout__ is queried by invoking os.get_terminal_size. If the terminal size cannot be successfully queried, either because the system doesn't support querying, or because we are not connected to a terminal, the value given in fallback parameter is used. Fallback defaults to (80, 24) which is the default size used by many terminal emulators. The value returned is a named tuple of type os.terminal_size. ZCOLUMNSrZLINES)rr;environrrrr>Z __stdout__r,AttributeErrorr.Z terminal_sizecolumnslines)Zfallbackr r Zsizer#r#r$r$s$  rcCs&tj|o$t||o$tj| SrU)r;rMrZaccessr~)rWr{r#r#r$ _access_checkUs r c stjrt|rSdStt}|durrtjdd}|durrztd}Wnt t fyptj }Yn0|szdS|rt |}| t tj}nt|}| tj}tjdkrRtj}|rt |}||vr|d|tdpt}dd| tjD}|rd d|D}tfd d |Dr>g}nfd d|D}ng}t}|D]T} tj| } | |vrb|| |D](} tj| | } t| |r| SqbdS) a3Given a command, mode, and a PATH string, return the path which conforms to the given mode on the PATH, or None if there is no such file. `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result of os.environ.get("PATH"), or can be overridden with a custom search path. NZPATHZCS_PATHZwin32rZPATHEXTcSsg|] }|r|qSr#r#rrr#r#r$rrzwhich..cSsg|]}t|qSr#)r;fsencoder r#r#r$rrc3s |]}|VqdSrU)Zlowerrr cmdr#r$Z rzwhich..csg|] }|qSr#r#r rr#r$rr)r;rMrr rJrrZgetZconfstrrrZdefpathr rZpathseprr>platformrZinsertZgetenv_WIN_DEFAULT_PATHEXTZanyrrOrr) rr{rMZ use_bytesrZpathext_sourceZpathextZfilesZseenZdirZnormdirZthefiler/r#rr$rZsV              r)r)F)FN)rrrNNN)rrNNr)NNrrNNNrNNr)r)ir(r;r>rNrZ collectionsr2ZzlibrZ ImportErrorrrZlzmarZpwdrZgrprr/rcrrrFrLrrr@rgrZ__all__r.rrrrr)r-r*r+r:rArErrTrXr\rr ror r r rrr Z stat_resultrrrrrfrrZsupports_dir_fdrZ supports_fdryrrZavoids_symlink_attacksrrrrrrrrrrrrrrrrrrrrrrrZ namedtuplerrrrrrrr ZF_OKZX_OKrr#r#r#r$Zs.             @  7 B A . 4   > <   A -   8  "      *       1