Sindbad~EG File Manager

Current Path : /proc/2568807/root/usr/local/lib/python3.12/test/__pycache__/
Upload File :
Current File : //proc/2568807/root/usr/local/lib/python3.12/test/__pycache__/test_shutil.cpython-312.pyc

�

'Μg����ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZmZmZmZmZmZmZmZmZmZmZmZddlZddlZddlZ	ddlZddl!m"Z"ddl#m$Z$ddl%m&Z&m'Z'ddl#m(Z(e&dzZ)e&dzZ*e&d	zZ+ejXj[d
�Z.ejXj[d�Z/ejXddd
k(Z0	ddl1Z1ddl2Z2dZ3	ddl4Z4ejjjmde7d���Z8d�Z9d�Z:d>d�Z;d�Z<d>d�Z=d�Z>d�Z?e?�Z@d�ZAGd�d�ZBGd�deBej��ZDGd�d eBej��ZEGd!�d"eBej��ZFGd#�d$eBej��ZGGd%�d&eBej��ZHGd'�d(eBej��ZIGd)�d*eI�ZJGd+�d,eBej��ZKGd-�d.ej��ZLGd/�d0ej��ZMGd1�d2eN�ZOej�e@d3�Gd4�d5eOej���ZQej�e.d6�Gd7�d8eOej���ZRGd9�d:ej��ZSGd;�d<ej��ZTeUd=k(rej��yy#e $rdZY��OwxYw#e $rdZ3Y���wxYw#e $rdZ4Y���wxYw)?�N)�make_archive�register_archive_format�unregister_archive_format�get_archive_formats�Error�unpack_archive�register_unpack_format�
RegistryError�unregister_unpack_format�get_unpack_formats�
SameFileError�_GiveupOnFastCopy)�support)�	os_helper)�TESTFN�FakePath)�warnings_helper�2�_SRC�_DST�darwin�sunos��aixTFzos.chdirzshouldn't call os.chdir()��side_effectc�8�tttdd�d��)N�EXDEV�zInvalid cross-device link)�OSError�getattr�errno)�args�kwargss  �-/usr/local/lib/python3.12/test/test_shutil.py�_fake_renamer&;s��
�'�%��"�-�/J�
K�K�c�B��tj���fd��}|S)Nc���	tj}tt_�|i|��|t_S#t_wxYw�N)�os�renamer&)r#r$�builtin_rename�funcs   �r%�wrapzmock_rename.<locals>.wrap@s4���	'��Y�Y�N�$�B�I���(��(�&�B�I���B�I�s	�&5�
A)�	functools�wraps)r.r/s` r%�mock_renamer2?s%����_�_�T��'��'��Kr'c���t|t�rtjj|�}|rdnd}|rdnd}t|||��5}|j
|�ddd�y#1swYyxYw)z�Write *content* to a file located at *path*.

    If *path* is a tuple instead of a string, os.path.join will be used to
    make a path.  If *binary* is true, the file will be opened in binary
    mode.
    �wb�wN�utf-8��encoding)�
isinstance�tupler+�path�join�open�write)r;�content�binary�moder8�fps      r%�
write_filerCJsX���$����w�w�|�|�T�"���4�s�D��t�7�H�	
�d�D�8�	,��
�����
-�	,�	,�s�A"�"A+c��d�}t|d�}djt|�D�cgc]3}tjt
j�j���5c}�}t|d�5}|||�D]}|j|��	ddd�tjj|�|k(sJ�ycc}w#1swY�3xYw)zBCreate a test file with an arbitrary size and random text content.c3�PK�||k\sJ�||kDr|��||z}||kDr�|r|��yy�wr*�)�total�steps  r%�chunkszwrite_test_file.<locals>.chunksZs?������}��}��d�l��J��T�M�E��d�l���K��s�&�&i r'r4N)
�minr<�range�random�choice�string�
ascii_letters�encoder=r>r+r;�getsize)r;�sizerI�bufsize�i�chunk�f�csizes        r%�write_test_filerXXs�����$��o�G��H�H�$�W�~�/�-�!��m�m�F�$8�$8�9�@�@�B�-�/�
0�E�	
�d�D�	�Q��D�'�*�E�
�G�G�E�N�+�
��7�7�?�?�4� �D�(�(�(��/�	�	�s�8C�3 C�Cc���t|t�rtjj|�}|rdnd}|rdnd}t|||��5}|j
�cddd�S#1swYyxYw)z�Return contents from a file located at *path*.

    If *path* is a tuple instead of a string, os.path.join will be used to
    make a path.  If *binary* is true, the file will be opened in binary
    mode.
    �rb�rNr6r7)r9r:r+r;r<r=�read)r;r@rAr8rBs     r%�	read_filer]jsU���$����w�w�|�|�T�"���4�s�D��t�7�H�	
�d�D�8�	,���w�w�y�
-�	,�	,�s�A!�!A*c��g}ttj|��D]�}tjj	||�}tjj|�r[tjj
|�s<|j|dz�t|�D]}|j|dz|z����|j|���|S)N�/)	�sortedr+�listdirr;r<�isdir�islink�append�rlistdir)r;�res�name�p�ns     r%rerexs���
�C��r�z�z�$�'�(���G�G�L�L��t�$��
�7�7�=�=���B�G�G�N�N�1�$5��J�J�t�c�z�"��a�[���
�
�4�#�:��>�*�!�
�J�J�t��)��Jr'c�
�ttd�syd}d}	tjdtj�d��5}|j
}|j
d�ddd�t|d�5}tjdtj�d��5}|j
}|j�}|j�}	tj||dd�	ddd�ddd�|�tj|�|�tj|�y	y	#1swY��xYw#t$rBYddd�ddd�|�tj|�|�tj|�yywxYw#1swYnxYw	ddd�n#1swYnxYw|�tj|�|�tj|�yy#|�tj|�|�tj|�wwxYw)
N�sendfileFr4��dir�deletes
0123456789rZr�T)
�hasattrr+�tempfile�NamedTemporaryFile�getcwdrgr>r=�filenorkr�unlinkr )�srcname�dstnamerV�src�dst�infd�outfds       r%�supports_file2file_sendfiler|�s����2�z�"���G��G�&�
�
(�
(��2�9�9�;�u�
M�QR��f�f�G�
�G�G�M�"�N��'�4�
 �C��,�,�T�r�y�y�{�5�Q�UX��(�(���z�z�|���
�
��� ��K�K��t�Q��2� �R�!������W�%������W�%��%N�
M���!� �R�!������W�%������W�%��!��
R�Q��Q�!�
 �
 �������W�%������W�%��������W�%������W�%��s��*G�D%�G�3+F�-E?�D1�$E?�%F�-G�%D.�*G�1	E<�:E?�;F�G�;E<�<E?�?F	�F�	G�F�G�1Hc���trmtjdk(rZtjdtj
z�}|j
d�dj
�d}t|d�dk\Sy)	Ni���z/usr/bin/dump -o %s�
�����i T)�AIX�sys�maxsize�
subprocess�	getoutput�
executable�split�int)�hdrs�maxdatas  r%�
_maxdataOKr��s_��
�s�{�{�j�(�
�
!�
!�"7�#�.�.�"H�
I���
�
�4� ��$�*�*�,�Q�/���7�2��*�,�,�r'c��eZdZdd�Zy)�BaseTestNc��tj|tj���}|j	t
j|�|S)zjCreate a temporary directory that will be cleaned up.

        Returns the path of the directory.
        )�prefixrm)rq�mkdtempr+rs�
addCleanupr�rmtree)�selfr��ds   r%r�zBaseTest.mkdtemp�s5��

���F��	�	��<�����	�(�(�!�,��r'r*)�__name__�
__module__�__qualname__r�rFr'r%r�r��s��r'r�c��eZdZd�Zej
d��Zej
d��Zej
d��Ze	jed�d��Ze	jed�d��Z
e	jed�d��Zd	�Zd
�Ze	j"ej&ddd
k(d�ej(ej*d����Zd�Ze	j"ej&ddd
k(d�ej(ej*d����Zd�Ze	j"ej&ddd
k(d�ej(ej*d����Zd�Zd�Ze	jej<d�d��Ze	jej<d�d��Z e	j"ej<d�d��Z!d�Z"ej
d��Z#e	jed�d��Z$e	je%e&d�d �e	j"ej&d!k(d"�d#���Z'd$�Z(y)%�
TestRmTreec�b�|j�}tjj|d�}tj|�ttjj|d�d�tj|�}|j|t�tj|�y)N�killme�somefile�foo)r�r+r;r<�mkdirrC�fsencode�assertIsInstance�bytes�shutilr�)r��tmp�victims   r%�test_rmtree_works_on_bytesz%TestRmTree.test_rmtree_works_on_bytes�sp���l�l�n�������c�8�,��
������2�7�7�<�<��
�3�U�;����V�$�����f�e�,��
�
�f�r'c�>��|j�}tjj|d�}tj|�tjj|d�}tj
||�|j
ttj|�|jtjj|��|jtjj|��g��fd�}tj||��|jt��d�|j�ddtjj �|j�dd|�|j#�dddt�y)Nrm�linkc�(���j|�yr*�rd�r#�errorss �r%�onerrorz@TestRmTree.test_rmtree_fails_on_symlink_onerror.<locals>.onerror������M�M�$�r'�r�r�rro�r�r+r;r<r��symlink�assertRaisesr r�r��
assertTrue�exists�lexists�assertEqual�len�assertIsrcr��r�r��dir_r�r�r�s     @r%�$test_rmtree_fails_on_symlink_onerrorz/TestRmTree.test_rmtree_fails_on_symlink_onerror�s����l�l�n���w�w�|�|�C��'��
������w�w�|�|�C��(��
�
�
�4������'�6�=�=�$�7���������t�,�-����������-�.���	 ��
�
�d�G�,�����V��a�(��
�
�f�Q�i��l�B�G�G�N�N�3�������1��t�,����f�Q�i��l�1�o�w�7r'c�8��|j�}tjj|d�}tj|�tjj|d�}tj
||�|j
ttj|�|jtjj|��|jtjj|��g��fd�}tj||��|jt��d�|j�ddtjj �|j�dd|�|j#�ddt�y)Nrmr�c�(���j|�yr*r�r�s �r%�onexcz<TestRmTree.test_rmtree_fails_on_symlink_onexc.<locals>.onexc�r�r'�r�r�rror��r�r�r�r�r�r�s     @r%�"test_rmtree_fails_on_symlink_onexcz-TestRmTree.test_rmtree_fails_on_symlink_onexc�s����l�l�n���w�w�|�|�C��'��
������w�w�|�|�C��(��
�
�
�4������'�6�=�=�$�7���������t�,�-����������-�.���	 ��
�
�d�%�(�����V��a�(��
�
�f�Q�i��l�B�G�G�N�N�3�������1��t�,����f�Q�i��l�G�4r'c��|j�}tjj|d�}tjj|d�}tjj|d�}|||fD]}tj|��tjj|d�}t|d�tjj|d�}tj||�tjj|d�}tj||�tjj|d�}	tj||	�tj|�|jtjj|��|jtjj|��|jtjj|��y�	N�dir1�dir2�dir3�file1r��link1�link2�link3)r�r+r;r<r�rCr�r�r��assertFalser�r��
r�r�r�r�r�r�r�r�r�r�s
          r%�test_rmtree_works_on_symlinksz(TestRmTree.test_rmtree_works_on_symlinks�sB���l�l�n���w�w�|�|�C��(���w�w�|�|�D�&�)���w�w�|�|�C��(���t�T�!�A��H�H�Q�K�"������S�'�*���5�%� ������T�7�+��
�
�
�4��������T�7�+��
�
�
�4��������T�7�+��
�
�
�5�%� ��
�
�d�����������-�.���������t�,�-���������u�-�.r'zonly relevant on Windowsc�~��|j�}tjj|d�}tj|�tjj|d�}tj||�|jtj|�|jttj|�|jtjj|��|jtjj!|��g��fd�}tj||��|j#t%��d�|j'�ddtjj(�|j#�dd|�|j+�dddt�y)Nrmr�c�(���j|�yr*r�r�s �r%r�zBTestRmTree.test_rmtree_fails_on_junctions_onerror.<locals>.onerrorr�r'r�r�rro�r�r+r;r<r��_winapi�CreateJunctionr�rrur�r r�r�r�r�r�r�r�r�rcr�r�s     @r%�&test_rmtree_fails_on_junctions_onerrorz1TestRmTree.test_rmtree_fails_on_junctions_onerrors+����l�l�n���w�w�|�|�C��'��
������w�w�|�|�C��(�����t�T�*����	�(�(�$�/����'�6�=�=�$�7���������t�,�-����������-�.���	 ��
�
�d�G�,�����V��a�(��
�
�f�Q�i��l�B�G�G�N�N�3�������1��t�,����f�Q�i��l�1�o�w�7r'c�x��|j�}tjj|d�}tj|�tjj|d�}tj||�|jtj|�|jttj|�|jtjj|��|jtjj!|��g��fd�}tj||��|j#t%��d�|j'�ddtjj(�|j#�dd|�|j+�ddt�y)Nrmr�c�(���j|�yr*r�r�s �r%r�z>TestRmTree.test_rmtree_fails_on_junctions_onexc.<locals>.onexc#r�r'r�r�rror�r�s     @r%�$test_rmtree_fails_on_junctions_onexcz/TestRmTree.test_rmtree_fails_on_junctions_onexcs'����l�l�n���w�w�|�|�C��'��
������w�w�|�|�C��(�����t�T�*����	�(�(�$�/����'�6�=�=�$�7���������t�,�-����������-�.���	 ��
�
�d�%�(�����V��a�(��
�
�f�Q�i��l�B�G�G�N�N�3�������1��t�,����f�Q�i��l�G�4r'c��|j�}tjj|d�}tjj|d�}tjj|d�}|||fD]}tj|��tjj|d�}t|d�tjj|d�}t
j||�tjj|d�}t
j||�tjj|d�}	t
j||	�tj|�|jtjj|��|jtjj|��|jtjj|��yr�)
r�r+r;r<r�rCr�r�r�r�r�r�r�r�s
          r%�test_rmtree_works_on_junctionsz)TestRmTree.test_rmtree_works_on_junctions+sH���l�l�n���w�w�|�|�C��(���w�w�|�|�D�&�)���w�w�|�|�C��(���t�T�!�A��H�H�Q�K�"������S�'�*���5�%� ������T�7�+�����t�U�+������T�7�+�����t�U�+������T�7�+�����u�e�,��
�
�d�����������-�.���������t�,�-���������u�-�.r'c�n��tj|j���}|jtt
j|�tj|d��|j�}t|dfd�tjj|d�}|jt�5}tj|�ddd�|jjj|�|jtjj!|��tj|d��|jtjj!|��g��fd�}tj||��|jt#��d�|j%�d	d	tj&�|j�d	d
|�|j)�d	dd
t�|j�d	dd
j|�|j%�d
d	tj*�|j�d
d
|�|j)�d
dd
t�|j�d
dd
j|�y#1swY���xYw)N�rmT��
ignore_errors�tstfile�c�(���j|�yr*r�r�s �r%r�z6TestRmTree.test_rmtree_errors_onerror.<locals>.onerrorTr�r'r�rorr��rq�mktempr�r��FileNotFoundErrorr�r�rCr+r;r<�NotADirectoryErrorr��	exception�filenamer�r�r�r��scandirr��rmdir)r�r��tmpdir�cmr�r�s     @r%�test_rmtree_errors_onerrorz%TestRmTree.test_rmtree_errors_onerrorAs�����?�?�t�|�|�~�6�����+�V�]�]�H�E��
�
�h�d�3�������F�I�&��+��7�7�<�<��	�2��
�
�
�1�
2�b��M�M�(�#�3�������.�.��9���������x�0�1��
�
�h�d�3���������x�0�1���	 ��
�
�h��0�����V��a�(��
�
�f�Q�i��l�B�J�J�/�������1��x�0����f�Q�i��l�1�o�/A�B�������1��a��1�1�8�<��
�
�f�Q�i��l�B�H�H�-�������1��x�0����f�Q�i��l�1�o�/A�B�������1��a��1�1�8�<�'3�
2�s�5J*�*J4c�V��tj|j���}|jtt
j|�tj|d��|j�}t|dfd�tjj|d�}|jt�5}tj|�ddd�|jjj|�|jtjj!|��tj|d��|jtjj!|��g��fd�}tj||��|jt#��d�|j%�d	d	tj&�|j�d	d
|�|j)�d	dt�|j�d	dj|�|j%�d
d	tj*�|j�d
d
|�|j)�d
dt�|j�d
dj|�y#1swY���xYw)Nr�Tr�r�r�c�(���j|�yr*r�r�s �r%r�z2TestRmTree.test_rmtree_errors_onexc.<locals>.onexctr�r'r�rorr�r�)r�r�r�r�r�r�s     @r%�test_rmtree_errors_onexcz#TestRmTree.test_rmtree_errors_onexcas�����?�?�t�|�|�~�6�����+�V�]�]�H�E��
�
�h�d�3�������F�I�&��+��7�7�<�<��	�2��
�
�
�1�
2�b��M�M�(�#�3�������.�.��9���������x�0�1��
�
�h�d�3���������x�0�1���	 ��
�
�h�e�,�����V��a�(��
�
�f�Q�i��l�B�J�J�/�������1��x�0����f�Q�i��l�,>�?�������1��.�.��9��
�
�f�Q�i��l�B�H�H�-�������1��x�0����f�Q�i��l�,>�?�������1��.�.��9�'3�
2�s�5J�J(N��cygwinz2This test can't be run on Cygwin (issue #1071513).c��d|_tjt�|j	t
jt�tjjtd�|_	tjjtd�|_
tj|j�tj|j�tjt�j}tj|j�j}tj|j�j}tjtj z}tj"|j|�tj"|j|�tj"t|�|j	tj"t|�|j	tj"|j|�|j	tj"|j|�tjt|j$��|j'|jdd�y)Nr�a�br�rz1Expected call to onerror function did not happen.)�
errorStater+r�rr�r�r�r;r<�child_file_path�child_dir_pathr�create_empty_file�stat�st_mode�S_IREAD�S_IEXEC�chmod�check_args_to_onerrorr��r��old_dir_mode�old_child_file_mode�old_child_dir_mode�new_modes     r%�
test_on_errorzTestRmTree.test_on_error�s���
���
���������
�
�v�.�!�w�w�|�|�F�C�8��� �g�g�l�l�6�3�7����#�#�D�$8�$8�9�
����$�$�%��w�w�v��.�.�� �g�g�d�&:�&:�;�C�C���W�W�T�%8�%8�9�A�A���<�<����,��
����%�%�x�0�
����$�$�h�/�
�����"�������&�,�7�������$�"6�"6�8K�L�������$�"5�"5�7I�J��
�
�f�d�&@�&@�A�������!�L�	Nr'c��|jdkr�|tjur|j||j�nq|tj
ur|j||j�nB|j|tj�|j|t|jg�|jt|dt��|xjdz
c_y|j|tj
�|j|t�|jt|dt��d|_y)Nrorr�r)r�r+rur�r�r�r�r�ra�assertInrr��
issubclassr �r�r.�arg�excs    r%r�z TestRmTree.check_args_to_onerror�s����?�?�Q���r�y�y� �� � ��d�&:�&:�;�����!�� � ��d�&9�&9�:��
�
�d�B�J�J�/��
�
�c�F�D�,?�,?�#@�A��O�O�J�s�1�v�w�7�8��O�O�q� �O����T�2�8�8�,����S�&�)��O�O�J�s�1�v�w�7�8��D�Or'c��d|_tjt�|j	t
jt�tjjtd�|_	tjjtd�|_
tj|j�tj|j�tjt�j}tj|j�j}tj|j�j}tjtj z}tj"|j|�tj"|j|�tj"t|�|j	tj"t|�|j	tj"|j|�|j	tj"|j|�tjt|j$��|j'|jdd�y)Nrr�r�r�rz/Expected call to onexc function did not happen.)r�r+r�rr�r�r�r;r<r�r�rr�r�r�r�r�r��check_args_to_onexcr�r�s     r%�test_on_exczTestRmTree.test_on_exc�s���
���
���������
�
�v�.�!�w�w�|�|�F�C�8��� �g�g�l�l�6�3�7����#�#�D�$8�$8�9�
����$�$�%��w�w�v��.�.�� �g�g�d�&:�&:�;�C�C���W�W�T�%8�%8�9�A�A���<�<����,��
����%�%�x�0�
����$�$�h�/�
�����"�������&�,�7�������$�"6�"6�8K�L�������$�"5�"5�7I�J��
�
�f�D�$<�$<�=�������!�J�	Lr'c��|jdkr�|tjur|j||j�nq|tj
ur|j||j�nB|j|tj�|j|t|jg�|jt|t��|xjdz
c_y|j|tj
�|j|t�|jt|t��d|_y)Nror�r)r�r+rur�r�r�r�r�rarrr�r9r rs    r%r
zTestRmTree.check_args_to_onexc�s����?�?�Q���r�y�y� �� � ��d�&:�&:�;�����!�� � ��d�&9�&9�:��
�
�d�B�J�J�/��
�
�c�F�D�,?�,?�#@�A��O�O�J�s�G�4�5��O�O�q� �O����T�2�8�8�,����S�&�)��O�O�J�s�G�4�5��D�Or'c����d�d��fd�}�fd�}tjt�|jtj
t�tjjtd�|_tjjtd�|_	tj|j�tj|j�tjt�j}tj|j�j}tj|j�j}tjtjz}tj |j|�tj |j|�tj t|�|jtj t|�|jtj |j|�|jtj |j|�t	j
t||��|j#��|j%��y)NFc�
��d�y�NTrF)r#�onerror_calleds �r%r�z7TestRmTree.test_both_onerror_and_onexc.<locals>.onerror�s���!�Nr'c�
��d�yrrF)r#�onexc_calleds �r%r�z5TestRmTree.test_both_onerror_and_onexc.<locals>.onexcs����Lr'r�r�)r�r�)r+r�rr�r�r�r;r<r�r�rr�r�r�r�r�r�r�r�)	r�r�r�r�r�rrrrs	       @@r%�test_both_onerror_and_onexcz&TestRmTree.test_both_onerror_and_onexc�s����
����	"�	 �	���������
�
�v�.�!�w�w�|�|�F�C�8��� �g�g�l�l�6�3�7����#�#�D�$8�$8�9�
����$�$�%��w�w�v��.�.�� �g�g�d�&:�&:�;�C�C���W�W�T�%8�%8�9�A�A���<�<����,��
����%�%�x�0�
����$�$�h�/�
�����"�������&�,�7�������$�"6�"6�8K�L�������$�"5�"5�7I�J��
�
�f�g�U�;�����%�����(r'c���	tj��fd�}|t_tjt�t	tdfd�tjt��t_y#�t_wxYw)Nc�:��|tk7r
t���|�Sr*)rr )�fnr#r$�
orig_lstats   �r%�raiserzFTestRmTree.test_rmtree_does_not_choke_on_failing_lstat.<locals>.raiser s�����<�!�)�O�%�b�>�)r'r�)r+�lstatr�rrCr�r�)r�rrs  @r%�+test_rmtree_does_not_choke_on_failing_lstatz6TestRmTree.test_rmtree_does_not_choke_on_failing_lstatsT���
	"����J�
*�
�B�H��H�H�V�������.��M�M�&�!�!�B�H��z�B�H�s�A$A3�3
Bc���tjtjtjtjhtj
kxrBtjtjvxr tjtjv}|r�|jtj�|jtjj�|j�}tjj!|d�}tj"|�	tj$}Gd�dt&���fd�}|t_|j)�tj|�|t_y|j+tj�|j+tjj�y#t_wxYw)Nr�c��eZdZy)�HTestRmTree.test_rmtree_uses_safe_fd_version_if_available.<locals>.CalledN)r�r�r�rFr'r%�Calledr:s�r'rc�����r*rF)r#r$rs  �r%�_raiserzITestRmTree.test_rmtree_uses_safe_fd_version_if_available.<locals>._raiser;s��� �Lr')r+r=r�rur��supports_dir_fdra�supports_fd�supports_follow_symlinksr�r��_use_fd_functionsr��avoids_symlink_attacksr�r;r<r��_rmtree_safe_fd�	Exceptionr�r�)r�r$�tmp_dirr��real_rmtreer rs      @r%�-test_rmtree_uses_safe_fd_version_if_availablez8TestRmTree.test_rmtree_uses_safe_fd_version_if_available-s4��� �g�g�r�w�w��	�	�2�8�8�D��/�/�0�D��Z�Z�2�>�>�9�D� �W�W��(C�(C�C�	���O�O�F�4�4�5��O�O�F�M�M�@�@�A��l�l�n�G������W�c�*�A��H�H�Q�K�
5�$�4�4��-�Y�-�!�)0��&��!�!�&�&�-�-��;�)4��&����V�5�5�6����V�]�]�A�A�B��*5��&�s
�%AG
�

Gzrequires safe rmtreec�*����|j�}tjj|d�}tj|�tjj|d�}tj|���fd�}d�tjtd|�5�|jt�5tj|�ddd�ddd�|jtjj|��|j�d�d�g��fd�}tjtd|�5�tj||��ddd�|jt��d�|j�dd|�|j�dd	|�|j�d	d|�|j�d	d	|�|j�d�y#1swY��$xYw#1swY��)xYw#1swY��xYw)
Nr�r�c�*���|��dz
�t�)Nr��r )�fd�close_count�
orig_closes ��r%�closez4TestRmTree.test_rmtree_fails_on_close.<locals>.closeNs����r�N��1��K��Mr'rr1roc�(���j|�yr*r�r�s �r%r�z4TestRmTree.test_rmtree_fails_on_close.<locals>.onexc]r�r'r�r�)r�r+r;r<r�r�	swap_attrr�r r�r�r�rbr�r�r�)	r�r�r�r�r1r�r/r�r0s	      @@@r%�test_rmtree_fails_on_closez%TestRmTree.test_rmtree_fails_on_closeEs�����l�l�n���w�w�|�|�C��(��
������w�w�|�|�D�&�)��
�����	���
�
�
�r�7�E�
2�j��"�"�7�+��
�
�d�#�,�3�	
������
�
�d�+�,�����a�(�����	 �
�
�
�r�7�E�
2�j��M�M�$�e�,�3�����V��a�(��
�
�f�Q�i��l�E�*�������1��t�,��
�
�f�Q�i��l�E�*�������1��t�,�����a�(�!,�+��3�
2��3�
2�s0�!G<�7G/�
G<�H	�/G9	�4G<�<H�	Hzdir_fd is not supportedc��|j�}d}tjj||�}tj|tj
�}|j
tj|�tj|�tjtjj|d��ttjj|dd�d�|jtjj|��tj||��|jtjj|��y)Nr��subdirr�r���dir_fd)r�r+r;r<r=�O_RDONLYr�r1r�rCr�r�r�r�r�)r�r(r��fullnamer8s     r%�test_rmtree_with_dir_fdz"TestRmTree.test_rmtree_with_dir_fdhs����,�,�.�����7�7�<�<���0������"�+�+�.��������&�)�
�����
��������h��1�2��2�7�7�<�<��(�J�?��G���������x�0�1��
�
�f�V�,����������1�2r'zdir_fd is supportedc��|j�}|jt�5tj|d��ddd�|jtjj|��y#1swY�8xYw)Nrr7)	r�r��NotImplementedErrorr�r�r�r+r;r�)r�r(s  r%�#test_rmtree_with_dir_fd_unsupportedz.TestRmTree.test_rmtree_with_dir_fd_unsupportedvsQ���,�,�.��
�
�
�2�
3��M�M�'�!�,�4���������w�/�0�4�
3�s�A5�5A>c���tj|j���\}}tj|�|jttj|�tj|�y�Nr�)
rq�mkstempr�r+r1r�r�r�r��remove)r��handler;s   r%�test_rmtree_dont_delete_filez'TestRmTree.test_rmtree_dont_delete_file}sJ���'�'�D�L�L�N�;����
��������,�f�m�m�T�B�
�	�	�$�r'c��tjt�	tjj	td�}tjj	td�}tj|�tj
||�|j
ttj|�tj|d��tjtd��y#tjtd��wxYw)N�cheese�shopTr�)
r+r�rr;r<r�r�r r�r��r�rxrys   r%�test_rmtree_on_symlinkz!TestRmTree.test_rmtree_on_symlink�s���	�����	6��'�'�,�,�v�x�0�C��'�'�,�,�v�v�.�C��H�H�S�M��J�J�s�C� ����g�v�}�}�c�:��M�M�#�T�2��M�M�&��5��F�M�M�&��5�s�B/C&�&Dc�|�tjt�	tjj	td�}tjj	td�}tj|�ttjj	|d�d�j
�tj||�|jttj|�tj|d��tjtd��y#tjtd��wxYw)NrFrG�spamr4Tr�)
r+r�rr;r<r=r1r�r�r�r r�r�rHs   r%�test_rmtree_on_junctionz"TestRmTree.test_rmtree_on_junction�s���
�����		6��'�'�,�,�v�x�0�C��'�'�,�,�v�v�.�C��H�H�S�M�������c�6�*�D�1�7�7�9��"�"�3��,����g�v�}�}�c�:��M�M�#�T�2��M�M�&��5��F�M�M�&��5�s�C'D�D;�mkfifo�requires os.mkfifo()�vxworks�%fifo requires special path on VxWorksc���tjt�	|jt�5tjt�ddd�|jtjjt��tjt�tjt�tjtjjtd��tjt�|jtjjt��y#1swY��xYw#tjt�wxYw)N�mypipe)r+rMrr�r�r�r�r�r;r�rur�r<r��r�s r%�test_rmtree_on_named_pipez$TestRmTree.test_rmtree_on_named_pipe�s���	�	�	�&��	��"�"�#5�6��
�
�f�%�7��O�O�B�G�G�N�N�6�2�3��I�I�f��
�����
�	�	�"�'�'�,�,�v�x�0�1��
�
�f�����������/�0�7�6��
�I�I�f��s"�E�D9�
:E�9E�>E�E c��d}|dz}tjjtgdg|z���}tj|�tj|�5tjt�ddd�y#1swYyxYw)N�(�
r�)	r+r;r<r�makedirsr�infinite_recursionr�r�)r��recursion_limit�directory_depth�bases    r%�!test_rmtree_above_recursion_limitz,TestRmTree.test_rmtree_above_recursion_limit�sa����)�B�.���w�w�|�|�F�?�s�e�o�&=�?��
���D��
�
'�
'��
8��M�M�&�!�9�
8�
8�s�A=�=B))r�r�r�r�r�skip_unless_symlinkr�r�r��unittest�
skipUnlessr�r�r�r�r�r��skipIfr��platform�skip_if_dac_override�skip_unless_working_chmodrr�rr
rrr*r�r$r4r;r>rDrIrLrpr+rTr]rFr'r%r�r��s�����"�"�8�#�8�$�"�"�5�#�5�$�"�"�/�#�/�*�X����"<�=�8�>�8�&�X����"<�=�5�>�5�&�X����"<�=�/�>�/�*=�@:�@�X�_�_�S�\�\�"�1�%��1�I�K��#�#��(�(�N�)�$�K�N�6 �6�X�_�_�S�\�\�"�1�%��1�I�K��#�#��(�(�L�)�$�K�L�6 �6�X�_�_�S�\�\�"�1�%��1�I�K��#�#��(�(�")�)�$�K�")�H"� C�0�X����1�1�3I�J� )�K� )�D�X����1�1�3L�M�3�N�3��X�_�_�V�-�-�/D�E�1�F�1���"�"�6�#�6��X����"<�=�6�>�6��X�����X�.�0F�G��X�_�_�S�\�\�Y�.�;�=�1�=�H�1�"r'r�c��eZdZd�Zd�Zejd��Zd�Zd�Z	d�Z
ejjd�d��Zd	�Zej eed
�d�ejej&ej*dk(d
�d����Zd�Zejd��Zejd��Zd�Zd�Zy)�TestCopyTreec	�N�|j�}tjj|j�d�}|j	t
j|�|j	t
jtjj|��t|dfd�tjtjj|d��t|ddfd�tj||�|jtjjtjj|d���|jtjjtjj|d���|jtjjtjj|dd���t|df�}|j|d�t|ddf�}|j|d�y)N�destination�test.txt�123�test_dir�456)r�r+r;r<r�r�r��dirnamerCr��copytreer��isfilerbr]r��r��src_dir�dst_dir�actuals    r%�test_copytree_simplez!TestCopyTree.test_copytree_simple�se���,�,�.���'�'�,�,�t�|�|�~�}�=������
�
�w�/�����
�
�r�w�w���w�'?�@��G�Z�(�%�0�
��������g�z�2�3��G�Z��4�e�<������)���������r�w�w�|�|�G�Z�'H�I�J�������
�
�b�g�g�l�l�7�J�&G�H�I���������r�w�w�|�|�G�Z�4>�(@�A�	B��G�Z�0�1�������'��G�Z��<�=�������'r'c	���|j�}|j�}|jtj|�|jtj|�t	|dfd�tjt
jj|d��tjt
jj|d��t	|ddfd�t	|ddfd�tj||d��|jt
jjt
jj|d���|jt
jjt
jj|d���|jt
jjt
jj|dd���t|df�}|j|d�t|ddf�}|j|d�|jt �5tj||d	��ddd�y#1swYyxYw)
Nznonexisting.txtrj�existing_dirzexisting.txtzwill be replacedzhas been replacedT)�
dirs_exist_okF)r�r�r�r�rCr+r�r;r<rnr�rorbr]r�r��FileExistsErrorrps    r%�test_copytree_dirs_exist_okz(TestCopyTree.test_copytree_dirs_exist_ok�s����,�,�.���,�,�.������
�
�w�/�����
�
�w�/��G�.�/��7�
��������g�~�6�7�
��������g�~�6�7��G�^�^�<�>P�Q��G�^�^�<�>Q�R�������=���������r�w�w�|�|�G�=N�'O�P�Q�������
�
�b�g�g�l�l�7�N�&K�L�M���������r�w�w�|�|�G�^�4B�(D�E�	F��G�%6�7�8�������'��G�^�^�D�E������!4�5�
�
�
��
/��O�O�G�W�E�B�0�
/�
/�s�I&�&I/c	�`�|j�}tjj|d�}tjj|d�}tjj|d�}tj|�tj|�t|dfd�tjj|d�}tjj|d�}tjtjj|d�|�ttd�r5tj|tjtjz�ttd	�r4ttd
�r$tj|tj�tj|�}tj ||d��|j#tjj%tjj|dd���tj&tjj|dd��}tj(d
k(r|j+d�r|dd}|j-|tjj|d��tj|�}	ttd�r&|j-|	j.|j.�ttd	�r'|j-|	j0|j0�yy)Nrxry�subzfile.txtr�r�zsub/link�lchmod�lchflags�	UF_NODUMPT��symlinks�ntz\\?\�)r�r+r;r<r�rCr�rpr|r��S_IRWXU�S_IRWXOr}r~rr�rnr�rc�readlinkrg�
startswithr�r��st_flags)
r�r(rqrr�sub_dir�src_link�dst_link�src_statrs�dst_stats
          r%�test_copytree_symlinksz#TestCopyTree.test_copytree_symlinks�s���,�,�.���'�'�,�,�w��.���'�'�,�,�w��.���'�'�,�,�w��.��
�����
������G�Z�(�%�0��7�7�<�<���0���7�7�<�<���4��
�
�
�2�7�7�<�<���4��	��2�x� ��I�I�h����t�|�|� ;�<��2�z�"�w�t�[�'A��K�K��$�.�.�1��8�8�H�%�������4�8���������r�w�w�|�|�G�U�F�'K�L�M����R�W�W�\�\�'�5�&�A�B���7�7�d�?�v�0�0��;��A�B�Z�F����������g�z�!B�C��8�8�H�%���2�x� ����X�-�-�x�/?�/?�@��2�z�"����X�.�.��0A�0A�B�#r'c
�t�tjj}tjj}|j	�}	||j	�d�}t|dfd�t|dfd�tj||d��t|ddfd�tj||d��t|ddfd�tj||dd��tj||dd	��t|dddfd�t|dd	d
fd�	tjdd�}tj|||��|j|||d���|j|||d���|j|||d���tj|�	tjdd
�}tj|||��|j|||d���|j|||dd	���|j|||dd���tj|�	d�}tj|||��|j|||dd	d
���|j|||dd���tj|�	tj|�tjtjj|��y#tj|�wxYw#tj|�wxYw#tj|�wxYw#tj|�tjtjj��wxYw)Nrhrirjztest.tmprkrl�	test_dir2r6�subdir2ztest.pyz*.tmp��ignorezsubdir*c�R�g}|D]�}tjj||�}tjj|�r(|j	�ddk(r|j|��jtjj
|�ddvs��|j|���|S)Nrr6z.py)r+r;r<rbr�rd�splitext)rx�namesrfrgr;s     r%�_filterz8TestCopyTree.test_copytree_with_exclude.<locals>._filter2s����C� %��!�w�w�|�|�C��6���G�G�M�M�$�/� �J�J�L��,��8��J�J�t�,��W�W�-�-�d�3�B�7�E�B��J�J�t�,�!&��Jr')r+r;r<r�r�rCr�r��ignore_patternsrnr�r�r�rm)r�r<r�rqrr�patternsr�s       r%�test_copytree_with_excludez'TestCopyTree.test_copytree_with_exclude
s����w�w�|�|���������,�,�.��:	4��4�<�<�>�=�9�G����,�e�4����,�e�4��H�H�T�'�:�.�/����Z�8�%�@��H�H�T�'�;�/�0����j�9�5�A��H�H�T�'�;��9�:��H�H�T�'�;�	�:�;����h�
�C�U�K����i��C�U�K�
'�!�1�1�'�;�G��������B�����t�G�Z�'@� A�B�� � ���W�j�(A�!B�C�� � ���W�k�(B�!C�D��
�
�g�&�
'�!�1�1�'�9�E��������B�� � ���W�j�(A�!B�C�� � ���W�k�9�(M�!N�O�� � ���W�k�8�(L�!M�N��
�
�g�&�
'�
�������A�� � ���W�k�9�-6�)8�"9�:�� � ���W�k�8�(L�!M�N��
�
�g�&��M�M�'�"��M�M�"�'�'�/�/�'�2�3��I�
�
�g�&���
�
�g�&��0�
�
�g�&���M�M�'�"��M�M�"�'�'�/�/�'�2�3�sY�C#M.�*BL �2M.�B
L:�M.�(AM�M.� L7�7M.�:M�M.�M+�+M.�.A	N7c
�L���tjj}tjj}�j	�}||d�}tj
||��tj
||d��tj
tjj|dd��t
|dddfd�g���fd�}|�j	�d�}tj|||���j|||ddd���|�j	�d�}tjt|�||���j|||ddd���|�j	�d�}ttj|��d	}�j|tj�tj|||���j|||ddd����jt!��d
�y)N�sourcerkr6rirlc����j|��j|t��j|t��j	t|�tt
|���|D]}�j|t��gSr*)rdr��str�listr�r��set)rxr�rg�invokationsr�s   ��r%�_ignorez?TestCopyTree.test_copytree_arg_types_of_ignore.<locals>._ignoreYsl������s�#��!�!�#�s�+��!�!�%��.����S��Z��S��Z��9����%�%�d�C�0���Ir'rhr�r�	)r+r;r<r�r�r�rCr�rnr�rr�r�r��DirEntryr�r�)	r�r<r�r(rqr�rr�
src_dir_entryr�s	`       @r%�!test_copytree_arg_types_of_ignorez.TestCopyTree.test_copytree_arg_types_of_ignoreKs�����w�w�|�|���������,�,�.���w��)��
����g���
����g�z�*�+�
��������g�z�8�<�=��G�Z��:�>��F���	��t�|�|�~�}�5��������9�����t�G�Z��$.� 0�1�	2��t�|�|�~�}�5�������)�7�7�C�����t�G�Z��$.� 0�1�	2��t�|�|�~�}�5���R�Z�Z��0�1�!�4�
����m�R�[�[�9����
�w�w�?�����t�G�Z��$.� 0�1�	2�	
����[�)�1�-r'c	���|j�}tjj|d�}tj|�tjj|d�}|jtj|�tj|d�t|dfd�tjtjj|d�d�t|dfd�tjtjj|d�d�tj|�	�}|jtj|�tj|d�t
j||�|jtj|�jtj|�j�|jtjtjj|d��jtjtjj|d��j�|jtjtjj|d��jtjtjj|d��j�tjj|tjj!|�d
�}|jtj|�jtj|�j�y)Nr�rhi�zpermissive.txtrjzrestrictive.txtrli�r�r�)r�r+r;r<r�r�r�r�r�rCrqrrnr�r�r�r�)r�r(rqrr�restrictive_subdir�restrictive_subdir_dsts      r%�!test_copytree_retains_permissionsz.TestCopyTree.test_copytree_retains_permissionsus3���,�,�.���'�'�,�,�w��1��
������'�'�,�,�w�
�6������
�
�w�/�
����%� ��G�-�.��6�
��������g�'7�8�%�@��G�.�/��7�
��������g�'8�9�5�A�%�-�-�'�:�����	�(�(�*<�=�
���#�U�+������)��������)�1�1�2�7�7�7�3C�3K�3K�L������������g�7G�!H�I�Q�Q��'�'�"�'�'�,�,�w�8H�"I�J�R�R�	T������������g�7H�!I�J�R�R��'�'�"�'�'�,�,�w�8I�"J�K�S�S�	U�!#�����g�.0�g�g�m�m�<N�.O�PQ�.R�"T��������!3�4�<�<��'�'�"8�9�A�A�	Cr'zos.chmodc���|j�}tjj|j�d�}|j	t
j|�|j	t
jtjj|��td�|_	|jt
j�5tj||�ddd�y#1swYyxYw)Nrhzka-boom)
r�r+r;r<r�r�r�rm�PermissionErrorrr�rrn)r��
mock_patchrqrrs    r%�test_copytree_winerrorz#TestCopyTree.test_copytree_winerror�s���
�,�,�.���'�'�,�,�t�|�|�~�}�=������
�
�w�/�����
�
�r�w�w���w�'?�@�!0��!;�
��
�
�
�v�|�|�
,��O�O�G�W�-�-�
,�
,�s�C+�+C4c����������fd�}g��j��tj�j����ttj
j
�d�dd��5}|j�ddd�tj��|���jt��d�y#1swY�=xYw)	Nc�@���jd��j|t��j|t��j|tj
j
�d���j|tj
j
�d��y�Nr�)rdr�r�r�r+r;r<)r�r�ry�flagr�rxs  ����r%�custom_cpfunzETestCopyTree.test_copytree_custom_copy_function.<locals>.custom_cpfun�sm����K�K����!�!�!�S�)��!�!�!�S�)����Q������S�%� 8�9����Q������S�%� 8�9r'r�r�r5r6r7��
copy_functionr�)r�rqr�r=r+r;r<r1r�rnr�r�)r�r�rVryr�rxs`  @@@r%�"test_copytree_custom_copy_functionz/TestCopyTree.test_copytree_custom_copy_function�s����	:����l�l�n���o�o�$�,�,�.�1��
�"�'�'�,�,�s�E�*�C�'�
B�a�
�G�G�I�C�����S��=�����T��A�&�C�
B�s�/B<�<CrMrNrOrPc�|�tjt�	tjj	td�}tj|�tjj	|d�}	tj
|�	tjtt�|jd�tj td�	�tj td�	�y#t$r}|jd|z�Yd}~��d}~wwxYw#tj$rR}|jd}|jt|�d�|d\}}}|jd|z|�Yd}~��d}~wwxYw#tj td�	�tj td�	�wxYw)
Nr6rR�os.mkfifo(): %sz$shutil.Error should have been raisedrr�z`%s` is a named pipeTr�)r+r�rr;r<rMr��skipTestr�rn�TESTFN2�failrr#r�r�r�)r�r6�pipe�er�rxry�	error_msgs        r%�test_copytree_named_pipez%TestCopyTree.test_copytree_named_pipe�s?��
	�����	7��W�W�\�\�&�(�3�F��H�H�V���7�7�<�<���1�D�
5��	�	�$��
B������0��	�	�@�A��M�M�&��5��M�M�'��6��#�
5��
�
�/�!�3�4�4��
5���<�<�
K�������� � ��V��a�0�&,�Q�i�#��S�)�� � �!7�$�!>�	�J�J��	
K��
�M�M�&��5��M�M�'��6�s[�AF�5C1�D�)F�1	D�:D�F�D�F�F�.AE;�6F�;F�F�8F;c���|j�}tjj|j�d�}t	|dfd�tj
tjj|d��t	|ddfd�g��fd�}t
j|||��|jt��d�y)	Nrhrirjrkrlc�,���j||f�yr*r�)rxry�copieds  �r%�_copyz6TestCopyTree.test_copytree_special_func.<locals>._copy�s����M�M�3��*�%r'r�ro)
r�r+r;r<rCr�r�rnr�r�)r�rqrrr�r�s    @r%�test_copytree_special_funcz'TestCopyTree.test_copytree_special_func�s�����,�,�.���'�'�,�,�t�|�|�~�}�=���G�Z�(�%�0�
��������g�z�2�3��G�Z��4�e�<���	&�	������>�����V��a�(r'c�V�|j�}tjj|d�}t	|d�tjj|d�}tj
|�||fD]j}tjdtjj|d��tj|tjj|d���ltjj|j�d�}|jttj||�tjj|j�d�}tj||d	�
�tj|�D]*\}}}|jd|�|jd|��,tjj|j�d�}tj||d	��|jdtj|��y)
Nri�abc�dir_a�
IDONTEXIST�broken�validrh�destination2T)�ignore_dangling_symlinks�destination3r)r�r+r;r<rCr�r�r�rr�rn�walk�assertNotInrra)	r�rq�
valid_filer�r�rr�root�dirs�filess	         r%�test_copytree_dangling_symlinksz,TestCopyTree.test_copytree_dangling_symlinks�sm���,�,�.���W�W�\�\�'�:�6�
��:�u�%������W�g�.��
������%��A��J�J�|�R�W�W�\�\�!�X�%>�?��J�J�z�2�7�7�<�<��7�#;�<� �
�'�'�,�,�t�|�|�~�}�=�����%����'�7�C��'�'�,�,�t�|�|�~�~�>�������4�H�!#����!1��D�$�����X�u�-��M�M�'�5�)�"2�
�'�'�,�,�t�|�|�~�~�>�������4�8��
�
�j�"�*�*�W�"5�6r'c	�
�|j�}tjj|j�d�}tjtjj|d��ttjj|dd�d�5	ddd�tjtjj|d�tjj|d�d��tj||d�	�|jtjjtjj|d���|jdtjtjj|d���tjj|j�d
�}tj||d�	�|jtjjtjj|d���|jdtjtjj|d���y#1swY���xYw)Nrh�real_dirrir4�link_to_dirT��target_is_directoryFrr�)r�r+r;r<r�r=r�r�rnr�rcrrar�)r�rqrrs   r%�test_copytree_symlink_dirz&TestCopyTree.test_copytree_symlink_dir�s|���,�,�.���'�'�,�,�t�|�|�~�}�=��
��������g�z�2�3�
�"�'�'�,�,�w�
�J�?��
F��G�
�
�
�2�7�7�<�<���4��7�7�<�<���7�'+�	-�	�����5�9��������������W�m�(L�M�N��
�
�j�"�*�*�R�W�W�\�\�'�=�-Q�"R�S��'�'�,�,�t�|�|�~�~�>�������4�8���������r�w�w�|�|�G�]�'K�L�M��
�
�j�"�*�*�R�W�W�\�\�'�=�-Q�"R�S�G�
F�s�I8�8Jc�@�|j�}|dz}|jtj|d�tj
j
|d�}t|d�tj||�}|jdgt	j|��y)N�destTr�)r�r�r�r�r+r;r<rCrnr�ra)r�rqrrrx�rvs     r%�test_copytree_return_valuez'TestCopyTree.test_copytree_return_valuess���,�,�.���F�"������
�
�w��5��g�g�l�l�7�E�*���3���
�_�_�W�g�
.�����%��"�*�*�R�.�1r'c���|j�}|jtj|d��tj
j
|dd�}tj
j
|dd�}t	j|�tj
j
|d�}t|d�tj||�}|jdgt	j|��y)NTr��t�pg�
somevendorz1.0�pol)r�r�r�r�r+r;r<rXrCrnr�ra)r��base_dirrqrrrxr�s      r%�test_copytree_subdirectoryz'TestCopyTree.test_copytree_subdirectorys����<�<�>������
�
�x�t��D��'�'�,�,�x��d�3���'�'�,�,�w��e�<��
���G���g�g�l�l�7�E�*���3���
�_�_�W�g�
.�����%��"�*�*�R�.�1r'N)r�r�r�rtryrr^r�r�r�r�r_�mock�patchr�r�r`rpr+rar�rbr�r�r�r�r�r�rFr'r%rfrf�s��(�&C�2�"�"�C�#�C�>?4�B(.�TC�6�]�]����$�.�%�.�'�$�X�����X�.�0F�G��"�"��X�_�_�S�\�\�Y�.�;�=�7�=�#�H�7�.)��"�"�7�#�7�4�"�"�T�#�T�&2�
2r'rfc��eZdZejd��Zejee	d�xse	jdk(d�ejd���Zejee	d�d�ejd���Z
ejd��Zejee	d	�xreed
�xr	eed�d�d
��Zej"d��Zejej"ej&d����Zd�Zd�Zejd��Zejee	d�d�d��Zejd��Zej"d��Zd�Zd�Zd�Zd�Zejd��Zejee	d�d�d��Z ejd ��Z!ejee	d!�d"�eje"jFd#k(d$�d%���Z$d&�Z%d'�Z&eje'xse(xse)d(�eje*d)�d*���Z+d+�Z,y,)-�TestCopyc���|j�}tjj|d�}tjj|d�}tjj|d�}tjj|d�}t	|d�t	|d�tj
||�tj
||�tj|tjtjz�tj|tj�|jtj|�jtj|�j�tj||�|jtj|�jtj|�j�tj|tj�tj||�|jtj|�jtj|�j�tj|tj�tj||�|jtj|�jtj|�j�tj|tj�tj||�|jtj|�jtj|�j�y)Nr��bar�baz�quux)r�r+r;r<rCr�r�r�r��S_IRWXGr��assertNotEqualr�r��copymoder��r�r(rxryr�r�s      r%�test_copymode_follow_symlinksz&TestCopy.test_copymode_follow_symlinks"s���,�,�.���g�g�l�l�7�E�*���g�g�l�l�7�E�*���7�7�<�<���/���7�7�<�<���0���3����3���
�
�
�3��!�
�
�
�3��!�
����d�l�l�4�<�<�/�0�
����d�l�l�#����B�G�G�C�L�0�0�"�'�'�#�,�2F�2F�G�����S�!���������-�-�r�w�w�s�|�/C�/C�D�	����d�l�l�#�����#�&���������-�-�r�w�w�s�|�/C�/C�D�
����d�l�l�#�����X�&���������-�-�r�w�w�s�|�/C�/C�D�
����d�l�l�#�����(�+���������-�-�r�w�w�s�|�/C�/C�Dr'r|r�zrequires os.lchmodc��tjdk(rtjntj}|j	�}tj
j
|d�}tj
j
|d�}tj
j
|d�}tj
j
|d�}t|d�t|d�tj||�tj||�tj|tjtjz�tj|tj�||tjtjz�||tj�tj|�j}tj||d��|j!tj"|�jtj"|�j�|j!tj|�j|�||tj�tj||d��|j!tj|�jtj|�j�||tj�tj||d��|j!tj|�jtj|�j�y)Nr�r�r�r�r�F��follow_symlinks)r+rgr�r|r�r;r<rCr�r�r�r�r�r�r�r�r�r)r��_lchmodr(rxryr�r��old_modes        r%� test_copymode_symlink_to_symlinkz)TestCopy.test_copymode_symlink_to_symlinkAs��!�g�g��o�"�(�(�2�9�9���,�,�.���g�g�l�l�7�E�*���g�g�l�l�7�E�*���7�7�<�<���/���7�7�<�<���0���3����3���
�
�
�3��!�
�
�
�3��!�
����d�l�l�4�<�<�/�0�
����d�l�l�#���$�,�,�t�|�|�3�4���$�,�,�'��7�7�3�<�'�'������(�E�B�������(�+�3�3����(�+�3�3�	5���������-�-�x�8���$�,�,�'�����#�u�=���������-�-�r�w�w�s�|�/C�/C�D���$�,�,�'�����X�u�=���������-�-�r�w�w�s�|�/C�/C�Dr'z requires os.lchmod to be missingc���|j�}tjj|d�}tjj|d�}tjj|d�}tjj|d�}t	|d�t	|d�tj
||�tj
||�t
j||d��y)Nr�r�r�r�Fr�)r�r+r;r<rCr�r�r�r�s      r%�*test_copymode_symlink_to_symlink_wo_lchmodz3TestCopy.test_copymode_symlink_to_symlink_wo_lchmodas����,�,�.���g�g�l�l�7�E�*���g�g�l�l�7�E�*���7�7�<�<���/���7�7�<�<���0���3����3���
�
�
�3��!�
�
�
�3��!�����(�E�Br'c�2�|j�}tjj|d�}tjj|d�}tjj|d�}tjj|d�}t	|d�tj
|�}tj||j|jdz
f�t	|d�|jtj
|�jtj
|�j�tj||�tj||�ttd�r%tj|t
j�n7tjdk(r$tj|t
j�ttd�r4tt
d	�r$tj |t
j"�tj$|�}ttd�stjdk(rQt'j(||d
��|j|j*tj
|�j*�t'j(||d��tj$|�}tjtj,vr0d
D]+}	|j/t1||	�t1||	�dz��-ttd�stjdk(r&|j3|j*|j*�ttd�r2t|d�r&|j3|j4|j4�t'j(||d��|j7t9tj
|�jtj
|�jz
�dk�y)Nr�r�r��quxgE@r|r�r}r~Tr�F��st_atime�st_mtimer�r�g�������?)r�r+r;r<rCr��utimer�r�r�r�rpr|r�rgr�r}r~rr��copystatr�r#�assertLessEqualr!r�r�r��abs)
r�r(rxryr�r�r��
src_link_stat�
dst_link_stat�attrs
          r%�test_copystat_symlinkszTestCopy.test_copystat_symlinksqs����,�,�.���g�g�l�l�7�E�*���g�g�l�l�7�E�*���7�7�<�<���/���7�7�<�<���/���3����7�7�3�<��
����x�(�(��(�(�4�/�1�	2��3������B�G�G�C�L�1�1�2�7�7�3�<�3H�3H�I�
�
�
�3��!�
�
�
�3��!��2�x� ��I�I�h����-�
�W�W��_��H�H�X�t�|�|�,��2�z�"�w�t�[�'A��K�K��$�.�.�1�����*�
��2�x� �B�G�G�t�O��O�O�H�h��E����
� 5� 5�r�w�w�s�|�7K�7K�L�����(�E�B�����*�
�
�8�8�r�2�2�2�.���$�$�W�]�D�%A�%,�]�D�%A�A�%E�G�/��2�x� �B�G�G�t�O����]�2�2�M�4I�4I�J��2�z�"�w�}�j�'I����]�3�3�]�5K�5K�L�����#�u�=�����B�G�G�C�L�1�1�B�G�G�C�L�4I�4I�I�J�� �	!r'�chflags�
EOPNOTSUPP�ENOTSUPz)requires os.chflags, EOPNOTSUPP & ENOTSUPc�v�|j�}tjj|d�}tjj|d�}t	|d�t	|d�d�}tj
}	tjtjfD])}||�t_tj||��+|tjtjz�t_|jttj||�|t_y#|t_wxYw)Nr��file2�xxxc�0���t��dd���fd�
}|S)NTr�c�����_��r*)r")r;�flagsr��err�exs   ��r%�_chflags_raiserzlTestCopy.test_copystat_handles_harmless_chflags_errors.<locals>.make_chflags_raiser.<locals>._chflags_raiser�s�������r'r-)rrrs` @r%�make_chflags_raiserzSTestCopy.test_copystat_handles_harmless_chflags_errors.<locals>.make_chflags_raiser�s�����B�@D�
�#�"r')
r�r+r;r<rCrr"rr	r�rr�r )r�r�r�rr�old_chflagsrs       r%�-test_copystat_handles_harmless_chflags_errorsz6TestCopy.test_copystat_handles_harmless_chflags_errors�s���
����������V�W�-�������V�W�-���5�%� ��5�%� �	#��j�j��	%��'�'����6��0��5��
�����u�-�7�-�U�-=�-=��
�
�-M�N�B�J����g�v����u�E�$�B�J���B�J�s
�=B"D+�+
D8c����	�
�|j�}tjj|d��
t	�
d�tjj|d�}t	|d�tj�
|�tj�
dd�tj�
dd�tj�
|�|jttj�
��ttj|���|jtj�
d�tj|d��tj|�t	|d�ttjd��	��	fd�}	tj�|t_tj�
|�|j!dtj|���t_d	d
���
fd�
}	tj�|t_
tj�
|��t_
tjj|d��
tjj|d
�}t	�
�
�t	||�tj�
dd�tj|dd�tj"|d�tjj|d�}tjj|d�}t	||�t	||�tj$�
|�tj$||�|jtj|d�d�|jtj|d�d�y#�t_wxYw#�t_
wxYw)Nr�r��user.foo�42zuser.bar�43�EPERMc�*��|dk(r���|||fi|��y)NrrF)�fnamer�valr$�
orig_setxattr�os_errors    ��r%�_raise_on_user_fooz3TestCopy.test_copyxattr.<locals>._raise_on_user_foo�s!����z�!����e�T�3�9�&�9r'Tr�c�V��|�k(rttjd���||��S)NzOperation not supportedr�)r r"r	)rr��orig_listxattrrxs  ��r%�
_raise_on_srcz.TestCopy.test_copyxattr.<locals>._raise_on_src�s)�����|��e�m�m�-F�G�G�!�%��I�Ir'�the_original�the_original_rozuser.the_valuesfiddlyi$�the_copy�the_copy_ro)r�r+r;r<rCr��
_copyxattr�setxattrr�r`�	listxattr�getxattrrBr r"rrr�r)r�r(ryr r#�srcro�dstror"rrrxs       @@@@r%�test_copyxattrzTestCopy.test_copyxattr�s�����,�,�.���g�g�l�l�7�E�*���3����g�g�l�l�7�E�*���3���	���#�s�#�
���C��U�+�
���C��U�+����#�s�#��������S� 1�2�F�2�<�<��;L�4M�N�������C��,����C��,�	.�	�	�	�#���3����5�;�;��0��	:�
	(��K�K�M�,�B�K����c�3�'��M�M�*�b�l�l�3�&7�8�'�B�K�48�	J�	*��\�\�N�(�B�L����c�3�'�)�B�L��g�g�l�l�7�N�3�������W�&7�8���3����5�%� �
���C�)�9�5�
���E�+�Y�7�
�������g�g�l�l�7�J�/�������W�m�4���3����5�%� �����S�!�����u�%�������S�*:�;�Y�G�������U�,<�=�y�I��9(�B�K��*�B�L�s�
AN!�81N1�!
N.�1
N>c�T�|j�}tjj|d�}tjj|d�}t	|d�tj
||�tj|dd�tj|ddd��tjj|d�}tjj|d	�}t	|d�tj
||�tj||d��|jtj|dd��d�|jttj|d�tj||d��|jtj|d�d�y)
Nr�r�ztrusted.foorrFr�r�r�)
r�r+r;r<rCr�r)r�r(r�r+r�r )r�r(rxr�ryr�s      r%�test_copyxattr_symlinksz TestCopy.test_copyxattr_symlinks�s&���,�,�.���g�g�l�l�7�E�*���7�7�<�<���/���3���
�
�
�3��!�
���C���.�
���H�m�U�E�J��g�g�l�l�7�E�*���7�7�<�<���/���3���
�
�
�3��!����(�H�e�D�������X�}�e�T�V[�\����'�2�;�;��]�C����(�C��?�������S�-�8�%�@r'c��d}|j�}t||fd�tjj	||�}|j�}|||�tjj	||�}||fS)Nrir)r�rCr+r;r<)r��methodrr�r��tmpdir2rs       r%�
_copy_filezTestCopy._copy_filesg����������F�E�?�E�*������V�U�+���,�,�.���u�g�������W�e�,���u�~�r'c�<�|jtj�\}}|jtj
j
|��|jt	j|�jt	j|�j�yr*)
r4r��copyr�r+r;r�r�r�r�)r�r�rs   r%�	test_copyzTestCopy.test_copys]�����v�{�{�3���u���������u�-�.���������/�/������1G�1G�Hr'c�f�|j�}tjj|d�}tjj|d�}tjj|d�}t	|d�tj
||�t
td�r5tj|tjtjz�tj||d��|jtjj|��|jt!|�t!|��tj"|�tj||d��|j%tjj|��|jtj&|�tj&|��t
td�rM|jtj(|�j*tj(|�j*�yy)Nr�r�r�r|Tr�F)r�r+r;r<rCr�rpr|r�r�r�r�r6r�rcr�r]rBr�r�rr�)r�r(rxryr�s     r%�test_copy_symlinkszTestCopy.test_copy_symlinks%s^���,�,�.���g�g�l�l�7�E�*���g�g�l�l�7�E�*���7�7�<�<���/���3���
�
�
�3��!��2�x� ��I�I�h����t�|�|� ;�<����H�c�4�8����������,�-�����3���3��8�
�	�	�#�����H�c�5�9���������s�+�,�������S�)�2�;�;�x�+@�A��2�x� ����R�X�X�h�/�7�7��X�X�c�]�2�2�
4�!r'r�zrequires os.utimec�,�|jtj�\}}|jtj
j
|��t	j|�}t	j|�}|j|j|j�dD]+}|jt||�t||�dz��-ttd�r4t|d�r'|jt|d�t|d��yyy)Nr�r�rr�)
r4r��copy2r�r+r;r�r�r�r�rr!rp)r�r�r�
file1_stat�
file2_statrs      r%�
test_copy2zTestCopy.test_copy2>s������v�|�|�4���u���������u�-�.��W�W�U�^�
��W�W�U�^�
�����+�+�Z�-?�-?�@�*�D�� � ���T�!:�!(��T�!:�Q�!>�
@�+��2�y�!�g�j�*�&E����W�Z��<�$�Z��<�
>�'F�!r'c��|j�}tjj|d�}tjj|d�}tjj|d�}t	|d�tj
||�t
td�r5tj|tjtjz�t
td�r4t
td�r$tj|tj�tj|�}tj|�}tj||d��|j!tjj#|��|j%t'|�t'|��tj(|�tj||d	��|j+tjj#|��|j%tj,|�tj,|��tj|�}tj.tj0vr0d
D]+}|j3t5||�t5||�dz��-t
td�rL|j%|j6|j6�|j9|j6|j6�t
td�r4t
|d�r'|j%|j:|j:�yyy)
Nr�r�r�r|r}r~Tr�Fr�r�r�)r�r+r;r<rCr�rpr|r�r�r�r}r~rr�r;r�rcr�r]rBr�r�r�r#rr!r�r�r�)	r�r(rxryr�r�rr�rs	         r%�test_copy2_symlinkszTestCopy.test_copy2_symlinksOs+���,�,�.���g�g�l�l�7�E�*���g�g�l�l�7�E�*���7�7�<�<���/���3���
�
�
�3��!��2�x� ��I�I�h����t�|�|� ;�<��2�z�"�w�t�[�'A��K�K��$�.�.�1��7�7�3�<������*�
����X�s�D�9����������,�-�����3���3��8�
�	�	�#�����X�s�E�:���������s�+�,�������S�)�2�;�;�x�+@�A��8�8�C�=��
�8�8�r�2�2�2�.���$�$�W�]�D�%A�%,�X�t�%<�q�%@�B�/��2�x� ����]�2�2�H�4D�4D�E����� 0� 0�(�2B�2B�C��2�z�"�w�}�j�'I����]�3�3�X�5F�5F�G�(J�"r'c��|j�}tjj|d�}tjj|d�}t	|d�tj
|dd�t
j||�|jtj|d�tj|d��tj|�y)Nr�r�rr)r�r+r;r<rCr)r�r;r�r+rB)r�r(rxrys    r%�test_copy2_xattrzTestCopy.test_copy2_xattrrs����,�,�.���g�g�l�l�7�E�*���g�g�l�l�7�E�*���3���
���C��U�+����S�#��������C��,����C��,�	.�	�	�	�#�r'c��tjtjfD]�}|j�}|j�}tj
j
|d�}t|d�|||�}|j|tj
j
|d��||tj
j
|d��}|j|tj
j
|d����y)Nr�r�)	r�r6r;r�r+r;r<rCr�)r�rrqrrrxr�s      r%�test_copy_return_valuezTestCopy.test_copy_return_values����;�;����-�B��l�l�n�G��l�l�n�G��'�'�,�,�w��.�C��s�E�"��C��!�B����R������g�u�!=�>��C������g�u�5�6�B����R������g�u�!=�>�.r'c�B�|jtj�yr*)�_test_copy_dirr�r6rSs r%�
test_copy_dirzTestCopy.test_copy_dir�s�����F�K�K�(r'c�B�|jtj�yr*)rFr�r;rSs r%�test_copy2_dirzTestCopy.test_copy2_dir�s�����F�L�L�)r'c�~�|j�}tjj|d�}|j�}tjj|d�}t	|d�t
jdk(rt}nt}|j||||�|j||||�|||�y�Nr��does_not_exist/�win32)
r�r+r;r<rCr�rbr��IsADirectoryErrorr�)r��	copy_funcrq�src_filer�ryrs       r%rFzTestCopy._test_copy_dir�s����,�,�.���7�7�<�<���/���|�|�~���g�g�l�l�7�$5�6���8�U�#��<�<�7�"�!�C�#�C����#�y�$��8�	
���#�y�$��4��(�D�!r'c���|j�}tjj|d�}tjj|d�}tjj|d�}tjj|d�}t	|d�tj
||�t
j||d��|jtjj|��|jtj|�tj|��t
j||�|jtjj|��y)Nrxryr�r�r�Fr�)
r�r+r;r<rCr�r��copyfiler�rcr�r�r�)r�r(rxryr�r�s      r%�test_copyfile_symlinkszTestCopy.test_copyfile_symlinks�s����,�,�.���g�g�l�l�7�E�*���g�g�l�l�7�E�*���7�7�<�<���4���w�w�|�|�G�V�,���3���
�
�
�3�������h��>���������x�0�1�������T�*�B�K�K��,A�B�����c�"����������,�-r'r�zrequires os.linkc�8�tjt�tjj	td�}tjj	td�}	t|dd��5}|j
d�ddd�	tj||�|jtjtj||�t|dd��5}|j|j�d�ddd�tj |�tj"td	�
�y#1swY��xYw#t$r}|jd|z�Yd}~��d}~wwxYw#1swY�pxYw#tj"td	�
�wxYw)NrFrGr5r6r7�cheddarz
os.link(): %sr[Tr�)r+r�rr;r<r=r>r�r�r�r�r�r
rRr�r\rBr�)r�rxryrVr�s     r%�'test_dont_copy_file_onto_link_to_itselfz0TestCopy.test_dont_copy_file_onto_link_to_itself�s��	������g�g�l�l�6�8�,���g�g�l�l�6�6�*��	6��c�3��1�Q����	�"�2�
3�����S�!�
���f�2�2�F�O�O�S�#�N��c�3��1�Q�� � �����9�5�2��I�I�c�N��M�M�&��5�2�1��#�
3��
�
�o��1�2�2��
3��2�1��
�M�M�&��5�sf�#E<�1D:�E<�E�">E<� !E0�E<�:E�?E<�	E-�E(�#E<�(E-�-E<�0E9�5E<�<Fc���tjt�tjj	td�}tjj	td�}	t|dd��5}|j
d�ddd�tjd|�|jtjtj||�t|dd��5}|j|j�d�ddd�tj|�tjtd�	�y#1swY��xYw#1swY�FxYw#tjtd�	�wxYw)
NrFrGr5r6r7rUr[Tr�)r+r�rr;r<r=r>r�r�r�r
rRr�r\rBr�)r�rxryrVs    r%�*test_dont_copy_file_onto_symlink_to_itselfz3TestCopy.test_dont_copy_file_onto_symlink_to_itself�s���	������g�g�l�l�6�8�,���g�g�l�l�6�6�*��	6��c�3��1�Q����	�"�2�

�J�J�x��%����f�2�2�F�O�O�S�#�N��c�3��1�Q�� � �����9�5�2��I�I�c�N��M�M�&��5�2�1��2�1��
�M�M�&��5�s=�#E�1D9�AE�!E�E�9E�>E�E�
E�E.rMrNrOrPc���	tjt�	|jtjtjtt�|jtjtjtt�tjt�y#t$r}|j	d|z�Yd}~��d}~wwxYw#tjt�wxYw)Nr�)r+rMrr�r�r�r��SpecialFileErrorrRr��__file__rB)r�r�s  r%�test_copyfile_named_pipez!TestCopy.test_copyfile_named_pipe�s���	1��I�I�f��	����f�5�5� &�����
B����f�5�5� &����6�
C�
�I�I�f����	1��M�M�+�a�/�0�0��	1��
�I�I�f��s#�B&�A0C�&	C
�/C�C
�C+c��|j�}|j�}tjj|d�}tjj|d�}t	|d�tj||�}|jtjj|��|jt|�t|��y)Nr�r�)r�r+r;r<rCr�rRr�r�r�r])r�rqrr�dst_filerPr�s      r%�test_copyfile_return_valuez#TestCopy.test_copyfile_return_value�s����,�,�.���,�,�.���7�7�<�<���/���7�7�<�<���/���8�U�#�
�_�_�X�x�
0����������r�*�+�����8�,�i��.A�Br'c�J�|j�}tjj|d�}t	|d�|jttj||�|jttj||�|jt|�d�yr�)r�r+r;r<rCr�r
r�rRrr�r])r�rqrPs   r%�test_copyfile_same_filez TestCopy.test_copyfile_same_file�sr���,�,�.���7�7�<�<���/���8�U�#����-����(�H�M����%����(�H�E�����8�,�e�4r'zMOn MACOS, Solaris and Windows the errors are not confusing (though different)zNot valid on AIX, see gh-92670c��|j�}tjj|d�}tjj|d�}t	|d�|jttj||�y)Nr�rL)	r�r+r;r<rCr�r�r�rR)r�rqrPrys    r%�test_copyfile_nonexistent_dirz&TestCopy.test_copyfile_nonexistent_dirs[���,�,�.���7�7�<�<���/���g�g�l�l�7�$5�6���8�U�#����+�V�_�_�h��Lr'c���|j�}tjj|d�}|j�}tjj|d�}t	|d�t
jdk(rt}nt}|j|tj||�|j|tj||�|j|tj||�yrK)r�r+r;r<rCr�rbr�rNr�r�rR)r�rqrPr�ryrs      r%�test_copyfile_copy_dirzTestCopy.test_copyfile_copy_dirs����,�,�.���7�7�<�<���/���|�|�~���g�g�l�l�7�$5�6���8�U�#��<�<�7�"�!�C�#�C����#�v�����=����#�v����'�B����#�v����g�>r'N)-r�r�r�rr^r�r_r`rpr+rgr�rar�rr"r�skip_unless_xattrr.�skip_unless_dac_overrider0r4r7r9r>r@rBrDrGrIrFrSrVrXr�rbr\r_ra�MACOS�SOLARISr�r�rcrerFr'r%r�r�s���"�"�E�#�E�<�X�����X�.�A�"�'�'�T�/�CW�X��"�"�E�#�Y�E�<�X�_�_�W�R��*�,N�O��"�"�
C�#�P�
C��"�"�(!�#�(!�T�X�����Y�/�3� ���5�3� ��	�2�D�F�%�	F�%�6� � �=J�!�=J�~�"�"�� � ��'�'�A�(�!�#�A�.�I��"�"�4�#�4�0�X�����W�-�/B�C�>�D�>� �"�"� H�#� H�D� � �
�!�
�
?�)�*�"�$�"�"�.�#�.� �X�����V�,�.@�A�6�B�6�&�"�"�6�#�6�(�X�����X�.�0F�G��X�_�_�S�\�\�Y�.�;�=��=�H��	C�
5��X�_�_�U�0�g�0��3B�C��X�_�_�S�:�;�M�<�	C�
M�?r'r�c��eZdZd�Zd)d�Zej�d��Zej�d��Zd�Z	ej�e
jejd�d�d���Zej�d	��Zej�d
��Zej�d��Zej�e
jejd�d
�d���Zej�e
jejd�d�d���Zd�Zej�d��Zej�e
jed�d���Zd�Zd�Zd�Zd�Zej�d��Zd�Zd�Zej�d��Zd�Z d�Z!d �Z"d!�Z#ej�d"��Z$ejJ�d#��Z&ejN�e
jPe)xre*�d$�d%���Z+ej�d&��Z,d'�Z-y()*�TestArchivesc��tj|�5}|j�}|j�t	|�cddd�S#1swYyxYwr*)�tarfiler=�getnames�sortr:)r�r;�tarr�s    r%�_tarinfozTestArchives._tarinfo(s7��
�\�\�$�
�3��L�L�N�E��J�J�L���<� �
�
�s�+A�Ac���|j�}tjj||�}tj|d��t|dfd�t|dfd�tjtjj|d��t|ddfd�tjtjj|d��|rt|d	fd�||fS)
NT)�exist_okr�rrr{�file3�sub2�outer)r�r+r;r<rXrCr�)r�r��root_dir�dists    r%�
_create_fileszTestArchives._create_files.s����<�<�>���w�w�|�|�H�h�/��
���D�4�(��D�'�?�E�*��D�'�?�E�*�
��������d�E�*�+��D�%��)�5�1�
��������d�F�+�,����'�*�E�2���!�!r'c��|j�\}}tj�5t5tj
j
dd�}t|d|�}|j|tj
j|�dz�|jtj
j|��|jtj|��tj|d�5}|j|j!�gd��ddd�ddd�ddd�tj�5t5tj
j
dd�}t|d||�}|j|tj
j|�dz�|jtj
j|��|jtj|��tj|d�5}|j|j!�gd��ddd�ddd�ddd�tj�5t5tj
j
d	d�}t|d|tj
j
|d
��}|j|tj
j|�dz�|jtj
j|��|jtj|��tj|d�5}|j|j!�ddg�ddd�ddd�ddd�y#1swY��wxYw#1swY��|xYw#1swY���xYw#1swY��xYw#1swY���xYw#1swY���xYw#1swY�hxYw#1swY�lxYw#1swYyxYw)
Nry�archiverp�.tarr[��.z./distz
./dist/subz./dist/sub2z./dist/file1z./dist/file2z./dist/sub/file3z./outer�dst2�rx�dist/subz	dist/sub2�
dist/file1�
dist/file2�dist/sub/file3�dst3r{r�r�)ryr�temp_cwd�no_chdirr+r;r<rr��abspathr�rorm�
is_tarfiler=�assertCountEqualrn�r�rwr��	base_namer{�tfs      r%�test_make_tarfilezTestArchives.test_make_tarfile<s���!�/�/�1���(�
�
�
�
!�8������U�I�6�I�"�9�e�X�>�G����W�b�g�g�o�o�i�&@�6�&I�J��O�O�B�G�G�N�N�7�3�4��O�O�G�.�.�w�7�8����g�s�+�r��%�%�b�k�k�m�$�%�,�$,�
!��
�
�
!�8������V�Y�7�I�"�9�e�X�x�H�G����W�b�g�g�o�o�i�&@�6�&I�J��O�O�B�G�G�N�N�7�3�4��O�O�G�.�.�w�7�8����g�s�+�r��%�%�b�k�k�m�G�H�,�$,�
!��
�
�
!�8������V�Y�7�I�"�9�e�X�#%�7�7�<�<��%�#@�B�G����W�b�g�g�o�o�i�&@�6�&I�J��O�O�B�G�G�N�N�7�3�4��O�O�G�.�.�w�7�8����g�s�+�r��%�%�b�k�k�m�#�%5�6�8�,�$,�
!�
!�),�+��$,�8��
!�
!��*,�+��$,�8��
!�
!��(,�+��$,�8��
!�
!�s��N)�CN�7#N�N�"N)�O�
C	O�#N6�9O�O�%O5�,C'O)�#O�6O)�>O5�N�N�N&	�!N)�)N3�6O�;O�O
	�O�O�O&�"O)�)O2	�.O5�5O>c�&�|j�\}}tjj|j	�dd�}tjj||�}t
j|�5t5t|d�}|j||dz�|jtjj|��|jtj|��tj|d�5}|j!|j#�gd��ddd�ddd�ddd�t
j|�5t5tjjdd�}t|d|��}|j||d	z�|jtjj|��|jtj|��tj|d
�5}|j!|j#�gd��ddd�ddd�ddd�y#1swY��xYw#1swY��#xYw#1swY��(xYw#1swY�AxYw#1swY�ExYw#1swYyxYw)Nryr{�gztar�.tar.gzzr:gzr}rp�r�r|r[r�)ryr+r;r<r��relpathr�
change_cwdr�rr�r�rormr�r=r�rnr�s      r%�!test_make_tarfile_without_rootdirz.TestArchives.test_make_tarfile_without_rootdirfs���!�/�/�1���(��G�G�L�L������	�B�	��G�G�O�O�I�x�8�	�
�
!�
!�(�
+�X�"�9�g�6�G����W�i�)�&;�<��O�O�B�G�G�N�N�7�3�4��O�O�G�.�.�w�7�8����g�v�.�"��%�%�b�k�k�m�$�%�/�.6�
+��
!�
!�(�
+�X������U�I�6�I�"�9�e�h�G�G����W�i�&�&8�9��O�O�B�G�G�N�N�7�3�4��O�O�G�.�.�w�7�8����g�s�+�r��%�%�b�k�k�m�G�H�,�
.6�
+�
+�/�.��.6�X��
+�
+��$,�+��
.6�X��
+�
+�sz�8I"�?B
I�	#I�,I�4I"�J� B,I;�#I/�/I;�7J�I�
I�I	�I"�"I,�/I8�4I;�;J	�J�Jc���|j�\}}tj�5t5tj
j
dd�}t|d|tj�}|j|tj
j|�dz�|jtj
j|��|jtj|��tj|d�5}|j!|j#�gd��ddd�ddd�ddd�y#1swY�xYw#1swY�xYw#1swYyxYw)Nryr{rpr|r[r})ryrr�r�r+r;r<r�curdirr�r�r�rormr�r=r�rnr�s      r%�&test_make_tarfile_with_explicit_curdirz3TestArchives.test_make_tarfile_with_explicit_curdir�s���!�/�/�1���(�
�
�
�
!�8������U�I�6�I�"�9�e�X�r�y�y�I�G����W�b�g�g�o�o�i�&@�6�&I�J��O�O�B�G�G�N�N�7�3�4��O�O�G�.�.�w�7�8����g�s�+�r��%�%�b�k�k�m�$�%�,�
$,�
!�
!�,�+��
$,�8��
!�
!�s;�E�CE�#E�)E�1E�E�E�E	�E�E#rpzNeed the tar command to runc��|j�\}}tjj|j	�d�}t
5t
|d||�}ddd�|j|dz�|jtjj|��tjj|d�}ddd|g}tjdk(rGddl}t|j�djd	�d�d
k\r|jdd�t!j"||t j$�
�|jtjj|��|j|j'|�|j'|��t
5t
|d||�}ddd�|j||dz�|jtjj|��t
5t
|d||d��}ddd�|j||dz�|jtjj|��y#1swY��xYw#1swY��xYw#1swY�fxYw)Nr{r�r�zarchive2.tarrpz-cfrrr~�r�z--no-mac-metadata��cwd�stdoutr|T��dry_run)ryr+r;r<r�r�rr�r�ror�rbr��mac_verr��insertr��
check_call�DEVNULLrq)r�rwr�r��tarball�tarball2�tar_cmdrbs        r%�test_tarfile_vs_tarz TestArchives.test_tarfile_vs_tar�s���"�/�/�1���(��G�G�L�L������;�	�
�"�9�g�x��J�G��	
����)�i�"7�8���������w�/�0��7�7�<�<��.�9���%���:���<�<�8�#�
��8�#�#�%�a�(�.�.�s�3�A�6�7�2�=����q�"5�6����g�8�%/�%7�%7�	9�	
��������x�0�1�������w�/����x�1H�I��"�9�e�X�x�H�G������)�f�"4�5���������w�/�0��"�9�e�X�x�+/�1�G��	
����)�f�"4�5���������w�/�0�O�X��:�X���X�s$�I)�,I6�J�)I3�6I?�Jc��|j�\}}tj�5t5tj
j
dd�}t|d|�}|j|tj
j|�dz�|jtj
j|��|jtj|��tj|�5}|j|j!�gd��ddd�ddd�ddd�tj�5t5tj
j
dd�}t|d||�}|j|tj
j|�dz�|jtj
j|��|jtj|��tj|�5}|j|j!�gd��ddd�ddd�ddd�tj�5t5tj
j
dd�}t|d|tj
j
|d	��}|j|tj
j|�dz�|jtj
j|��|jtj|��tj|�5}|j|j!�d
dg�ddd�ddd�ddd�y#1swY��uxYw#1swY��zxYw#1swY��xYw#1swY��~xYw#1swY���xYw#1swY���xYw#1swY�hxYw#1swY�lxYw#1swYyxYw)Nryr{�zip�.zip��dist/�	dist/sub/�
dist/sub2/r�r�r�rvr�r�r�r�r�r�r�r�r{r�r�)ryrr�r�r+r;r<rr�r�r�ro�zipfile�
is_zipfile�ZipFiler��namelist�r�rwr�r�r{�zfs      r%�test_make_zipfilezTestArchives.test_make_zipfile�s���!�/�/�1���(�
�
�
�
!�8������U�I�6�I�"�9�e�X�>�G����W�b�g�g�o�o�i�&@�6�&I�J��O�O�B�G�G�N�N�7�3�4��O�O�G�.�.�w�7�8�����)�R��%�%�b�k�k�m�"�#�*�
$,�
!��
�
�
!�8������V�Y�7�I�"�9�e�X�x�H�G����W�b�g�g�o�o�i�&@�6�&I�J��O�O�B�G�G�N�N�7�3�4��O�O�G�.�.�w�7�8�����)�R��%�%�b�k�k�m�G�H�*�
$,�
!��
�
�
!�8������V�Y�7�I�"�9�e�X�#%�7�7�<�<��%�#@�B�G����W�b�g�g�o�o�i�&@�6�&I�J��O�O�B�G�G�N�N�7�3�4��O�O�G�.�.�w�7�8�����)�R��%�%�b�k�k�m�$�&6�7�9�*�$,�
!�
!�'*�)��
$,�8��
!�
!��&*�)��
$,�8��
!�
!��&*�)��$,�8��
!�
!�s��N&�CN�6#N�N�!N&�O
�CO�#N3�7O�?O
�#O2�*C&O&�#O�3O&�;O2�N�N�N#	�N&�&N0�3N=�8O�O
	�O
