o ƚRekd@sdZddlZddlZddlZddlmZddlZzddlmZWne y/ddl mZYnwddl Z ddl m Z zddlZdZWn e yMdZYnwzdd lmZWn e yadZYnwzdd lmZWn e yudZYnwgd ZGd d d eZGdddeZGdddeZGdddeZGdddeZzeWn eydZYnwdfddZddZddZ 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/gdBfdCZ0er'e-d>gd?fe0dD<dEdFZ1dkdHdIZ2dJdKZ3  dldLdMZ4dNdOZ5dPdQZ6  GdkdRdSZ7dTdUZ8dVdWZ9dXdYZ:dZd[Z;d\d]ge;gd=fd^ge;gdAfd_ge:gdBfd`ZdS)nzUtility 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 /builddir/build/BUILDROOT/alt-python310-pip-21.3.1-3.el8.x86_64/opt/alt/python310/lib/python3.10/site-packages/pip/_vendor/distlib/_backport/shutil.pyr/src@eZdZdZdS)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!r2rc@r")rz+Raised when a command could not be executedNr#r r r r!r6r%rc@r") ReadErrorz%Raised when an archive cannot be readNr#r r r r!r&9r%r&c@r") RegistryErrorzVRaised when a registry operation with the archiving and unpacking registries failsNr#r r r r!r'<r%r'@cCs ||}|s dS||q)z=copy data from file-like object fsrc to file-like object fdstrN)readwrite)fsrcfdstlengthbufr r r!rFs   rcCsZttjdrztj||WStyYdSwtjtj|tjtj|kS)NsamefileF)hasattrospathr/OSErrornormcasersrcdstr r r! _samefileNs  r8c Cst||r td||f||fD]}zt|}Wn ty#Yqwt|jr0td|qt|d+}t|d }t ||Wdn1sLwYWddSWddS1sdwYdS)zCopy data from src to dstz`%s` and `%s` are the same filez`%s` is a named piperbwbN) r8rr1statr3S_ISFIFOst_moderopenr)r6r7fnstr+r,r r r!r Zs$        "r cCs4ttdrt|}t|j}t||dSdS)zCopy mode bits from src to dstchmodN)r0r1r;S_IMODEr=rA)r6r7r@moder r r!r ns   r c Cst|}t|j}ttdrt||j|jfttdr%t||ttdrYt|dr[z t ||j WdSt yX}ztt drL|j t j krMWYd}~dSd}~wwdSdS)zCCopy all stat info (mode bits, atime, mtime, flags) from src to dstutimerAchflagsst_flags EOPNOTSUPPN)r1r;rBr=r0rDst_atimest_mtimerArErFr3errnorG)r6r7r@rCwhyr r r!r us"       r cC:tj|rtj|tj|}t||t||dS)zVCopy data and mode bits ("cp src dst"). The destination may be a directory. N)r1r2isdirjoinbasenamer r r5r r r!r   r cCrL)z]Copy data and all stat info ("cp -p src dst"). The destination may be a directory. N)r1r2rMrNrOr r r5r r r!r rPr 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)r2names ignored_namespatternpatternsr r!_ignore_patternssz)ignore_patterns.._ignore_patternsr )rZr[r rYr!rs rc Cst|}|dur|||}nt}t|g}|D]} | |vr"qtj|| } tj|| } z:tj| rUt| } |rEt| | n$tj | sO|rOWq|| | ntj | rdt | | |||n|| | Wqt y} z| | jdWYd} ~ qd} ~ wty}z|| | t|fWYd}~qd}~wwzt||Wn&ty}ztdurt|trn | ||t|fWYd}~nd}~ww|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)r1listdirrUmakedirsr2rNislinkreadlinksymlinkexistsrMrrrRargsEnvironmentErrorappendstrr r3 WindowsError isinstance)r6r7symlinksignore copy_functionignore_dangling_symlinksrVrWerrorsnamesrcnamedstnamelinktoerrrKr r r!rsR $        rc Csb|rdd}n|durdd}z tj|rtdWnty/|tjj|tYdSwg}zt|}WntjyL|tj|tYnw|D]D}tj||}zt |j }Wn tjyld}Ynwt |ryt |||qOzt|WqOtjy|tj|tYqOwzt|WdStjy|tj|tYdSw)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. cWsdSrQr rbr r r!onerrorszrmtree..onerrorNcWsrQr rrr r r!rssz%Cannot call rmtree on a symbolic linkr)r1r2r^r3sysexc_infor\errorrNlstatr=r;S_ISDIRrremovermdir)r2 ignore_errorsrsrVrmfullnamerCr r r!rsJ    rcCstj|tjjSrQ)r1r2rOrstripsep)r2r r r! _basename*srcCs|}tj|r*t||rt||dStj|t|}tj|r*td|z t||WdSt yhtj|r[t ||rMtd||ft ||ddt |YdSt ||t|YdSw)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)rh)r1r2rMr8renamerNrrarr3 _destinsrcrrr unlink)r6r7real_dstr r r!r/s&         rcCsNt|}t|}|tjjs|tjj7}|tjjs"|tjj7}||SrQ)rendswithr1r2r~ startswithr5r r r!rWs   rcCLtdus|dur dSzt|}Wn tyd}Ynw|dur$|dSdS)z"Returns a gid, given a group name.N)rKeyErrorrmresultr r r!_get_gid`  rcCr)z"Returns an uid, given a user name.Nr)rrrr r r!_get_uidlrrgzipcs ddd}ddi} trd|d<d| d<|d ur"|| vr"td ||d | |d} tj| } tj| sI|d urB|d | |sIt | |d urR|d t t fdd} |st | d||} z| j|| dW| | S| w| 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|_|_|SrQ)gidgnameuiduname)tarinforgroupownerrr r! _set_uid_gidsz#_make_tarball.._set_uid_gidzw|%s)rT)_BZ2_SUPPORTED ValueErrorformatgetr1r2dirnamerainfor]rrrr>addclose) base_namebase_dircompressverbosedry_runrrloggertar_compression compress_ext archive_name archive_dirrtarr rr! _make_tarballxs:        rcCs\|rd}nd}ddlm}ddlm}z |d|||g|dWdS|y-td|w) Nz-rz-rqr)DistutilsExecError)spawnzip)rzkunable to create zip file '%s': could neither import the 'zipfile' module nor find a standalone zip utility)distutils.errorsrdistutils.spawnrr)r zip_filenamerr zipoptionsrrr r r!_call_external_zips   rcCs|d}tj|}tj|s!|dur|d||s!t|zddl}Wn ty2d}Ynw|dur@t|||||S|durK|d|||s|j |d|j d}t |D]+\} } } | D]#} tj tj | | } tj| r|| | |dur|d| qbq[||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')r1r2rrarr]zipfile ImportErrorrZipFile ZIP_DEFLATEDwalknormpathrNisfiler*r)rrrrrrrrrdirpathdirnames filenamesrmr2r r r! _make_zipfilesD         r)rrzgzip'ed tar-file)rrzbzip2'ed tar-file)rNzuncompressed tar filezZIP file)gztarbztarrrrcCddtD}||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 ).0rmregistryr r r! sz'get_archive_formats..)_ARCHIVE_FORMATSitemssortformatsr r r!rs rrcCsv|durg}t|tstd|t|ttfstd|D]}t|ttfr-t|dkr1tdq|||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))rgr TypeErrortuplelistlenr)rmfunction extra_args descriptionelementr r r!r s   rcCs t|=dSrQ)rrmr r r!r s rc  Cs"t} |dur|dur|d|tj|}|st||dur&tj}||d} zt|} Wn ty>t d|w| d} | dD]\} }|| | <qG|dkr\|| d<|| d <z| ||fi| }W|durz|duru|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", "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') r1getcwddebugr2rchdircurdirrrr)rrroot_dirrrrrrrsave_cwdkwargs format_infofuncargvalfilenamer r r!r#sB            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)rr )rrmrr r r!r`s"z&get_unpack_formats..)_UNPACK_FORMATSrrrr r r!rZs rc Csli}tD]\}}|dD]}|||<qq|D]}||vr*d}t||||fqt|ts4tddS)z+Checks what gets registered as an unpacker.rz!%s is already registered for "%s"z*The registered function must be a callableN)rrr'rgrr) extensionsrrexisting_extensionsrmrext extensionmsgr r r!_check_unpack_optionses   rcCs,|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)rr)rmrrrrr r r!rws rcCs t|=dS)z*Removes the pack format from the registry.N)rrr r r!rs rcCs*tj|}tj|st|dSdS)z1Ensure that the parent directory of `path` existsN)r1r2rrMr])r2rr r r!_ensure_directorys  rc Cszddl}Wn tytdw||std|||}zR|D]F}|j}|ds5d|vr6q'tj j |g| dR}|sFq't || dsm||j}t|d}z ||W|~q'|~wq'W|dS|w)z+Unpack zip `filename` to `extract_dir` rNz/zlib not supported, cannot unpack this archive.z%s is not a zip file/z..r:)rrr& is_zipfilerinfolistrrr1r2rNsplitrrr)r>r*r) r extract_dirrrrrmtargetdatafr r r!_unpack_zipfiles:          rcCsPzt|}Wntjytd|wz ||W|dS|w)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|Sq qdS)Nr)rrr)rrmrrr r r!_find_unpack_formats   rcCs|durt}|dur4zt|}Wnty td|w|d}|||fit|ddSt|}|durCtd|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}') r1rrrrrdictrr&)rrrrrrr r r!rs    r)r()FN)rrrNNN)FF)rrN)Nr)NNrrNNN)NN)?r$r1rtr;os.pathrrScollections.abcrr collectionsrJrrrrpwdrgrpr__all__rcrrrr& Exceptionr'rf NameErrorrr8r r r r r rrrrrrrrrrrrrrrrrrrrrrrrrrr r r r!s             R1(    >  0    7  %