o Ƌ|c@s"dZddlZddlZddlZddlZddlZddlZz ddlZ[dZWn e y.dZYnwz ddl Z [ dZ Wn e yCdZ Ynwz ddl Z [ dZ Wn e yXdZ YnwejdkZdZZejdkrlddlZnerrddlZervdndZeed oejd aeoeed Zd Zgd ZGdddeZGdddeZGdddeZGdddeZGdddeZGddde Z!Gddde Z"ddZ#ddZ$efd d!Z%dd"d#Z&d$d%Z'd&d'Z(d(d)Z)dd*d+d,Z*dd*d-d.Z+eed/rdd*d0d1Z,nd2d1Z,dd*d3d4Z-dd*d5d6Z.dd*d7d8Z/d9d:Z0 dd;d<Z1dde/ddfd=d>Z2eej3d?r@d@dAZ4dBdCZ5ndDdAZ4dEdCZ5dFdGZ6dHdIZ7ej8ejej9ej:hej;kojejvZ?ddJdKZ@e?e@_AdLdMZBe/fdNdOZCdPdQZDdRdSZEdTdUZFdVdWZG  ddYdZZH  dd[d\ZId]eHd^gd_dfiZJereHd`gdadfeJdb<eIgdcdfeJdd<e reHdegdfdfeJdg<e reHdhgdidfeJdj<dkdlZKddndoZLdpdqZM  ddrdsZNdtduZOdvdwZP  mddxdyZQdzd{ZRd|d}ZSd~dZTddZUdgeUgd_fdgeTgdcfdZVerddgeUgdafeVdb<e r,ddgeUgdffeVdg<e r9ddgeUgdifeVdj<ddZWdddZXeedrdeYdeZddZ[de[j\_de[j]_de[j^_ddZ_nerveYdeZddZ[ddZ_dddZ`dddZaddZbejcejdBdfddZedS)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. NTFntposixiisendfilelinux _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##/opt/conda/lib/python3.10/shutil.pyr;src@eZdZdZdS)rz5Raised when source and destination are the same file.Nr r!r"__doc__r#r#r#r$r>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$rAr(rc@r%)rz+Raised when a command could not be executedNr&r#r#r#r$rEr(rc@r%) ReadErrorz%Raised when an archive cannot be readNr&r#r#r#r$r)Hr(r)c@r%) RegistryErrorzVRaised when a registry operation with the archiving and unpacking registries failsNr&r#r#r#r$r*Kr(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+Or(r+c Csz |}|}Wnty}zt|d}~wwz t|||WdStyI}z|j|_|j|_|j t j t j hvrBt||dd}~ww)zhCopy a regular file content or metadata by using high-performance fcopyfile(3) syscall (macOS). N) fileno Exceptionr+rrOSErrornamefilename filename2errnoEINVALENOTSUP)fsrcfdstflagsinfdoutfderrr#r#r$_fastcopy_fcopyfileTs" r;c Cs$z |}|}Wnty}zt|d}~wwz tt|jd}Wn ty1d}Ynwtj dkr= 2.6.33 only. Niili@rTF)r,r-r+maxosfstatst_sizer.sysmaxsizeminrr/r0r1r2ZENOTSOCK_USE_CP_SENDFILEZENOSPClseekSEEK_CUR)r5r6r8r9r:Z blocksizeoffsetZsentr#r#r$_fastcopy_sendfilehsF      rGc Cs|j}|j}tt|6} ||}|sn%||kr5|d| }||Wdn1s/wYn||qWddS1sEwYdS)zreadinto()/memoryview() based variant of copyfileobj(). *fsrc* must support readinto() method and both files must be open in binary mode. TN)readintowrite memoryview bytearray)r5r6lengthZ fsrc_readinto fdst_writeZmvnZsmvr#r#r$_copyfileobj_readintos  "rOcCs0|st}|j}|j} ||}|sdS||q )z=copy data from file-like object fsrc to file-like object fdstTN) COPY_BUFSIZEreadrI)r5r6rLZ fsrc_readrMbufr#r#r$rsrcCst|tjr$ttjdr$z tj|t|WSty#YdSwttjdr=ztj||WSty<YdSwtj tj |tj tj |kS)NsamestatFsamefile) isinstancer=DirEntryhasattrpathrSstatr.rTnormcaseabspathsrcdstr#r#r$ _samefiles   r_cCst|tjr |St|SN)rUr=rVrYfnr#r#r$_statsrccCs t|tjr |Stj|Sr`)rUr=rV is_symlinkrXislinkrar#r#r$_islinks rffollow_symlinksc Cs:td||t||rtd||d}t||gD]4\}}zt|}Wn ty/Yqwt |j rGt |t j r?|jn|}td|trP|dkrP|j}q|sbt|rbt t |||St|d}zt|du}trzt||tj|WWdWWdStyYnDwtrzt|||WWdWWdStyYn!wtr|dkrt||t|t|WdWWdSt ||Wdn1swYWnt!y } zt j"|st#d|| d} ~ wwWd|S1swY|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 pipeZrbwbNzDirectory does not exist: )$r@auditr_rformat enumeratercr.rYS_ISFIFOst_moderUr=rVrXr_WINDOWSr?rfsymlinkreadlinkopen_HAS_FCOPYFILEr;rZ_COPYFILE_DATAr+rCrGrOrBrPrIsADirectoryErrorexistsFileNotFoundError) r]r^rh file_sizeirbstr5r6er#r#r$rsv       "          rcCsntd|||s"t|r"tj|r"ttdr 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@rjrfr=rXrerWlstatr{rcchmodrYS_IMODErn)r]r^rhZ stat_funcZ chmod_funcryr#r#r$r s  r listxattrc Csz tj||d}Wnty(}z|jtjtjtjfvrWYd}~dSd}~ww|D]5}ztj|||d}tj||||dWq+ty`}z|jtj tjtjtjfvrVWYd}~q+d}~wwdS)zCopy extended filesystem attributes from `src` to `dst`. Overwrite existing attributes. If `follow_symlinks` is false, symlinks won't be followed. rgN) r=rr.r2r4ZENODATAr3getxattrsetxattrZEPERM)r]r^rhnamesrzr/valuer#r#r$ _copyxattr6s*  rcOdSr`r#)argskwargsr#r#r$rNc sXtd||ddddd|pt|otj| }|r%fdd}nfdd}t|tjr8|j|d }n|d ||d }t |j }|d ||j |j f|dt |||d z |d |||d Wn tynYnwt|d rz |d||j|d WdSty}zdD]}tt|r|jtt|krnqWYd}~dSd}~wwdS)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)nsrhcWrr`r#)rrhrr#r#r$_nop_rzcopystat.._nopcs tt|Sr`)getattrr=r/rr#r$lookupf zcopystat..lookupcstt|}|tjvr |SSr`)rr=supports_follow_symlinks)r/rbrr#r$rks  rgrYutimer}st_flagschflags)Z EOPNOTSUPPr4)r@rjrfr=rXrerUrVrYr~rn st_atime_ns st_mtime_nsrNotImplementedErrorrWrr.r2r) r]r^rhZfollowrrymodewhyr:r#rr$r Qs@       r cCBtj|rtj|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. rg)r=rXisdirjoinbasenamerr r]r^rhr#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". rg)r=rXrrrrr 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|Sr`)extendfnmatchfilterset)rXr ignored_namespatternpatternsr#r$_ignore_patternssz)ignore_patterns.._ignore_patternsr#)rrr#rr$rs rc Cs2|dur|t|dd|D}nt}tj||dg} |tup%|tu} |D]} | j|vr0q(tj|| j} tj|| j} | rD| n| }zf| }|r`tjdkr`| j dd}|j t j kr`d}|rt | }|rxt|| t|| | dn3tj|s|rWq(| rt|| ||||dn||| n| rt|| ||||dn||| Wq(ty}z| |jdWYd}~q(d}~wty}z| | | t|fWYd}~q(d}~wwzt||Wn&ty}zt|d ddur| ||t|fWYd}~nd}~ww| rt| |S) NcSsg|]}|jqSr#r).0xr#r#r$ sz_copytree..)exist_okrFrg) dirs_exist_okrZwinerror)r=fspathrmakedirsr r r/rXrrdrYst_reparse_tagIO_REPARSE_TAG_MOUNT_POINTrqrpr ruis_dirr rrrr.appendstrr)entriesr]r^symlinksignore copy_functionignore_dangling_symlinksrrerrorsZ use_srcentryZsrcentryZsrcnameZdstnameZsrcobjrdr|linktor:rr#r#r$ _copytreesj           rc CsXtd||t| }t|}Wdn1swYt||||||||dS)a'Recursively copy a directory tree and return the destination directory. 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. If dirs_exist_ok is false (the default) and `dst` already exists, a `FileExistsError` is raised. If `dirs_exist_ok` is true, the copying operation will continue if it encounters existing directories, and files within the `dst` tree will be overwritten by corresponding files from the `src` tree. zshutil.copytreeN)rr]r^rrrrr)r@rjr=scandirlistr) r]r^rrrrrZitrrr#r#r$r s(   r st_file_attributescCsJz|jdd}t|jo|jtj@o|jtjk WSty$YdSwNFrg)rYS_ISDIRrnrFILE_ATTRIBUTE_REPARSE_POINTrrr.)entryryr#r#r$ _rmtree_isdir7s     rcCsFzt|}t|jp|jtj@o|jtjkWSt y"YdSw)NF) r=r|rYS_ISLNKrnrrrrr.)rXryr#r#r$_rmtree_islink@s     rcCs$z|jddWStyYdSwr)rr.)rr#r#r$rIs  cCs tj|Sr`)r=rXre)rXr#r#r$rOrc Cs*zt| }t|}Wdn1swYWnty/|tj|tg}Ynw|D]F}|j}t|r_z |rDtdWntyX|tjj |tYq2wt ||q2zt |Wq2tyx|tj |tYq2wzt |WdSty|tj |tYdSw)N%Cannot call rmtree on a symbolic link) r=rrr.r@exc_inforXrrdre_rmtree_unsafeunlinkrmdir)rXonerror scandir_itrrfullnamer#r#r$rSs>       rc CsDzt| }t|}Wdn1swYWnty:}z||_|tj|tWYd}~dSd}~ww|D]}tj||j }z|j dd}Wn tyZd}Yn$w|r~z|j dd} t | j }Wnty}|tj|tYq=w|rztj|j tj|d} d} Wnty|tj|tYq=wzUtj| t| rt| ||zt| d} tj|j |dWn*ty|tj|tYnwztdty|tjj|tYnwW| st| q=| st| wwz tj|j |dWq=ty|tj|tYq=wdS)NFrg)dir_fdTr)r=rrr.r0r@rrXrr/rrYrrnr|rrO_RDONLYrSr>_rmtree_safe_fdcloserrer) topfdrXrrrr:rrrorig_stdirfdZ dirfd_closedr#r#r$rrsz            rc Cstd||r dd}n|durdd}trt|tr!t|}zt|}Wnty;|tj|t YdSwz t |tj }d}WntyZ|tj |t YdSwzUtj |t|rt|||zt|d}t|Wn*ty|tj|t Ynwztdty|tj j|t YnwW|st|dSdS|st|wwz t|rtdWnty|tj j|t YdSwt||S) 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.rmtreecWrr`r#rr#r#r$rrzrmtree..onerrorNcWsr`r#rr#r#r$rsFTr)r@rj_use_fd_functionsrUbytesr=fsdecoder|r-rrrrrXrSr>rrrr.rerr)rX ignore_errorsrrfdZ fd_closedr#r#r$rsf             rcCs0t|}tjjtjjp d}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=rrXsepaltseprrstrip)rXrr#r#r$ _basenames rc CsNtd|||}tj|r1t||rt||dStj|t|}tj |r1t d|z t||W|St ytj |rZt |}t||t|Y|Stj|rt||rmt d||ft|st|tjst|rtjdkrtd||ft|||ddt|Y|S|||t|Y|Sw) 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'.darwinzKCannot move the non-empty directory '%s': Lacking write permission to '%s'.T)rr)r@rjr=rXrr_renamerrrurr.rerqrpr _destinsrc _is_immutableaccessW_OKlistdirplatformPermissionErrorr r)r]r^rZreal_dstrr#r#r$rsR              rcCsVtj|}tj|}|tjjs|tjj7}|tjjs&|tjj7}||Sr`)r=rXr[endswithr startswithr\r#r#r$rGs     rcCs(t|}tjtjg}t|do|j|vS)Nr)rcrY UF_IMMUTABLE SF_IMMUTABLErWr)r]ryZimmutable_statesr#r#r$rPs rcCj|durdSzddlm}Wn tyYdSwz||}Wn ty*d}Ynw|dur3|dSdS)z"Returns a gid, given a group name.Nr)getgrnam)Zgrpr ImportErrorKeyError)r/rresultr#r#r$_get_gidU   rcCr)z"Returns an uid, given a user name.Nr)getpwnamr)pwdrrr)r/rrr#r#r$_get_uidgrrgzipc sV|durd} n"tr|dkrd} ntr|dkrd} ntr"|dkr"d} ntd|d dl} |r3d | nd} |d | } tj| } | rZtj | sZ|durS| d | |sZt | |durc| d t t fdd}|s| | d| }|}|durtj||}z|j|||dW|n|w|durtj| } | 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}r..tar creating %szCreating tar archivecs,dur |_|_dur|_|_|Sr`)gidZgnameuiduname)Ztarinforgroupownerrr#r$ _set_uid_gidsz#_make_tarball.._set_uid_gidzw|%s)r)_ZLIB_SUPPORTED_BZ2_SUPPORTED_LZMA_SUPPORTED ValueErrorrktarfiler=rXdirnameruinforrrrrraddrr[) base_namebase_dircompressverbosedry_runrrloggerroot_dirZtar_compressionr Z compress_extZ archive_name archive_dirrtararcnamer#rr$ _make_tarballysH          rcCsddl}|d} tj|} | r'tj| s'|dur |d| |s't| |dur2|d| ||s|j| d|jd} tj |} |durOtj ||}tj |}| tj krj| || |durj|d|t |D]l\} }}| }|durtj||}tj |}t|D] }tj | |}tj ||} | || |dur|d|q|D],}tj | |}tj |}tj|rtj ||} | || |dur|d|qqoWdn1swY|durtj| } | 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 itw)Z compressionz adding '%s')zipfiler=rXr rur rZipFileZ ZIP_DEFLATEDnormpathrcurdirrIwalkrelpathsortedisfiler[)r rrrrrrrrZ zip_filenamerZzfrdirpathZdirnamesZ filenamesZ arcdirpathr/rXr#r#r$ _make_zipfilesh                 r#r)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/registryr#r#r$rsz'get_archive_formats..)_ARCHIVE_FORMATSitemssortZformatsr#r#r$rs rrcCsv|durg}t|std|t|ttfstd|D]}t|ttfr,t|dkr0tdq|||dft|<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)F)callable TypeErrorrUtuplerlenr')r/function extra_args descriptionZelementr#r#r$rs  rcCs t|=dSr`)r'rr#r#r$r.s rc  CsFtd||||zt|} Wntytd|dw||||d} | d} | dD]\} } | | | <q-|dur=tj}| d}d}|durn|rSt|}|| d<nt}|dura| d |tj |}|snt |z| ||fi| }W|dur|dur| d |t ||S|dur|dur| d |t |ww) 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_archivezunknown archive format '%s'N)rrrrrrzchanging into '%s'zchanging back to '%s') r@rjr'rrr=rrgetcwddebugrXr[chdir)r rkrrrrrrr format_inforfuncargvalZsupport_root_dirZsave_cwdr0r#r#r$r1sL            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)rr3r#)rr/r r#r#r$rss"z&get_unpack_formats..)_UNPACK_FORMATSr(r)r*r#r#r$rms rc Csji}tD]\}}|dD]}|||<qq|D]}||vr*d}t||||fqt|s3tddS)z+Checks what gets registered as an unpacker.rz!%s is already registered for "%s"z*The registered function must be a callableN)r;r(r*r+r,) extensionsr/r0Zexisting_extensionsr/r ext extensionmsgr#r#r$_check_unpack_optionsxs  r@cCs,|durg}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)r@r;)r/r<r/r0r1r#r#r$rs rcCs t|=dS)z*Removes the pack format from the registry.N)r;rr#r#r$rs rcCs*tj|}tj|st|dSdS)z1Ensure that the parent directory of `path` existsN)r=rXr rr)rXr r#r#r$_ensure_directorys  rAc Csddl}||std|||}zd|D]X}|j}|ds'd|vr(qtjj |g| dR}|s8qt || dsq| |d"}t |d }t||Wdn1s]wYWdn1slwYqW|dS|w)z+Unpack zip `filename` to `extract_dir` rNz%s is not a zip file/z..rri)rZ is_zipfiler)rZinfolistr0rr=rXrsplitrArrrrr) r0 extract_dirrr$r r/Z targetpathsourcetargetr#r#r$_unpack_zipfiles2      rHcCsXddl}z||}Wn|jytd|wz ||W|dS|w)zAUnpack tar/tar.gz/tar.bz2/tar.xz `filename` to `extract_dir` rNz/%s is not a compressed or uncompressed tar file)r rrZTarErrorr)Z extractallr)r0rEr Ztarobjr#r#r$_unpack_tarfiles rIrr)rr$z.tar.gzz.tgzz.tar.bz2z.tbz2z.tar.xzz.txzcCs:tD]\}}|dD] }||r|Sq qdS)Nr)r;r(r)r0r/r r>r#r#r$_find_unpack_formats   rJcCstd||||durt}t|}t|}|durGzt|}Wnty3td|dw|d}|||fit |ddSt |}|durVt 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}'r2rzUnknown archive format '{0}') r@rjr=r4rr;rrrkdictrJr))r0rErkr7r8rr#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=rLf_bavailf_frsizef_blocksf_bfree_ntuple_diskusage)rXryfreetotalusedr#r#r$rM%s    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 _getdiskusagerR)rXrTrSrUr#r#r$rM6s cCstd||||dur|durtd|}|}|durd}nt|tr3t|}|dur3td||dur:d}nt|tsNt |}|durNtd|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 setzno such user: {!r}zno such group: {!r}) r@rjrrUrr LookupErrorrkintrr=r)rXuserrZ_userZ_groupr#r#r$rAs$  rPc Csz ttjd}Wn ttfyd}Ynwz ttjd}Wn ttfy-d}Ynw|dks6|dkr`z ttj}Wnt tt fyQt |}Ynw|dkrY|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)rXr=environrrrr@ __stdout__r,AttributeErrorr. terminal_sizecolumnslines)Zfallbackrarbsizer#r#r$ras*rcCs&tj|ot||otj| Sr`)r=rXrurr)rbrr#r#r$ _access_checks rdc stjrt|r SdStt}|dur9tjdd}|dur9ztd}Wnt t fy8tj }Ynw|s=dS|rNt |}| t tj}n t|}| tj}tjdkrtj}|rht |}||vrr|d|tdpxt}dd| tjD}|rd d|D}tfd d |Drg}n fd d|D}ng}t}|D](} tj| } | |vr|| |D]} tj| | } t| |r| SqqdS) 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. NPATHCS_PATHwin32rZPATHEXTcSsg|]}|r|qSr#r#rr=r#r#r$rzwhich..cSsg|]}t|qSr#)r=fsencoderhr#r#r$rsc3s"|] }|VqdSr`)lowerrrhcmdr#r$ s zwhich..csg|]}|qSr#r#rhrlr#r$rri)r=rXr rdrUrr]getconfstrr_rdefpathrjrDpathseprr@rrinsertgetenv_WIN_DEFAULT_PATHEXTanyrrZr r) rmrrXZ use_bytesrZpathext_sourceZpathextfilesseendirZnormdirZthefiler/r#rlr$rs\             r)r)F)FN)rrrNNNN)rrNNNN)Nr)NNrrNNN)NN)rZ)fr'r=r@rYr collectionsr2zlibrrrrZlzmarr/rorrrPrWrrrCrsru__all__r.rrrrr)r-r*r+r;rGrOrr_rcrfrr rr r r rrr stat_resultrrrrrrrrsupports_dir_fdr supports_fdrrrZavoids_symlink_attacksrrrrrrrr#r'rrrrrr@rrrArHrIr;rJrr namedtuplerRrTrUrSrMrrrdF_OKX_OKrr#r#r#r$s>         @  @ B A 0  8   B B  F ?  <         *      1