�
O�O#�O&�&O/	�+O2�2O;c�H�|j�\}}tjj|j	�dd�}tjj||�}t
j|�5t5t|d�}|j||dz�|jtjj|��|jtj|��tj|�5}|j!|j#�gd��ddd�ddd�ddd�|j�\}}t
j|�5t5tjjdd�}t|d|��}|j||dz�|jtjj|��|jtj|��tj|�5}|j!|j#�gd��ddd�ddd�ddd�y#1swY��0xYw#1swY��5xYw#1swY��:xYw#1swY�AxYw#1swY�ExYw#1swYyxYw)Nryr{r�r�r�r�r�)ryr+r;r<r�r�rr�r�rr�r�ror�r�r�r�r�r�s      r%�!test_make_zipfile_without_rootdirz.TestArchives.test_make_zipfile_without_rootdir�s���!�/�/�1���(��G�G�L�L������	�B�	��G�G�O�O�I�x�8�	�
�
!�
!�(�
+�X�"�9�e�4�G����W�i�&�&8�9��O�O�B�G�G�N�N�7�3�4��O�O�G�.�.�w�7�8�����)�R��%�%�b�k�k�m�"�#�*�.6�
+�"�/�/�1���(�
�
!�
!�(�
+�X������U�I�6�I�"�9�e�h�G�G����W�i�&�&8�9��O�O�B�G�G�N�N�7�3�4��O�O�G�.�.�w�7�8�����)�R��%�%�b�k�k�m�G�H�*�
.6�
+�
+�*�)��.6�X��
+�
+��&*�)��
.6�X��
+�
+�sz�8I3�?B	I&�#I�+I&�3I3�+J�2B+J�#J�J�J�I#�I&�&I0	�+I3�3I=�J	�J�J	�J�J!c���|j�\}}tj�5t5tj
j
dd�}t|d|tj�}|j|tj
j|�dz�|jtj
j|��|jtj|��tj|�5}|j!|j#�gd��ddd�ddd�ddd�y#1swY�xYw#1swY�xYw#1swYyxYw)Nryr{r�r�r�)ryrr�r�r+r;r<rr�r�r�r�ror�r�r�r�r�r�s      r%�&test_make_zipfile_with_explicit_curdirz3TestArchives.test_make_zipfile_with_explicit_curdirs���"�/�/�1���(�
�
�
�
!�8������U�I�6�I�"�9�e�X�r�y�y�I�G����W�b�g�g�o�o�i�&@�6�&I�J��O�O�B�G�G�N�N�7�3�4��O�O�G�.�.�w�7�8�����)�R��%�%�b�k�k�m�"�#�*�
$,�
!�
!�*�)��
$,�8��
!�
!�s;�E�CE
�#E�(E
�0E�E
�E
�
E	�E�E"r�zNeed the zip command to runc��|j�\}}tjj|j	�d�}t
5t
|d||�}ddd�|j|dz�|jtjj|��tjj|d�}dddd|g}tj||tj��|jtjj|��tj|�5}|j�}ddd�tj|�5}|j�}	ddd�|jt!�t!	��y#1swY��IxYw#1swY�ixYw#1swY�GxYw)Nr{r�r�zarchive2.zipz-qz-rr�)ryr+r;r<r�r�rr�r�ror�r�r�r�r�r�r`)
r�rwr�r�r{�archive2�zip_cmdr�r��names2s
          r%�test_zipfile_vs_zipz TestArchives.test_zipfile_vs_zipsA��"�/�/�1���(��G�G�L�L������;�	�
�"�9�e�X�x�H�G��	
����)�f�"4�5���������w�/�0��7�7�<�<��.�9���$��n�h�?�����g�8�%/�%7�%7�	9�	
��������x�0�1�
�_�_�W�
%���K�K�M�E�&�
�_�_�X�
&�"��[�[�]�F�'��������v��7�'�X��&�
%��
&�
&�s$�F�2F+� F7�F(�+F4�7G�unzipzNeed the unzip command to runc���|j�\}}tjj|j	�d�}t
5t
|d||�}ddd�|j|dz�|jtjj|��dd|g}tj|�5	tj|tj��ddd�y#1swY��xYw#tj$r^}|j j#d��}d	|vr|j%d
�d}|j'|j)||��Yd}~��d}~wwxYw#1swYyxYw)Nr{r�r�r�z-t)�stderr�replace)r�zunrecognized option: tzunzip doesn't support -tz{}

