a �DOg&��@sndZddlZddlZddlZddlZddlZddlZzddlZ[dZWne y\dZYn0zddl Z [ dZ Wne y�dZ Yn0zddl Z [ dZ Wne y�dZ Yn0zddlmZWne y�dZYn0zddlmZWne �ydZYn0ejdkZdZZejdk�r,ddlZne�r:ddlZe�rDd nd Zeed ��o^ej�d �ae�oneed �ZdZgd�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�de�Z"Gdd�de�Z#Gdd�de$�Z%Gdd�de$�Z&dd�Z'd d!�Z(efd"d#�Z)d�d$d%�Z*d&d'�Z+d(d)�Z,d*d+�Z-dd,�d-d.�Z.dd,�d/d0�Z/eed1��rbdd,�d2d3�Z0nd4d3�Z0dd,�d5d6�Z1dd,�d7d8�Z2dd,�d9d:�Z3d;d<�Z4d�d=d>�Z5dde3ddfd?d@�Z6eej7dA��r�dBdC�Z8dDdE�Z9ndFdC�Z8dGdE�Z9dHdI�Z:dJdK�Z;ejhej?k�o.ej@ejAv�o.ejejBvZCd�dLdM�ZDeCeD_EdNdO�ZFe3fdPdQ�ZGdRdS�ZHdTdU�ZIdVdW�ZJdXdY�ZKd�d[d\�ZLd�d]d^�ZMd_eLd`gdafiZNe�r�eLdbgdcfeNdd<eMgdefeNdf<e �r�eLdggdhfeNdi<e �r�eLdjgdkfeNdl<dmdn�ZOd�dpdq�ZPdrds�ZQd�dtdu�ZRdvdw�ZSdxdy�ZTd�dzd{�ZUd|d}�ZVd~d�ZWd�d��ZXdd��d�d��ZYd�geYgdafd�geXgdefd��ZZe�r�d�d�geYgdcfeZdd<e �r�d�d�geYgdhfeZdi<e �r�d�d�geYgdkfeZdl<d�d��Z[d�dd��d�d��Z\eed���re�]d��e�^d�d��Z_d�e_j`_d�e_ja_d�e_jb_d�d��Zcn$e�r8e�]d��e�^d�d��Z_d�d��Zcd�d�d��Zdd�d�d��Zed�d��ZfejgejhBdfd�d��ZidS)�z�Utility 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)�getgrnam�nt�posixii�sendfile�linux� _fcopyfilez%.COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS;.MSC)� copyfileobj�copyfile�copymode�copystat�copy�copy2�copytree�move�rmtree�Error�SpecialFileError� ExecError� make_archive�get_archive_formats�register_archive_format�unregister_archive_format�get_unpack_formats�register_unpack_format�unregister_unpack_format�unpack_archive�ignore_patterns�chown�which�get_terminal_size� SameFileErrorc@s eZdZdS)rN)�__name__� __module__� __qualname__�r%r%�/usr/lib64/python3.9/shutil.pyrEsrc@seZdZdZdS)r!z5Raised when source and destination are the same file.N�r"r#r$�__doc__r%r%r%r&r!Hsr!c@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)Nr'r%r%r%r&rKsrc@seZdZdZdS)rz+Raised when a command could not be executedNr'r%r%r%r&rOsrc@seZdZdZdS)� ReadErrorz%Raised when an archive cannot be readNr'r%r%r%r&r)Rsr)c@seZdZdZdS)� RegistryErrorzVRaised when a registry operation with the archiving and unpacking registries failsNr'r%r%r%r&r*Usr*c@seZdZdZdS)�_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+Ysr+c Cs�z|��}|��}Wn,ty@}zt|��WYd}~n d}~00zt�|||�WnVty�}z>|j|_|j|_|j t j t j hvr�t|��n|d�WYd}~n d}~00dS)zhCopy a regular file content or metadata by using high-performance fcopyfile(3) syscall (macOS). N) �fileno� Exceptionr+rr�OSError�name�filename� filename2�errno�EINVAL�ENOTSUP)�fsrc�fdst�flags�infd�outfd�errr%r%r&�_fastcopy_fcopyfile^s  r;c CsFz|��}|��}Wn,ty@}zt|��WYd}~n d}~00ztt�|�jd�}Wntynd}Yn0tj dkr�t |d�}d}zt� ||||�}Wn�t�y(}zr|j |_ |j |_|jtjkr�dat|��|jtjkr�|d�|dk�rt�|dtj�dk�rt|��|�WYd}~q�d}~00|dk�r8�qB||7}q�dS)z�Copy 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. Ni�ili@rF)r,r-r+�max�os�fstat�st_sizer.�sys�maxsize�minrr/r0r1r2�ENOTSOCK�_USE_CP_SENDFILE�ENOSPC�lseek�SEEK_CUR)r5r6r8r9r:� blocksize�offset�sentr%r%r&�_fastcopy_sendfilers8         rKc Cs�|j}|j}tt|���j}||�}|s*qtq||krj|d|��}|�|�Wd�qr1s^0Yq||�qWd�n1s�0YdS)z�readinto()/memoryview() based variant of copyfileobj(). *fsrc* must support readinto() method and both files must be open in binary mode. N)�readinto�write� memoryview� bytearray)r5r6�length� fsrc_readinto� fdst_write�mv�n�smvr%r%r&�_copyfileobj_readinto�s*rVcCs0|st}|j}|j}||�}|s"q,||�qdS)z=copy data from file-like object fsrc to file-like object fdstN)� COPY_BUFSIZE�readrM)r5r6rP� fsrc_readrR�bufr%r%r&r �sr cCs�t|tj�rHttjd�rHztj�|��t�|��WStyFYdS0ttjd�rzztj�||�WStyxYdS0tj� tj� |��tj� tj� |��kS)N�samestatF�samefile) � isinstancer=�DirEntry�hasattr�pathr[�statr.r\�normcase�abspath��src�dstr%r%r&� _samefile�s   �rgcCst|tj�r|��St�|�S�N)r]r=r^ra��fnr%r%r&�_stat�srkcCs t|tj�r|��Stj�|�Srh)r]r=r^� is_symlinkr`�islinkrir%r%r&�_islink�srn��follow_symlinksc Cs^t�d||�t||�r(td�||���d}t||g�D]h\}}z t|�}Wnty^Yq80t� |j �r�t |t j �r~|jn|}td|��tr8|dkr8|j}q8|s�t|�r�t �t �|�|��n�t|d���x}�zt|d����}t�r4z2t||tj�|WWd�WWd�St�y0Yn0n�t�r�z.t||�|WWd�WWd�St�y|Yn0nDt�r�|dk�r�t||t|t��|Wd�WWd�St ||�Wd�n1�s�0YWnHt!�y8} z.t j�"|��s"t#d|���| �n�WYd} ~ n d} ~ 00Wd�n1�sP0Y|S) z�Copy 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 pipe�rb�wbNzDirectory does not exist: )$r@�auditrgr!�format� enumeraterkr.ra�S_ISFIFO�st_moder]r=r^r`r�_WINDOWSr?rn�symlink�readlink�open�_HAS_FCOPYFILEr;r�_COPYFILE_DATAr+rDrKrVrBrWr �IsADirectoryError�exists�FileNotFoundError) rerfrp� file_size�irj�str5r6�er%r%r&r �sP       $ $".8r cCspt�d||�|sFt|�rFtj�|�rFttd�r@tjtj}}qRdSn t tj }}||�}||t � |j ��dS)z�Copy 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.copymode�lchmodN)r@rsrnr=r`rmr_�lstatr�rk�chmodra�S_IMODErw)rerfrp� stat_func� chmod_funcr�r%r%r&r *s  r � listxattrc Cs�ztj||d�}Wn>tyP}z&|jtjtjtjfvr:�WYd}~dSd}~00|D]l}z&tj|||d�}tj||||d�WqVty�}z(|jtj tjtjtjfvr��WYd}~qVd}~00qVdS)z�Copy extended filesystem attributes from `src` to `dst`. Overwrite existing attributes. If `follow_symlinks` is false, symlinks won't be followed. roN) r=r�r.r2r4�ENODATAr3�getxattr�setxattr�EPERM)rerfrp�namesr�r/�valuer%r%r&� _copyxattr@s �r�cOsdSrhr%)�args�kwargsr%r%r&r�Xsc s`t�d||�ddd�dd��|p6t|�o4tj�|� }|rJ�fdd�}n �fdd�}t|tj�rp|j|d �}n|d �||d �}t� |j �}|d �||j |j f|d�t |||d �z|d �|||d �Wnty�Yn0t|d ��r\z|d�||j|d �WnXt�yZ}z>dD]*}tt|��r|jtt|�k�r�qF�q�WYd}~n d}~00dS)a�Copy 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)�nsrpcWsdSrhr%)r�rpr�r%r%r&�_nopiszcopystat.._nopcs tt|��Srh)�getattrr=�r/�r�r%r&�lookuppszcopystat..lookupcstt|��}|tjvr|S�Srh)r�r=�supports_follow_symlinks)r/rjr�r%r&r�us  rora�utimer��st_flags�chflags)� EOPNOTSUPPr4)r@rsrnr=r`rmr]r^rar�rw� st_atime_ns� st_mtime_nsr��NotImplementedErrorr_r�r.r2r�) rerfrp�followr�r��mode�whyr:r%r�r&r [s4    �   r cCsBtj�|�r"tj�|tj�|��}t|||d�t|||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. ro)r=r`�isdir�join�basenamer r �rerfrpr%r%r&r �s r cCsBtj�|�r"tj�|tj�|��}t|||d�t|||d�|S)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". ro)r=r`r�r�r�r r r�r%r%r&r�s rcs�fdd�}|S)z�Function 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|�Srh)�extend�fnmatch�filter�set)r`r�� ignored_names�pattern��patternsr%r&�_ignore_patterns�sz)ignore_patterns.._ignore_patternsr%)r�r�r%r�r&r�s rc CsD|dur$|t�|�dd�|D��}nt�}tj||d�g} |tupJ|tu} |D�]�} | j|vrbqPtj�|| j�} tj�|| j�} | r�| n| }z�| � �}|r�tjdkr�| j dd�}|j t j kr�d}|�r8t� | �}|r�t�|| �t|| | d�nBtj�|��s |�r WqP| ���r,t|| ||||d�n ||| �n*| ���rXt|| ||||d�n ||| �WqPt�y�}z| �|jd�WYd}~qPd}~0t�y�}z | �| | t|�f�WYd}~qPd}~00qPzt||�WnLt�y0}z2t|d d�du�r| �||t|�f�WYd}~n d}~00| �r@t| ��|S) NcSsg|] }|j�qSr%r�)�.0�xr%r%r&� ��z_copytree..)�exist_okrFro)� dirs_exist_okr�winerror)r=�fspathr��makedirsrr r/r`r�rlra�st_reparse_tag�IO_REPARSE_TAG_MOUNT_POINTrzryr r�is_dirrrr�r�r.�append�strr�)�entriesrerf�symlinks�ignore� copy_function�ignore_dangling_symlinksr�r��errors� use_srcentry�srcentry�srcname�dstname�srcobjrlr��linktor:r�r%r%r&� _copytree�s^         �   �$,*r�c CsXt�d||�t�|��}t|�}Wd�n1s60Yt||||||||d�S)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)r�rerfr�r�r�r�r�)r@rsr=�scandir�listr�) rerfr�r�r�r�r��itrr�r%r%r&r s( & �r�st_file_attributescCsNz4|jdd�}t�|j�o2|jtj@o0|jtjk WStyHYdS0dS�NFro)ra�S_ISDIRrwr��FILE_ATTRIBUTE_REPARSE_POINTr�r�r.)�entryr�r%r%r&� _rmtree_isdirAs    � r�cCsJz0t�|�}t�|j�p.|jtj@o.|jtjkWSt yDYdS0dS)NF) r=r�ra�S_ISLNKrwr�r�r�r�r.)r`r�r%r%r&�_rmtree_islinkJs    � r�cCs(z|jdd�WSty"YdS0dSr�)r�r.)r�r%r%r&r�Ss cCs tj�|�Srh)r=r`rm)r`r%r%r&r�Ysc Cs2z6t�|��}t|�}Wd�n1s*0YWn(ty^|tj|t���g}Yn0|D]�}|j}t|�r�z|��r�td��Wn*ty�|tjj |t���YqdYn0t ||�qdzt� |�Wqdty�|tj |t���Yqd0qdzt� |�Wn&t�y,|tj |t���Yn0dS)N�%Cannot call rmtree on a symbolic link) r=r�r�r.r@�exc_infor`r�rlrm�_rmtree_unsafe�unlink�rmdir)r`�onerror� scandir_itr�r��fullnamer%r%r&r�]s0 *       r�c Cs`z6t�|��}t|�}Wd�n1s*0YWn>tyt}z&||_|tj|t���WYd}~dSd}~00|D�]�}tj�||j �}z|j dd�}Wnty�d}YnP0|�rz|j dd�} t � | j �}Wn*t�y|tj|t���YqzYn0|�rztj|j tj|d�} d} Wn&t�yN|tj|t���Yn�0z�tj�| t�| ���r�t| ||�z"t�| �d} tj|j |d�Wn&t�y�|tj|t���Yn0n6z td��Wn(t�y�|tjj|t���Yn0W| �st�| �n| �st�| �0qzztj|j |d�Wqzt�yX|tj|t���Yqz0qzdS)NFro)�dir_fdTr�)r=r�r�r.r0r@r�r`r�r/r�rar�rwr�r{�O_RDONLYr[r>�_rmtree_safe_fd�closer�rmr�) �topfdr`r�r�r�r:r�r�r��orig_st�dirfd� dirfd_closedr%r%r&r�|s^ *         �r�c Cs�t�d|�|rdd�}n|dur*dd�}t�r�t|t�rDt�|�}zt�|�}Wn&tyx|tj|t� ��YdS0zt� |tj �}d}Wn&ty�|tj |t� ��YdS0z�tj � |t�|���r"t|||�zt�|�d}t�|�Wn&t�y|tj|t� ��Yn0n6z td��Wn(t�yV|tj j|t� ��Yn0W|�s~t�|�n|�s|t�|�0nLzt|��r�td��Wn*t�y�|tj j|t� ��YdS0t||�SdS) a�Recursively 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.rmtreecWsdSrhr%�r�r%r%r&r��szrmtree..onerrorNcWs�dSrhr%r�r%r%r&r��sFTr�)r@rs�_use_fd_functionsr]�bytesr=�fsdecoder�r-r�r{r�r`r[r>r�r�r�r.rmr�r�)r`� ignore_errorsr�r��fd� fd_closedr%r%r&r�sV          �  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=r�r`�sep�altsepr��rstrip)r`r�r%r%r&� _basename�s r�c CsRt�d||�|}tj�|�rbt||�r8t�||�dStj�|t|��}tj� |�rbt d|��zt�||�Wn�t �yLtj� |�r�t� |�}t�||�t�|�n�tj�|��r4t||�r�t d||f��t|��s t�|tj��st�|��rtjdk�rtd||f��t|||dd�t|�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'.�darwinzKCannot move the non-empty directory '%s': Lacking write permission to '%s'.T)r�r�)r@rsr=r`r�rg�renamer�r�rrr.rmrzryr�� _destinsrc� _is_immutable�access�W_OK�listdir�platform�PermissionErrorrr)rerfr��real_dstr�r%r%r&rsL          �  �����  rcCsVtj�|�}tj�|�}|�tjj�s2|tjj7}|�tjj�sL|tjj7}|�|�Srh)r=r`rc�endswithr�� startswithrdr%r%r&r�Qs    r�cCs(t|�}tjtjg}t|d�o&|j|vS)Nr�)rkra� UF_IMMUTABLE� SF_IMMUTABLEr_r�)rer��immutable_statesr%r%r&r�Zs r�cCsLtdus|durdSz t|�}Wnty6d}Yn0|durH|dSdS)z"Returns a gid, given a group name.N�)r�KeyError�r/�resultr%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_uidks   r �gzipcs(|durd}nDtr |dkr d}n2tr2|dkr2d}n trD|dkrDd}ntd�|���d dl} |rfd |nd} |d | } tj�| �} | r�tj� | �s�|dur�|� d | �|s�t� | �|dur�|� d �t ���t �������fdd�} |�s$| �| d|�}z|j|| d�W|��n |��0| S)a�Create 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. Nr�r �gz�bzip2�bz2�xzzCbad value for 'compress', or compression format not supported : {0}r�.�.tar� creating %szCreating tar archivecs,�dur�|_�|_�dur(�|_�|_|Srh)�gid�gname�uid�uname)�tarinfo�r�group�ownerrr%r&� _set_uid_gid�sz#_make_tarball.._set_uid_gidzw|%s�r�)�_ZLIB_SUPPORTED�_BZ2_SUPPORTED�_LZMA_SUPPORTED� ValueErrorrt�tarfiler=r`�dirnamer�infor�r rr{�addr�)� base_name�base_dir�compress�verbose�dry_runrr�logger�tar_compressionr � compress_ext� archive_name� archive_dirr�tarr%rr&� _make_tarballws>   �      r/c Cs�ddl}|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|� | | �|du�r|�d| ��qq�Wd�n1�sv0Y|S) z�Create 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 it�w)� compressionz adding '%s')�zipfiler=r`r!rr"r��ZipFile� ZIP_DEFLATED�normpath�curdirrM�walk�sortedr��isfile)r$r%r'r(r)r3� zip_filenamer-�zfr`�dirpath�dirnames� filenamesr/r%r%r&� _make_zipfile�sF   ��        2r@r.)r&Nzuncompressed tar file)r&r zgzip'ed tar-file�gztarzZIP file�zip)r&r zbzip2'ed tar-file�bztar)r&rzxz'ed tar-file�xztarcCsdd�t��D�}|��|S)z�Returns a list of supported formats for archiving and unarchiving. Each element of the returned sequence is a tuple (name, description) cSsg|]\}}||df�qS)rr%)r�r/�registryr%r%r&r��r�z'get_archive_formats..)�_ARCHIVE_FORMATS�items�sort��formatsr%r%r&r�s �rr�cCst|dur g}t|�s td|��t|ttf�s6td��|D]&}t|ttf�rXt|�dkr:td��q:|||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� TypeErrorr]�tupler��lenrF)r/�function� extra_args� description�elementr%r%r&r�s   rcCs t|=dSrh)rFr�r%r%r&rsrc  CsBt�d||||�t��} |durP|dur6|�d|�tj�|�}|sPt�|�|dur^tj}||d�} z t |} Wn t y�t d|�d�Yn0| d} | dD]\} }|| | <q�|dkr�|| d <|| d <z@| ||fi| ��}W|du�r>|du�r|�d | �t�| �n,|du�r<|du�r2|�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')r(r)zunknown archive format '%s'r�rBrrzchanging back to '%s') r@rsr=�getcwd�debugr`rc�chdirr7rFrr)r$rt�root_dirr%r'r(rrr)�save_cwdr�� format_info�func�arg�valr0r%r%r&rs@           �    rcCsdd�t��D�}|��|S)z�Returns a list of supported formats for unpacking. Each element of the returned sequence is a tuple (name, extensions, description) cSs"g|]\}}||d|df�qS)r�r%)r�r/r"r%r%r&r�Ur�z&get_unpack_formats..)�_UNPACK_FORMATSrGrHrIr%r%r&rOs �rc Csji}t��D]\}}|dD] }|||<qq |D]$}||vr0d}t||||f��q0t|�sftd��dS)z+Checks what gets registered as an unpacker.rz!%s is already registered for "%s"z*The registered function must be a callableN)r^rGr*rKrL) � extensionsrOrP�existing_extensionsr/r"�ext� extension�msgr%r%r&�_check_unpack_optionsZs  � rdcCs,|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)rdr^)r/r_rOrPrQr%r%r&rls rcCs t|=dS)z*Removes the pack format from the registry.N)r^r�r%r%r&r�srcCs&tj�|�}tj�|�s"t�|�dS)z1Ensure that the parent directory of `path` existsN)r=r`r!r�r�)r`r!r%r%r&�_ensure_directory�s  rec Cs�ddl}|�|�std|��|�|�}z�|��D]�}|j}|�d�s2d|vrPq2tjj |g|� d��R�}|spq2t |�|� d�s2|� |d��D}t |d��}t||�Wd�n1s�0YWd�q21s�0Yq2W|��n |��0dS)z+Unpack zip `filename` to `extract_dir` rNz%s is not a zip file�/z..�rrr)r3� is_zipfiler)r4�infolistr0rr=r`r��splitrer�r{r r�) r0� extract_dirr3rBr"r/� targetpath�source�targetr%r%r&�_unpack_zipfile�s(     �JrorcCsbddl}z|�|�}Wn |jy6td|��Yn0z|j||d�W|��n |��0dS)zAUnpack tar/tar.gz/tar.bz2/tar.xz `filename` to `extract_dir` rNz/%s is not a compressed or uncompressed tar filer)r r{�TarErrorr)� extractallr�)r0rkr�r �tarobjr%r%r&�_unpack_tarfile�s� rsrr0)r.rBz.tar.gzz.tgzz.tar.bz2z.tbz2z.tar.xzz.txzcCs:t��D],\}}|dD]}|�|�r|SqqdS)Nr)r^rGr�)r0r/r"rbr%r%r&�_find_unpack_format�s   rtcCs�t�d|||�|dur t��}t�|�}t�|�}|durBi}nd|i}|dur�z t|}Wn"ty�td�|��d�Yn0|d}|||fit |d��|��nPt |�}|dur�t d�|���t|d}t t|d�|B}|||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. If `filter` is given, it is passed to the underlying extraction function. zshutil.unpack_archiveNr�zUnknown unpack format '{0}'rSrzUnknown archive format '{0}') r@rsr=rTr�r^rrrt�dictrtr))r0rkrtr�� filter_kwargsrYrZr�r%r%r&r�s*      r�statvfs� disk_usage�usageztotal used freezTotal space in byteszUsed space in byteszFree space in bytescCs@t�|�}|j|j}|j|j}|j|j|j}t|||�S)z�Return 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=rw�f_bavail�f_frsize�f_blocks�f_bfree�_ntuple_diskusage)r`r��free�total�usedr%r%r&rx s    cCs"t�|�\}}||}t|||�S)z�Return 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~)r`r�rr�r%r%r&rxscCs�t�d|||�|dur(|dur(td��|}|}|dur>d}n(t|t�rft|�}|durftd�|���|durtd}n(t|t�s�t |�}|dur�td�|���t � |||�dS)z�Change 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 set�����zno such user: {!r}zno such group: {!r}) r@rsrr]r�r � LookupErrorrt�intrr=r)r`�userr�_user�_groupr%r%r&r%s$  r��P�c Cs�zttjd�}Wnttfy,d}Yn0zttjd�}WnttfyZd}Yn0|dksl|dkr�zt�tj���}Wn"t tt fy�t� |�}Yn0|dkr�|j }|dkr�|j }t� ||f�S)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. �COLUMNSr�LINES)r�r=�environrrr r@� __stdout__r,�AttributeErrorr.� terminal_size�columns�lines)�fallbackr�r��sizer%r%r&r Es$  r cCs&tj�|�o$t�||�o$tj�|� Srh)r=r`rr�r�)rjr�r%r%r&� _access_checkvs �r�c s�tj���rt�|�r�SdSt�t�}|durrtj�dd�}|durrzt�d�}Wnt t fyptj }Yn0|szdS|r�t� |�}|� t� tj��}nt�|�}|� tj�}tjdk�rRtj}|r�t� |�}||vr�|�d|�t�d�p�t}dd�|� tj�D�}|�rd d�|D�}t�fd d �|D���r>�g}n�fd d�|D�}n�g}t�}|D]X} tj�| �} | |v�rb|�| �|D],} tj�| | �} t| |��r�| S�q��qbdS) 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. N�PATH�CS_PATH�win32r�PATHEXTcSsg|] }|r|�qSr%r%�r�rar%r%r&r��r�zwhich..cSsg|]}t�|��qSr%)r=�fsencoder�r%r%r&r��r�c3s |]}����|���VqdSrh)�lowerr�r���cmdr%r&� �r�zwhich..csg|] }�|�qSr%r%r�r�r%r&r��r�)r=r`r!r�r]r�r��get�confstrr�r�defpathr�rj�pathsepr�r@r�r7�insert�getenv�_WIN_DEFAULT_PATHEXT�anyr�rbr#r�) r�r�r`� use_bytesr7�pathext_source�pathext�files�seen�dir�normdir�thefiler/r%r�r&r{sV              r)r)F)FN)r rrNNN)rrN)Nr�)NNrrNNN)Nr�)NN)NN)r�)jr(r=r@rar�� collectionsr2�zlibr� ImportErrorr r�lzmar�pwdr�grprr/rxrrrWr_r�rrDr|r��__all__r.rr!rrr)r-r*r+r;rKrVr rgrkrnr r r�r r rrr�r� stat_resultr�r�r�r�r{r�r��supports_dir_fdr�� supports_fdr�r�r�avoids_symlink_attacksr�rr�r�rr r/r@rFrrrrrrdrrrerorsr^rtrr�� namedtupler~r�r�rrxrr r��F_OK�X_OKrr%r%r%r&�s>             @  @ B � A� 0 8� � � B B   � A - ���� � 8 �   � � � �1       1