Edit File: shutil.cpython-36.pyc
3 )�]b/d���������������-���@���s ��d�Z�ddlZddlZddlZddlmZ�ddlZddlZddlZddl m Z �yddlZdZW�n�e k rt���dZY�nX�yddlmZ�W�n�e k r����dZY�nX�ydd lmZ�W�n�e k r����dZY�nX�d ddd dddddddddddddddddgZG�dd��de�ZG�d d��de�ZG�d!d��de�ZG�d"d#��d#e�ZG�d$d%��d%e�Zye�W�n�ek �rj���dZY�nX�ded(d �Zd)d*��Zd+d��Zd,d��Zd-d ��Z d.d��Z!d/d��Z"d0d��Z#dde"dfd1d�Z$dfd2d�Z%d3d4��Z&d5d��Z'd6d7��Z(d8d9��Z)d:d;��Z*dgd=d>�Z+dhd?d@�Z,didAdB�Z-e+djgdDfe+dkgdFfe+dlgdGfe-g�dHfdI�Z.e�rRe+dmgdFfe.dJ<�dKd��Z/dndMd�Z0dNd��Z1dodOd�Z2dPd��Z3dQdR��Z4dpdSd�Z5dTd��Z6dUdV��Z7dWdX��Z8dYdZ��Z9d[d\ge9g�dDfd]ge9g�dGfd^ge8g�dHfd_�Z:e�r�d`ge9g�dFfe:dJ<�dadb��Z;dqdcd�Z<dS�)rz�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. �����N)�abspath����)�tarfileTF)�getpwnam)�getgrnam�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_patternsc���������������@���s���e�Zd�ZdS�)r���N)�__name__� __module__�__qualname__��r���r����/usr/lib/python3.6/shutil.pyr���,���s���c���������������@���s���e�Zd�ZdZdS�)r���z|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)N)r���r���r����__doc__r���r���r���r ���r���/���s���c���������������@���s���e�Zd�ZdZdS�)r���z+Raised when a command could not be executedN)r���r���r���r!���r���r���r���r ���r���3���s���c���������������@���s���e�Zd�ZdZdS�)� ReadErrorz%Raised when an archive cannot be readN)r���r���r���r!���r���r���r���r ���r"���6���s���r"���c���������������@���s���e�Zd�ZdZdS�)� RegistryErrorzVRaised when a registry operation with the archiving and unpacking registries failsN)r���r���r���r!���r���r���r���r ���r#���9���s���r#�������i���c�������������C���s$���x|�j�|�}|sP�|j|��qW�dS�)z=copy data from file-like object fsrc to file-like object fdstN)�read�write)�fsrc�fdstZlengthZbufr���r���r ���r���C���s ���� c�������������C���sX���t�tjd�r0ytjj|�|�S��tk r.���dS�X�tjjtjj|���tjjtjj|��kS�)N�samefileF)�hasattr�os�pathr)����OSError�normcaser���)�src�dstr���r���r ���� _samefileK���s����r1���c�������������C���s����t�|�|�rtd|�|f���xL|�|gD�]@}ytj|�}W�n�tk rJ���Y�q$X�tj|j�r$td|���q$W�t|�d��&}t|d��}t ||��W�dQ�R�X�W�dQ�R�X�dS�)zCopy data from src to dstz`%s` and `%s` are the same filez`%s` is a named pipe�rb�wbN) r1���r���r+����statr-����S_ISFIFO�st_moder����openr���)r/���r0����fn�str'���r(���r���r���r ���r���W���s���� c�������������C���s0���t�td�r,tj|��}tj|j�}tj||��dS�)zCopy mode bits from src to dst�chmodN)r*���r+���r4����S_IMODEr6���r:���)r/���r0���r9����moder���r���r ���r ���k���s���� c�������������C���s����t�j|��}tj|j�}tt�d�r4t�j||j|jf��tt�d�rJt�j||��tt�d�r�t|d�r�yt�j ||j ��W�n<�tk r��}�z ttd��s�|jtj kr���W�Y�dd}~X�nX�dS�)zCCopy all stat info (mode bits, atime, mtime, flags) from src to dst�utimer:����chflags�st_flags� EOPNOTSUPPN)r+���r4���r;���r6���r*���r=����st_atime�st_mtimer:���r>���r?���r-����errnor@���)r/���r0���r9���r<����whyr���r���r ���r ���r���s���� c�������������C���s:���t�jj|�r"t�jj|t�jj|���}t|�|��t|�|��dS�)zVCopy data and mode bits ("cp src dst"). The destination may be a directory. N)r+���r,����isdir�join�basenamer���r ���)r/���r0���r���r���r ���r�������s���� c�������������C���s:���t�jj|�r"t�jj|t�jj|���}t|�|��t|�|��dS�)z]Copy data and all stat info ("cp -p src dst"). The destination may be a directory. N)r+���r,���rE���rF���rG���r���r ���)r/���r0���r���r���r ���r�������s���� c�����������������s�����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 filesc����������������s,���g�}x��D�]}|j�tj||���q W�t|�S�)N)�extend�fnmatch�filter�set)r,����names� ignored_names�pattern)�patternsr���r ����_ignore_patterns����s���� z)ignore_patterns.<locals>._ignore_patternsr���)rO���rP���r���)rO���r ���r�������s����c�������������C���s���t�j|��}|dk r||�|�}nt��}t�j|��g�}�x|D��] } | |krJq:t�jj|�| �} t�jj|| �}ytt�jj| �r�t�j| �}|r�t�j||��q�t�jj |��r�|r�w:|| |��n(t�jj | �r�t| ||||��n || |��W�q:�tk �r�} �z|j | jd���W�Y�dd} ~ X�q:�tk �rD�}�z|j| |t|�f��W�Y�dd}~X�q:X�q:W�yt|�|��W�nP�tk �r��}�z2tdk �r�t|t��r�n|j |�|t|�f��W�Y�dd}~X�nX�|�r�t|��dS�)a���Recursively 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+����listdirrK����makedirsr,���rF����islink�readlink�symlink�existsrE���r ���r���rH����args�EnvironmentError�append�strr ���r-����WindowsError� isinstance)r/���r0����symlinks�ignoreZ copy_functionZignore_dangling_symlinksrL���rM����errors�nameZsrcnameZdstnameZlinkto�errrD���r���r���r ���r �������sD����$ *&c����������$���C���st��|rdd��}n|dkrdd��}yt�jj|��r4td��W�n(�tk r^���|t�jj|�tj����dS�X�g�}yt�j|��}W�n(�t�jk r����|t�j|�tj����Y�nX�x�|D�]�}t�jj|�|�}yt�j |�j }W�n�t�jk r����d}Y�nX�tj|�r�t |||��q�yt�j|��W�q��t�jk �r0���|t�j|tj����Y�q�X�q�W�yt�j|���W�n*�t�jk �rn���|t�j|�tj����Y�nX�dS�)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 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. c��������������W���s���d�S�)Nr���)rW���r���r���r ����onerror��s����zrmtree.<locals>.onerrorNc��������������W���s�����d�S�)Nr���)rW���r���r���r ���rb�����s����z%Cannot call rmtree on a symbolic linkr���)r+���r,���rS���r-����sys�exc_inforQ����errorrF����lstatr6���r4����S_ISDIRr����remove�rmdir)r,���� ignore_errorsrb���rL���r`����fullnamer<���r���r���r ���r�������s>���� c�������������C���s���t�jj|�jt�jj��S�)N)r+���r,���rG����rstrip�sep)r,���r���r���r ���� _basename'��s����rn���c�������������C���s����|}t�jj|�rTt|�|�r*t�j|�|��dS�t�jj|t|���}t�jj|�rTtd|���yt�j|�|��W�nf�t k r����t�jj|��r�t |�|�r�td|�|f���t|�|dd��t|���nt |�|��t�j|���Y�nX�dS�)a���Recursively 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)r]���)r+���r,���rE���r1����renamerF���rn���rV���r���r-���� _destinsrcr ���r���r����unlink)r/���r0���Zreal_dstr���r���r ���r���,��s$���� c�������������C���sN���t�|��}�t�|�}|�jtjj�s*|�tjj7�}�|jtjj�sD|tjj7�}|j|��S�)N)r����endswithr+���r,���rm���� startswith)r/���r0���r���r���r ���rp���T��s����rp���c�������������C���sN���t�dks|�dkrdS�yt�|��}W�n�tk r8���d}Y�nX�|dk rJ|d�S�dS�)z"Returns a gid, given a group name.N����)r����KeyError)r`����resultr���r���r ����_get_gid]��s���� rw���c�������������C���sN���t�dks|�dkrdS�yt�|��}W�n�tk r8���d}Y�nX�|dk rJ|d�S�dS�)z"Returns an uid, given a user name.Nrt���)r���ru���)r`���rv���r���r���r ����_get_uidi��s���� rx����gzipc���������� ������s��ddd�}ddi} t�r&d|d<�d| d<�|d k rD|| krDtd j|���|�d�| j|d��} tjj| �}tjj|�s�|d k r�|jd|��|s�tj |��|d k r�|jd ��t ���t���������fdd�}|��s�tj | d||���} z| j||d��W�d | j���X�| S�)a���Create 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. Zgz��)ry���Nry���z.gz�bz2�bzip2z.bz2NzCbad value for 'compress', or compression format not supported : {0}z.tarzcreating %szCreating tar archivec����������������s,�����d�k r��|�_��|�_�d�k r(�|�_�|�_|�S�)N)�gidZgname�uid�uname)Ztarinfo)r}����group�ownerr~���r���r ����_set_uid_gid���s����z#_make_tarball.<locals>._set_uid_gidzw|%s)rJ���)�_BZ2_SUPPORTED� ValueError�format�getr+���r,����dirnamerV����inforR���rx���rw���r���r7����add�close)� base_name�base_dir�compress�verbose�dry_runr����r�����loggerZtar_compressionZcompress_extZarchive_name�archive_dirr�����tarr���)r}���r����r����r~���r ���� _make_tarballu��s4���� r����c�������������C���sd���|r d}nd}ddl�m}�ddlm}�y|d|||�g|d��W�n �|k r^���td�|��Y�nX�d�S�) Nz-rz-rqr���)�DistutilsExecError)�spawn�zip)r����zkunable to create zip file '%s': could neither import the 'zipfile' module nor find a standalone zip utility)Zdistutils.errorsr����Zdistutils.spawnr����r���)r�����zip_filenamer����r����Z zipoptionsr����r����r���r���r ����_call_external_zip���s����r����c�������������C���s$��|�d�}t�jj|��}t�jj|�sB|dk r4|jd|��|sBt�j|��yddl}W�n�tk rf���d}Y�nX�|dkr�t||||��n�|dk r�|jd||��|�s |j |d|j d�}xht�j|�D�]Z\} } }xN|D�]F}t�jjt�jj | |��} t�jj| �r�|j| | ��|dk r�|jd| ��q�W�q�W�|j���|S�) am��Create 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. z.zipNzcreating %sr���z#creating '%s' and adding '%s' to it�w)Zcompressionzadding '%s')r+���r,���r����rV���r����rR����zipfile�ImportErrorr�����ZipFileZZIP_DEFLATED�walk�normpathrF����isfiler&���r����)r����r����r����r����r����r����r����r����r�����dirpathZdirnames� filenamesr`���r,���r���r���r ���� _make_zipfile���s8���� r����r����zgzip'ed tar-filer|���zbzip2'ed tar-filezuncompressed tar filezZIP file)�gztar�bztarr����r����r����c��������������C���s���dd��t�j��D��}�|�j���|�S�)z�Returns a list of supported formats for archiving and unarchiving. Each element of the returned sequence is a tuple (name, description) c�������������S���s���g�|�]\}}||d��f�qS�)rt���r���)�.0r`����registryr���r���r ���� <listcomp>��s����z'get_archive_formats.<locals>.<listcomp>)�_ARCHIVE_FORMATS�items�sort)�formatsr���r���r ���r������s����rz���c�������������C���s~���|dkrg�}t�|tj�s$td|���t�|ttf�s:td��x0|D�](}t�|ttf��s`t|�dkr@td��q@W�|||ft|�<�dS�)au��Registers 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 sequencert���z+extra_args elements are : (arg_name, value))r\����collections�Callable� TypeError�tuple�list�lenr����)r`����function� extra_args�description�elementr���r���r ���r�����s���� c�������������C���s ���t�|�=�d�S�)N)r����)r`���r���r���r ���r�����s����c �������������C���s��t�j��} |dk r>|dk r$|jd|��t�jj|��}�|s>t�j|��|dkrLt�j}||d�} yt|�}W�n �tk r����t d|���Y�nX�|d�}x|d�D�]\} }|| | <�q�W�|dkr�|| d<�|| d <�z||�|f| �}W�d|dk r�|dk r�|jd | ��t�j| ��X�|S�)a���Create 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')r����r����zunknown archive format '%s'r���r���r����r����r����zchanging back to '%s') r+����getcwd�debugr,���r����chdir�curdirr����ru���r����)r����r����Zroot_dirr����r����r����r����r����r����Zsave_cwd�kwargs�format_info�func�arg�val�filenamer���r���r ���r��� ��s6���� c��������������C���s���dd��t�j��D��}�|�j���|�S�)z�Returns a list of supported formats for unpacking. Each element of the returned sequence is a tuple (name, extensions, description) c�������������S���s"���g�|�]\}}||d��|d�f�qS�)r�������r���)r����r`���r����r���r���r ���r����]��s����z&get_unpack_formats.<locals>.<listcomp>)�_UNPACK_FORMATSr����r����)r����r���r���r ���r���W��s����c������� ������C���sz���i�}x.t�j��D�]"\}}x|d�D�]}|||<�q W�qW�x,|�D�]$}||kr:d}t||||�f���q:W�t|tj�svtd��dS�)z+Checks what gets registered as an unpacker.r���z!%s is already registered for "%s"z*The registered function must be a callableN)r����r����r#���r\���r����r����r����) � extensionsr����r����Zexisting_extensionsr`���r����Zext� extension�msgr���r���r ����_check_unpack_optionsb��s���� r����c�������������C���s,���|dkrg�}t�|||��||||ft|�<�dS�)aM��Registers 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����r����r����r���r���r ���r���t��s����c�������������C���s ���t�|�=�dS�)z*Removes the pack format from the registry.N)r����)r`���r���r���r ���r������s����c�������������C���s&���t�jj|��}t�jj|�s"t�j|��dS�)z1Ensure that the parent directory of `path` existsN)r+���r,���r����rE���rR���)r,���r����r���r���r ����_ensure_directory���s����r����c������� ������C���s����yddl�}W�n�tk r(���td��Y�nX�|j|��s@td|����|j|��}z�x�|j��D�]�}|j}|jd�sVd|krtqVtj j |f|jd����}|s�qVt|��|j d�sV|j|j�}t|d�}z|j|��W�d|j���~X�qVW�W�d|j���X�dS�)z+Unpack zip `filename` to `extract_dir` r���Nz/zlib not supported, cannot unpack this archive.z%s is not a zip file�/z..r3���)r����r����r"���Z is_zipfiler����Zinfolistr����rs���r+���r,���rF����splitr����rr���r%���r7���r&���r����) r�����extract_dirr����r����r����r`����target�data�fr���r���r ����_unpack_zipfile���s0���� r����c�������������C���sP���yt�j|��}W�n"�t�jk r0���td|����Y�nX�z|j|��W�d|j���X�dS�)z:Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir` z/%s is not a compressed or uncompressed tar fileN)r���r7���ZTarErrorr"���Z extractallr����)r����r����Ztarobjr���r���r ����_unpack_tarfile���s����r����z.tar.gzz.tgzz.tarz.zip)r����r����r����z.bz2c�������������C���s:���x4t�j��D�](\}}x|d�D�]}|�j|�r|S�qW�q W�d�S�)Nr���)r����r����rr���)r����r`���r����r����r���r���r ����_find_unpack_format���s ���� r����c���������� ���C���s����|dkrt�j��}|dk rhyt|�}W�n"�tk rF���tdj|���Y�nX�|d�}||�|ft|d����nHt|��}|dkr�tdj|����t|�d�}tt|�d��}||�|f|��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", 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}'r���rt���zUnknown archive format '{0}') r+���r����r����ru���r����r�����dictr����r"���)r����r����r����r����r����r����r���r���r ���r������s������@��)r����)FN)ry���r���r���NNN)FF)r���r���N)r����ry���)r����r|���)r����N)r����r|���)Nrz���)NNr���r���NNN)Nrz���)NN)=r!���r+���rc���r4���Zos.pathr���rI���r����rC���rz���r���r{���r����r�����pwdr���Zgrpr����__all__rX���r���r���r���r"���� Exceptionr#���r[���� NameErrorr���r1���r���r ���r ���r���r���r���r ���r���rn���r���rp���rw���rx���r����r����r����r����r���r���r���r���r���r����r���r���r����r����r����r����r����r���r���r���r���r ����<module> ���s���� Q 1( � = 0 � 6� %