**Unzip Output**
{})ryr+r;r<r�r�rr�r�rorr�r��check_output�STDOUT�CalledProcessError�output�decoder�r��format)	r�rwr�r�r{r�r�details�msgs	         r%�test_unzip_zipfilezTestArchives.test_unzip_zipfile2s+��"�/�/�1���(��G�G�L�L������;�	�
�"�9�e�X�x�H�G��	
����)�f�"4�5���������w�/�0��D�'�*��
�
!�
!�(�
+�
4��'�'��
�8I�8I�J�,�
+��X���0�0�
4��*�*�+�+�9�+�=��+�w�6��M�M�"<�=�2���	�	�#�*�*�S�'�2�3�3��
4��,�
+�s=�C,�<E,�>%C8�,C5�8E)�AE$�E,�$E)�)E,�,E5c��|j�}tjj|d�}|j	t
t|d�y)Nr{r)r�r+r;r<r��
ValueErrorr)r�r�r�s   r%�test_make_archivezTestArchives.test_make_archiveKs5��������G�G�L�L���3�	����*�l�I�u�Er'c���tr1tjd�d}tjd�d}ndx}}|j�\}}tjj|j�d�}t|d||||��}|jtjj|��t|d||�}|jtjj|��t|d||||��}|jtjj|��t|d||dd��}|jtjj|��y)	Nrr�r{r���owner�grouprp�	kjhkjhkjg�oihohoh)
�UID_GID_SUPPORT�grp�getgrgid�pwd�getpwuidryr+r;r<r�rr�ro)r�r�r�rwr�r�rfs       r%�test_make_archive_owner_groupz*TestArchives.test_make_archive_owner_groupPs����L�L��O�A�&�E��L�L��O�A�&�E�"�"�E�E�!�/�/�1���(��G�G�L�L������;�	��9�e�X�x�u�!&�(����������s�+�,��9�e�X�x�@����������s�+�,��9�e�X�x�!&�e�5����������s�+�,��9�e�X�x�!,�I�?����������s�+�,r'�Requires grp and pwd supportc
��|j�\}}tjj|j	�d�}tjd�d}tjd�d}tj|�5t5t|d|d||��}ddd�ddd�|jtjj��tj |�}	|j#�D]:}|j%|j&d�|j%|j(d��<	|j+�y#1swY��xYw#1swY��xYw#|j+�wxYw)Nr{rr�rxr�)ryr+r;r<r�r�r�r�r�rr�r�rr�rormr=�
getmembersr��uid�gidr1)	r�rwr�r�r�r��archive_namer{�members	         r%�test_tarfile_root_ownerz$TestArchives.test_tarfile_root_ownerls��"�/�/�1���(��G�G�L�L������;�	����Q���"�����Q���"��
�
!�
!�(�
+�X�'�	�7�H�f�.3�5�B�L�.6�
+�
	
��������|�4�5��,�,�|�,��	�!�,�,�.��� � ����Q�/�� � ����Q�/�/�
�M�M�O�.6�X��
+�
+��
�M�M�O�s1�E�E� E�4A
E+�E	�E�E(�+E=c�z���tj����fd�}td|gd�	t5�j	t
�5t
dd�ddd�ddd��jtj���td�y#1swY�AxYw#1swY�ExYw#td�wxYw)Nc����jd|��j|d��jtj���t	���Nrw�basename)r�r�r+rs�RuntimeError)r�r��kw�current_dirr�s   ��r%�archiverz<TestArchives.test_make_archive_cwd_default.<locals>.archiver�sA������Z��,����Y�
�3����R�Y�Y�[�+�6��.� r'r�xxx filer�)	r+rsrr�r�r�rr�r)r�r�r�s` @r%�test_make_archive_cwd_defaultz*TestArchives.test_make_archive_cwd_default�s�����i�i�k��	!�	 ��x��Z�@�	-���&�&�|�4� ��U�3�5��
���R�Y�Y�[�+�6�%�e�,�	5�4�����

&�e�,�s:�B-�B!�
B�B!�,B-�B	�B!�!B*�&B-�-
B:c�������tj���j�����fd�}g���fd�}td|gd�	t	j
td|�5��j
t�5tdd���ddd�ddd��jtj����j���g�td�y#1swY�UxYw#1swY�YxYw#td�wxYw)Nc�����jd|��j|tjj	�d���jtj
���t
��r�)r�r�r+r;r<rsr��r�r�r�r�rwr�s   ���r%r�z4TestArchives.test_make_archive_cwd.<locals>.archiver�sP������Z��,����Y������[�*�(M�N����R�Y�Y�[�(�3��.� r'c�8���j|��|�yr*r�)r;r��
orig_chdirs ��r%�_chdirz2TestArchives.test_make_archive_cwd.<locals>._chdir�s����K�K����t�r'rr��chdirr��rw)r+rsr�rrr3r�r�rr�r)r�r�r�r�r�r�rws`  @@@@r%�test_make_archive_cwdz"TestArchives.test_make_archive_cwd�s�����i�i�k���<�<�>��	!�
��	�	 ��x��Z�@�	-��"�"�2�w��7�:��&�&�|�4� ��U�X�F�5�8�
���R�Y�Y�[�+�6����T�H�k�#:�;�%�e�,�5�4��8�7��
&�e�,�s=�C4�#C(�9C�C(�AC4�C%	�!C(�(C1�-C4�4
Dc�����tj���j�����fd�}d|_t	d|gd�	t
5�j
t�5tdd���ddd�ddd��jtj���td�y#1swY�AxYw#1swY�ExYw#td�wxYw)Nc����j|d��j|d���jtj���t��)Nr�rw)r�r+rsr�r�s   ���r%r�zFTestArchives.test_make_archive_cwd_supports_root_dir.<locals>.archiver�sE������Y�
�3����R�
�^�X�6����R�Y�Y�[�+�6��.� r'Trr�r�r�)r+rsr��supports_root_dirrr�r�r�rr�r)r�r�r�rws` @@r%�'test_make_archive_cwd_supports_root_dirz4TestArchives.test_make_archive_cwd_supports_root_dir�s�����i�i�k���<�<�>��	!�
&*��"���x��Z�@�	-���&�&�|�4� ��U�X�F�5��
���R�Y�Y�[�+�6�%�e�,�	5�4�����

&�e�,�s<�C�B<�!B0�0B<�8,C�0B9	�5B<�<C�C�
Cc�B�|j�}tj|�5t5|j	tdd�d�|j
tjjd��ddd�ddd�y#1swY�xYw#1swYyxYw)N�testrpztest.tar�
r�rr�r�r�rr�r+r;ro�r�rws  r%�test_make_tarfile_in_curdirz(TestArchives.test_make_tarfile_in_curdir�sd���<�<�>��
�
!�
!�(�
+�X����\�&�%�8�*�E��O�O�B�G�G�N�N�:�6�7�.6�
+�
+�X�X��
+�
+��#�B�AB	�8B�	B	�B�Bc�B�|j�}tj|�5t5|j	tdd�d�|j
tjjd��ddd�ddd�y#1swY�xYw#1swYyxYw)Nr�r�ztest.zipr�r�s  r%�test_make_zipfile_in_curdirz(TestArchives.test_make_zipfile_in_curdir�sf���<�<�>��
�
!�
!�(�
+�X����\�&�%�8�*�E��O�O�B�G�G�N�N�:�6�7�.6�
+�
+�X�X��
+�
+�rc��|jttdd�|jttdd�d�|jttdd�ddg�tdd�dgd�t�D��cgc]\}}|��	}}}|j	d|�td�t�D��cgc]\}}|��	}}}|j
d|�ycc}}wcc}}w)	Nrr�c��tSr*��xrFr'r%�<lambda>z;TestArchives.test_register_archive_format.<locals>.<lambda>����Qr'c��tSr*rrFr'r%rz;TestArchives.test_register_archive_format.<locals>.<lambda>�rr')r�ro)r�rorc��tSr*rrFr'r%rz;TestArchives.test_register_archive_format.<locals>.<lambda>�s��qr'r�)r��	TypeErrorrrrrr�)r�rg�params�formatss    r%�test_register_archive_formatz)TestArchives.test_register_archive_format�s������)�%<�e�Q�G����)�%<�e�Y��	����)�%<�e�Y�!�9�-�	/�	 ��y�6�(�J�G�,?�,A�B�,A�L�D�&�4�,A��B��
�
�e�W�%�!�%�(�,?�,A�B�,A�L�D�&�4�,A��B������(��C��Cs�8C�1Cc	��|jtjt�d��dD�]�}|j	|��5|j�}tjj|d�}|jt�5}ttd||��ddd�|jjjtj�|j|jj |�|j#tjj%t�d���t'j(|��\}}t
j*|�|jt,�5}ttd||��ddd�|j|jjtj.�|j|jj |�|j#tjj%t�d���ddd����y#1swY���xYw#1swY��xYw#1swY��$xYw)Nr|�FTr��nonexistingrpr��r�rrur�subTestr�r+r;r<r�r�rr�r�r"�ENOENTr�r�r�rqrAr1r��ENOTDIR�r�r�r(�nonexisting_filer��tmp_fd�tmp_files       r%�test_make_tarfile_rootdir_nodirz,TestArchives.test_make_tarfile_rootdir_nodir�s������	�(�(�V�H�D�/�:�$�G����g��.��,�,�.��#%�7�7�<�<���#G� ��&�&�'8�9�R� ���0@�'�R�:�� � ����!3�!3�U�\�\�B�� � ����!6�!6�8H�I�� � ������6�(�$��!@�A�$,�#3�#3��#@� ������� ��&�&�'9�:�b� ����'�J�;�� � ����!3�!3�U�]�]�C�� � ����!6�!6��A�� � ������6�(�$��!@�A�#/�.�%�
:�9��;�:��/�.��?�AI�H+�CI�4H8�BI�+H5�0I�8I�=I�I	c	��|jtjt�d��dD�]�}|j	|��5|j�}tjj|d�}|jt�5}ttd||��ddd�|jjjtj�|j|jj |�|j#tjj%t�d���t'j(|��\}}t
j*|�|jt,�5}ttd||��ddd�|j|jjtj.�|j|jj |�|j#tjj%t�d���ddd����y#1swY���xYw#1swY��xYw#1swY��$xYw)Nr�rr�rr�r�rrs       r%�test_make_zipfile_rootdir_nodirz,TestArchives.test_make_zipfile_rootdir_nodir�s���	
���	�(�(�V�H�D�/�:�$�G����g��.��,�,�.��#%�7�7�<�<���#G� ��&�&�'8�9�R� ���0@�'�R�:�� � ����!3�!3�U�\�\�B�� � ����!6�!6�8H�I�� � ������6�(�$��!@�A�$,�#3�#3��#@� ������� ��&�&�'9�:�b� ����'�J�;�� � ����!3�!3�U�]�]�C�� � ����!6�!6��A�� � ������6�(�$��!@�A�#/�.�%�
:�9��;�:��/�.�rc��|j|d�fi|��|j|tfi|��|j|tfi|��y)Nc��|Sr*rF�r;s r%rz3TestArchives.check_unpack_archive.<locals>.<lambda>s��r')�#check_unpack_archive_with_converterr)r�r�r$s   r%�check_unpack_archivez!TestArchives.check_unpack_archivesT��0��0�0��%�	1�)/�	1�0��0�0��H�	(� &�	(�0��0�0���L�V�Lr'c��|j�\}}t|�}|jd�tjj|j
�d�}t||||�}|j
�}	t||�||	�fi|��|jt|	�|�|j
�}
t||�||
�fd|i|��|jt|
�|�|jtj�5t|t�fi|��ddd�|jt�5t|t�fddi|��ddd�y#1swY�@xYw#1swYyxYw)Nrvr{r�r)ryrerBr+r;r<r�rrr�r�r��	ReadErrorrr�)r�r��	converterr$rwr��expectedr�r�r3�tmpdir3s           r%r!z0TestArchives.check_unpack_archive_with_converters?��!�/�/�1���(��H�%������ ��G�G�L�L������;�	��	�6�8�X�F���,�,�.���y��*�I�g�,>�I�&�I�����'�*�H�5��,�,�.���y��*�I�g�,>�	!�v�	!��	!�����'�*�H�5�
�
�
�v�/�/�
0��9�V�,�7��7�1�
�
�
�z�
*��9�V�,�E�U�E�f�E�+�
*�1�
0��
*�
*�s�E+�	E7�+E4�7Fc���|j|d��|j|d��tjdtf�5|j|�ddd�y#1swYyxYw)N�
fully_trusted��filter�datazPython 3.14)r"r�check_warnings�DeprecationWarning)r�r�s  r%�check_unpack_tarballz!TestArchives.check_unpack_tarball/s]���!�!�&��!�A��!�!�&��!�8�
�
+�
+�� 2�3�5��%�%�f�-�5�5�5�s�A�A&c�&�|jd�y)Nrp�r/rSs r%�test_unpack_archive_tarz$TestArchives.test_unpack_archive_tar6s���!�!�%�(r'c�&�|jd�y)Nr�r1rSs r%�test_unpack_archive_gztarz&TestArchives.test_unpack_archive_gztar9����!�!�'�*r'c�&�|jd�y)N�bztarr1rSs r%�test_unpack_archive_bztarz&TestArchives.test_unpack_archive_bztar=r5r'z(AIX MAXDATA must be 0x20000000 or largerc�&�|jd�y)N�xztarr1rSs r%�test_unpack_archive_xztarz&TestArchives.test_unpack_archive_xztarAs��	
�!�!�'�*r'c��|jd�|jt�5|jdd��ddd�y#1swYyxYw)Nr�r,r*)r"r�rrSs r%�test_unpack_archive_zipz$TestArchives.test_unpack_archive_zipFs=���!�!�%�(�
�
�
�y�
)��%�%�e�F�%�;�*�
)�
)�s�A�A
c���t�}�fd�}tdddg|dg�tdd��jttddg|�td�tddg|��j
ddgd	ft���jddgd	ft��td��jt�|�y)
Nc�r���j|d��j|d��j|d�y)Nr��	stuff.boo�xx)r�)r��extract_dir�extrar�s   �r%�_booz/TestArchives.test_unpack_registry.<locals>._booPs3������U�A�&����X�{�3����[�$�/r'�Booz.booz.b2)rCr�r@rA�Boo2r�)	rr	rr�r
rrr�r�)r�r
rDs`  r%�test_unpack_registryz!TestArchives.test_unpack_registryLs����$�&��	0�
	�u�v�u�o�t�l�^�L��{�D�)�	
���-�)?��!�(�D�	*�	!��'��v��x��6��
�
�v��x��,�.@�.B�C����%�&��2�.�0B�0D�E�	!��(����+�-�w�7r'N)rx).r�r�r�rqryr�
requires_zlibr�r�r�r_r`r��whichr�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr"r!r/r2r4�requires_bz2r8�
requires_lzmarar�r�r;r=rGrFr'r%rkrk$s��� �"��W����'8��'8�R�W����H��H�8
%��W�����X�������e�,�6�8�*1�8��*1�X�W����%9��%9�N�W����H��H�:�W����
#��
#��W�����X�������e�,�6�8�8�8��8�0�W�����X�������g�.�8�:�4�:��4�,F�
�W����-��-�6�W�����X����*H�I��J���*-�"-�.-�&8��W����8��8�)� B�.�W����B��B�2M�F�0.�)��W����+��+��W����+��+��W�����X�_�_�S�-���-�/Y�Z�+�[��+��W����<��<�
8r'rkc��eZdZejeed�d�d��Zejed�ejee	d�d�d���Z
y)	�TestMisc�
disk_usagez)disk_usage not available on this platformc�0�tjtjj	t
��}dD]"}|j
t||�t��$|j|jd�|j|jd�|j|jd�|j|j|j�|j|j|j�tjt
�y)N)rG�used�freer)r�rNr+r;rmr[r�r!r��
assertGreaterrGrP�assertGreaterEqualrQ)r��usagers   r%�test_disk_usagezTestMisc.test_disk_usageis����!�!�"�'�'�/�/�(�";�<��-�D��!�!�'�%��"6��<�.����5�;�;��*����5�:�:�q�)�����
�
�A�.�������U�Z�Z�8����5�;�;��
�
�3�	���(�#r'r��chownzrequires os.chownc�^����j�}tj|���t�d��j	t
�5t
j��ddd��j	t�5t
j�d��ddd��j	t�5t
j�d��ddd��j	t�5t
j�d�ddd��j	t�5t
j�d�ddd�tj�}tj�}d��fd	�	}t
j�||�|�||�t
j�|�|�|�t
j�|��|�|�t
j�|��|�|�
�t
j|||�||||�t
j||�|||�t
j||��|||�t
j||��|||�
�	tj|�d}tj |�d}t
j�||�|�||�t
j|||�||||�y#1swY���xYw#1swY��YxYw#1swY��1xYw#1swY��
xYw#1swY���xYw#t"$rYywxYw)
Nr�ztesting chown functionznon-existing username)�userznon-existing groupname)r��spamg��Q�	@c���tj��}|��j||j�|��j||j�yyr*)r+r�r��st_uid�st_gid)r;r�r��sr�r�s    ��r%�check_chownz(TestMisc.test_chown.<locals>.check_chown�sH�������!�A���� � ��a�h�h�/���� � ��a�h�h�/�r')r�r)NN)r�rqr�rCr�r�r�rV�LookupErrorrr+�getuid�getgidr�r�r�r��KeyError)r�rmr�r�r^rXr�r�s`      @r%�
test_chownzTestMisc.test_chownxsd����,�,�.���?�?�w�/���8�5�6�
�
�
�z�
*��L�L��"�+��
�
�{�
+��L�L��(?�@�,��
�
�{�
+��L�L��)A�B�,��
�
�y�
)��L�L��7�+�*��
�
�y�
)��L�L��4�(�*��i�i�k���i�i�k��	0�	���X�s�C�(��H�c�3�'����X�s�#��H�c�"����X�C�(��H�c�"����X�S�)��H�#�&����W�c�3�'��G�S�#�&����W�c�"��G�S�!����W�3�'��G�S�!����W�C�(��G��%�
	+��<�<��$�Q�'�D��L�L��%�a�(�E�

�L�L��4��/���#�s�+��L�L��$��.����c�*�k+�
*��,�
+��,�
+��*�
)��*�
)��D�	��	�sN�
K�=K,�2K9�'L�L�,0L �K)�,K6�9L�L�L� 	L,�+L,N)r�r�r�r_r`rpr�rUr�r+rcrFr'r%rMrMgst���X������6�D�F�$�F�$��X����*H�I��X�����W�-�/B�C�:+�D�J�:+r'rMc���eZdZd�Zd�Zd�Zd�Zd�Zeje
jdk7d�d��Zeje
jdk(d	�d
��Z
eje
jdk(d	�d��Zeje
jdk(d	�d��Zej"d
��Zd�Zd�Zeje
jdk(d�d��Zd�Zd�Zd�Zd�Zd�Zd�Zeje
jdk(d�d��Zeje
jdk(d�d��Zeje
jdk(d�d��Zeje
jdk(d�d��Zeje
jdk(d�d��Z eje
jdk(d�d��Z!y) �	TestWhichc��|jd��|_tj|jdd��|_tj|jjtj�|j|jj�t
jj|jj�\|_|_|j|_t
j"|_d|_y)N�Tmp)r�z.Exe�rmr��suffixz.EXE)r��temp_dirrqrr�	temp_filer+r�rgr��S_IXUSRr�r1r;r�rm�file�env_pathr��extrSs r%�setUpzTestWhich.setUp�s������E��2��
�"�4�4����<A�<B�D���	������$�$�d�l�l�3�������,�,�-� �g�g�m�m�D�N�N�,?�,?�@����$�)�����
��i�i�����r'c�F�t|t�r|j�S|S)zM
        In this class we're testing with str, so convert s to a str
        )r9r�r��r�r]s  r%�to_text_typezTestWhich.to_text_type�s���a����8�8�:���r'c��tj|j|j��}|j	||j
j�y�Nr )r�rIrmrmr�rkrg�r�r�s  r%�
test_basiczTestWhich.test_basic�s4��
�\�\�$�)�)�$�(�(�
3������T�^�^�0�0�1r'c��tj|jj|j��}|j||jj�yru)r�rIrkrgrjr�rvs  r%�test_absolute_cmdzTestWhich.test_absolute_cmd�s<���\�\�$�.�.�-�-�D�M�M�
B������T�^�^�0�0�1r'c�&�tjj|j�\}}tjj	||j
�}t
j|��5tj||j��}|j||�ddd�t
j|j��5tj||��}|j|�ddd�y#1swY�[xYw#1swYyxYwru)
r+r;r�rmr<rmrr�r�rIrjr��assertIsNone)r�r��tail_dirr�r�s     r%�test_relative_cmdzTestWhich.test_relative_cmd�s��� �W�W�]�]�4�8�8�4���(��'�'�,�,�x����3��
�
!�
!�x�
0����g�D�M�M�:�B����R��)�1��
!�
!�t�x�x�
0����g�H�5�B����b�!�1�
0�	1�
0��1�
0�s�-4C;�	)D�;D�DrMztest is for non win32c�$�tjj|j�}t	j
|j��5t
j|j|��}|j|�ddd�y#1swYyxYwru)
r+r;rmrmrr�r�rIrmr{�r�r�r�s   r%�test_cwd_non_win32zTestWhich.test_cwd_non_win32�sZ���7�7�?�?�4�8�8�,��
�
!�
!�t�x�x�
0����d�i�i�h�7�B����b�!�1�
0�
0�s�
3B�Bztest is for win32c	���tjj|j�}t	j
|j��5tjjdd��5tj|j|��}|j|tjj|j|j��ddd�tjjdd��5tj|j|��}|j|�ddd�ddd�y#1swY�nxYw#1swY�xYw#1swYyxYw)Nr �shutil._win_path_needs_curdirT��return_valueF)r+r;rmrmrr�r_r�r�r�rIrmr�r<r�r{rs   r%�test_cwd_win32zTestWhich.test_cwd_win32�s����7�7�?�?�4�8�8�,��
�
!�
!�t�x�x�
0����$�$�%D�SW�$�X��\�\�$�)�)�(�;��� � ��R�W�W�\�\�$�+�+�t�y�y�%I�J�Y����$�$�%D�SX�$�Y��\�\�$�)�)�(�;���!�!�"�%�Z�1�
0�X�X��Z�Y��1�
0�s=�
"E�,A&D?�)E�;3E�.E�?E	�E�E	�E�E c�n�tjtj|j��}|dz}|j�|dz}|j
�|dz}|j
�tj|��5tjjdd��5tjd|��}ddd�|jtjj!�tjj!|��ddd�y#1swY�^xYw#1swYyxYw)Nr�z	hello.exer r�Tr�)�pathlib�Pathr+�fsdecodermr��touchrr�r_r�r�r�rIr�r;r�)r�r��elsewhere_in_path_dir�match_elsewhere_in_path�
exe_in_cwdr�s      r%�*test_cwd_win32_added_before_all_other_pathz4TestWhich.test_cwd_win32_added_before_all_other_path�s����<�<����D�H�H� 5�6�� (�6� 1���#�#�%�"7�+�"E���%�%�'���+�
�����
�
!�
!�x�
0����$�$�%D�SW�$�X��\�\�+�4I�J��Y�
���R�W�W�_�_�R�0�"�'�'�/�/�*�2M�N�	1�
0�X�X��1�
0�s%�"D+�*D�AD+�D(	�$D+�+D4c�"�tjtj|j��}|dz}|dz}|j�|j�|dz}|dz}|j
�|j
�tjjt|�t|�g�}tjjtjd|tj���j�dk(sJ�y)Nr�r�z
hello.com.exez	hello.com�r;rA)r�r�r+r�rmr�r��pathsepr<r�r;r�r�rI�F_OK�lower)r�r�r�r��
pathext_match�
path_match�	test_paths       r%�)test_pathext_match_before_path_full_matchz3TestWhich.test_pathext_match_before_path_full_match	s����<�<����D�H�H� 5�6���&� ���&� ���
�
���
�
����.�
��K�'�
����������J�J�O�O�S��Y��D�	�$:�;�	��w�w�������i����!
���5�7�o�&�	&�&r'c��tj|jjtj
�tj|jjtj�r|jd�tj|j|jtj��}|j|�y)Nzcan't set the file read-onlyr�)r+r�rkrgr�r��access�W_OKr�r�rIrmrmr{rvs  r%�test_non_matching_modez TestWhich.test_non_matching_mode%	su��	������$�$�d�l�l�3�
�9�9�T�^�^�(�(�"�'�'�2��M�M�8�9�
�\�\�$�)�)�$�(�(����
A�����"�r'c�h�tjj|j�\}}t	j
|��5t
j|j|��}|j|tjj||j��ddd�y#1swYyxYwru)r+r;r�rmrr�r�rIrmr�r<)r�r�r|r�s    r%�test_relative_pathzTestWhich.test_relative_path.	sn���W�W�]�]�4�8�8�4���(�
�
!�
!�x�
0����d�i�i�h�7�B����R������h��	�	�!B�C�1�
0�
0�s
�AB(�(B1c�h�tjd|j��}|j|�y)Nzfoo.exer )r�rIrmr{rvs  r%�test_nonexistent_filezTestWhich.test_nonexistent_file4	s$��
�\�\�)�$�(�(�
3�����"�r'zpathext check is Windows-onlyc���tj|jdd|j��}|j	||j
jdd|jz�y)N���r )r�rIrmrmr�rkrgrorvs  r%�test_pathext_checkingzTestWhich.test_pathext_checking9	sL��
�\�\�$�)�)�C�R�.�t�x�x�
8������T�^�^�0�0��"�5����@�Ar'c��tj�5}|j|d<tj|j
�}|j
||jj�ddd�y#1swYyxYw�N�PATH)	r�EnvironmentVarGuardrnr�rIrmr�rkrg�r��envr�s   r%�test_environ_pathzTestWhich.test_environ_pathA	sU��
�
*�
*�
,���-�-�C��K����d�i�i�(�B����R����!4�!4�5�-�
,�
,�s�AA3�3A<c	��tj�5}d|d<tjj	d|j
d��5t
jtd|j
�5tj|j
�5tj|j�}|j|�ddd�ddd�ddd�ddd�y#1swY�"xYw#1swY�&xYw#1swY�*xYw#1swYyxYw)Nr�r��
os.confstrT�r��create�defpath)rr�r_r�r�rmrr3r+r�r�rIrmr{r�s   r%�test_environ_path_emptyz!TestWhich.test_environ_path_emptyG	s���
�
*�
*�
,���C��K����$�$�\����,0�%�2��"�"�2�y�$�(�(�;��%�%�d�h�h�/��\�\�$�)�)�,���!�!�"�%�0�<�2�-�
,�
0�/��<�;��2�2��-�
,�sS�2D�&C7�- C+�
1C	�>C+�C7�D�C(
�$C+�+C4�0C7�7D	�<D�Dc	���tjj|jj�}t
jdk(rUtj}t|t�rtj|�}tjj||�}tj�5}tj|d<tj j#d|j$d��5t'j(td|j$�5t+j,|j.�}|j1|�tj2|j$�5t+j,|j.�}|j5||�ddd�ddd�ddd�ddd�y#1swY�"xYw#1swY�&xYw#1swY�*xYw#1swYyxYw)NrMr�r�Tr�r�)r+r;r�rkrgr�rbr�r9r�r�r<rr�r�r_r�r�rmrr3r�rIrmr{r�r�)r��expected_cwdr�r�r�s     r%�test_environ_path_cwdzTestWhich.test_environ_path_cwdR	sI���w�w�'�'����(;�(;�<���<�<�7�"��Y�Y�F��,��.����V�,���7�7�<�<���=�L��
*�
*�
,���*�*�C��K����$�$�\����,0�%�2��"�"�2�y�$�(�(�;��\�\�$�)�)�,���!�!�"�%��)�)�$�(�(�3����d�i�i�0�B��$�$�R��6�4�<�2�-�
,�4�3��<�;��2�2��-�
,�sV�0AG�0&G�AG�&2F9	�G� G�(G�9G
�>G�G�
G�G	�G�G&c�Z�tj�5}|jdd�tjjdtd��5tjtd|j�5tj|j�}ddd�ddd�|j|jj �tjjd|jd��5tjtdd�5tj|j�}ddd�ddd�|j||jj �ddd�y#1swY��xYw#1swY��xYw#1swY�XxYw#1swY�\xYw#1swYyxYw)Nr�r�T)rr�r�r�r�)rr��popr_r�r�r�rr3r+rmr�rIrmr�rkrgr�s   r%�test_environ_path_missingz#TestWhich.test_environ_path_missingh	s3��
�
*�
*�
,���G�G�F�D�!����$�$�\�z�,0�%�2��"�"�2�y�$�(�(�;��\�\�$�)�)�,��<�2�
���R����!4�!4�5����$�$�\����,0�%�2��"�"�2�y�"�5��\�\�$�)�)�,��6�2�
���R����!4�!4�5�-�
,�<�;��2�2��6�5��2�2��-�
,�sl�9F!�&E=�4 E1�E=�AF!�6F� F	�2F�:.F!�1E:�6E=�=F	�F!�	F�F�F	�F!�!F*c��tjj|j�}t	j
|j��5t	j�5}|j|d<tj|jd��}|j|�ddd�ddd�y#1swY�xYw#1swYyxYw)Nr r�r�)r+r;rmrmrr�r�rnr�rIrmr{)r�r�r�r�s    r%�test_empty_pathzTestWhich.test_empty_pathz	s����7�7�?�?�4�8�8�,��
�
!�
!�t�x�x�
0�
�
*�
*�
,���-�-�C��K����d�i�i�b�1�B����b�!�-�1�
0�
,�
,��1�
0�s%�
B>�AB2�!B>�2B;	�7B>�>Cc���tj�5}|jdd�tj|j
�}|j
|�ddd�y#1swYyxYwr�)rr�r�r�rIrmr{r�s   r%�test_empty_path_no_PATHz!TestWhich.test_empty_path_no_PATH�	sJ��
�
*�
*�
,���G�G�F�D�!����d�i�i�(�B����b�!�-�
,�
,�s�AA!�!A*ztest specific to Windowsc���|jd�}tj|j|jd�|��}t	j
|jtj�|j|j�tjj|j�}tjj|�d}tj�5}t!|t"�r|n|j%�|d<t'j(||j��}|j+||j�ddd�y#1swYyxYw)N�.xyz�Tmp2rhr�PATHEXTr )rsrqrrrjr+r�rgr�rlr�r1r;r�r�rr�r9r�r�r�rIr��r�ro�temp_filexyz�programr�r�s      r%�test_pathextzTestWhich.test_pathext�	s�������'���2�2�t�}�}�:>�:K�:K�F�:S�\_�a��
����"�"�D�L�L�1�����*�*�+��'�'�"�"�<�#4�#4�5���'�'�"�"�7�+�A�.��
�
*�
*�
,��$.�s�C�$8�S�c�j�j�l�C�	�N����g�D�M�M�:�B����R��!2�!2�3�-�
,�
,�s
�+A#E�E c�p�|jd�}tj|j|jd�|��}|j	|j
�tjj|j�}tjj|�d}tj�5}t|t�r|n|j��d�|d<t!j"||j��}|j%||j�ddd�y#1swYyxYw)Nr�r�rhr�;r�r )rsrqrrrjr�r1r+r;r�rgr�rr�r9r�r�r�rIr�r�s      r%�test_pathext_with_empty_strz%TestWhich.test_pathext_with_empty_str�	s�������'���2�2�t�}�}�:>�:K�:K�F�:S�\_�a������*�*�+��'�'�"�"�<�#4�#4�5���'�'�"�"�7�+�A�.��
�
*�
*�
,��'1�#�s�';������N�a�P�C�	�N����g�D�M�M�:�B����R��!2�!2�3�-�
,�
,�s
�=A&D,�,D5c� �tj�5}t|jt�r|jn|jj�|d<d|d<tjj|j|jd��}t|d�j�t
j|d�|jtj|jd��|�ddd�y#1swYyxYw)Nr��.testr�ztest_program.testr5���test_program�rr�r9rjr�r�r+r;r<rsr=r1r�r�r�rI)r�r�r�s   r%�%test_pathext_applied_on_files_in_pathz/TestWhich.test_pathext_applied_on_files_in_path�	s���
�
*�
*�
,��+5�d�m�m�S�+I�$�-�-�t�}�}�Oc�Oc�Oe�C��K�$�C�	�N������T�]�]�D�4E�4E�FY�4Z�[�I���C� �&�&�(��H�H�Y��&����V�\�\�$�*;�*;�N�*K�L�i�X�-�
,�
,�s�C&D�D
c�v�tjjdd��5}|jt	j
dtj��|jd�|j�|jt	j
dd��|j�ddd�tjjdd��5}|jt	j
dtj��|jd�ddd�y#1swY�xxYw#1swYyxYw)Nz&_winapi.NeedCurrentDirectoryForExePathTr��dontcarerF)r_r�r�r�r��_win_path_needs_curdirr+�X_OK�assert_called_once_with�
reset_mock�assert_not_calledr�)r��need_curdir_mocks  r%�test_win_path_needs_curdirz$TestWhich.test_win_path_needs_curdir�	s���
�]�]�
 �
 �!I�X\�
 �
]�aq��O�O�F�9�9�*�b�g�g�N�O��4�4�Z�@��'�'�)��O�O�F�9�9�*�a�H�I��.�.�0�^��]�]�
 �
 �!I�X]�
 �
