a ljkd@sdZddlZddlZddlZddlmZddlZzddlmZWne y^ddl mZYn0ddl Z ddl m Z zddlZdZWne ydZYn0zdd lmZWne ydZYn0zdd lmZWne ydZYn0gd ZGd d d eZGdddeZGdddeZGdddeZGdddeZzeWneyddZYn0dfddZddZddZ ddZ!dd Z"d!d"Z#d#d$Z$d%d&Z%dde$dfd'd(Z&dgd)d*Z'd+d,Z(d-d.Z)d/d0Z*d1d2Z+d3d4Z,dhd6d7Z-did8d9Z.djd:d;Z/e-dgd?fe-d@gdAfe/gdBfdCZ0erLe-d>gd?fe0dD<dEdFZ1dkdHdIZ2dJdKZ3dldLdMZ4dNdOZ5dPdQZ6dmdRdSZ7dTdUZ8dVdWZ9dXdYZ:dZd[Z;d\d]ge;gd=fd^ge;gdAfd_ge:gdBfd`ZdS)ozUtility functions for copying and archiving files and directory trees. XXX The functions here don't copy the resource fork or other metadata on Mac. N)abspath)Callable)tarfileTF)getpwnam)getgrnam) copyfileobjcopyfilecopymodecopystatcopycopy2copytreemovermtreeErrorSpecialFileError ExecError make_archiveget_archive_formatsregister_archive_formatunregister_archive_formatget_unpack_formatsregister_unpack_formatunregister_unpack_formatunpack_archiveignore_patternsc@s eZdZdS)rN)__name__ __module__ __qualname__r r H/usr/lib/python3.9/site-packages/pip/_vendor/distlib/_backport/shutil.pyr/src@seZdZdZdS)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)Nrrr__doc__r r r r!r2src@seZdZdZdS)rz+Raised when a command could not be executedNr"r r r r!r6src@seZdZdZdS) ReadErrorz%Raised when an archive cannot be readNr"r r r r!r$9sr$c@seZdZdZdS) RegistryErrorzVRaised when a registry operation with the archiving and unpacking registries failsNr"r r r r!r%<sr%@cCs ||}|sq||qdS)z=copy data from file-like object fsrc to file-like object fdstN)readwrite)fsrcfdstlengthbufr r r!rFs rcCsZttjdr2ztj||WSty0YdS0tjtj|tjtj|kS)NsamefileF)hasattrospathr-OSErrornormcasersrcdstr r r! _samefileNs  r6c Cst||rtd||f||fD]>}zt|}WntyFYq"0t|jr"td|q"t|dD}t|d}t ||Wdn1s0YWdn1s0YdS)zCopy data from src to dstz`%s` and `%s` are the same filez`%s` is a named piperbwbN) r6rr/statr1S_ISFIFOst_moderopenr)r4r5fnstr)r*r r r!r Zs      r cCs0ttdr,t|}t|j}t||dS)zCopy mode bits from src to dstchmodN)r.r/r9S_IMODEr;r?)r4r5r>moder r r!r ns   r c Cst|}t|j}ttdr4t||j|jfttdrJt||ttdrt|drzt ||j Wn<t y}z$tt dr|j t j krWYd}~n d}~00dS)zCCopy all stat info (mode bits, atime, mtime, flags) from src to dstutimer?chflagsst_flags EOPNOTSUPPN)r/r9r@r;r.rBst_atimest_mtimer?rCrDr1errnorE)r4r5r>rAwhyr r r!r us       r cCs:tj|r"tj|tj|}t||t||dS)zVCopy data and mode bits ("cp src dst"). The destination may be a directory. N)r/r0isdirjoinbasenamer r r3r r r!r s  r cCs:tj|r"tj|tj|}t||t||dS)z]Copy data and all stat info ("cp -p src dst"). The destination may be a directory. N)r/r0rJrKrLr r r3r 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|SN)extendfnmatchfilterset)r0names ignored_namespatternpatternsr r!_ignore_patternssz)ignore_patterns.._ignore_patternsr )rVrWr rUr!rs rc Cst|}|dur|||}nt}t|g}|D]} | |vrFq6tj|| } tj|| } zttj| rt| } |rt| | qtj | s|rWq6|| | n(tj | rt | | |||n || | Wq6t y } z| | jdWYd} ~ q6d} ~ 0tyD}z || | t|fWYd}~q6d}~00q6zt||WnRty}z8tdurt|trn| ||t|fWYd}~n d}~00|rt |dS)aRecursively copy a directory tree. The destination directory must not already exist. 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. Nr)r/listdirrQmakedirsr0rKislinkreadlinksymlinkexistsrJrrrNargsEnvironmentErrorappendstrr r1 WindowsError isinstance)r4r5symlinksignore copy_functionignore_dangling_symlinksrRrSerrorsnamesrcnamedstnamelinktoerrrIr r r!rsD$        $,*rc Csh|rdd}n|durdd}ztj|r4tdWn(ty^|tjj|tYdS0g}zt|}Wn&tjy|tj|tYn0|D]}tj||}zt |j }Wntjyd}Yn0t |rt |||qzt|Wqtjy(|tj|tYq0qzt|Wn(tjyb|tj|tYn0dS)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 os.listdir, os.remove, or os.rmdir; 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. cWsdSrMr r^r r r!onerrorszrmtree..onerrorNcWsdSrMr rnr r r!rosz%Cannot call rmtree on a symbolic linkr)r/r0rZr1sysexc_inforXerrorrKlstatr;r9S_ISDIRrremovermdir)r0 ignore_errorsrorRrifullnamerAr r r!rs>       rcCstj|tjjSrM)r/r0rLrstripsep)r0r r r! _basename*sr{cCs|}tj|rTt||r*t||dStj|t|}tj|rTtd|zt||Wndt ytj|rt ||rtd||ft ||ddt |nt ||t|Yn0dS)aRecursively move a file or directory to another location. This is similar to the Unix "mv" command. 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. A lot more could be done here... A look at a mv.c shows a lot of the issues this implementation glosses over. Nz$Destination path '%s' already existsz.Cannot move a directory '%s' into itself '%s'.T)rd)r/r0rJr6renamerKr{r]rr1 _destinsrcrrr unlink)r4r5real_dstr r r!r/s$          rcCsNt|}t|}|tjjs*|tjj7}|tjjsD|tjj7}||SrM)rendswithr/r0rz startswithr3r r r!r}Ws  r}cCsLtdus|durdSz t|}Wnty6d}Yn0|durH|dSdS)z"Returns a gid, given a group name.N)rKeyErrorriresultr r r!_get_gid`s   rcCsLtdus|durdSz t|}Wnty6d}Yn0|durH|dSdS)z"Returns an uid, given a user name.Nr)rrrr r r!_get_uidls   rgzipcs ddd}ddi} tr&d|d<d| d<|d urD|| vrDtd ||d | |d} tj| } tj| s|d ur|d | |st | |d ur|d t t fdd} |st | 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", 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", or ".bz2"). Returns the output filename. gz)rNrz.gzbz2bzip2.bz2NzCbad value for 'compress', or compression format not supported : {0}.tar creating %szCreating tar archivecs,dur|_|_dur(|_|_|SrM)gidgnameuiduname)tarinforgroupownerrr r! _set_uid_gidsz#_make_tarball.._set_uid_gidzw|%s)rP)_BZ2_SUPPORTED ValueErrorformatgetr/r0dirnamer]inforYrrrr<addclose) base_namebase_dircompressverbosedry_runrrloggertar_compression compress_ext archive_name archive_dirrtarr rr! _make_tarballxs6       rcCsb|r d}nd}ddlm}ddlm}z|d|||g|dWn|y\td|Yn0dS) Nz-rz-rqr)DistutilsExecError)spawnzip)rzkunable to create zip file '%s': could neither import the 'zipfile' module nor find a standalone zip utility)Zdistutils.errorsrZdistutils.spawnrr)r zip_filenamerrZ zipoptionsrrr r r!_call_external_zips   rcCs|d}tj|}tj|sB|dur4|d||sBt|z ddl}Wntydd}Yn0|dur~t||||n|dur|d|||s|j |d|j d}t |D]V\} } } | D]F} tj tj | | } tj| r|| | |dur|d| qq||S) amCreate a zip file from all the files under 'base_dir'. The output zip file will be named 'base_name' + ".zip". Uses either the "zipfile" Python module (if available) or the InfoZIP "zip" utility (if installed and found on the default search path). If neither tool is available, raises ExecError. Returns the name of the output zip file. .zipNrrz#creating '%s' and adding '%s' to itw) compressionz adding '%s')r/r0rr]rrYzipfile ImportErrorrZipFile ZIP_DEFLATEDwalknormpathrKisfiler(r)rrrrrrrrrdirpathdirnames filenamesrir0r r r! _make_zipfiles<          r)rrzgzip'ed tar-file)rrzbzip2'ed tar-file)rNzuncompressed tar filezZIP file)gztarbztarrrrcCsddtD}||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 ).0riregistryr r r! z'get_archive_formats..)_ARCHIVE_FORMATSitemssortformatsr r r!rs rrcCsv|dur g}t|ts"td|t|ttfs8td|D]&}t|ttfrZt|dkr|dur$|d|tj|}|s>t||durLtj}||d} z t|} Wntyt d|Yn0| d} | dD]\} }|| | <q|dkr|| d<|| d <z<| ||fi| }W|dur|dur|d | t| n,|dur$|dur|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", "bztar" or "gztar". '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. Nzchanging into '%s')rrzunknown archive format '%s'rrrrrzchanging back to '%s') r/getcwddebugr0rchdircurdirrrr)rrroot_dirrrrrrrsave_cwdkwargs format_infofuncargvalfilenamer r r!r#s>            rcCsddtD}||S)zReturns a list of supported formats for unpacking. Each element of the returned sequence is a tuple (name, extensions, description) cSs"g|]\}}||d|dfqS)rr )rrirr r r!r`rz&get_unpack_formats..)_UNPACK_FORMATSrrrr r r!rZs rc Csli}tD]\}}|dD] }|||<qq |D]$}||vr0d}t||||fq0t|tshtddS)z+Checks what gets registered as an unpacker.rz!%s is already registered for "%s"z*The registered function must be a callableN)rrr%rcrr) extensionsrrexisting_extensionsrirext extensionmsgr r r!_check_unpack_optionses    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)rirrrrr r r!rws rcCs t|=dS)z*Removes the pack format from the registry.N)rrr r r!rsrcCs&tj|}tj|s"t|dS)z1Ensure that the parent directory of `path` existsN)r/r0rrJrY)r0rr r r!_ensure_directorys  rc Csz ddl}Wnty&tdYn0||s>td|||}z|D]}|j}|dsRd|vrpqRtj j |g| dR}|sqRt || dsR||j}t|d}z||W|~qR|~0qRW|n |0dS)z+Unpack zip `filename` to `extract_dir` rNz/zlib not supported, cannot unpack this archive.z%s is not a zip file/z..r8)rrr$ is_zipfilerinfolistrrr/r0rKsplitrrr'r<r(r) r extract_dirrrrritargetdatafr r r!_unpack_zipfiles4          rcCsVzt|}Wn tjy.td|Yn0z||W|n |0dS)z:Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir` z/%s is not a compressed or uncompressed tar fileN)rr<TarErrorr$ extractallr)rrtarobjr r r!_unpack_tarfiles  rz.tar.gzz.tgzrr)rrrrcCs:tD],\}}|dD]}||r|SqqdS)Nr)rrr)rrirrr r r!_find_unpack_formats   rcCs|durt}|durjz t|}Wn tyDtd|Yn0|d}|||fit|dnLt|}|durtd|t|d}tt|d}|||fi|dS)aUnpack 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", or "gztar". 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. NzUnknown unpack format '{0}'rrzUnknown archive format '{0}') r/rrrrrdictrr$)rrrrrrr r r!rs   r)r&)FN)rrrNNN)FF)rrN)Nr)NNrrNNN)Nr)NN)?r#r/rpr9Zos.pathrrOcollections.abcrr collectionsrHrrrrpwdrgrpr__all__r_rrrr$ Exceptionr%rb NameErrorrr6r r r r r rrrr{rr}rrrrrrrrrrrrrrrrrrrrr r r r!s                R 1(    >  0     7  %