^�br����V�:�:�:�r�w�w�O�P��4�4�Z�@�_�
^�^�
]��_�
^�s�B
D#�AD/�#D,�/D8c���tj�5}t|jt�r|jn|jj�|d<d|d<tjj|j|jd��}t|d�j�t
j|d�|jtj|jd��|�tjj|j|jd��}t|d�j�t
j|d�|jtj|jd��|�|jtj|jd�tj ��|�ddd�y#1swYyxYw)	Nr�r�r��test.exer5r�z
test.exe.test)rA)rr�r9rjr�r�r+r;r<rsr=r1r�r�r�rIr�)r�r��exe�dot_tests    r%�"test_pathext_preferred_for_executez,TestWhich.test_pathext_preferred_for_execute�	sN��
�
*�
*�
,��+5�d�m�m�S�+I�$�-�-�t�}�}�Oc�Oc�Oe�C��K�$�C�	�N��'�'�,�,�t�}�}�d�.?�.?�
�.K�L�C���c�N� � �"��H�H�S�%� �
���V�\�\�$�*;�*;�J�*G�H�#�N��w�w�|�|�D�M�M�4�3D�3D�_�3U�V�H���3��%�%�'��H�H�X�u�%�
���V�\�\�$�*;�*;�J�*G�H�(�S�
���V�\�\�$�*;�*;�J�*G�b�g�g�V�X[�\�)-�
,�
,�s�GG%�%G.c�Z�tj�5}t|jt�r|jn|jj�|d<d|d<tjj|j|jd��}t|d�j�t
j|d�tjj|j|jd��}t|d�j�t
j|d�|jtj|jd��|�|jtj|jd��|�ddd�y#1swYyxYw)	Nr�z
.exe2;.exer�r�r5r�z	test.exe2r�r�)r�r�r��exe2s    r%�&test_pathext_given_extension_preferredz0TestWhich.test_pathext_given_extension_preferred�	s��
�
*�
*�
,��+5�d�m�m�S�+I�$�-�-�t�}�}�Oc�Oc�Oe�C��K�)�C�	�N��'�'�,�,�t�}�}�d�.?�.?�
�.K�L�C���c�N� � �"��H�H�S�%� ��7�7�<�<��
�
�t�/@�/@��/M�N�D���s�O�!�!�#��H�H�T�5�!�
���V�\�\�$�*;�*;�J�*G�H�#�N����V�\�\�$�*;�*;�F�*C�D�d�K�-�
,�
,�s�FF!�!F*N)"r�r�r�rprsrwryr}r_r`r�rbr�r�r�r�rrcr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rFr'r%rere�si����2�
2�"��X�������0�0�2�"�2�"��X�������0�,�.�
&�.�
&��X�������0�,�.�O�.�O�"�X�������0�,�.�&�.�&�"�#�#��$��D��
�X�������0�8�:�B�:�B�6�	&�7�,6�$"�"��X�������0�2L�M�4�N�4�"�X�������0�2L�M�
4�N�
4� �X�������0�2L�M�	Y�N�	Y��X�������0�2L�M�
A�N�
A��X�������0�2L�M�]�N�]�0�X�������0�2L�M�L�N�Lr'rec��eZdZd�Zd�Zy)�TestWhichBytesc��tj|�tj|j�|_tj|j
�|_tj|jj�|j_tj|j�|_tj|j�|_	tj|j�|_
yr*)rerpr+r�rmrmrkrgrjr�rorSs r%rpzTestWhichBytes.setUp�	s���������;�;�t�x�x�(����K�K��	�	�*��	� �k�k�$�.�.�*=�*=�>��������D�M�M�2��
��k�k�$�+�+�.����;�;�t�x�x�(��r'c�F�t|t�r|j�S|S)zQ
        In this class we're testing with bytes, so convert s to a bytes
        )r9r�rPrrs  r%rszTestWhichBytes.to_text_type�	s���a����8�8�:���r'N)r�r�r�rprsrFr'r%r�r��	s��)�r'r�c���eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	e
d��Ze
d	��Zd
�Z
e
d��Zd�Ze
d
��Zd�Zej&ej*j,d�d��Zd�Zd�Zd�Zd�Zej:e
d���Zej:e
d���Zej:e
d���Z ej:e
d���Z!d�Z"d�Z#e
d��Z$e
d��Z%d�Z&e
d��Z'ej:d��Z(ej:d ��Z)ejTej&e+ed!�xre+e,d"�xr	e+e,d#�d$�d%���Z-y&)'�TestMovec��d}|j�|_|j�|_tjj|j|�|_tjj|j|�|_t|jd�5}|jd�ddd�y#1swYyxYw)Nr�r4rY)
r�rqrrr+r;r<rPr^r=r>)r�r�rVs   r%rpzTestMove.setUp
s}�����|�|�~����|�|�~��������T�\�\�8�<��
������T�\�\�8�<��
�
�$�-�-��
&�!�
�G�G�G��'�
&�
&�s�!B<�<Cc�p�t|d�5}|j�}ddd�tj||�t|d�5}|j	|j��ddd�|jtjj|��y#1swY��xYw#1swY�DxYw�NrZ)	r=r\r��mover�r�r+r;r�)r�rxry�real_dstrV�contentss      r%�_check_move_filezTestMove._check_move_file
s~��
�#�t�_���v�v�x�H�����C���
�(�D�
!�Q����X�q�v�v�x�0�"����������,�-��_��"�
!�s�B �!B,� B)�,B5c�$�ttj|��}tj||�|j|ttj|���|j
tjj|��yr*)	r`r+rar�r�r�r�r;r�)r�rxryr�r�s     r%�_check_move_dirzTestMove._check_move_dir
s[���"�*�*�S�/�*�����C�������6�"�*�*�X�*>�#?�@����������,�-r'c�f�|j|j|j|j�yr*)r�rPr^rSs r%�test_move_filezTestMove.test_move_file
s �����d�m�m�T�]�]�D�M�M�Jr'c�f�|j|j|j|j�yr*)r�rPrrr^rSs r%�test_move_file_to_dirzTestMove.test_move_file_to_dir"
s �����d�m�m�T�\�\�4�=�=�Ir'c�|�t|j�}|j||j|j�yr*)rrPr�rrr^)r�rxs  r%�"test_move_file_to_dir_pathlike_srcz+TestMove.test_move_file_to_dir_pathlike_src&
s*���t�}�}�%�����c�4�<�<����?r'c�|�t|j�}|j|j||j�yr*)rrrr�rPr^�r�rys  r%�"test_move_file_to_dir_pathlike_dstz+TestMove.test_move_file_to_dir_pathlike_dst+
s*���t�|�|�$�����d�m�m�S�$�-�-�@r'c�$�|j�yr*)r�rSs r%�test_move_file_other_fsz TestMove.test_move_file_other_fs0
s��	
���r'c�$�|j�yr*)r�rSs r%�test_move_file_to_dir_other_fsz'TestMove.test_move_file_to_dir_other_fs5
s��	
�"�"�$r'c���tj|j���}	|j|j||�tj|�y#tj|�wxYwr@)rqr�r�r�rqrr��r�rrs  r%�
test_move_dirzTestMove.test_move_dir:
sN���/�/�d�l�l�n�5��	&�� � ����w��@����W�%��I���W�%�s�A�A0c�$�|j�yr*)r�rSs r%�test_move_dir_other_fszTestMove.test_move_dir_other_fsB
s��	
���r'c
���|j|j|jtjj|jtjj
|j���yr*)r�rqrrr+r;r<r�rSs r%�test_move_dir_to_dirzTestMove.test_move_dir_to_dirG
sF�����T�\�\�4�<�<��G�G�L�L����r�w�w�'7�'7����'E�F�	Hr'c�$�|j�yr*)r�rSs r%�test_move_dir_to_dir_other_fsz&TestMove.test_move_dir_to_dir_other_fsL
s��	
�!�!�#r'c
�&�|j|jtjjz|j
tjj
|j
tjj|j���yr*)r�rqr+r;�seprrr<r�rSs r%�test_move_dir_sep_to_dirz!TestMove.test_move_dir_sep_to_dirQ
sS�����T�\�\�B�G�G�K�K�7�����G�G�L�L����r�w�w�'7�'7����'E�F�	Hr'zrequires os.path.altsepc
�&�|j|jtjjz|j
tjj
|j
tjj|j���yr*)r�rqr+r;�altseprrr<r�rSs r%�test_move_dir_altsep_to_dirz$TestMove.test_move_dir_altsep_to_dirU
sS�����T�\�\�B�G�G�N�N�:�D�L�L��G�G�L�L����r�w�w�'7�'7����'E�F�	Hr'c���t|jd�5	ddd�|jtjtj
|j|j�y#1swY�NxYw)Nr4)r=r^r�r�rr�rPrrrSs r%�"test_existing_file_inside_dest_dirz+TestMove.test_existing_file_inside_dest_dirZ
sE��
�$�-�-��
&��'����&�,�,����T�]�]�D�L�L�Q�'�
&�s�A&�&A/c���tjj|jd�}|j	t
jt
j|j|�y�Nr�)r+r;r<rqr�r�rr�r�s  r%�test_dont_move_dir_in_itselfz%TestMove.test_dont_move_dir_in_itself`
s:���g�g�l�l�4�<�<��/�����&�,�,����T�\�\�3�Gr'c	��tjt�	dD]{\}}tjj	t|�}tjj	t|�}|jt
j||�d|�d|�d����}	tjt�y#tjt�wxYw)N))�srcdirzsrcdir/dest�)_destinsrc() wrongly concluded that dst (z) is not in src (�)�r�)
r+r�rr;r<r�r��
_destinsrcrr�rHs   r%�test_destinsrc_false_negativez&TestMove.test_destinsrc_false_negativee
s���
�����	%�7���S��g�g�l�l�6�3�/���g�g�l�l�6�3�/������ 1� 1�#�s� ;�>A�3�"H� �I�8�
���V�$��I���V�$���BB6�6Cc	��tjt�	dD]{\}}tjj	t|�}tjj	t|�}|jt
j||�d|�d|�d����}	tjt�y#tjt�wxYw)N))r
zsrc/dest)r
z
srcdir.newrz
) is in src (rr)
r+r�rr;r<r�r�rrr�rHs   r%�test_destinsrc_false_positivez&TestMove.test_destinsrc_false_positiveq
s���
�����	%�N���S��g�g�l�l�6�3�/���g�g�l�l�6�3�/��� � ��!2�!2�3��!<�9<�c�!C�!�D�O�
���V�$��I���V�$�rc���tjj|jd�}tj|j
|�t
j||j�|jtjj|j��|jtjj|j
|j��yr
)r+r;r<rqr�rPr�r�r^r�rc�samefiler�s  r%�test_move_file_symlinkzTestMove.test_move_file_symlink}
s����g�g�l�l�4�<�<��/��
�
�
�4�=�=�#�&����C����'���������t�}�}�5�6�������(�(�����
�
�F�Gr'c��d}tjj|j|�}tj|j
|�t
j||j�tjj|j|�}|jtjj|��|jtjj|j
|��yr
)r+r;r<rqr�rPr�r�rrr�rcr)r�r�ry�
final_links    r%�test_move_file_symlink_to_dirz&TestMove.test_move_file_symlink_to_dir�
s������g�g�l�l�4�<�<��2��
�
�
�4�=�=�#�&����C����&��W�W�\�\�$�,�,��9�
���������z�2�3�������(�(����
�C�Dr'c�L�tjj|jd�}tjj|jd�}tj||�tjj|j
d�}t
j||�|jtjj|��|jtjj|�tjj|��y�Nr�r�r�)r+r;r<rqr�rrr�r�r�rcr��realpath�r�rxryr�s    r%�test_move_dangling_symlinkz#TestMove.test_move_dangling_symlink�
s����g�g�l�l�4�<�<��/���g�g�l�l�4�<�<��/��
�
�
�3����7�7�<�<����f�5�����C��"���������x�0�1�������)�)�#�.����0@�0@��0J�Kr'c�<�tjj|jd�}tjj|jd�}tj|�tj
||�tjj|jd�}tj||�|jtjj|��|jtjj||��yr)r+r;r<rqr�r�rrr�r�r�rcrrs    r%�test_move_dir_symlinkzTestMove.test_move_dir_symlink�
s����g�g�l�l�4�<�<��/���g�g�l�l�4�<�<��/��
����
�
�
�
�3����7�7�<�<����f�5�����C��"���������x�0�1�������(�(��h�7�8r'c	��tj|j|j�}|j	|t
jj|jt
jj|j���yr*)	r�r�rPrrr�r+r;r<r�rvs  r%�test_move_return_valuezTestMove.test_move_return_value�
sT��
�[�[�������
5�����������T�\�\�2�7�7�+;�+;�D�M�M�+J�K�	Mr'c��tj|jtjj|jd��}|j|tjj|jd��yr
)r�r�rPr+r;r<rrr�rvs  r%� test_move_as_rename_return_valuez)TestMove.test_move_as_rename_return_value�
sL��
�[�[���������T�\�\�5�(I�
J������R�W�W�\�\�$�,�,��>�?r'c���g��fd�}tj|j|j|��|j	t��d�y)Nc�,���j||f�yr*r��rxry�moveds  �r%r�z7TestMove.test_move_file_special_function.<locals>._copy�
�����L�L�#�s��$r'r�r�)r�r�rPrrr�r��r�r�r*s  @r%�test_move_file_special_functionz(TestMove.test_move_file_special_function�
s9�����	%����D�M�M�4�<�<�u�E�����U��Q�'r'c���g��fd�}tjtjj	|j
d��tjtjj	|j
d��t
j|j
|j|��|jt��d�y)Nc�,���j||f�yr*r�r)s  �r%r�z6TestMove.test_move_dir_special_function.<locals>._copy�
r+r'�child�child1r�r)rr�r+r;r<rqr�r�rrr�r�r,s  @r%�test_move_dir_special_functionz'TestMove.test_move_dir_special_function�
s{�����	%��#�#�B�G�G�L�L����w�$G�H��#�#�B�G�G�L�L����x�$H�I����D�L�L�$�,�,�e�D�����U��Q�'r'c�Z�|j�|_tjj	tjj|j�tjj
|j�j��}|j|j|�	tj|j|�|jtjj|��tj|�y#tj|�wxYwr*)r�rqr+r;r<rmr��upperr�r�r�r�rbr�r�s  r%�test_move_dir_caseinsensitivez&TestMove.test_move_dir_caseinsensitive�
s����|�|�~����'�'�,�,���������-���� � ����.�4�4�6�8��	
���D�L�L�'�2�	��K�K����g�.��O�O�B�G�G�M�M�'�2�3��H�H�W���B�H�H�W��s
�/AD�D*c���tjj|jd�}tjj|jd�}tj
|j|d��t
j||�|jtjj|��|jtjj|j|��|jtjj|��tj
|j|d��|jtj�5t
j||�ddd�|jtjj|j|��|jtjj|��y#1swY�qxYw)N�	linktodirTr�)r+r;r<rqrrr�r�r�r�rcrr�r�r�r)r�ryrxr�s    r%�"_test_move_symlink_to_dir_into_dirz+TestMove._test_move_symlink_to_dir_into_dir�
s'���g�g�l�l�4�<�<��5���7�7�<�<����k�:��
�
�
�4�<�<��$�?����C�����������x�0�1�������(�(����x�@�A����������,�-�	�
�
�4�<�<��$�?�
�
�
�v�|�|�
,��K�K��S�!�-�������(�(����x�@�A���������s�+�,�-�
,�s�#G*�*G3c�:�|j|j�yr*)r8rrrSs r%�!test_move_symlink_to_dir_into_dirz*TestMove.test_move_symlink_to_dir_into_dir�
s���/�/����=r'c��tjj|jd�}tj|j
|d��|j
|�y)N�otherlinktodirTr�)r+r;r<rqr�rrr8r�s  r%�,test_move_symlink_to_dir_into_symlink_to_dirz5TestMove.test_move_symlink_to_dir_into_symlink_to_dir�
s=���g�g�l�l�4�<�<�)9�:��
�
�
�4�<�<��$�?��/�/��4r'r}�SF_IMMUTABLE�	UF_OPAQUEzrequires lchflagsc� �	tjt�tjttj
�|j
ttjtt�|jttj�v�tjttj�tjtj j#td��tjttj
�|j
ttjtt�|jttj�v�tj j%t�rAtjttj�tj&t�tj j%t�rBtjttj�tj&t�yy#tj j%t�rAtjttj�tj&t�tj j%t�rBtjttj�tj&t�wwxYw)Nr0)r+r��
TESTFN_SRCr}r�r>r�r�r�r��
TESTFN_DSTr�rar?rr�r;r<r�r�rSs r%�test_move_dir_permission_deniedz(TestMove.test_move_dir_permission_denied�
s���	-��H�H�Z� ��K�K�
�D�$5�$5�6�
���o�v�{�{�J�
�S����Z�2�:�:�<�7�8�
�K�K�
�D�N�N�3��'�'������Z��(I�J��K�K�
�D�$5�$5�6�
���o�v�{�{�J�
�S����Z�2�:�:�<�7�8��w�w�~�~�j�)����J����7�� � ��,��w�w�~�~�j�)����J����7�� � ��,�*���w�w�~�~�j�)����J����7�� � ��,��w�w�~�~�j�)����J����7�� � ��,�*�s
�E6I�CL
N).r�r�r�rpr�r�r�r�r�r�r2r�r�r�r�r�rrr_r`r+r;rrrrrrrr^rrr r"r$r&r-r2r5r8r:r=rgrpr�rCrFr'r%r�r�
s7���.�.�K�J�@�
A�
�����%��%�&�����H�
�$��$�H��X��������)B�C�H�D�H�R�H�

%�
%��"�"��H��#�H��"�"��E��#�E��"�"��L��#�L��"�"��9��#�9�M�
@��(��(��(��(��$�-��-�"�"�"�>�#�>��"�"�5�#�5�
�'�'��X�����Z�0�8�$�T�>�:�8�$�T�;�7�,�.�-�	.�(�
-r'r�c��eZdZGd�de�Zd�Zejed�d��Z	ejed�d��Z
ejed�d��Zy)	�TestCopyFilec�2�eZdZdZdZdZdd�Zd�Zd�Zd�Z	y)�TestCopyFile.FauxFNc� �||_||_yr*)�_raise_in_exit�_suppress_at_exit)r��
raise_in_exit�suppress_at_exits   r%�__init__zTestCopyFile.Faux.__init__s��"/�D��%5�D�"r'c��y)Nr�rF)r�r#s  r%r\zTestCopyFile.Faux.reads��r'c��d|_yr)�_enteredrSs r%�	__enter__zTestCopyFile.Faux.__enter__s	�� �D�Mr'c�j�|||f|_|jrd|_td��|jS)NT�Cannot close)�_exited_withrI�_raisedr rJ)r��exc_type�exc_val�exc_tbs    r%�__exit__zTestCopyFile.Faux.__exit__!s8�� (�'�6� 9�D���"�"�#����n�-�-��)�)�)r'r)
r�r�r�rPrTrUrMr\rQrYrFr'r%�FauxrGs%��������	6�	�	!�	*r'rZc���dd�}tjtd|�5|jt�5tj
dd�ddd�ddd�y#1swY�xYw#1swYyxYw)Nc�&�|dk(rtd��J�)N�srcfilezCannot open "srcfile"r-)r�rAs  r%�_openz4TestCopyFile.test_w_source_open_fails.<locals>._open)s���9�$��5�6�6��1r'r=r]�destfile�r[)rr3r�r�r rR)r�r^s  r%�test_w_source_open_failsz%TestCopyFile.test_w_source_open_fails(sT��	�
�
�
�v�v�u�
5��"�"�7�+����	�:�6�,�6�
5�+�+��6�
5�s"�A*�A�
A*�A'	�#A*�*A3zskipped on macOSc���|j��d�fd�	}tjtd|�5tjdd�ddd�|j�j�|j�jdtu�|j�jdjd�y#1swY�rxYw)	Nc�6��|dk(r�S|dk(rtd��J�)Nr]r_�Cannot open "destfile"r-)r�rAr]s  �r%r^z2TestCopyFile.test_w_dest_open_fails.<locals>._open6s)����9�$����:�%��6�7�7��1r'r=r]r_rr�)rdr`)rZrr3r�rRr�rPrTr r�r#)r�r^r]s  @r%�test_w_dest_open_failsz#TestCopyFile.test_w_dest_open_fails2s�����)�)�+��	��
�
�v�v�u�
5��O�O�I�z�2�6�����(�(�)�����,�,�Q�/�7�:�;�����-�-�a�0�5�5�4�	6�	6�
5�s�B;�;Cc� ���|j��|jd��d	��fd�	}tjtd|�5tjdd�ddd�|j�j�|j�j�|j�j�|j�jdtu�|j�jdjd�y#1swY��xYw)
NTc�$��|dk(r�S|dk(r�SJ��Nr]r_rF�r�rAr_r]s  ��r%r^z3TestCopyFile.test_w_dest_close_fails.<locals>._openI�"����9�$����:�%����1r'r=r]r_rr�)rSr`)rZrr3r�rRr�rPrUrTr r�r#�r�r^r_r]s  @@r%�test_w_dest_close_failsz$TestCopyFile.test_w_dest_close_failsDs�����)�)�+���9�9�T�?��	��
�
�v�v�u�
5��O�O�I�z�2�6�����(�(�)�����)�)�*�����(�(�)�����,�,�Q�/�7�:�;�����-�-�a�0�5�5�*�	,�
6�
5�s�D�D
c�P���|jd��|j��d��fd�	}tjtd|�5|j	t
�5tjdd�ddd�ddd�|j�j�|j�j�|j�j�|j�jddu�|j�j�y#1swY��xYw#1swY��xYw)NTc�$��|dk(r�S|dk(r�SJ�rhrFris  ��r%r^z5TestCopyFile.test_w_source_close_fails.<locals>._open_rjr'r=r]r_rr`)rZrr3r�r�r rRr�rPr�rUrTrks  @@r%�test_w_source_close_failsz&TestCopyFile.test_w_source_close_failsYs�����)�)�D�/���9�9�;��	��
�
�v�v�u�
5��"�"�7�+����	�:�6�,�6�	
����(�(�)�����)�)�*�����)�)�*�����,�,�Q�/�4�7�8�������(�
,�+��6�
5�s$�D�D�3D�D	�D�D%N)r�r�r��objectrZrar_rarhrerlrorFr'r%rErEsy��*�v�*�$7��X�_�_�U�.�/�6�0�6�"�X�_�_�U�.�/�,�0�,�(�X�_�_�U�.�/�)�0�)r'rEc��eZdZdZed��Zed��Zd�Zejd��Z
d�Zd�Zd�Z
d	�Zej ej$d
k7d�d��Zy
)�TestCopyFileObji c�8�tt|j�yr*)rXr�FILESIZE��clss r%�
setUpClasszTestCopyFileObj.setUpClassss�������-r'c�h�tjt�tjt�yr*)rrurr�rus r%�
tearDownClasszTestCopyFileObj.tearDownClassws������ �����!r'c�6�tjt�yr*�rrur�rSs r%�tearDownzTestCopyFileObj.tearDown|�������!r'c#�K�ttd�5}ttd�5}||f��ddd�ddd�y#1swY�xYw#1swYyxYw�w�NrZr4�r=rr�rHs   r%�	get_fileszTestCopyFileObj.get_files�D����
�&�$�
�3��g�t�$���C�j� �%� �
�$�$�� �
��/�A�A�<�A�	A�A	�A�A�
Ac���t|d�5}t|d�5}|j|j�|j��ddd�ddd�y#1swY�xYw#1swYyxYwr�)r=r�r\)r�rxry�fsrc�fdsts     r%�assert_files_eqzTestCopyFileObj.assert_files_eq�sN��
�#�t�_���c�4��D�� � �����d�i�i�k�:�!��_� ����_�s"�
A&�/A�	A&�A#	�A&�&A/c��|j�5\}}tj||�ddd�|jtt
�y#1swY�$xYwr*)r�r��copyfileobjr�rr�rHs   r%�test_contentzTestCopyFileObj.test_content�s@��
�^�^�
��#�s����s�C�(�����V�W�-��
�s�A�Ac��|j�5\}}tj||�|jrJ�|jrJ�	ddd�y#1swYyxYwr*)r�r�r��closedrHs   r%�test_file_not_closedz$TestCopyFileObj.test_file_not_closed�sH��
�^�^�
��#�s����s�C�(��z�z�!�>��z�z�!�>�z��
�
�s�6A�Ac�(�|j�5\}}tj||�|j|j	�|j
�|j|j	�|j
�ddd�y#1swYyxYwr*)r�r�r�r��tellrtrHs   r%�test_file_offsetz TestCopyFileObj.test_file_offset�sb��
�^�^�
��#�s����s�C�(����S�X�X�Z����7����S�X�X�Z����7��
�
�s�A.B�Br�zWindows onlyc��tjjd�5}tjt
t�ddd�jsJ�|j|jddd�tjtj�d��5}|jd�ddd�j}|j!t"j$|�tjjd�5}tj|t�ddd�|j|jddd�tjtj�d��5}	ddd�|j}|j!t"j$|�tjjd�5}tj|t�ddd�|jrJ�|j'|t�y#1swY���xYw#1swY��mxYw#1swY��xYw#1swY��xYw#1swY�axYw)	Nzshutil._copyfileobj_readintorroiFrlsfoor)r_r�r�r�rRrr��calledr��	call_argsrqrrr+rsr>rgr�rrur�)r��mrVrs    r%�
test_win_implzTestCopyFileObj.test_win_impl�s����]�]�
 �
 �!?�
@�A��O�O�F�G�,�A��x�x��x�	
������Q���*�O�<��
(�
(�R�Y�Y�[��
G�1�
�G�G�F�O�H��������	�(�(�%�0�
�]�]�
 �
 �!?�
@�A��O�O�E�7�+�A�������Q���*�A�.��
(�
(�R�Y�Y�[��
G�1��H��������	�(�(�%�0�
�]�]�
 �
 �!?�
@�A��O�O�E�7�+�A��8�8��|����U�G�,�3A�
@��H�
G��A�
@��
H�
G��A�
@�s;�H� H�H*�3H7�I�H�H'�*H4�7I�IN)r�r�r�rt�classmethodrwryr|�
contextlib�contextmanagerr�r�r�r�r�r_rar+rgr�rFr'r%rrrrps����H��.��.��"��"�"����!��!�
;�
.�
"�8��X�_�_�R�W�W��_�n�5�-�6�-r'rrc��eZdZdZdZdZdZed��Zed��Z	d�Z
ejd��Z
d	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zy)�_ZeroCopyFileTestz#Tests common to all zero-copy APIs.i�r'r�c��tt|j�ttd�5}|j	�|_t
|j
�|jk(sJ�	ddd�y#1swYyxYwr�)rXrrtr=r\�FILEDATAr�)rvrVs  r%rwz_ZeroCopyFileTest.setUpClass�sP�������-�
�&�$�
�1��6�6�8�C�L��s�|�|�$����4�4�4� �
�
�s�:A/�/A8c�6�tjt�yr*)rrurrus r%ryz_ZeroCopyFileTest.tearDownClass�s������ r'c�6�tjt�yr*r{rSs r%r|z_ZeroCopyFileTest.tearDown�r}r'c#�K�ttd�5}ttd�5}||f��ddd�ddd�y#1swY�xYw#1swYyxYw�wrr�rHs   r%r�z_ZeroCopyFileTest.get_files�r�r�c��td��)Nzmust be implemented in subclass)r=)r�r#r$s   r%�zerocopy_funz_ZeroCopyFileTest.zerocopy_fun�s��!�"C�D�Dr'c��|j�|j�|j�|j�yr*)r|ryrwrprSs r%�resetz_ZeroCopyFileTest.reset�s*���
�
�����������
�
�r'c���|j�5\}}|j||�ddd�|jttd��|j
�|j�5\}}tjjd�5}tjtt�ddd�jrJ�	ddd�y#1swY��xYw#1swY�-xYw#1swYyxYw)NT�r@zshutil.copyfileobj)
r�r�r�r]r�r�r_r�r�r�rRrr�)r�rxryr�s    r%�test_regular_copyz#_ZeroCopyFileTest.test_regular_copy�s���
�^�^�
��#�s����c�3�'������7�4�8�$�-�-�H�
�^�^�
��#�s����$�$�%9�:�a������0�;��x�x��<�x��
�	�
��
;�:���
�s/�C�*#C$�
C�,C$�C�C!	�C$�$C-c�d�|j|j�|j�5\}}|jtt
f�5|j
||�ddd�ddd�|jttd��|j�y#1swY�=xYw#1swY�AxYw)NTr�)r�r�r�r�r rr�r�r]rr�rHs   r%�test_same_filez _ZeroCopyFileTest.test_same_file�s�������
�
�#�
�^�^�
��#�s��"�"�G�->�#?�@��!�!�#�s�+�A��	
����6�$�7����G�A�@���
�s#�B&�B�B&�B#	�B&�&B/c� �tjtj���}|j	t
�5}t
j|d�ddd�|jjj|�y#1swY�0xYw)Nr��new)rqr�r+rsr�r�r�rRr�r�r�)r�rgr�s   r%�test_non_existent_srcz'_ZeroCopyFileTest.test_non_existent_src�s]�����2�9�9�;�/��
�
�
�0�
1�R��O�O�D�%�(�2�������.�.��5�2�
1�s�B�B
c����tdz�tdz�|j�fd��|j�fd��t�d�5	ddd�t�d�5}t�d�5}|j||�ddd�ddd�|j	t�d��d	�y#1swY�cxYw#1swY�;xYw#1swY�?xYw)
Nrxryc�.��tj��Sr*�rru)rvs�r%rz3_ZeroCopyFileTest.test_empty_file.<locals>.<lambda>�����	� 0� 0�� 9r'c�.��tj��Sr*r�)rws�r%rz3_ZeroCopyFileTest.test_empty_file.<locals>.<lambda>�r�r'r4rZTr�r')rr�r=r�r�r])r�rxryrwrvs   @@r%�test_empty_filez!_ZeroCopyFileTest.test_empty_file�s�����5�.���5�.�����9�:����9�:�
�'�4�
 ��!��'�4�
 �C��g�t�$���!�!�#�s�+�%�!�	
����7�4�8�#�>�!�
 ��%�$��!�
 �s0�	B-�
C�,B9�?C�-B6�9C	�>C�Cc���tjj|jt��5|jttjtt�ddd�y#1swYyxYw)Nr)
r_r�r��
PATCHPOINT�ZeroDivisionErrorr�r�rRrr�rSs r%�test_unhandled_exceptionz*_ZeroCopyFileTest.test_unhandled_exceptionsS��
�]�]�
 �
 ����->�!�@����/�$�o�o�v�w�
@�@�@�@�s�/A(�(A1c�|�tjj|jt	t
jd���5|j�5\}}|jt�5|j||�ddd�ddd�ddd�y#1swY�xYw#1swY�xYw#1swYyxYw�N�yor)r_r�r�r�r r"�EINVALr�r�rr�rHs   r%�test_exception_on_first_callz._ZeroCopyFileTest.test_exception_on_first_calls����]�]�
 �
 ����-4�U�\�\�4�-H�!�J����!�Z�c�3��&�&�'8�9��%�%�c�3�/�:�"�J�J�:�9��"�!��J�J�s<�B2�B&�.B�B&�	B2�B#�B&�&B/	�+B2�2B;c�H�tjj|jt	t
jd���5|j�5\}}|jt|j||�ddd�ddd�y#1swY�xYw#1swYyxYwr�)
r_r�r�r�r r"�ENOSPCr�r�r�rHs   r%�test_filesystem_fullz&_ZeroCopyFileTest.test_filesystem_fulls���]�]�
 �
 ����-4�U�\�\�4�-H�!�J����!�Z�c�3��!�!�'�4�+<�+<�c�3�G�"�J�J�!�!��J�J�s$�B�&B�;B�B	�B�B!N)r�r�r��__doc__rtr�r�r�rwryr|r�r�r�r�r�r�r�r�r�r�r�r�rFr'r%r�r��s���-� �H��H��J��5��5��!��!�"����!��!�
E�� �H�6�?�@�0�Hr'r�zos.sendfile() not supportedc�F�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�TestZeroCopySendfile�os.sendfilec�.�tj||�Sr*)r��_fastcopy_sendfile)r�r�r�s   r%r�z!TestZeroCopySendfile.zerocopy_fun"s���(�(��t�4�4r'c��tj|j�5}ttd�5}|jt�5|j||�ddd�tj||�ddd�ddd�|jttd��|j�y#1swY�[xYw#1swY�IxYw#1swY�MxYw)Nr4Tr�)�io�BytesIOr�r=r�r�rr�r�r�r�r]rHs   r%�test_non_regular_file_srcz.TestZeroCopySendfile.test_non_regular_file_src%s���
�Z�Z��
�
�
&�#��g�t�$���&�&�'8�9��%�%�c�3�/�:��"�"�3��,�%�'�	
����7�4�8�$�-�-�H�	:�9��%�$��'�
&�s:�C�C�B4�C�8C�4B=�9C�C		�C�Cc��ttd�5}tj�5}|j	t
�5|j
||�ddd�tj||�|jd�|j|j�|j�ddd�ddd�y#1swY�kxYw#1swY�xYw#1swYyxYw)NrZr)
r=rr�r�r�rr�r�r��seekr�r\r�rHs   r%�test_non_regular_file_dstz.TestZeroCopySendfile.test_non_regular_file_dst.s���
�&�$�
�3�������&�&�'8�9��%�%�c�3�/�:��"�"�3��,������� � �����T�]�]�;�� �
�9�9����� �
�s:�C�C�B9�AC�(C�9C�>C�C	�
C�Cc�������fd�}g�tj�tjj	dd|��5|j�5\}}|j
t�5}tj||�ddd�ddd�ddd��sJ�|jjjtj�y#1swY�RxYw#1swY�VxYw#1swY�ZxYw)Nc�n���s�jd��|i|��Sttjd��)Nr�)rdr r"�EBADF)r#r$r��
orig_sendfiles  ��r%rkzDTestZeroCopySendfile.test_exception_on_second_call.<locals>.sendfile8s3�������D�!�$�d�5�f�5�5��e�k�k�4�0�0r'r�T)r�r)r+rkr_r�r�r�r�r r�r�r�r�r"r�)r�rkrxryr�r�r�s     @@r%�test_exception_on_second_callz2TestZeroCopySendfile.test_exception_on_second_call7s����	1������
�
�]�]�
 �
 ��t�-5�!�7����!�Z�c�3��&�&�w�/�2��-�-�c�3�7�0�"�7�
��t�������+�+�U�[�[�9�0�/��"�!��7�7�s;�C'�C�'C�>C�C'�C�C�C$	� C'�'C0c�h�tjjdt��5}|j	�5\}}tj||�|jsJ�	ddd�ddd�|jttd��|j�y#1swY�=xYw#1swY�AxYw)N�os.fstatrTr�)r_r�r�r r�r�r�r�r�r]r�r��r�r�rxrys    r%�test_cant_get_sizez'TestZeroCopySendfile.test_cant_get_sizeIs����]�]�
 �
 ���
 �
A�Q����!�Z�c�3��)�)�#�s�3��x�x��x�"�B�	
����7�4�8�$�-�-�H�"�!��B�
A�s"�B(�(B� B(�B%	�!B(�(B1c��tjj�}d|_tjj	d|��5}|j�5\}}t
j||�|jsJ�	ddd�ddd�|jttd��|j�y#1swY�=xYw#1swY�AxYw)Nir�r�Tr�)
r_r��Mock�st_sizer�r�r�r�r�r�r]r�r��r�r�r�rxrys     r%�test_small_chunksz&TestZeroCopySendfile.test_small_chunksSs���
�}�}�!�!�#�� ���
�]�]�
 �
 ��$�
 �
?�1����!�Z�c�3��)�)�#�s�3��x�x��x�"�@�	
����7�4�8�$�-�-�H�"�!��@�
?�s$�C	�(B=�C	�=C	�C	�	Cc���tjj�}|jdz|_tjjd|��5}|j
�5\}}tj||�|jsJ�	ddd�ddd�|jttd��|j�y#1swY�=xYw#1swY�AxYw)Ni@r�r�Tr�)r_r�r�rtr�r�r�r�r�r�r�r]r�r�r�s     r%�test_big_chunkz#TestZeroCopySendfile.test_big_chunk`s���
�}�}�!�!�#���}�}�(9�:���
�]�]�
 �
 ��$�
 �
?�1����!�Z�c�3��)�)�#�s�3��x�x��x�"�@�	
����7�4�8�$�-�-�H�"�!��@�
?�s$�C�%(C
�C�
C	�C�Cc��tjjdt��5}|j	tt
jtt�|jdd}|j|tjjt��tjt�t!tdd��|j#tjtdz�|j	tt
jttdz�|jdd}|j|d	�ddd�y#1swYyxYw)
Nr�rrrshelloTr��3i�)r_r�r�r�r�r�rRrr�r�r�r+r;rQrrurCr�)r�r��	blocksizes   r%�test_blocksize_argz'TestZeroCopySendfile.test_blocksize_argms���
�]�]�
 �
 ��->�!�@�CD����/�$�o�o�v�w�
@����A��q�)�I�
���Y�������(?�@����W�%��w���6��O�O�I�,�,�g��m�<����/�$�o�o�w��#�
�
G����A��q�)�I����Y��0�@�@�@�s�DE
�
Ec��tjsJ�	tjj	|j
t
tjd���5}|j�5\}}|jt�5tj||�ddd�ddd�|jsJ�	ddd�tjrJ�tjj	|j
�5}tjtt �|jrJ�	ddd�dt_y#1swY��xYw#1swY��xYw#1swY��xYw#1swY�9xYw#dt_wxYw)Nr�rT)r��_USE_CP_SENDFILEr_r�r�r�r r"�ENOTSOCKr�r�rr�r�rRrr�r�s    r%�test_file2file_not_supportedz1TestZeroCopySendfile.test_file2file_not_supporteds���&�&�&�&�	+����$�$��O�O� '����� =�%�?�BC��^�^�%��#�s��*�*�+<�=��1�1�#�s�;�>�&��x�x��x�
?��.�.�.�.����$�$�T�_�_�5�������0��8�8�#�|�8�6�'+�F�#�>�=��&�%��?�?��6�5��'+�F�#�sm�AE,�E�(E�D<�E� E�7AE,�:-E �(E,�<E�E�E	�
E�E�E,� E)�%E,�,
E9N)
r�r�r�r�r�r�r�r�r�r�r�r�r�rFr'r%r�r�s8���J�5�I�<�:�$I�I�I�1�$+r'r�z
macOS onlyc��eZdZdZd�Zy)�TestZeroCopyMACOSzposix._fcopyfilec�L�tj||tj�Sr*)r��_fastcopy_fcopyfile�posix�_COPYFILE_DATArHs   r%r�zTestZeroCopyMACOS.zerocopy_fun�s���)�)�#�s�E�4H�4H�I�Ir'N)r�r�r�r�r�rFr'r%r�r��s
��#�J�Jr'r�c� �eZdZd�Zd�Zd�Zejeje
jj��d�eje
ed�d�d���Zejej"d�d	��Zy
)�TestGetTerminalSizec��tj�}|j|jd�|j|jd�y)z�Check if get_terminal_size() returns a meaningful value.

        There's no easy portable way to actually check the size of the
        terminal, so let's check if it returns something sensible instead.
        rN)r��get_terminal_sizerS�columns�lines)r�rRs  r%�test_does_not_crashz'TestGetTerminalSize.test_does_not_crash�s:���'�'�)��������a�0�����
�
�A�.r'c��tj�5}d|d<|d=tj�}ddd�|j	j
d�tj�5}|d=d|d<tj�}ddd�|j	|jd�y#1swY�{xYw#1swY�2xYw)z.Check if environment variables have precedence�777�COLUMNS�LINESNi	�888ix)rr�r�r�r�r�r��r�r�rRs   r%�test_os_environ_firstz)TestGetTerminalSize.test_os_environ_first�s����
*�
*�
,��"�C�	�N��G���+�+�-�D�-�	
������s�+�
�
*�
*�
,���I�� �C��L��+�+�-�D�-�	
������S�)�-�
,��-�
,�s�B,�*B8�,B5�8Cc��tj�5}d|d<d|d<tj�}ddd�|j	j
d�|j	|jd�y#1swY�BxYw)Nrr��yyyr�r)rr�r�r�rSr�r�r�s   r%�test_bad_environz$TestGetTerminalSize.test_bad_environ�sh��
�
*�
*�
,��"�C�	�N� �C��L��+�+�-�D�-�	
������a�0�����
�
�A�.�-�
,�s�A5�5A>z
not on ttyr�zneed os.get_terminal_size()c��	tjddg�j�j�}td�t|d�f}tj�5}|d=|d=tj�}ddd�|j|�y#tt
tjf$r|jd�Y��wxYw#1swY�QxYw)	z�Check if stty returns the same results ignoring env

        This test will fail if stdin and stdout are connected to
        different terminals with different sizes. Nevertheless, such
        situations should be pretty rare.
        �sttyrRzstty invocation failedr�rr�r�N)r�r�r�r�r�r�r�r�r�rr�r�r�r�)r�rRr&r�rss     r%�test_stty_matchz#TestGetTerminalSize.test_stty_match�s���	4��*�*�F�F�+;�<�C�C�E�K�K�M�D���Q��L�#�d�1�g�,�/��
�
*�
*�
,���G���I���-�-�/�F�-�
	
����6�*��"�?��-�-�/�	4��M�M�2�3�	4��
-�
,�s�3B�%C�/C
�C
�CzWASI has no /dev/nullc��tj�5}|d=|d=tjtdd�5tjd��}ddd�|jjd�|j|jd�ttjdd	�
�5}tjtd|�5tjd��}ddd�ddd�|j|jd�|j|jd
�ddd�y#1swY��xYw#1swY�^xYw#1swY�bxYw#1swYyxYw)Nr�r��
__stdout__)rW�)�fallbackrWr�r5r6r7)�rVrrV)
rr�rr3r�r�r�r�r�r�r=r+�devnull)r�r�rRrVs    r%�
test_fallbackz!TestGetTerminalSize.test_fallback�s��
�
*�
*�
,���G���I���"�"�3��d�;��/�/��B��<����T�\�\�2�.����T�Z�Z��,��b�j�j�#��8�A��"�"�3��a�8��/�/��B��9�9�
���T�\�\�2�.����T�Z�Z��,�!-�
,�
<�;��9�8��9�8��-�
,�sT�"E�D.�AE�*E�D:�E�%AE�.D7	�3E�:E�?E�E	�E�EN)r�r�r�r�r�r�r_r`r+�isattyr�r�rtrpr�rar�is_wasirrFr'r%r�r��s���/�
*�/��X�������3�>�>�#8�#8�#:�;�\�J��X�����%8�9�6�8�+�8�K�+�*�X�_�_�W�_�_�&=�>�-�?�-r'r�c��eZdZdZd�Zy)�PublicAPITestsz>Ensures that the correct values are exposed in the public API.c��|jttd��gd�}ttd�stjdk(r|jd�|j
ttj�t|��y)N�__all__)r�rRr�rr6r;rnr�r�rrZ�	ExecErrorrrrrrr	rrr�rVrIr�r
�statvfsr�rN)	r�rpr�r+rgrdr�r�r	)r��
target_apis  r%�test_module_all_attributez(PublicAPITests.test_module_all_attribute�s]�������	�2�3�<�
��2�y�!�R�W�W��_����l�+�����V�^�^�,�c�*�o�>r'N)r�r�r�r�r
rFr'r%rr�s
��H�?r'r�__main__)F)Wr_�
unittest.mockr�rqr�r�r+�os.pathr"r0r�r�rLrNr�r�rrrrrrr	r
rrr
rrm�warningsr�r��ImportErrorr�r�test.supportr�test.support.os_helperrrrr�rArBrbr�rhrir�r�r�r�r�r�r��AssertionErrorr�r&r2rCrXr]rer|�SUPPORTS_SENDFILEr�r��TestCaser�rfr�rkrMrer�r�rErrrpr�rar�r�r�rr��mainrFr'r%�<module>rs����
��
��	������
�
��	�6�6�6�6�������"�3�(�
�3�,��
�f�_�
�
�f�_�
�������)��

�,�,�
!�
!�'�
*��	�l�l�2�A��%�������O����=�=���z�"�#>�?��A��L�	��)�$�
�&�:0�1���	�	�}"��8�,�,�}"�@`2�8�X�.�.�`2�DC?�x��*�*�C?�L@	8�8�X�.�.�@	8�FM+�x��*�*�M+�`xL��(�+�+�xL�v	�Y��&L-�x��*�*�L-�^Y)�8�$�$�Y)�xG-�h�'�'�G-�TaH��aH�H����&�&�(E�F�s+�,�h�.?�.?�s+�G�s+�l����U��L�)�J�)�8�+<�+<�J�*�J�L-�(�+�+�L-�^?�X�&�&�?�$�z���H�M�M�O���Ag���E���$���O���
���G��s6�*J3� 
K�+K�3J>�=J>�K�K�K�K

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists