Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_shutil.cpython-311.pyc
�

�KeZ����ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZmZmZmZmZmZmZmZmZmZmZmZddlZddlZ	ddlZn
#e$rdZYnwxYwddl m!Z!ddl"m#Z#ddl$m%Z%m&Z&e%dzZ'e%dzZ(e%dzZ)ej*�+d	��Z,ej*�+d
��Z-ej*dd�dkZ.	ddl/Z/ddl0Z0d
Z1n
#e$rdZ1YnwxYw	ddl2Z2n
#e$rdZ2YnwxYwej3�4de5d�����Z6d�Z7d�Z8d=d�Z9d�Z:d=d�Z;d�Z<d�Z=e=��Z>d�Z?Gd�d��Z@Gd�de@ejA��ZBGd�de@ejA��ZCGd �d!e@ejA��ZDGd"�d#e@ejA��ZEGd$�d%e@ejA��ZFGd&�d'e@ejA��ZGGd(�d)eG��ZHGd*�d+e@ejA��ZIGd,�d-ejA��ZJGd.�d/ejA��ZKGd0�d1eL��ZMejNe>d2��Gd3�d4eMejA����ZOejNe,d5��Gd6�d7eMejA����ZPGd8�d9ejA��ZQGd:�d;ejA��ZReSd<krejT��dSdS)>�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�2�_SRC�_DST�darwin�sunos��aixTFzos.chdirzshouldn't call os.chdir()��side_effectc�J�tttdd��d���)N�EXDEV�zInvalid cross-device link)�OSError�getattr�errno)�args�kwargss  �:/usr/local/apps/python3/lib/python3.11/test/test_shutil.py�_fake_renamer%9s��
�'�%��"�-�-�/J�
K�
K�K�c�F��tj����fd���}|S)Nc���	tj}tt_�|i|��|t_S#|t_wxYw�N)�os�renamer%)r"r#�builtin_rename�funcs   �r$�wrapzmock_rename.<locals>.wrap>sD���	'��Y�N�$�B�I��4��(��(�(�&�B�I�I���B�I�&�&�&�&s	�$4�A)�	functools�wraps)r-r.s` r$�mock_renamer1=s8����_�T���'�'�'�'���'��Kr&c���t|t��rtjj|�}|rdnd}|rdnd}t|||���5}|�|��ddd��dS#1swxYwYdS)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�moder7�fps      r$�
write_filerBHs����$����#��w�|�T�"���"�4�4�s�D��*�t�t�7�H�	
�d�D�8�	,�	,�	,���
���������������������������s�A*�*A.�1A.c�h�d�}t|d��}d�d�t|��D����}t|d��5}|||��D]}|�|���	ddd��n#1swxYwYt
j�|��|ksJ�dS)zBCreate a test file with an arbitrary size and random text content.c3�TK�||ksJ�||kr|V�||z}||k�|r|V�dSdSr)�)�total�steps  r$�chunkszwrite_test_file.<locals>.chunksXsZ������}�}�}�}��d�l�l��J�J�J��T�M�E��d�l�l��	��K�K�K�K�K�	�	r&i r&c�n�g|]2}tjtj�������3SrE)�random�choice�string�
ascii_letters�encode)�.0�is  r$�
<listcomp>z#write_test_file.<locals>.<listcomp>asA��/�/�/���m�F�$8�9�9�@�@�B�B�/�/�/r&r3N)�minr;�ranger<r=r*r:�getsize)r:�sizerH�bufsize�chunk�f�csizes       r$�write_test_filerZVs������$��o�o�G��H�H�/�/�$�W�~�~�/�/�/�
0�
0�E�	
�d�D�	�	��Q��V�D�'�*�*�	�	�E�
�G�G�E�N�N�N�N�	��������������������7�?�?�4� � �D�(�(�(�(�(�(s�%B�B�	Bc���t|t��rtjj|�}|rdnd}|rdnd}t|||���5}|���cddd��S#1swxYwYdS)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�rNr5r6)r8r9r*r:r;r<�read)r:r?r@r7rAs     r$�	read_filer_hs����$����#��w�|�T�"���"�4�4�s�D��*�t�t�7�H�	
�d�D�8�	,�	,�	,����w�w�y�y���������������������s�A(�(A,�/A,c���g}ttj|����D]�}tj�||��}tj�|��retj�|��sF|�|dz��t|��D]}|�|dz|z�����|�|����|S)N�/)	�sortedr*�listdirr:r;�isdir�islink�append�rlistdir)r:�res�name�p�ns     r$rgrgvs���
�C��r�z�$�'�'�(�(�����G�L�L��t�$�$��
�7�=�=����	�B�G�N�N�1�$5�$5�	��J�J�t�c�z�"�"�"��a�[�[�
+�
+���
�
�4�#�:��>�*�*�*�*�
+�
�J�J�t������Jr&c�6�ttd��sdSd}d}	tjdtj��d���5}|j}|�d��ddd��n#1swxYwYt|d��5}tjdtj��d���5}|j}|���}|���}	tj	||dd��	ddd��ddd��|�tj|��|�tj|��d	Sd	S#t$rHYddd��ddd��|�tj|��|�tj|��dSdSwxYw#1swxYwY	ddd��n#1swxYwY|�tj|��|�tj|��dSdS#|�tj|��|�tj|��wwxYw)
N�sendfileFr3��dir�deletes
0123456789r\r�T)
�hasattrr*�tempfile�NamedTemporaryFile�getcwdrir=r<�filenormr�unlinkr)�srcname�dstnamerX�src�dst�infd�outfds       r$�supports_file2file_sendfiler~�s8���2�z�"�"���u��G��G�&�
�
(��2�9�;�;�u�
M�
M�
M�	#�QR��f�G�
�G�G�M�"�"�"�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#����	#�	#�	#�	#��'�4�
 �
 �
	 �C��,�T�r�y�{�{�5�Q�Q�Q�	
 �UX��(���z�z�|�|���
�
���� ��K��t�Q��2�2�2� �	
 �	
 �	
 �	
 �	
 �	
 �
	 �
	 �
	 �
	 �
	 �
	 �����W�%�%�%�����W�%�%�%�%�%�����!�!�!� �	
 �	
 �	
 �	
 �	
 �	
 �
	 �
	 �
	 �
	 �
	 �
	 �����W�%�%�%�����W�%�%�%�%�%���!����
	
 �	
 �	
 �	
 ����	
 �	
 �	
 �	
 �	
 �
	 �
	 �
	 �
	 �
	 �
	 �
	 �
	 �
	 �
	 �
	 ����
	 �
	 �
	 �
	 �����W�%�%�%�����W�%�%�%�%�%��������W�%�%�%�����W�%�%�%�%����s��(G)�A.�"G)�.A2�2G)�5A2�6G)�	)F.�20F�#E�:F�;F.�G)�
F�F�F.�G)�F�F�F	�F.�F	�F.�"G)�.F2�2G)�5F2�6G)�)/Hc��trxtjdkrhtjdtjz��}|�d��d���d}t|d��dkSdS)	Ni���z/usr/bin/dump -o %s�
�����i T)�AIX�sys�maxsize�
subprocess�	getoutput�
executable�split�int)�hdrs�maxdatas  r$�
_maxdataOKr��sm��
��s�{�j�(�(�
�
!�"7�#�.�"H�
I�
I���
�
�4� � ��$�*�*�,�,�Q�/���7�2���*�,�,��tr&c��eZdZdd�ZdS)�BaseTestNc��tj|tj�����}|�t
j|��|S)zjCreate a temporary directory that will be cleaned up.

        Returns the path of the directory.
        )�prefixro)rs�mkdtempr*ru�
addCleanupr�rmtree)�selfr��ds   r$r�zBaseTest.mkdtemp�s;��

��F��	���<�<�<�����	�(�!�,�,�,��r&r))�__name__�
__module__�__qualname__r�rEr&r$r�r��s(�����������r&r�c�4�eZdZd�Zejd���Zejd���Zej	e
d��d���Zej	e
d��d���Zd�Z
ejejdd	�d
kd��ejejd�������Zd
�Zd�Zd�Zej	ejd��d���Zejejd��d���Zd�Zejd���Zej	e
d��d���ZdS)�
TestRmTreec�x�|���}tj�|d��}tj|��ttj�|d��d��tj|��}|�|t��tj
|��dS)N�killme�somefile�foo)r�r*r:r;�mkdirrB�fsencode�assertIsInstance�bytes�shutilr�)r��tmp�victims   r$�test_rmtree_works_on_bytesz%TestRmTree.test_rmtree_works_on_bytes�s����l�l�n�n������c�8�,�,��
�������2�7�<�<��
�3�3�U�;�;�;���V�$�$�����f�e�,�,�,��
�f�����r&c���|���}tj�|d��}tj|��tj�|d��}tj||��|�ttj	|��|�
tj�|����|�
tj�|����g��fd�}tj	||���|�
t���d��|��ddtjj��|�
�dd|��|��dddt��dS)Nro�linkc�2����|��dSr)�rf�r"�errorss �r$�onerrorz8TestRmTree.test_rmtree_fails_on_symlink.<locals>.onerror������M�M�$�����r&�r�r�rrq)r�r*r:r;r��symlink�assertRaisesrr�r��
assertTrue�exists�lexists�assertEqual�len�assertIsrer��r�r��dir_r�r�r�s     @r$�test_rmtree_fails_on_symlinkz'TestRmTree.test_rmtree_fails_on_symlink�sh����l�l�n�n���w�|�|�C��'�'��
�������w�|�|�C��(�(��
�
�4��������'�6�=�$�7�7�7��������t�,�,�-�-�-���������-�-�.�.�.���	 �	 �	 �	 �	 ��
�d�G�,�,�,�,�����V���a�(�(�(��
�
�f�Q�i��l�B�G�N�3�3�3�������1��t�,�,�,����f�Q�i��l�1�o�w�7�7�7�7�7r&c��|���}tj�|d��}tj�|d��}tj�|d��}|||fD]}tj|���tj�|d��}t|d��tj�|d��}tj||��tj�|d��}tj||��tj�|d��}	tj||	��tj|��|�	tj�
|����|�tj�
|����|�tj�
|����dS�	N�dir1�dir2�dir3�file1r��link1�link2�link3)r�r*r:r;r�rBr�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�s����l�l�n�n���w�|�|�C��(�(���w�|�|�D�&�)�)���w�|�|�C��(�(���t�T�!�	�	�A��H�Q�K�K�K�K�����S�'�*�*���5�%� � � �����T�7�+�+��
�
�4���������T�7�+�+��
�
�4���������T�7�+�+��
�
�5�%� � � ��
�d������������-�-�.�.�.��������t�,�,�-�-�-��������u�-�-�.�.�.�.�.r&zonly relevant on Windowsc����|���}tj�|d��}tj|��tj�|d��}tj||��|�tj	|��|�
ttj
|��|�tj�|����|�tj�|����g��fd�}tj
||���|�t%���d��|��ddtjj��|��dd|��|��dddt��dS)Nror�c�2����|��dSr)r�r�s �r$r�z:TestRmTree.test_rmtree_fails_on_junctions.<locals>.onerror�r�r&r�r�rrq)r�r*r:r;r��_winapi�CreateJunctionr�rrwr�rr�r�r�r�r�r�r�r�rer�r�s     @r$�test_rmtree_fails_on_junctionsz)TestRmTree.test_rmtree_fails_on_junctions�s�����l�l�n�n���w�|�|�C��'�'��
�������w�|�|�C��(�(����t�T�*�*�*����	�(�$�/�/�/����'�6�=�$�7�7�7��������t�,�,�-�-�-���������-�-�.�.�.���	 �	 �	 �	 �	 ��
�d�G�,�,�,�,�����V���a�(�(�(��
�
�f�Q�i��l�B�G�N�3�3�3�������1��t�,�,�,����f�Q�i��l�1�o�w�7�7�7�7�7r&c��|���}tj�|d��}tj�|d��}tj�|d��}|||fD]}tj|���tj�|d��}t|d��tj�|d��}t
j||��tj�|d��}t
j||��tj�|d��}	t
j||	��tj	|��|�
tj�|����|�tj�|����|�tj�|����dSr�)
r�r*r:r;r�rBr�r�r�r�r�r�r�r�s
          r$�test_rmtree_works_on_junctionsz)TestRmTree.test_rmtree_works_on_junctionss����l�l�n�n���w�|�|�C��(�(���w�|�|�D�&�)�)���w�|�|�C��(�(���t�T�!�	�	�A��H�Q�K�K�K�K�����S�'�*�*���5�%� � � �����T�7�+�+����t�U�+�+�+�����T�7�+�+����t�U�+�+�+�����T�7�+�+����u�e�,�,�,��
�d������������-�-�.�.�.��������t�,�,�-�-�-��������u�-�-�.�.�.�.�.r&c�:��tj|������}|�tt
j|��tj|d���|���}t|dfd��tj	�
|d��}|�t��5}tj|��ddd��n#1swxYwY|�|j
j|��|�tj	�|����tj|d���|�tj	�|����g��fd�}tj||���|�t#���d��|��d	d	tj��|��d	d
|��|��d	dd
t��|��d	dd
j|��|��d
d	tj��|��d
d
|��|��d
dd
t��|��d
dd
j|��dS)N�roT��
ignore_errors�tstfile�c�2����|��dSr)r�r�s �r$r�z.TestRmTree.test_rmtree_errors.<locals>.onerror+r�r&r�rqrr�)rs�mktempr�r��FileNotFoundErrorr�r�rBr*r:r;�NotADirectoryErrorr��	exception�filenamer�r�r�r��scandirr��rmdir)r�r��tmpdir�cmr�r�s     @r$�test_rmtree_errorszTestRmTree.test_rmtree_errorss�����?�t�|�|�~�~�6�6�6�����+�V�]�H�E�E�E��
�h�d�3�3�3�3��������F�I�&��+�+�+��7�<�<��	�2�2��
�
�
�1�
2�
2�	$�b��M�(�#�#�#�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$����	$�	$�	$�	$������.��9�9�9��������x�0�0�1�1�1��
�h�d�3�3�3�3��������x�0�0�1�1�1���	 �	 �	 �	 �	 ��
�h��0�0�0�0�����V���a�(�(�(��
�
�f�Q�i��l�B�J�/�/�/�������1��x�0�0�0����f�Q�i��l�1�o�/A�B�B�B�������1��a��1�8�<�<�<��
�
�f�Q�i��l�B�H�-�-�-�������1��x�0�0�0����f�Q�i��l�1�o�/A�B�B�B�������1��a��1�8�<�<�<�<�<s�C&�&C*�-C*N��cygwinz2This test can't be run on Cygwin (issue #1071513).c�z�d|_tjt��|�t
jt��tj�td��|_	tj�td��|_
tj|j	��tj|j
��tj
t��j}tj
|j	��j}tj
|j
��j}tjtjz}tj|j	|��tj|j
|��tjt|��|�tjt|��|�tj|j	|��|�tj|j
|��tjt|j���|�|jdd��dS)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_error9s���
���
����������
�v�.�.�.�!�w�|�|�F�C�8�8��� �g�l�l�6�3�7�7����#�D�$8�9�9�9�
���$�%�%�%��w�v���.�� �g�d�&:�;�;�C���W�T�%8�9�9�A���<���,��
���%�x�0�0�0�
���$�h�/�/�/�
����"�"�"������&�,�7�7�7������$�"6�8K�L�L�L������$�"5�7I�J�J�J��
�f�d�&@�A�A�A�A������!�L�	N�	N�	N�	N�	Nr&c��|jdkr�|tjur|�||j��nl|tjur|�||j��nB|�|tj��|�	|t|jg��|�t|dt����|xjdz
c_dS|�|tj��|�|t��|�t|dt����d|_dS)Nrqrr�r)r�r*rwr�r�r�r�r�rc�assertInrr��
issubclassr)r�r-�arg�excs    r$r�z TestRmTree.check_args_to_onerrorXs"���?�Q����r�y� � �� � ��d�&:�;�;�;�;����!�!�� � ��d�&9�:�:�:�:��
�
�d�B�J�/�/�/��
�
�c�F�D�,?�#@�A�A�A��O�O�J�s�1�v�w�7�7�8�8�8��O�O�q� �O�O�O�O����T�2�8�,�,�,����S�&�)�)�)��O�O�J�s�1�v�w�7�7�8�8�8��D�O�O�Or&c���	tj��fd�}|t_tjt��t	tdfd��tjt���t_dS#�t_wxYw)Nc�L��|tkrt����|��Sr))rr)�fnr"r#�
orig_lstats   �r$�raiserzFTestRmTree.test_rmtree_does_not_choke_on_failing_lstat.<locals>.raiservs#�����<�<�!�)�)�O�%�:�b�>�>�)r&r�)r*�lstatr�rrBr�r�)r�r�r�s  @r$�+test_rmtree_does_not_choke_on_failing_lstatz6TestRmTree.test_rmtree_does_not_choke_on_failing_lstatss����
	"���J�
*�
*�
*�
*�
*�
�B�H��H�V���������.�.�.��M�&�!�!�!�!�B�H�H�H��z�B�H�!�!�!�!s�A&A7�7Bc�b��tjtjtjtjhtjko/tjtjvotjtjv}|r�|�	tj��|�	tjj
��|���}tj�|d��}tj|��	tj}Gd�dt&����fd�}|t_|��tj|��|t_dS#|t_wxYw|�tj��|�tjj
��dS)Nr�c��eZdZdS)�HTestRmTree.test_rmtree_uses_safe_fd_version_if_available.<locals>.CalledN)r�r�r�rEr&r$�Calledr�s�������r&rc�����r)rE)r"r#rs  �r$�_raiserzITestRmTree.test_rmtree_uses_safe_fd_version_if_available.<locals>._raiser�s��� �Lr&)r*r<r�rwr��supports_dir_fdrc�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_rmtreerrs      @r$�-test_rmtree_uses_safe_fd_version_if_availablez8TestRmTree.test_rmtree_uses_safe_fd_version_if_available�sn��� �g�r�w��	�2�8�D��/�0�D��Z�2�>�9�D� �W��(C�C�	��	C��O�O�F�4�5�5�5��O�O�F�M�@�A�A�A��l�l�n�n�G�����W�c�*�*�A��H�Q�K�K�K�
5�$�4��-�-�-�-�-�Y�-�-�-�!�!�!�!�!�)0��&��!�!�&�&�-��;�;�;�)4��&�&�&����&�4�4�4�4����V�5�6�6�6����V�]�A�B�B�B�B�Bs
�<AE�E)zdir_fd is not supportedc���|���}d}tj�||��}tj|tj��}|�tj|��tj|��tjtj�|d����ttj�|dd��d��|�
tj�|����tj
||���|�tj�|����dS)Nr��subdirr�r���dir_fd)r�r*r:r;r<�O_RDONLYr��closer�rBr�r�r�r�r�)r�rr��fullnamers     r$�test_rmtree_with_dir_fdz"TestRmTree.test_rmtree_with_dir_fd�s���,�,�.�.�����7�<�<���0�0�����"�+�.�.�������&�)�)�)�
������
������h��1�1�2�2�2��2�7�<�<��(�J�?�?��G�G�G��������x�0�0�1�1�1��
�f�V�,�,�,�,���������1�1�2�2�2�2�2r&zdir_fd is supportedc�"�|���}|�t��5tj|d���ddd��n#1swxYwY|�tj�|����dS)Nrr)	r�r��NotImplementedErrorr�r�r�r*r:r�)r�rs  r$�#test_rmtree_with_dir_fd_unsupportedz.TestRmTree.test_rmtree_with_dir_fd_unsupported�s����,�,�.�.��
�
�
�2�
3�
3�	-�	-��M�'�!�,�,�,�,�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-����	-�	-�	-�	-��������w�/�/�0�0�0�0�0s�A�A�Ac��tj|������\}}tj|��|�ttj|��tj	|��dS�Nr�)
rs�mkstempr�r*rr�r�r�r��remove)r��handler:s   r$�test_rmtree_dont_delete_filez'TestRmTree.test_rmtree_dont_delete_file�s]���'�D�L�L�N�N�;�;�;����
���������,�f�m�T�B�B�B�
�	�$�����r&c��tjt��	tj�td��}tj�td��}tj|��tj||��|�ttj	|��tj	|d���tj	td���dS#tj	td���wxYw)N�cheese�shopTr�)
r*r�rr:r;r�r�rr�r��r�rzr{s   r$�test_rmtree_on_symlinkz!TestRmTree.test_rmtree_on_symlink�s���	������	6��'�,�,�v�x�0�0�C��'�,�,�v�v�.�.�C��H�S�M�M�M��J�s�C� � � ����g�v�}�c�:�:�:��M�#�T�2�2�2�2��M�&��5�5�5�5�5�5��F�M�&��5�5�5�5�5���s�B/C'�'Dc��tjt��	tj�td��}tj�td��}tj|��ttj�|d��d�����tj||��|�	ttj|��tj|d���tjtd���dS#tjtd���wxYw)Nr#r$�spamr3Tr�)
r*r�rr:r;r<rr�r�r�rr�r�r%s   r$�test_rmtree_on_junctionz"TestRmTree.test_rmtree_on_junction�s���
������		6��'�,�,�v�x�0�0�C��'�,�,�v�v�.�.�C��H�S�M�M�M������c�6�*�*�D�1�1�7�7�9�9�9��"�3��,�,�,����g�v�}�c�:�:�:��M�#�T�2�2�2�2��M�&��5�5�5�5�5�5��F�M�&��5�5�5�5�5���s�C/D'�'E)r�r�r�r�r�skip_unless_symlinkr�r��unittest�
skipUnlessr�r�r�r��skipIfr��platform�skip_if_dac_override�skip_unless_working_chmodr�r�rrr�r
rrr!r&r)rEr&r$r�r��s����������"�8�8�#�"�8�$�"�/�/�#�"�/�*�X���"<�=�=�8�8�>�=�8�&�X���"<�=�=�/�/�>�=�/�*=�=�=�B�X�_�S�\�"�1�"�%��1�I�K�K��#��(�N�N�)�(�$�#�K�K�N�6 � � �6"�"�"� C�C�C�0�X���1�3L�M�M�3�3�N�M�3��X�_�V�-�/D�E�E�1�1�F�E�1�����"�6�6�#�"�6��X���"<�=�=�6�6�>�=�6�6�6r&r�c��eZdZd�Zd�Zejd���Zd�Zd�Z	d�Z
ej�
d��d���Zd	�Zejeed
��d��ejejejdkd
��d�������Zd�Zejd���Zejd���Zd�Zd�ZdS)�TestCopyTreec	��|���}tj�|���d��}|�t
j|��|�t
jtj�|����t|dfd��tj	tj�|d����t|ddfd��tj
||��|�tj�tj�|d������|�tj�
tj�|d������|�tj�tj�|dd������t|df��}|�|d��t|ddf��}|�|d��dS)N�destination�test.txt�123�test_dir�456)r�r*r:r;r�r�r��dirnamerBr��copytreer��isfilerdr_r��r��src_dir�dst_dir�actuals    r$�test_copytree_simplez!TestCopyTree.test_copytree_simple�s����,�,�.�.���'�,�,�t�|�|�~�~�}�=�=������
�w�/�/�/�����
�r�w���w�'?�'?�@�@�@��G�Z�(�%�0�0�0�
������g�z�2�2�3�3�3��G�Z��4�e�<�<�<�����)�)�)��������r�w�|�|�G�Z�'H�'H�I�I�J�J�J������
�
�b�g�l�l�7�J�&G�&G�H�H�I�I�I��������r�w�|�|�G�Z�4>�(@�(@�A�A�	B�	B�	B��G�Z�0�1�1�������'�'�'��G�Z��<�=�=�������'�'�'�'�'r&c	�P�|���}|���}|�tj|��|�tj|��t	|dfd��tjt
j�|d����tjt
j�|d����t	|ddfd��t	|ddfd��tj	||d���|�
t
j�t
j�|d������|�
t
j�t
j�|d������|�
t
j�t
j�|dd������t|df��}|�|d��t|ddf��}|�|d��|�t ��5tj	||d	���ddd��dS#1swxYwYdS)
Nznonexisting.txtr6�existing_dirzexisting.txtzwill be replacedzhas been replacedT)�
dirs_exist_okF)r�r�r�r�rBr*r�r:r;r:r�r;rdr_r�r��FileExistsErrorr<s    r$�test_copytree_dirs_exist_okz(TestCopyTree.test_copytree_dirs_exist_ok�s����,�,�.�.���,�,�.�.������
�w�/�/�/�����
�w�/�/�/��G�.�/��7�7�7�
������g�~�6�6�7�7�7�
������g�~�6�6�7�7�7��G�^�^�<�>P�Q�Q�Q��G�^�^�<�>Q�R�R�R������=�=�=�=��������r�w�|�|�G�=N�'O�'O�P�P�Q�Q�Q������
�
�b�g�l�l�7�N�&K�&K�L�L�M�M�M��������r�w�|�|�G�^�4B�(D�(D�E�E�	F�	F�	F��G�%6�7�8�8�������'�'�'��G�^�^�D�E�E������!4�5�5�5�
�
�
��
/�
/�	C�	C��O�G�W�E�B�B�B�B�	C�	C�	C�	C�	C�	C�	C�	C�	C�	C�	C�	C����	C�	C�	C�	C�	C�	Cs�6J�J�"Jc	��|���}tj�|d��}tj�|d��}tj�|d��}tj|��tj|��t|dfd��tj�|d��}tj�|d��}tjtj�|d��|��ttd��r,tj|tj
tjz��ttd	��r4ttd
��rtj|tj
��tj|��}tj||d���|�tj�tj�|dd������tjtj�|dd����}tjd
kr|�d��r
|dd�}|�|tj�|d����tj|��}	ttd��r |�|	j|j��ttd	��r"|�|	j|j��dSdS)Nrzr{�subzfile.txtr�r�zsub/link�lchmod�lchflags�	UF_NODUMPT��symlinks�ntz\\?\�)r�r*r:r;r�rBr�rrrHr��S_IRWXU�S_IRWXOrIrJr�r�r:r�re�readlinkri�
startswithr�r��st_flags)
r�rr=r>�sub_dir�src_link�dst_link�src_statr?�dst_stats
          r$�test_copytree_symlinksz#TestCopyTree.test_copytree_symlinkss����,�,�.�.���'�,�,�w��.�.���'�,�,�w��.�.���'�,�,�w��.�.��
������
�������G�Z�(�%�0�0�0��7�<�<���0�0���7�<�<���4�4��
�
�2�7�<�<���4�4��	�	�	��2�x� � �	=��I�h���t�|� ;�<�<�<��2�z�"�"�	2�w�t�[�'A�'A�	2��K��$�.�1�1�1��8�H�%�%������4�8�8�8�8��������r�w�|�|�G�U�F�'K�'K�L�L�M�M�M���R�W�\�\�'�5�&�A�A�B�B���7�d�?�?�v�0�0��;�;�?��A�B�B�Z�F���������g�z�!B�!B�C�C�C��8�H�%�%���2�x� � �	A����X�-�x�/?�@�@�@��2�z�"�"�	C����X�.��0A�B�B�B�B�B�	C�	Cr&c
�0�tjj}tjj}|���}	||���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	|||���|�
|||d������|�|||d������|�|||d������tj|��n#tj|��wxYw	tjdd
��}tj	|||���|�|||d������|�|||dd	������|�|||dd������tj|��n#tj|��wxYw	d�}tj	|||���|�|||dd	d
������|�|||dd������tj|��n#tj|��wxYw	tj|��tjtj�
|����dS#tj|��tjtj�
|����wxYw)Nr4r5r6ztest.tmpr7r8�	test_dir2r�subdir2ztest.pyz*.tmp��ignorezsubdir*c�r�g}|D]�}tj�||��}tj�|��r4|���ddkr|�|���utj�|��ddvr|�|����|S)Nr�rz.py)r*r:r;rdr�rf�splitext)rz�namesrhrir:s     r$�_filterz8TestCopyTree.test_copytree_with_exclude.<locals>._filterJs����C� %�-�-��!�w�|�|�C��6�6���G�M�M�$�/�/�-� �J�J�L�L��,��8�8��J�J�t�,�,�,�,��W�-�-�d�3�3�B�7�E�B�B��J�J�t�,�,�,���Jr&)r*r:r;r�r�rBr�r��ignore_patternsr:r�r�r�r9)r�r;r�r=r>�patternsrbs       r$�test_copytree_with_excludez'TestCopyTree.test_copytree_with_exclude"s���w�|�������,�,�.�.��:	4��d�4�<�<�>�>�=�9�9�G����,�e�4�4�4����,�e�4�4�4��H�T�T�'�:�.�.�/�/�/����Z�8�%�@�@�@��H�T�T�'�;�/�/�0�0�0����j�9�5�A�A�A��H�T�T�'�;��9�9�:�:�:��H�T�T�'�;�	�:�:�;�;�;����h�
�C�U�K�K�K����i��C�U�K�K�K�
'�!�1�'�;�G�G�������B�B�B�B������t�t�G�Z�'@�'@� A� A�B�B�B�� � �����W�j�(A�(A�!B�!B�C�C�C�� � �����W�k�(B�(B�!C�!C�D�D�D��
�g�&�&�&�&���
�g�&�&�&�&����
'�!�1�'�9�E�E�������B�B�B�B�� � �����W�j�(A�(A�!B�!B�C�C�C�� � �����W�k�9�(M�(M�!N�!N�O�O�O�� � �����W�k�8�(L�(L�!M�!M�N�N�N��
�g�&�&�&�&���
�g�&�&�&�&����
'�
�
�
������A�A�A�A�� � �����W�k�9�-6�)8�)8�"9�"9�:�:�:�� � �����W�k�8�(L�(L�!M�!M�N�N�N��
�g�&�&�&�&���
�g�&�&�&�&����&��M�'�"�"�"��M�"�'�/�/�'�2�2�3�3�3�3�3��
�M�'�"�"�"��M�"�'�/�/�'�2�2�3�3�3�3���sX�D
O�B$G<�'O�<H�O�B&K�<O�K'�'O�+A-M-�O�-N�O�APc
�����tjj}tjj}����}||d��}tj||����tj||d����tjtj�|dd����t
|dddfd��g���fd�}|����d��}tj|||�����	|||ddd������|����d��}tjtj|��||�����	|||ddd������|����d��}ttj
|����d	}��|tj��tj|||�����	|||ddd��������t#���d
��dS)N�sourcer7rr5r8c�X����|����|t����|t����t|��tt
|������|D]}��|t���gSr))rfr��str�listr�r��set)rzrari�invokationsr�s   ��r$�_ignorez?TestCopyTree.test_copytree_arg_types_of_ignore.<locals>._ignoreqs�������s�#�#�#��!�!�#�s�+�+�+��!�!�%��.�.�.����S��Z�Z��S��Z�Z���9�9�9��
1�
1���%�%�d�C�0�0�0�0��Ir&r4r]r�	)r*r:r;r�r�r�rBr�r:r��pathlib�Pathrjr�r��DirEntryr�r�)	r�r;r�rr=rmr>�
src_dir_entryrls	`       @r$�!test_copytree_arg_types_of_ignorez.TestCopyTree.test_copytree_arg_types_of_ignorecsq�����w�|�������,�,�.�.���$�w��)�)��
����g������
����g�z�*�*�+�+�+�
������g�z�8�<�<�=�=�=��G�Z��:�>��F�F�F���	�	�	�	�	�	��$�t�|�|�~�~�}�5�5�������9�9�9�9������t�t�G�Z��$.� 0� 0�1�1�	2�	2�	2��$�t�|�|�~�~�}�5�5������W�-�-�w�w�G�G�G�G������t�t�G�Z��$.� 0� 0�1�1�	2�	2�	2��$�t�|�|�~�~�}�5�5���R�Z��0�0�1�1�!�4�
����m�R�[�9�9�9���
�w�w�?�?�?�?������t�t�G�Z��$.� 0� 0�1�1�	2�	2�	2�	
����[�)�)�1�-�-�-�-�-r&c	��|���}tj�|d��}tj|��tj�|d��}|�tj|��tj|d��t|dfd��tjtj�|d��d��t|dfd��tjtj�|d��d��tj|�	��}|�tj|��tj|d��t
j||��|�
tj|��jtj|��j��|�
tjtj�|d����jtjtj�|d����j��|�
tjtj�|d����jtjtj�|d����j��tj�|tj�|��d
��}|�
tj|��jtj|��j��dS)Nrgr4i�zpermissive.txtr6zrestrictive.txtr8i�r�r�)r�r*r:r;r�r�r�r�r�rBrsrr:r�r�r�r�)r�rr=r>�restrictive_subdir�restrictive_subdir_dsts      r$�!test_copytree_retains_permissionsz.TestCopyTree.test_copytree_retains_permissions�s����,�,�.�.���'�,�,�w��1�1��
�������'�,�,�w�
�6�6������
�w�/�/�/�
���%� � � ��G�-�.��6�6�6�
������g�'7�8�8�%�@�@�@��G�.�/��7�7�7�
������g�'8�9�9�5�A�A�A�%�-�'�:�:�:�����	�(�*<�=�=�=�
��#�U�+�+�+�����)�)�)�������)�)�1�2�7�7�3C�3C�3K�L�L�L����������g�7G�!H�!H�I�I�Q��'�"�'�,�,�w�8H�"I�"I�J�J�R�	T�	T�	T����������g�7H�!I�!I�J�J�R��'�"�'�,�,�w�8I�"J�"J�K�K�S�	U�	U�	U�!#����g�.0�g�m�m�<N�.O�.O�PQ�.R�"T�"T�������!3�4�4�<��'�"8�9�9�A�	C�	C�	C�	C�	Cr&zos.chmodc��|���}tj�|���d��}|�t
j|��|�t
jtj�|����td��|_	|�
t
j��5tj||��ddd��dS#1swxYwYdS)Nr4zka-boom)
r�r*r:r;r�r�r�r9�PermissionErrorrr�rr:)r��
mock_patchr=r>s    r$�test_copytree_winerrorz#TestCopyTree.test_copytree_winerror�s��
�,�,�.�.���'�,�,�t�|�|�~�~�}�=�=������
�w�/�/�/�����
�r�w���w�'?�'?�@�@�@�!0��!;�!;�
��
�
�
�v�|�
,�
,�	.�	.��O�G�W�-�-�-�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.����	.�	.�	.�	.�	.�	.s�C:�:C>�C>c�����������fd�}g������tj��������ttj��d��dd���5}|���ddd��n#1swxYwYtj	��|�����
t���d��dS)	Nc�n����d����|t����|t����|tj��d������|tj��d����dS�Nr�)rfr�rir�r*r:r;)r�r�r{�flagr�rzs  ����r$�custom_cpfunzETestCopyTree.test_copytree_custom_copy_function.<locals>.custom_cpfun�s�����K�K������!�!�!�S�)�)�)��!�!�!�S�)�)�)����Q�����S�%� 8� 8�9�9�9����Q�����S�%� 8� 8�9�9�9�9�9r&r�r�r4r5r6��
copy_functionr�)r�rsr�r<r*r:r;rr�r:r�r�)r�r�rXr{rrzs`  @@@r$�"test_copytree_custom_copy_functionz/TestCopyTree.test_copytree_custom_copy_function�s������	:�	:�	:�	:�	:�	:�	:�	:����l�l�n�n���o�$�,�,�.�.�1�1�1��
�"�'�,�,�s�E�*�*�C�'�
B�
B�
B�	�a�
�G�G�I�I�I�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	����S��=�=�=�=�����T���A�&�&�&�&�&s�:B�B�"B�mkfifo�requires os.mkfifo()�vxworks�%fifo requires special path on VxWorksc��tjt��	tj�td��}tj|��tj�|d��}	tj|��n/#t$r"}|�d|z��Yd}~nd}~wwxYw	tj	tt��|�d��nq#tj$r_}|j
d}|�t|��d��|d\}}}|�d|z|��Yd}~nd}~wwxYwtjtd�	��tjtd�	��dS#tjtd�	��tjtd�	��wxYw)
Nr�mypipe�os.mkfifo(): %sz$shutil.Error should have been raisedrr�z`%s` is a named pipeTr�)r*r�rr:r;r�ry�skipTestr�r:�TESTFN2�failrr"r�r�r�)r�r�pipe�er�rzr{�	error_msgs        r$�test_copytree_named_pipez%TestCopyTree.test_copytree_named_pipe�s���
	������	7��W�\�\�&�(�3�3�F��H�V�����7�<�<���1�1�D�
5��	�$������"�
5�
5�
5��
�
�/�!�3�4�4�4�4�4�4�4�4�����
5����
B�����0�0�0��	�	�@�A�A�A�A��
�<�
K�
K�
K������� � ��V���a�0�0�0�&,�Q�i�#��S�)�� � �!7�$�!>�	�J�J�J�J�J�J�J�J�����	
K����
�M�&��5�5�5�5��M�'��6�6�6�6�6�6��
�M�&��5�5�5�5��M�'��6�6�6�6�6���sa�AF�5B
�	F�

B6�B1�,F�1B6�6F�:C/�F�/E�>AE�F�E�F�8Gc����|���}tj�|���d��}t	|dfd��tjtj�|d����t	|ddfd��g��fd�}t
j|||���|�t���d��dS)	Nr4r5r6r7r8c�6����||f��dSr)r�)rzr{�copieds  �r$�_copyz6TestCopyTree.test_copytree_special_func.<locals>._copy�s����M�M�3��*�%�%�%�%�%r&r�rq)
r�r*r:r;rBr�r�r:r�r�)r�r=r>r�r�s    @r$�test_copytree_special_funcz'TestCopyTree.test_copytree_special_func�s�����,�,�.�.���'�,�,�t�|�|�~�~�}�=�=���G�Z�(�%�0�0�0�
������g�z�2�2�3�3�3��G�Z��4�e�<�<�<���	&�	&�	&�	&�	&�	�����>�>�>�>�����V���a�(�(�(�(�(r&c��|���}tj�|d��}t	|d��tj�|d��}tj|��||fD]h}tjdtj�|d����tj|tj�|d�����itj�|���d��}|�ttj
||��tj�|���d��}tj
||d	�
��tj|��D]2\}}}|�d|��|�
d|���3tj�|���d��}tj
||d	���|�
dtj|����dS)
Nr5�abc�dir_a�
IDONTEXIST�broken�validr4�destination2T)�ignore_dangling_symlinks�destination3rK)r�r*r:r;rBr�r�r�rr�r:�walk�assertNotInr�rc)	r�r=�
valid_filer�r�r>�root�dirs�filess	         r$�test_copytree_dangling_symlinksz,TestCopyTree.test_copytree_dangling_symlinks�s����,�,�.�.���W�\�\�'�:�6�6�
��:�u�%�%�%�����W�g�.�.��
�������%��	=�	=�A��J�|�R�W�\�\�!�X�%>�%>�?�?�?��J�z�2�7�<�<��7�#;�#;�<�<�<�<��'�,�,�t�|�|�~�~�}�=�=�����%���'�7�C�C�C��'�,�,�t�|�|�~�~�~�>�>������4�H�H�H�H�!#���!1�!1�	*�	*��D�$�����X�u�-�-�-��M�M�'�5�)�)�)�)��'�,�,�t�|�|�~�~�~�>�>������4�8�8�8�8��
�
�j�"�*�W�"5�"5�6�6�6�6�6r&c	�D�|���}tj�|���d��}tjtj�|d����ttj�|dd��d��5	ddd��n#1swxYwYtjtj�|d��tj�|d��d���tj||d�	��|�	tj�
tj�|d������|�dtjtj�|d������tj�|���d
��}tj||d�	��|�
tj�
tj�|d������|�dtjtj�|d������dS)Nr4�real_dirr5r3�link_to_dirT)�target_is_directoryFrKr�)r�r*r:r;r�r<r�r�r:r�rer�rcr�)r�r=r>s   r$�test_copytree_symlink_dirz&TestCopyTree.test_copytree_symlink_dirs���,�,�.�.���'�,�,�t�|�|�~�~�}�=�=��
������g�z�2�2�3�3�3�
�"�'�,�,�w�
�J�?�?��
F�
F�	�	��	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�
�
�2�7�<�<���4�4��7�<�<���7�7�'+�	-�	-�	-�	-�	����5�9�9�9�9������������W�m�(L�(L�M�M�N�N�N��
�
�j�"�*�R�W�\�\�'�=�-Q�-Q�"R�"R�S�S�S��'�,�,�t�|�|�~�~�~�>�>������4�8�8�8�8��������r�w�|�|�G�]�'K�'K�L�L�M�M�M��
�
�j�"�*�R�W�\�\�'�=�-Q�-Q�"R�"R�S�S�S�S�Ss�(B6�6B:�=B:c�V�|���}|dz}|�tj|d��tj�|d��}t|d��tj||��}|�	dgt	j
|����dS)N�destTr�)r�r�r�r�r*r:r;rBr:r�rc)r�r=r>rz�rvs     r$�test_copytree_return_valuez'TestCopyTree.test_copytree_return_value s����,�,�.�.���F�"������
�w��5�5�5��g�l�l�7�E�*�*���3�����
�_�W�g�
.�
.�����%��"�*�R�.�.�1�1�1�1�1r&c��|���}|�tj|d���tj�|dd��}tj�|dd��}t	j|��tj�|d��}t|d��tj	||��}|�
dgt	j|����dS)NTr��t�pg�
somevendorz1.0�pol)r�r�r�r�r*r:r;�makedirsrBr:r�rc)r��base_dirr=r>rzr�s      r$�test_copytree_subdirectoryz'TestCopyTree.test_copytree_subdirectory*s����<�<�>�>������
�x�t��D�D�D��'�,�,�x��d�3�3���'�,�,�w��e�<�<��
��G�����g�l�l�7�E�*�*���3�����
�_�W�g�
.�
.�����%��"�*�R�.�.�1�1�1�1�1r&N)r�r�r�r@rErr*rYrersrwr+�mock�patchr{r�r,rrr*r-r�r.r�r�r�r�r�r�rEr&r$r2r2�s�������(�(�(�&C�C�C�2�"�C�C�#�"�C�>?4�?4�?4�B(.�(.�(.�TC�C�C�6�]����$�$�.�.�%�$�.�'�'�'�$�X�����X�.�.�0F�G�G��"��X�_�S�\�Y�.�;�=�=�7�7�=�=�#�"�H�G�7�.)�)�)��"�7�7�#�"�7�4�"�T�T�#�"�T�&2�2�2�
2�
2�
2�
2�
2r&r2c�V�eZdZejd���Zejee	d��d��ejd�����Z
ejee	d��d��ejd�����Zejd���Z
ejee	d��oeed	��oeed
��d��d���Zejd
���Zejejejd�������Zd�Zd�Zejd���Zejee	d��d��d���Zejd���Zejd���Zd�Zd�Zd�Zd�Zejd���Zejee	d��d��d���Zejd���Z ejee	d ��d!��eje!j"d"kd#��d$�����Z#d%�Z$d&�Z%eje&pe'pe(d'��eje)d(��d)�����Z*d*�Z+d+S),�TestCopyc��|���}tj�|d��}tj�|d��}tj�|d��}tj�|d��}t	|d��t	|d��tj||��tj||��tj|tjtj	z��tj|tj
��|�tj|��jtj|��j��tj||��|�tj|��jtj|��j��tjdk�rjtj|tj
��tj||��|�tj|��jtj|��j��tj|tj
��tj||��|�tj|��jtj|��j��tj|tj
��tj||��|�tj|��jtj|��j��dSdS)Nr��bar�baz�quuxrM)r�r*r:r;rBr�r�r�rO�S_IRWXGrP�assertNotEqualr�r��copymoder�ri�r�rrzr{rUrVs      r$�test_copymode_follow_symlinksz&TestCopy.test_copymode_follow_symlinks:sN���,�,�.�.���g�l�l�7�E�*�*���g�l�l�7�E�*�*���7�<�<���/�/���7�<�<���0�0���3������3�����
�
�3��!�!�!�
�
�3��!�!�!�
���d�l�4�<�/�0�0�0�
���d�l�#�#�#����B�G�C�L�L�0�"�'�#�,�,�2F�G�G�G����S�!�!�!���������-�r�w�s�|�|�/C�D�D�D�
�7�d�?�?��H�S�$�,�'�'�'��O�H�c�*�*�*����R�W�S�\�\�1�2�7�3�<�<�3G�H�H�H��H�S�$�,�'�'�'��O�C��*�*�*����R�W�S�\�\�1�2�7�3�<�<�3G�H�H�H��H�S�$�,�'�'�'��O�H�h�/�/�/����R�W�S�\�\�1�2�7�3�<�<�3G�H�H�H�H�H��?r&rHzrequires os.lchmodc��|���}tj�|d��}tj�|d��}tj�|d��}tj�|d��}t	|d��t	|d��tj||��tj||��tj|tjtj	z��tj|tj��tj
|tjtj	z��tj
|tj��tj
||d���|�tj|��jtj|��j��|�tj|��jtj|��j��tj
|tj��tj
||d���|�tj|��jtj|��j��tj
|tj��tj
||d���|�tj|��jtj|��j��dS�Nr�r�r�r�F��follow_symlinks)r�r*r:r;rBr�r�r�rOr�rHrPr�r�r�r�r�r�r�s      r$� test_copymode_symlink_to_symlinkz)TestCopy.test_copymode_symlink_to_symlinkZs5���,�,�.�.���g�l�l�7�E�*�*���g�l�l�7�E�*�*���7�<�<���/�/���7�<�<���0�0���3������3�����
�
�3��!�!�!�
�
�3��!�!�!�
���d�l�4�<�/�0�0�0�
���d�l�#�#�#�
�	�(�D�L���5�6�6�6�
�	�(�D�L�)�)�)����(�E�B�B�B�B������(�+�+�3���(�+�+�3�	5�	5�	5����B�G�C�L�L�0�"�'�#�,�,�2F�G�G�G�
�	�(�D�L�)�)�)����#�u�=�=�=�=���������-�r�w�s�|�|�/C�D�D�D�
�	�(�D�L�)�)�)����X�u�=�=�=�=���������-�r�w�s�|�|�/C�D�D�D�D�Dr&z requires os.lchmod to be missingc���|���}tj�|d��}tj�|d��}tj�|d��}tj�|d��}t	|d��t	|d��tj||��tj||��t
j||d���dSr�)r�r*r:r;rBr�r�r�r�s      r$�*test_copymode_symlink_to_symlink_wo_lchmodz3TestCopy.test_copymode_symlink_to_symlink_wo_lchmodxs����,�,�.�.���g�l�l�7�E�*�*���g�l�l�7�E�*�*���7�<�<���/�/���7�<�<���0�0���3������3�����
�
�3��!�!�!�
�
�3��!�!�!����(�E�B�B�B�B�B�Br&c�b�|���}tj�|d��}tj�|d��}tj�|d��}tj�|d��}t	|d��tj|��}tj||j|jdz
f��t	|d��|�	tj|��jtj|��j��tj
||��tj
||��ttd��rtj|t
j
��ttd��r4tt
d��rtj|t
j��tj|��}ttd��rIt#j||d	�
��|�	|jtj|��j��t#j||d�
��tj|��}tjtjvr:dD]7}	|�t-||	��t-||	��d
z���8ttd��r |�|j|j��ttd��r0t|d��r |�|j|j��t#j||d�
��|�t5tj|��jtj|��jz
��dk��dS)Nr�r�r��quxgE@rHrIrJTr�F��st_atime�st_mtimer�rSg�������?)r�r*r:r;rBr��utimer�r�r�r�rrrHrPrIrJr�r��copystatr�r	�assertLessEqualr r�rSr��abs)
r�rrzr{rUrVrW�
src_link_stat�
dst_link_stat�attrs
          r$�test_copystat_symlinkszTestCopy.test_copystat_symlinks�s���,�,�.�.���g�l�l�7�E�*�*���g�l�l�7�E�*�*���7�<�<���/�/���7�<�<���/�/���3������7�3�<�<��
���x�(��(�4�/�1�	2�	2�	2��3��������B�G�C�L�L�1�2�7�3�<�<�3H�I�I�I�
�
�3��!�!�!�
�
�3��!�!�!��2�x� � �	.��I�h���-�-�-��2�z�"�"�	2�w�t�[�'A�'A�	2��K��$�.�1�1�1����*�*�
��2�x� � �	M��O�H�h��E�E�E�E����
� 5�r�w�s�|�|�7K�L�L�L����(�E�B�B�B�B����*�*�
�
�8�r�2�2�2�.�
G�
G���$�$�W�]�D�%A�%A�%,�]�D�%A�%A�A�%E�G�G�G�G��2�x� � �	K����]�2�M�4I�J�J�J��2�z�"�"�	M�w�}�j�'I�'I�	M����]�3�]�5K�L�L�L����#�u�=�=�=�=�����B�G�C�L�L�1�B�G�C�L�L�4I�I�J�J�� �	!�	!�	!�	!�	!r&�chflags�
EOPNOTSUPP�ENOTSUPz)requires os.chflags, EOPNOTSUPP & ENOTSUPc�x�|���}tj�|d��}tj�|d��}t	|d��t	|d��d�}tj}	tjtjfD],}||��t_tj
||���-|tjtjz��t_|�ttj
||��|t_dS#|t_wxYw)Nr��file2�xxxc�8���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)r�r�r�s` @r$�make_chflags_raiserzSTestCopy.test_copystat_handles_harmless_chflags_errors.<locals>.make_chflags_raiser�s@�������B�@D�
�
�
�
�
�
�
�
�#�"r&)
r�r*r:r;rBr�r!r�r�r�r�r�r)r�r�r�r�r��old_chflagsr�s       r$�-test_copystat_handles_harmless_chflags_errorsz6TestCopy.test_copystat_handles_harmless_chflags_errors�s��
����������V�W�-�-������V�W�-�-���5�%� � � ��5�%� � � �	#�	#�	#��j��	%��'���6�
.�
.��0�0��5�5��
����u�-�-�-�-�,�,�U�-=��
�-M�N�N�B�J����g�v���u�E�E�E�$�B�J�J�J���B�J�$�$�$�$s
�BD+�+D9c�����	�
�|���}tj�|d���
t	�
d��tj�|d��}t	|d��tj�
|��tj�
dd��tj�
dd��tj�
|��|�ttj
�
����ttj
|������|�tj�
d��tj|d����tj|��t	|d��ttjd���	��	fd�}	tj�|t_tj�
|��|�dtj
|�����t_n#�t_wxYwd	d
���
fd�
}	tj
�|t_
tj�
|���t_
n#�t_
wxYwtj�|d���
tj�|d
��}t	�
�
��t	||��tj�
dd��tj|dd��tj|d��tj�|d��}tj�|d��}t	||��t	||��tj�
|��tj||��|�tj|d��d��|�tj|d��d��dS)Nr�r��user.foo�42zuser.bar�43�EPERMc�.��|dkr���|||fi|��dS)Nr�rE)�fnamer��valr#�
orig_setxattr�os_errors    ��r$�_raise_on_user_fooz3TestCopy.test_copyxattr.<locals>._raise_on_user_foo�s5����z�!�!����
�e�T�3�9�9�&�9�9�9�9�9r&Tr�c�^��|�krttjd����||���S)NzOperation not supportedr�)rr!r�)r�r��orig_listxattrrzs  ��r$�
_raise_on_srcz.TestCopy.test_copyxattr.<locals>._raise_on_src�s4�����|�|��e�m�-F�G�G�G�!�>�%��I�I�I�Ir&�the_original�the_original_rozuser.the_valuesfiddlyi$�the_copy�the_copy_ro)r�r*r:r;rBr��
_copyxattr�setxattrr�rb�	listxattr�getxattrrrr!r�r�r�r�)r�rr{r�r��srcro�dstror�r�r�rzs       @@@@r$�test_copyxattrzTestCopy.test_copyxattr�s��������,�,�.�.���g�l�l�7�E�*�*���3������g�l�l�7�E�*�*���3�����	��#�s�#�#�#�
��C��U�+�+�+�
��C��U�+�+�+���#�s�#�#�#�������S� 1� 1�2�2�F�2�<��;L�;L�4M�4M�N�N�N������C��,�,���C��,�,�	.�	.�	.�	�	�#�����3������5�;��0�0��	:�	:�	:�	:�	:�	:�
	(��K�M�,�B�K���c�3�'�'�'��M�M�*�b�l�3�&7�&7�8�8�8�'�B�K�K��-�B�K�'�'�'�'�48�	J�	J�	J�	J�	J�	J�	J�	J�	*��\�N�(�B�L���c�3�'�'�'�)�B�L�L��>�B�L�)�)�)�)��g�l�l�7�N�3�3������W�&7�8�8���3������5�%� � � �
��C�)�9�5�5�5�
��E�+�Y�7�7�7�
��������g�l�l�7�J�/�/������W�m�4�4���3������5�%� � � ����S�!�!�!����u�%�%�%������S�*:�;�;�Y�G�G�G������U�,<�=�=�y�I�I�I�I�Is�$AH�H�!-I�I)c�p�|���}tj�|d��}tj�|d��}t	|d��tj||��tj|dd��tj|ddd���tj�|d��}tj�|d	��}t	|d��tj||��tj||d���|�	tj
|dd���d��|�ttj
|d��tj||d���|�	tj
|d��d��dS)
Nr�r�ztrusted.foor�r�Fr�r�r�)
r�r*r:r;rBr�r�r�r�r�r�r�r)r�rrzrUr{rVs      r$�test_copyxattr_symlinksz TestCopy.test_copyxattr_symlinkssr���,�,�.�.���g�l�l�7�E�*�*���7�<�<���/�/���3�����
�
�3��!�!�!�
��C���.�.�.�
��H�m�U�E�J�J�J�J��g�l�l�7�E�*�*���7�<�<���/�/���3�����
�
�3��!�!�!���(�H�e�D�D�D�D������X�}�e�T�T�T�V[�\�\�\����'�2�;��]�C�C�C���(�C��?�?�?�?������S�-�8�8�%�@�@�@�@�@r&c��d}|���}t||fd��tj�||��}|���}|||��tj�||��}||fS)Nr5r�)r�rBr*r:r;)r��methodr�r�r��tmpdir2r�s       r$�
_copy_filezTestCopy._copy_file*s{�����������F�E�?�E�*�*�*�����V�U�+�+���,�,�.�.����u�g��������W�e�,�,���u�~�r&c�6�|�tj��\}}|�tj�|����|�t	j|��j	t	j|��j	��dSr))
rr��copyr�r*r:r�r�r�r�)r�r�r�s   r$�	test_copyzTestCopy.test_copy4sk�����v�{�3�3���u��������u�-�-�.�.�.���������/������1G�H�H�H�H�Hr&c��|���}tj�|d��}tj�|d��}tj�|d��}t	|d��tj||��t
td��r,tj|tj	tj
z��tj||d���|�
tj�|����|�t!|��t!|����tj|��tj||d���|�tj�|����|�tj|��tj|����t
td��rF|�tj|��jtj|��j��dSdS)Nr�r�r�rHTr�F)r�r*r:r;rBr�rrrHr�rOrPr�r	r�rer�r_rr�rQr�r�)r�rrzr{rUs     r$�test_copy_symlinkszTestCopy.test_copy_symlinks:s����,�,�.�.���g�l�l�7�E�*�*���g�l�l�7�E�*�*���7�<�<���/�/���3�����
�
�3��!�!�!��2�x� � �	=��I�h���t�|� ;�<�<�<���H�c�4�8�8�8�8���������,�,�-�-�-�����3����3���8�8�8�
�	�#������H�c�5�9�9�9�9��������s�+�+�,�,�,������S�)�)�2�;�x�+@�+@�A�A�A��2�x� � �	4����R�X�h�/�/�7��X�c�]�]�2�
4�
4�
4�
4�
4�	4�	4r&r�zrequires os.utimec�h�|�tj��\}}|�tj�|����t	j|��}t	j|��}|�|j	|j	��dD]7}|�
t||��t||��dz���8ttd��rDt|d��r6|�t|d��t|d����dSdSdS)Nr�r�r�rS)
rr��copy2r�r*r:r�r�r�r�r�r rr)r�r�r��
file1_stat�
file2_statr�s      r$�
test_copy2zTestCopy.test_copy2Ss3�����v�|�4�4���u��������u�-�-�.�.�.��W�U�^�^�
��W�U�^�^�
�����+�Z�-?�@�@�@�*�	@�	@�D�� � ���T�!:�!:�!(��T�!:�!:�Q�!>�
@�
@�
@�
@��2�y�!�!�	>�g�j�*�&E�&E�	>����W�Z��<�<�$�Z��<�<�
>�
>�
>�
>�
>�	>�	>�	>�	>r&c���|���}tj�|d��}tj�|d��}tj�|d��}t	|d��tj||��t
td��r,tj|tj	tj
z��t
td��r4t
td��rtj|tj��tj|��}tj
|��}tj||d���|�tj�|����|�t'|��t'|����tj|��tj||d	���|�tj�|����|�tj|��tj|����tj
|��}tjtjvr:d
D]7}|�t5||��t5||��dz���8t
td��r@|�|j|j��|�|j|j��t
td��r2t
|d��r$|�|j|j��dSdSdS)
Nr�r�r�rHrIrJTr�Fr�r�rS)r�r*r:r;rBr�rrrHr�rOrPrIrJr�r�rr�rer�r_rr�rQr�r	r�r r�r�rS)	r�rrzr{rUrWr�rXr�s	         r$�test_copy2_symlinkszTestCopy.test_copy2_symlinksds����,�,�.�.���g�l�l�7�E�*�*���g�l�l�7�E�*�*���7�<�<���/�/���3�����
�
�3��!�!�!��2�x� � �	=��I�h���t�|� ;�<�<�<��2�z�"�"�	2�w�t�[�'A�'A�	2��K��$�.�1�1�1��7�3�<�<�����*�*�
���X�s�D�9�9�9�9���������,�,�-�-�-�����3����3���8�8�8�
�	�#������X�s�E�:�:�:�:��������s�+�+�,�,�,������S�)�)�2�;�x�+@�+@�A�A�A��8�C�=�=��
�8�r�2�2�2�.�
B�
B���$�$�W�]�D�%A�%A�%,�X�t�%<�%<�q�%@�B�B�B�B��2�x� � �	D����]�2�H�4D�E�E�E����� 0�(�2B�C�C�C��2�z�"�"�	H�w�}�j�'I�'I�	H����]�3�X�5F�G�G�G�G�G�	H�	H�	H�	Hr&c���|���}tj�|d��}tj�|d��}t	|d��tj|dd��t
j||��|�tj	|d��tj	|d����tj
|��dS)Nr�r�r�r�)r�r*r:r;rBr�r�rr�r�r)r�rrzr{s    r$�test_copy2_xattrzTestCopy.test_copy2_xattr�s����,�,�.�.���g�l�l�7�E�*�*���g�l�l�7�E�*�*���3�����
��C��U�+�+�+���S�#���������C��,�,���C��,�,�	.�	.�	.�	�	�#�����r&c�(�tjtjfD]�}|���}|���}tj�|d��}t|d��|||��}|�|tj�|d����||tj�|d����}|�|tj�|d������dS)Nr�r�)	r�r	rr�r*r:r;rBr�)r�r�r=r>rzr�s      r$�test_copy_return_valuezTestCopy.test_copy_return_value�s����;���-�	?�	?�B��l�l�n�n�G��l�l�n�n�G��'�,�,�w��.�.�C��s�E�"�"�"���C��!�!�B����R�����g�u�!=�!=�>�>�>���C�����g�u�5�5�6�6�B����R�����g�u�!=�!=�>�>�>�>�	?�	?r&c�D�|�tj��dSr))�_test_copy_dirr�r	�r�s r$�
test_copy_dirzTestCopy.test_copy_dir�s�����F�K�(�(�(�(�(r&c�D�|�tj��dSr))rr�rrs r$�test_copy2_dirzTestCopy.test_copy2_dir�s�����F�L�)�)�)�)�)r&c��|���}tj�|d��}|���}tj�|d��}t	|d��t
jdkrt}nt}|�	||||��|�	||||��|||��dS�Nr��does_not_exist/�win32)
r�r*r:r;rBr�r.ry�IsADirectoryErrorr�)r��	copy_funcr=�src_filer�r{r�s       r$rzTestCopy._test_copy_dir�s����,�,�.�.���7�<�<���/�/���|�|�~�~���g�l�l�7�$5�6�6���8�U�#�#�#��<�7�"�"�!�C�C�#�C����#�y�$��8�8�8�	
���#�y�$��4�4�4��	�(�D�!�!�!�!�!r&c��|���}tj�|d��}tj�|d��}tj�|d��}tj�|d��}t	|d��tj||��t
j||d���|�tj�	|����|�
tj|��tj|����t
j||��|�tj�	|����dS)Nrzr{rVr�r�Fr�)
r�r*r:r;rBr�r��copyfiler�rer�rQr�)r�rrzr{rVr�s      r$�test_copyfile_symlinkszTestCopy.test_copyfile_symlinks�s ���,�,�.�.���g�l�l�7�E�*�*���g�l�l�7�E�*�*���7�<�<���4�4���w�|�|�G�V�,�,���3�����
�
�3��������h��>�>�>�>��������x�0�0�1�1�1������T�*�*�B�K��,A�,A�B�B�B����c�"�"�"���������,�,�-�-�-�-�-r&r�zrequires os.linkc�r�tjt��tj�td��}tj�td��}	t|dd���5}|�d��ddd��n#1swxYwY	tj||��n/#t$r"}|�	d|z��Yd}~nd}~wwxYw|�
tjtj
||��t|dd���5}|�|���d��ddd��n#1swxYwYtj|��tjtd	�
��dS#tjtd	�
��wxYw)Nr#r$r4r5r6�cheddarz
os.link(): %sr]Tr�)r*r�rr:r;r<r=r�ryr�r�r�r
r&r�r^rr�)r�rzr{rXr�s     r$�'test_dont_copy_file_onto_link_to_itselfz0TestCopy.test_dont_copy_file_onto_link_to_itself�s��	�������g�l�l�6�8�,�,���g�l�l�6�6�*�*��	6��c�3��1�1�1�
#�Q����	�"�"�"�
#�
#�
#�
#�
#�
#�
#�
#�
#�
#�
#����
#�
#�
#�
#�
3����S�!�!�!�!��"�
3�
3�
3��
�
�o��1�2�2�2�2�2�2�2�2�����
3�������f�2�F�O�S�#�N�N�N��c�3��1�1�1�
6�Q�� � ������9�5�5�5�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6����
6�
6�
6�
6��I�c�N�N�N��M�&��5�5�5�5�5�5��F�M�&��5�5�5�5�5���s�%F�7B�
F�B�F� B�!F�%B;�:F�;
C'�C"�F�"C'�'AF�()E�F�E!�!F�$E!�%F�F6c��tjt��tj�td��}tj�td��}	t|dd���5}|�d��ddd��n#1swxYwYtjd|��|�tj
tj||��t|dd���5}|�|�
��d��ddd��n#1swxYwYtj|��tjtd�	��dS#tjtd�	��wxYw)
Nr#r$r4r5r6r)r]Tr�)r*r�rr:r;r<r=r�r�r�r
r&r�r^rr�)r�rzr{rXs    r$�*test_dont_copy_file_onto_symlink_to_itselfz3TestCopy.test_dont_copy_file_onto_symlink_to_itself�s���	�������g�l�l�6�8�,�,���g�l�l�6�6�*�*��	6��c�3��1�1�1�
#�Q����	�"�"�"�
#�
#�
#�
#�
#�
#�
#�
#�
#�
#�
#����
#�
#�
#�
#�

�J�x��%�%�%����f�2�F�O�S�#�N�N�N��c�3��1�1�1�
6�Q�� � ������9�5�5�5�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6�
6����
6�
6�
6�
6��I�c�N�N�N��M�&��5�5�5�5�5�5��F�M�&��5�5�5�5�5���sU�%E(�7B�
E(�B�E(� B�!AE(�7)D,� E(�,D0�0E(�3D0�4E(�(Fr�r�r�r�c���	tjt��n/#t$r"}|�d|z��Yd}~nd}~wwxYw	|�tjtjtt��|�tjtjtt��tjt��dS#tjt��wxYw)Nr�)r*r�rryr�r�r��SpecialFileErrorr&r��__file__r)r�r�s  r$�test_copyfile_named_pipez!TestCopy.test_copyfile_named_pipe�s���	1��I�f�������	1�	1�	1��M�M�+�a�/�0�0�0�0�0�0�0�0�����	1����	����f�5� &����
B�
B�
B����f�5� &���6�
C�
C�
C�
�I�f�������B�I�f�������s!��
A�A�A�A,C�C.c���|���}|���}tj�|d��}tj�|d��}t	|d��tj||��}|�tj�|����|�	t|��t|����dS)Nr�r�)r�r*r:r;rBr�r&r�r�r�r_)r�r=r>�dst_filer$r�s      r$�test_copyfile_return_valuez#TestCopy.test_copyfile_return_values����,�,�.�.���,�,�.�.���7�<�<���/�/���7�<�<���/�/���8�U�#�#�#�
�_�X�x�
0�
0���������r�*�*�+�+�+�����8�,�,�i��.A�.A�B�B�B�B�Br&c�p�|���}tj�|d��}t	|d��|�ttj||��|�ttj||��|�
t|��d��dSr~)r�r*r:r;rBr�r
r�r&rr�r_)r�r=r$s   r$�test_copyfile_same_filez TestCopy.test_copyfile_same_file
s����,�,�.�.���7�<�<���/�/���8�U�#�#�#����-���(�H�M�M�M����%���(�H�E�E�E�����8�,�,�e�4�4�4�4�4r&zMOn MACOS, Solaris and Windows the errors are not confusing (though different)zNot valid on AIX, see gh-92670c��|���}tj�|d��}tj�|d��}t	|d��|�ttj||��dS)Nr�r )	r�r*r:r;rBr�r�r�r&)r�r=r$r{s    r$�test_copyfile_nonexistent_dirz&TestCopy.test_copyfile_nonexistent_dirso���,�,�.�.���7�<�<���/�/���g�l�l�7�$5�6�6���8�U�#�#�#����+�V�_�h��L�L�L�L�Lr&c��|���}tj�|d��}|���}tj�|d��}t	|d��t
jdkrt}nt}|�	|tj||��|�	|tj||��|�	|tj||��dSr)r�r*r:r;rBr�r.ryr"r�r�r&)r�r=r$r�r{r�s      r$�test_copyfile_copy_dirzTestCopy.test_copyfile_copy_dir&s����,�,�.�.���7�<�<���/�/���|�|�~�~���g�l�l�7�$5�6�6���8�U�#�#�#��<�7�"�"�!�C�C�#�C����#�v����=�=�=����#�v���'�B�B�B����#�v���g�>�>�>�>�>r&N),r�r�r�rr*r�r+r,rrr*r�r-r�r�r!r��skip_unless_xattrr�skip_unless_dac_overriderrr
rrrrrrrrr'r*r,r�r.r0r3r5�MACOS�SOLARISr�r�r7r9rEr&r$r�r�6s�������"�I�I�#�"�I�>�X�����X�.�.�0D�E�E��"�E�E�#�"�F�E�E�8�X�_�W�W�R��*�*�,N�O�O��"�
C�
C�#�"�P�O�
C��"�&!�&!�#�"�&!�P�X�����Y�/�/�3� ����5�5�3� ���	�2�2�D�F�F�%�%�	F�F�%�6� �=J�=J�!� �=J�~�"�� ��'�A�A�(�'�!� �#�"�A�.���I�I�I��"�4�4�#�"�4�0�X�����W�-�-�/B�C�C�>�>�D�C�>� �"� H� H�#�"� H�D� �
�
�!� �
�
?�
?�
?�)�)�)�*�*�*�"�"�"�$�"�.�.�#�"�.� �X�����V�,�,�.@�A�A�6�6�B�A�6�&�"�6�6�#�"�6�(�X�����X�.�.�0F�G�G��X�_�S�\�Y�.�;�=�=���=�=�H�G��	C�	C�	C�
5�
5�
5��X�_�U�0�g�0��3B�C�C��X�_�S�:�;�;�M�M�<�;�	C�C�
M�?�?�?�?�?r&r�c���eZdZej��d���Zd�Zd!d�Zej��ej	e
jd��d��d�����Zej��d���Z
ej��ej	e
jd	��d
��d�����Zej��ej	e
jd��d
��d�����Zd�Zej��d���Zej��ej	ed��d�����Zd�Zd�Zej��d���Zd�Zd�Zd�Zd�Zej��d���Zej��d���Zej��eje o
e!��d��d�����Z"ej��d���Z#d�Z$d S)"�TestArchivesc��|�d��\}}|���}tj|��tj�|��}tj�tj�|��d��}tj	|��5t5tj�|��}t|d|d��}ddd��n#1swxYwYddd��n#1swxYwY|�
||dz��|�tj�|����|�t!j|����t!j|d��5}|�|���gd���ddd��n#1swxYwYtj	|��5t5t|d|d��}ddd��n#1swxYwYddd��n#1swxYwY|�
||d	z��|�tj�|����|�t!j|����t!j|d
��5}|�|���gd���ddd��dS#1swxYwYdS)Nr��archive�gztar�.�.tar.gzzr:gz)rCz./subz./sub2z./file1z./file2z./sub/file3�tar�.tarr])�
_create_filesr�r*r�r:r9r;�basenamer�
change_cwd�no_chdir�abspathrr�r�r;�tarfile�
is_tarfiler<�assertCountEqual�getnames)	r��root_dirr�r�work_dir�
rel_base_name�	base_name�tarball�tfs	         r$�test_make_tarballzTestArchives.test_make_tarball=s���"�/�/��3�3���(��,�,�.�.��
�������7�?�?�7�+�+������R�W�%5�%5�g�%>�%>�	�J�J�
�
�
!�(�
+�
+�	J�	J�X�	J�	J�����
�6�6�I�"�=�'�8�S�I�I�G�	J�	J�	J�	J�	J�	J�	J�	J�	J�	J�	J����	J�	J�	J�	J�	J�	J�	J�	J�	J�	J�	J�	J�	J�	J�	J����	J�	J�	J�	J�
	
����)�i�"7�8�8�8��������w�/�/�0�0�0�����*�7�3�3�4�4�4�
�\�'�6�
*�
*�	I�b��!�!�"�+�+�-�-�#H�#H�#H�
I�
I�
I�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I����	I�	I�	I�	I��
!�(�
+�
+�	H�	H�X�	H�	H�"�=�%��3�G�G�G�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H����	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H����	H�	H�	H�	H�����)�f�"4�5�5�5��������w�/�/�0�0�0�����*�7�3�3�4�4�4�
�\�'�3�
'�
'�	H�2��!�!�"�+�+�-�-�#G�#G�#G�
H�
H�
H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H����	H�	H�	H�	H�	H�	Hs��1D�92C7�+D�7C;	�;D�>C;	�?D�D�D� +G�G�G�6H4�>H�H4�H!	�!H4�$H!	�%H4�4H8�;H8�+K>�>L�Lc���tj|��5}|���}|���t	|��cddd��S#1swxYwYdSr))rLr<rO�sortr9)r�r:rEras    r$�_tarinfozTestArchives._tarinfoas���
�\�$�
�
�	 �3��L�L�N�N�E��J�J�L�L�L���<�<�	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 �	 �	 s�7A�A� A�distc��|���}tj�||��}tj|d���t|dfd��t|dfd��tjtj�|d����t|ddfd��tjtj�|d����|rt|d	fd��||fS)
NT)�exist_okr�r�r�rG�file3�sub2�outer)r�r*r:r;r�rBr�)r�r�rPrZs    r$rGzTestArchives._create_filesgs����<�<�>�>���w�|�|�H�h�/�/��
��D�4�(�(�(�(��D�'�?�E�*�*�*��D�'�?�E�*�*�*�
������d�E�*�*�+�+�+��D�%��)�5�1�1�1�
������d�F�+�+�,�,�,��	3���'�*�E�2�2�2���!�!r&rEzNeed the tar command to runc���|���\}}tj�|���d��}t
5t
|d||��}ddd��n#1swxYwY|�||dz��|�tj�	|����tj�|d��}ddd|g}tj||tj���|�tj�	|����|�|�
|��|�
|����t
5t
|d||��}ddd��n#1swxYwY|�||dz��|�tj�	|����t
5t
|d||d	�
��}ddd��n#1swxYwY|�||dz��|�tj�	|����dS)NrArBrDzarchive2.tarrEz-cf��cwd�stdoutrFT)�dry_run)rGr*r:r;r�rJrr�r�r;r��
check_call�DEVNULLrY)r�rPr�rSrT�tarball2�tar_cmds       r$�test_tarfile_vs_tarz TestArchives.test_tarfile_vs_tarus��"�/�/�1�1���(��G�L�L�������;�;�	�
�	K�	K�"�9�g�x��J�J�G�	K�	K�	K�	K�	K�	K�	K�	K�	K�	K�	K����	K�	K�	K�	K�	
����)�i�"7�8�8�8��������w�/�/�0�0�0��7�<�<��.�9�9���%���:����g�8�%/�%7�	9�	9�	9�	9�	
�������x�0�0�1�1�1�������w�/�/����x�1H�1H�I�I�I��	I�	I�"�9�e�X�x�H�H�G�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I����	I�	I�	I�	I�����)�f�"4�5�5�5��������w�/�/�0�0�0��	1�	1�"�9�e�X�x�+/�1�1�1�G�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1����	1�	1�	1�	1�	
����)�f�"4�5�5�5��������w�/�/�0�0�0�0�0s6�A0�0A4�7A4�F!�!F%�(F%�>H�H#�&H#c�L�|���\}}|���}tj|��tj�|��}tj�tj�|��d��}tj	|��5t5tj�|��}t|d|��}ddd��n#1swxYwYddd��n#1swxYwY|�
||dz��|�tj�|����|�t!j|����t!j|��5}|�|���gd���ddd��n#1swxYwYtj	|��5t5tj�|��}t|d||��}ddd��n#1swxYwYddd��n#1swxYwY|�
||dz��|�tj�|����|�t!j|����t!j|��5}|�|���gd���ddd��dS#1swxYwYdS)NrA�zip�.zip)�dist/�	dist/sub/�
dist/sub2/�
dist/file1�
dist/file2�dist/sub/file3r_)rmrnrorprqrr)rGr�r*r�r:r9r;rHrrIrJrKrr�r�r;�zipfile�
is_zipfile�ZipFilerN�namelist)	r�rPr�rrQrRrSrh�zfs	         r$�test_make_zipfilezTestArchives.test_make_zipfile�s_��"�/�/�1�1���(��,�,�.�.��
�������7�?�?�7�+�+������R�W�%5�%5�g�%>�%>�	�J�J�
�
�
!�(�
+�
+�	?�	?�X�	?�	?�����
�6�6�I��}�e�X�>�>�C�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?����	?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?����	?�	?�	?�	?�	
����i�&�0�1�1�1��������s�+�+�,�,�,�����*�3�/�/�0�0�0�
�_�S�
!�
!�	�R��!�!�"�+�+�-�-����
�
�
�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��
!�(�
+�
+�	I�	I�X�	I�	I�����
�6�6�I��}�e�X�x�H�H�C�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I����	I�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I����	I�	I�	I�	I�	
����i�&�0�1�1�1��������s�+�+�,�,�,�����*�3�/�/�0�0�0�
�_�S�
!�
!�	D�R��!�!�"�+�+�-�-�C�C�C�
D�
D�
D�	D�	D�	D�	D�	D�	D�	D�	D�	D�	D�	D�	D����	D�	D�	D�	D�	D�	Ds��0D�81C5�)D�5C9	�9D�<C9	�=D�D�D�+G�G�G�3I�;2H9�-I�9H=	�=I�H=	�I�I�I�!+L�L� LrkzNeed the zip command to runc���|���\}}tj�|���d��}t
5t
|d||��}ddd��n#1swxYwY|�||dz��|�tj�	|����tj�|d��}dddd|g}tj||tj���|�tj�	|����tj|��5}|���}ddd��n#1swxYwYtj|��5}|���}	ddd��n#1swxYwY|�t!|��t!|	����dS)NrArkrlzarchive2.zipz-qz-rra)rGr*r:r;r�rJrr�r�r;r�rerfrsrurvrb)
r�rPr�rSrA�archive2�zip_cmdrwra�names2s
          r$�test_zipfile_vs_zipz TestArchives.test_zipfile_vs_zip�sf��"�/�/�1�1���(��G�L�L�������;�;�	�
�	I�	I�"�9�e�X�x�H�H�G�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I����	I�	I�	I�	I�	
����)�f�"4�5�5�5��������w�/�/�0�0�0��7�<�<��.�9�9���$��n�h�?����g�8�%/�%7�	9�	9�	9�	9�	
�������x�0�0�1�1�1�
�_�W�
%�
%�	"���K�K�M�M�E�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"�
�_�X�
&�
&�	#�"��[�[�]�]�F�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#����	#�	#�	#�	#���������v���7�7�7�7�7s6�A0�0A4�7A4�E5�5E9�<E9�F5�5F9�<F9�unzipzNeed the unzip command to runc�.�|���\}}tj�|���d��}t
5t
|d||��}ddd��n#1swxYwY|�||dz��|�tj�	|����dd|g}tj|��5	tj
|tj���n{#tj$ri}|j�d���}d	|vr|�d
��d}|�|�||����Yd}~nd}~wwxYwddd��dS#1swxYwYdS)NrArkrlr~z-t)�stderr�replace)r�zunrecognized option: tzunzip doesn't support -tz{}

**Unzip Output**
{})rGr*r:r;r�rJrr�r�r;rrIr��check_output�STDOUT�CalledProcessError�output�decoder�r��format)	r�rPr�rSrAr{r��details�msgs	         r$�test_unzip_zipfilezTestArchives.test_unzip_zipfile�s#��"�/�/�1�1���(��G�L�L�������;�;�	�
�	I�	I�"�9�e�X�x�H�H�G�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I����	I�	I�	I�	I�	
����)�f�"4�5�5�5��������w�/�/�0�0�0��D�'�*��
�
!�(�
+�
+�	4�	4�
4��'��
�8I�J�J�J�J�J���0�
4�
4�
4��*�+�+�9�+�=�=��+�w�6�6��M�M�"<�=�=�=�2���	�	�#�*�*�S�'�2�2�3�3�3�3�3�3�3�3�����
4����	4�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4����	4�	4�	4�	4�	4�	4sO�A0�0A4�7A4�F
�! D�F
�E:�AE5�0F
�5E:�:F
�
F�Fc��|���}tj�|d��}|�t
t|d��dS)NrAr�)r�r*r:r;r��
ValueErrorr)r�r�rSs   r$�test_make_archivezTestArchives.test_make_archive�sD���������G�L�L���3�3�	����*�l�I�u�E�E�E�E�Er&c�J�tr5tjd��d}tjd��d}ndx}}|���\}}tj�|�	��d��}t|d||||���}|�tj�|����t|d||��}|�tj�|����t|d||||���}|�tj�|����t|d||dd���}|�tj�|����dS)	Nrr�rArk��owner�grouprE�	kjhkjhkjg�oihohoh)
�UID_GID_SUPPORT�grp�getgrgid�pwd�getpwuidrGr*r:r;r�rr�r;)r�r�r�rPr�rSrhs       r$�test_make_archive_owner_groupz*TestArchives.test_make_archive_owner_group�sk���	#��L��O�O�A�&�E��L��O�O�A�&�E�E�"�"�E�E�!�/�/�1�1���(��G�L�L�������;�;�	��9�e�X�x�u�!&�(�(�(���������s�+�+�,�,�,��9�e�X�x�@�@���������s�+�+�,�,�,��9�e�X�x�!&�e�5�5�5���������s�+�+�,�,�,��9�e�X�x�!,�I�?�?�?���������s�+�+�,�,�,�,�,r&�Requires grp and pwd supportc
�D�|���\}}tj�|���d��}tjd��d}tjd��d}tj
|��5t5t|d|d||���}ddd��n#1swxYwYddd��n#1swxYwY|�
tj�|����tj|��}	|���D]8}|�|jd��|�|jd���9	|���dS#|���wxYw)NrArrBrZr�)rGr*r:r;r�r�r�r�r�rrIrJrr�r;rLr<�
getmembersr��uid�gidr)	r�rPr�rSr�r��archive_namerA�members	         r$�test_tarfile_root_ownerz$TestArchives.test_tarfile_root_owners��"�/�/�1�1���(��G�L�L�������;�;�	���Q����"����Q����"��
�
!�(�
+�
+�	B�	B�X�	B�	B�'�	�7�H�f�.3�5�B�B�B�L�	B�	B�	B�	B�	B�	B�	B�	B�	B�	B�	B����	B�	B�	B�	B�	B�	B�	B�	B�	B�	B�	B�	B�	B�	B�	B����	B�	B�	B�	B�
	
�������|�4�4�5�5�5��,�|�,�,��	�!�,�,�.�.�
0�
0��� � ���Q�/�/�/�� � ���Q�/�/�/�/�
0�
�M�M�O�O�O�O�O��G�M�M�O�O�O�O���sC�C�B<�0C�<C	�C�C	�C�C�C�%A
F	�	Fc����tj��}|���}d�}g���fd�}td|gd��	t	jtd|��5�	t
dd|���n#t$rYnwxYwddd��n#1swxYwY|�tj��|��|��||g��td��dS#td��wxYw)Nc��t���r))�RuntimeError)r"�kws  r$�_breaksz3TestArchives.test_make_archive_cwd.<locals>._breaks-s���.�.� r&c�H����|���|��dSr)r�)r:r��
orig_chdirs ��r$�_chdirz2TestArchives.test_make_archive_cwd.<locals>._chdir0s+����K�K������J�t�����r&r��xxx file�chdir)rP)
r*rur�rr�	swap_attrrr
r�r)r��current_dirrPr�r�r�r�s     @@r$�test_make_archive_cwdz"TestArchives.test_make_archive_cwd*so�����i�k�k���<�<�>�>��	!�	!�	!���	�	�	�	�	�	�	 ��w��J�?�?�?�		-��"�2�w��7�7�
�:�� ����A�A�A�A�A�� �����D�����
�
�
�
�
�
�
�
�
�
�
����
�
�
�
�

���R�Y�[�[�+�6�6�6����T�H�k�#:�;�;�;�%�e�,�,�,�,�,��%�e�,�,�,�,���sU�C/�#B�%A8�7B�8
B�B�B�B�C/�B�C/�B�AC/�/Dc�r�|���}tj|��5t5|�tdd��d��|�tj�	d����ddd��n#1swxYwYddd��dS#1swxYwYdS)N�testrEztest.tar�
r�rrIrJr�rr�r*r:r;�r�rPs  r$�test_make_tarfile_in_curdirz(TestArchives.test_make_tarfile_in_curdir@s���<�<�>�>��
�
!�(�
+�
+�	8�	8�X�	8�	8����\�&�%�8�8�*�E�E�E��O�O�B�G�N�N�:�6�6�7�7�7�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8����	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8����	8�	8�	8�	8�	8�	8�5�B,�AB�B,�B	�B,�B	�B,�,B0�3B0c�r�|���}tj|��5t5|�tdd��d��|�tj�	d����ddd��n#1swxYwYddd��dS#1swxYwYdS)Nr�rkztest.zipr�r�s  r$�test_make_zipfile_in_curdirz(TestArchives.test_make_zipfile_in_curdirGs ���<�<�>�>��
�
!�(�
+�
+�	8�	8�X�	8�	8����\�&�%�8�8�*�E�E�E��O�O�B�G�N�N�:�6�6�7�7�7�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8����	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8����	8�	8�	8�	8�	8�	8r�c���|�ttdd��|�ttdd�d��|�ttdd�ddg��tdd�dgd��d	�t��D��}|�d|��td��d
�t��D��}|�d|��dS)Nr�r�c��tSr)��xrEr&r$�<lambda>z;TestArchives.test_register_archive_format.<locals>.<lambda>R���Q�r&c��tSr)r�rEr&r$r�z;TestArchives.test_register_archive_format.<locals>.<lambda>Tr�r&)r�rq)r�rqrc��tSr)r�rEr&r$r�z;TestArchives.test_register_archive_format.<locals>.<lambda>Ws��q�r&r�c��g|]\}}|��SrErE�rOri�paramss   r$rQz=TestArchives.test_register_archive_format.<locals>.<listcomp>X���B�B�B�L�D�&�4�B�B�Br&c��g|]\}}|��SrErEr�s   r$rQz=TestArchives.test_register_archive_format.<locals>.<listcomp>\r�r&)r��	TypeErrorrrr�rr�)r��formatss  r$�test_register_archive_formatz)TestArchives.test_register_archive_formatOs������)�%<�e�Q�G�G�G����)�%<�e�Y�Y��	�	�	����)�%<�e�Y�Y�!�9�-�	/�	/�	/�	 ��y�y�6�(�J�G�G�G�B�B�,?�,A�,A�B�B�B���
�
�e�W�%�%�%�!�%�(�(�(�B�B�,?�,A�,A�B�B�B�������(�(�(�(�(r&c��|�|d���|�|tj��|�|t��dS)Nc��|Sr)rE�r:s r$r�z3TestArchives.check_unpack_archive.<locals>.<lambda>bs��d�r&)�#check_unpack_archive_with_converterrorpr)r�r�s  r$�check_unpack_archivez!TestArchives.check_unpack_archiveasP���0�0��9J�9J�K�K�K��0�0����F�F�F��0�0���B�B�B�B�Br&c�6�|���\}}t|��}|�d��tj�|���d��}t||||��}|���}t||��||����|�	t|��|��|���}	t||��||	��|���|�	t|	��|��|�
tjt|t����|�
tt|t��d���dS)Nr_rA)r�r�)rGrgrr*r:r;r�rrr�r�r��	ReadErrorrr�)
r�r��	converterrPr��expectedrSr�r�tmpdir3s
          r$r�z0TestArchives.check_unpack_archive_with_converterfsa��!�/�/�1�1���(��H�%�%������ � � ��G�L�L�������;�;�	��	�6�8�X�F�F���,�,�.�.���y�y��*�*�I�I�g�,>�,>�?�?�?�����'�*�*�H�5�5�5��,�,�.�.���y�y��*�*�I�I�g�,>�,>�v�N�N�N�N�����'�*�*�H�5�5�5����&�*�N�I�I�f�<M�<M�N�N�N����*�n�i�i��6G�6G�PU��V�V�V�V�Vr&c�0�|�d��dS)NrE�r�rs r$�test_unpack_archive_tarz$TestArchives.test_unpack_archive_tar{s���!�!�%�(�(�(�(�(r&c�0�|�d��dS)NrBr�rs r$�test_unpack_archive_gztarz&TestArchives.test_unpack_archive_gztar~����!�!�'�*�*�*�*�*r&c�0�|�d��dS)N�bztarr�rs r$�test_unpack_archive_bztarz&TestArchives.test_unpack_archive_bztar�r�r&z(AIX MAXDATA must be 0x20000000 or largerc�0�|�d��dS)N�xztarr�rs r$�test_unpack_archive_xztarz&TestArchives.test_unpack_archive_xztar�s��	
�!�!�'�*�*�*�*�*r&c�0�|�d��dS)Nrkr�rs r$�test_unpack_archive_zipz$TestArchives.test_unpack_archive_zip�s���!�!�%�(�(�(�(�(r&c���t��}�fd�}tdddg|dg��tdd����ttddg|��td��tddg|����ddgd	ft������ddgd	ft����td����t��|��dS)
Nc�����|d����|d����|d��dS)Nr��	stuff.boo�xx)r�)r��extract_dir�extrar�s   �r$�_booz/TestArchives.test_unpack_registry.<locals>._boo�sK������U�A�&�&�&����X�{�3�3�3����[�$�/�/�/�/�/r&�Booz.booz.b2)r�r�r�r��Boo2r�)	rr	rr�r
rr�r�r�)r�r�r�s`  r$�test_unpack_registryz!TestArchives.test_unpack_registry�s���$�&�&��	0�	0�	0�	0�	0�
	�u�v�u�o�t�l�^�L�L�L��{�D�)�)�)�	
���-�)?��!�(�D�	*�	*�	*�	!��'�'�'��v��x��6�6�6��
�
�v��x��,�.@�.B�.B�C�C�C����%�&��2�.�0B�0D�0D�E�E�E�	!��(�(�(����+�-�-�w�7�7�7�7�7r&N)rZ)%r�r�r�r�
requires_zlibrVrYrGr+r,r��whichrirxr}r�r�r�r�r�r�r�r�r�r�r�r�r��requires_bz2r��
requires_lzmar-r�r�r�r�r�rEr&r$r?r?9sa�������W����!H�!H���!H�F � � �"�"�"�"��W�����X�����e�,�,�6�8�8�1�1�8�8���1�B�W����"D�"D���"D�H�W�����X�����e�,�,�6�8�8�8�8�8�8���8�0�W�����X�����g�.�.�8�:�:�4�4�:�:���4�,F�F�F�
�W����-�-���-�6�W�����X���*H�I�I���J�I����*-�-�-�,8�8�8��W����8�8���8�)�)�)�$C�C�C�
W�W�W�*)�)�)��W����+�+���+��W����+�+���+��W�����X�_�S�-�����-�/Y�Z�Z�+�+�[�Z���+��W����)�)���)�8�8�8�8�8r&r?c���eZdZejeed��d��d���Zejed��ejee	d��d��d�����Z
dS)	�TestMisc�
disk_usagez)disk_usage not available on this platformc�"�tjtj�t
����}dD]+}|�t||��t���,|�	|j
d��|�	|jd��|�|j
d��|�|j
|j��|�	|j
|j
��tjt
��dS)N)rF�used�freer)r�r�r*r:r9r/r�r r��
assertGreaterrFr��assertGreaterEqualr�)r��usager�s   r$�test_disk_usagezTestMisc.test_disk_usage�s����!�"�'�/�/�(�";�";�<�<��-�	=�	=�D��!�!�'�%��"6�"6��<�<�<�<����5�;��*�*�*����5�:�q�)�)�)�����
�A�.�.�.������U�Z�8�8�8����5�;��
�3�3�3�	��(�#�#�#�#�#r&r��chownzrequires os.chownc���������}tj|����t�d����t
��5t
j���ddd��n#1swxYwY��t��5t
j�d���ddd��n#1swxYwY��t��5t
j�d���ddd��n#1swxYwY��t��5t
j�d��ddd��n#1swxYwY��t��5t
j�d��ddd��n#1swxYwYtj��}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|||��||||��dS#t"$rYdSwxYw)
Nr�ztesting chown functionznon-existing username)�userznon-existing groupname)r��spamg��Q�	@c���tj���}|���||j��|���||j��dSdSr))r*r�r��st_uid�st_gid)r:r�r��sr�r�s    ��r$�check_chownz(TestMisc.test_chown.<locals>.check_chown�sY������!�!�A���� � ��a�h�/�/�/���� � ��a�h�/�/�/�/�/��r&)r�r)NN)r�rsr�rBr�r�r�r��LookupErrorr�r*�getuid�getgidr�r�r�r��KeyError)r�r9r�r�r�r�r�r�s`      @r$�
test_chownzTestMisc.test_chown�s������,�,�.�.���?�w�/�/�/���8�5�6�6�6�
�
�
�z�
*�
*�	#�	#��L��"�"�"�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#����	#�	#�	#�	#��
�
�{�
+�
+�	A�	A��L��(?�@�@�@�@�	A�	A�	A�	A�	A�	A�	A�	A�	A�	A�	A����	A�	A�	A�	A��
�
�{�
+�
+�	C�	C��L��)A�B�B�B�B�	C�	C�	C�	C�	C�	C�	C�	C�	C�	C�	C����	C�	C�	C�	C��
�
�y�
)�
)�	,�	,��L��7�+�+�+�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,����	,�	,�	,�	,��
�
�y�
)�
)�	)�	)��L��4�(�(�(�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)����	)�	)�	)�	)��i�k�k���i�k�k��	0�	0�	0�	0�	0�	0�	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��%�%�a�(�E�

�L��4��/�/�/��K��#�s�+�+�+��L��$��.�.�.��K���c�*�*�*�*�*���	�	�	��D�D�	���sl�A7�7A;�>A;�B?�?C�C�$D�D�D�,E�E�E�3F�F�F� 4M�
M*�)M*N)r�r�r�r+r,rrr�r�r�r*rrEr&r$r�r��s��������X������6�6�D�F�F�$�$�F�F�$��X���*H�I�I��X�����W�-�-�/B�C�C�:+�:+�D�C�J�I�:+�:+�:+r&r�c�N�eZdZd�Zd�Zd�Zd�Zd�Zej	d���Z
d�Zd�Ze
jejd	kd
��d���Zd�Zd
�Zd�Zd�Zd�Zd�Ze
jejd	kd��d���Ze
jejd	kd��d���ZdS)�	TestWhichc���|�d���|_tj|jdd���|_tj|jjtj	��|�
|jj��t
j�
|jj��\|_|_|j|_t
j|_d|_dS)N�Tmp)r�z.Exe�ror��suffixz.EXE)r��temp_dirrsrt�	temp_filer*r�rir��S_IXUSRr�rr:r�ro�file�env_path�curdir�extrs r$�setUpzTestWhich.setUp�s������E��2�2��
�"�4���<A�<B�D�D�D���	����$�d�l�3�3�3������,�-�-�-� �g�m�m�D�N�,?�@�@����$�)����
��i�������r&c��tj|j|j���}|�||jj��dS�Nr�)r�r�rror�rri�r�r�s  r$�
test_basiczTestWhich.test_basic
s;��
�\�$�)�$�(�
3�
3�
3������T�^�0�1�1�1�1�1r&c��tj|jj|j���}|�||jj��dSr)r�r�rrirr�rs  r$�test_absolute_cmdzTestWhich.test_absolute_cmds@���\�$�.�-�D�M�
B�
B�
B������T�^�0�1�1�1�1�1r&c��tj�|j��\}}tj�||j��}t
j|���5tj	||j
���}|�||��ddd��n#1swxYwYt
j|j���5tj	||���}|�|��ddd��dS#1swxYwYdSr)
r*r:r�ror;rrrIr�r�rr��assertIsNone)r�r��tail_dir�relpathr�s     r$�test_relative_cmdzTestWhich.test_relative_cmdsn�� �W�]�]�4�8�4�4���(��'�,�,�x���3�3��
�
!�x�
0�
0�
0�	*�	*���g�D�M�:�:�:�B����R��)�)�)�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*����	*�	*�	*�	*��
!�t�x�
0�
0�
0�	"�	"���g�H�5�5�5�B����b�!�!�!�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"�	"�	"s$�"2B � B$�'B$�,C>�>D�Dc��tj�|j��}t	j|j���5t
j|j|���}tj
dkr?|�|tj�|j
|j����n|�|��ddd��dS#1swxYwYdS)Nr�r!)r*r:r9rorrIr�r�rr�r.r�r;rr)r�r�r�s   r$�test_cwdzTestWhich.test_cwd"s����7�?�?�4�8�,�,��
�
!�t�x�
0�
0�
0�	&�	&���d�i�h�7�7�7�B��|�w�&�&�� � ��R�W�\�\�$�+�t�y�%I�%I�J�J�J�J��!�!�"�%�%�%�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&����	&�	&�	&�	&�	&�	&s�BC�C�Cc�T�tj|jjtj��tj|jjtj��r|�d��tj
|j|jtj���}|�
|��dS)Nzcan't set the file read-only)r:r@)r*r�rrir�r��access�W_OKr�r�r�rrorrs  r$�test_non_matching_modez TestWhich.test_non_matching_mode.s���	����$�d�l�3�3�3�
�9�T�^�(�"�'�2�2�	:��M�M�8�9�9�9�
�\�$�)�$�(���
A�
A�
A�����"�����r&c�X�tj�|j��\}}t	j|���5t
j|j|���}|�	|tj�
||j����ddd��dS#1swxYwYdSr)r*r:r�rorrIr�r�rr�r;)r�r�rr�s    r$�test_relative_pathzTestWhich.test_relative_path7s����W�]�]�4�8�4�4���(�
�
!�x�
0�
0�
0�	D�	D���d�i�h�7�7�7�B����R�����h��	�!B�!B�C�C�C�	D�	D�	D�	D�	D�	D�	D�	D�	D�	D�	D�	D����	D�	D�	D�	D�	D�	Ds�AB�B#�&B#c�f�tjd|j���}|�|��dS)Nzfoo.exer�)r�r�rorrs  r$�test_nonexistent_filezTestWhich.test_nonexistent_file=s2��
�\�)�$�(�
3�
3�
3�����"�����r&r!zpathext check is Windows-onlyc��tj|jdd�|j���}|�||jjdd�|jz��dS)N���r�)r�r�rror�rrirrs  r$�test_pathext_checkingzTestWhich.test_pathext_checkingBsU��
�\�$�)�C�R�C�.�t�x�
8�
8�
8������T�^�0��"��5���@�A�A�A�A�Ar&c���tj��5}|j|d<tj|j��}|�||jj��ddd��dS#1swxYwYdS�N�PATH)	r�EnvironmentVarGuardrr�r�rr�rri�r��envr�s   r$�test_environ_pathzTestWhich.test_environ_pathJs���
�
*�
,�
,�	6���-�C��K���d�i�(�(�B����R���!4�5�5�5�	6�	6�	6�	6�	6�	6�	6�	6�	6�	6�	6�	6����	6�	6�	6�	6�	6�	6s�AA%�%A)�,A)c	��tj��5}d|d<tj�d|jd���5t
jtd|j��5tj	|j��5tj|j��}|�
|��ddd��n#1swxYwYddd��n#1swxYwYddd��n#1swxYwYddd��dS#1swxYwYdS)Nr�r-�
os.confstrT��return_value�create�defpath)rr.r+r�r�rorr�r*rIr�r�rrr/s   r$�test_environ_path_emptyz!TestWhich.test_environ_path_emptyPs���
�
*�
,�
,�	&���C��K���$�$�\���,0�%�2�2�
&�
&��"�2�y�$�(�;�;�
&�
&��%�d�h�/�/�
&�
&��\�$�)�,�,���!�!�"�%�%�%�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&����
&�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&����
&�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&����
&�
&�
&�
&�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&����	&�	&�	&�	&�	&�	&s}�-C=�!C%�"C�</B7	�+C�7B;
�;C�>B;
�?C�C%�C�C%�C�C%�C=�%C)	�)C=�,C)	�-C=�=D�Dc	��tj�|jj��}t
jdkrUtj}t|t��rtj
|��}tj�||��}tj
��5}tj|d<tj�d|jd���5t'jtd|j��5t+j|j��}|�|��tj|j��5t+j|j��}|�||��ddd��n#1swxYwYddd��n#1swxYwYddd��n#1swxYwYddd��dS#1swxYwYdS)Nr!r-r3Tr4r7)r*r:rHrrir�r.rr8r�r�r;rr.�pathsepr+r�r�rorr�r�r�rrrIr�)r��expected_cwdrr0r�s     r$�test_environ_path_cwdzTestWhich.test_environ_path_cwd[s����w�'�'���(;�<�<���<�7�"�"��Y�F��,��.�.�
-���V�,�,���7�<�<���=�=�L��
*�
,�
,�	7���*�C��K���$�$�\���,0�%�2�2�	
7�	
7��"�2�y�$�(�;�;�	
7�	
7��\�$�)�,�,���!�!�"�%�%�%��)�$�(�3�3�7�7���d�i�0�0�B��$�$�R��6�6�6�7�7�7�7�7�7�7�7�7�7�7����7�7�7�7�	
7�	
7�	
7�	
7�	
7�	
7�	
7�	
7�	
7�	
7�	
7����	
7�	
7�	
7�	
7�	
7�	
7�	
7�	
7�	
7�	
7�	
7�	
7�	
7�	
7�	
7����	
7�	
7�	
7�	
7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7����	7�	7�	7�	7�	7�	7s�"7G�!F,�:AF�0E>	�2F�>F
�F�F
�F�	F,�F�F,�F�F,� G�,F0	�0G�3F0	�4G�G�Gc�@�tj��5}|�dd��tj�dtd���5tjtd|j
��5tj|j
��}ddd��n#1swxYwYddd��n#1swxYwY|�||jj��tj�d|j
d���5tjtdd��5tj|j
��}ddd��n#1swxYwYddd��n#1swxYwY|�||jj��ddd��dS#1swxYwYdS)Nr-r3T)rr6r7r4r�)rr.�popr+r�r�r�rr�r*ror�r�rr�rrir/s   r$�test_environ_path_missingz#TestWhich.test_environ_path_missingqs���
�
*�
,�
,�	6���G�G�F�D�!�!�!���$�$�\�z�,0�%�2�2�
-�
-��"�2�y�$�(�;�;�
-�
-��\�$�)�,�,��
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-����
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-����
-�
-�
-�
-�
���R���!4�5�5�5���$�$�\���,0�%�2�2�
-�
-��"�2�y�"�5�5�
-�
-��\�$�)�,�,��
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-����
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-����
-�
-�
-�
-�
���R���!4�5�5�5�	6�	6�	6�	6�	6�	6�	6�	6�	6�	6�	6�	6����	6�	6�	6�	6�	6�	6s��>F�!B0�3B�
B0�B�B0� B�!B0�$F�0B4	�4F�7B4	�8A
F�E�E�8E�E�E�E�E�F�E	�F�"E	�##F�F�Fc�~�tj�|j��}t	j|j���5t	j��5}|j|d<tj	|j
d���}|�|��ddd��n#1swxYwYddd��dS#1swxYwYdS)Nr�r-r�)r*r:r9rorrIr.rr�r�rr)r�r�r0r�s    r$�test_empty_pathzTestWhich.test_empty_path�s(���7�?�?�4�8�,�,��
�
!�t�x�
0�
0�
0�	"�	"�
�
*�
,�
,�	"�03��-�C��K���d�i�b�1�1�1�B����b�!�!�!�		"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"�	"�	"s5�B2�;B�B2�B	�B2�!B	�"B2�2B6�9B6c���tj��5}|�dd��tj|j��}|�|��ddd��dS#1swxYwYdSr,)rr.r>r�r�rrr/s   r$�test_empty_path_no_PATHz!TestWhich.test_empty_path_no_PATH�s���
�
*�
,�
,�	"���G�G�F�D�!�!�!���d�i�(�(�B����b�!�!�!�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"�	"�	"s�AA&�&A*�-A*ztest specific to Windowsc��d}tj|jd|���}tj|jtj��|�|j	��tj
�|j��}tj
�|��d}tj��5}||d<tj||j���}|�||j��ddd��dS#1swxYwYdS)N�.xyz�Tmp2r	r�PATHEXTr�)rsrtrr*r�rir�r
r�rr:rHr`rr.r�r�r��r�r�temp_filexyz�programr0r�s      r$�test_pathextzTestWhich.test_pathext�s2�����2�t�}�:@��N�N�N��
���"�D�L�1�1�1�����*�+�+�+��'�"�"�<�#4�5�5���'�"�"�7�+�+�A�.��
�
*�
,�
,�	4�� �C�	�N���g�D�M�:�:�:�B����R��!2�3�3�3�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4����	4�	4�	4�	4�	4�	4s�9<D�D�	Dc���d}tj|jd|���}|�|j��t
j�|j��}t
j�	|��d}tj��5}|�d�|d<tj
||j���}|�||j��ddd��dS#1swxYwYdS)NrErFr	r�;rGr�)rsrtrr�rr*r:rHrir`rr.r�r�r�rHs      r$�test_pathext_with_empty_strz%TestWhich.test_pathext_with_empty_str�s!�����2�t�}�:@��N�N�N������*�+�+�+��'�"�"�<�#4�5�5���'�"�"�7�+�+�A�.��
�
*�
,�
,�	4�� #�Y�Y�Y�C�	�N���g�D�M�:�:�:�B����R��!2�3�3�3�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4�	4����	4�	4�	4�	4�	4�	4s�?C!�!C%�(C%N)r�r�r�rrrrrrr/r#r%r'r+r,r�r.r*r1r8r<r?rArCrKrNrEr&r$rr�s����������2�2�2�
2�2�2�"�"�"�
&�
&�
&��#���$�#��D�D�D����
�X�����0�8�:�:�B�B�:�:�B�6�6�6�	&�	&�	&�7�7�7�,6�6�6�$"�"�"�"�"�"��X�����0�2L�M�M�4�4�N�M�4�"�X�����0�2L�M�M�
4�
4�N�M�
4�
4�
4r&rc��eZdZd�ZdS)�TestWhichBytesc�z�t�|��tj|j��|_tj|j��|_tj|jj��|j_tj|j��|_tj|j	��|_	dSr))
rrr*r�rorrrirrrs r$rzTestWhichBytes.setUp�s}����������;�t�x�(�(����K��	�*�*��	� �k�$�.�*=�>�>�����k�$�+�.�.����;�t�x�(�(����r&N)r�r�r�rrEr&r$rPrP�s#������)�)�)�)�)r&rPc��eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	e
d���Ze
d	���Zd
�Z
e
d���Zd�Ze
d
���Zd�Zejejjd��d���Zd�Zd�Zd�Zd�Zeje
d�����Zeje
d�����Zeje
d�����Z eje
d�����Z!d�Z"d�Z#e
d���Z$e
d���Z%d�Z&ej'eje(ed��oe(e)d��oe(e)d ��d!��d"�����Z*d#S)$�TestMovec��d}|���|_|���|_tj�|j|��|_tj�|j|��|_t|jd��5}|�	d��ddd��dS#1swxYwYdS)Nr�r3r�)
r�r=r>r*r:r;r$r2r<r=)r�r�rXs   r$rzTestMove.setUp�s������|�|�~�~����|�|�~�~�������T�\�8�<�<��
�����T�\�8�<�<��
�
�$�-��
&�
&�	�!�
�G�G�G����	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s�C�C�Cc��t|d��5}|���}ddd��n#1swxYwYtj||��t|d��5}|�||�����ddd��n#1swxYwY|�tj�|����dS�Nr\)	r<r^r��mover�r�r*r:r�)r�rzr{�real_dstrX�contentss      r$�_check_move_filezTestMove._check_move_file�s)��
�#�t�_�_�	 ���v�v�x�x�H�	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 ���C�����
�(�D�
!�
!�	1�Q����X�q�v�v�x�x�0�0�0�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1����	1�	1�	1�	1���������,�,�-�-�-�-�-s�2�6�6�")B�B�Bc�@�ttj|����}tj||��|�|ttj|������|�tj�|����dSr))	rbr*rcr�rWr�r�r:r�)r�rzr{rXrYs     r$�_check_move_dirzTestMove._check_move_dir�sy���"�*�S�/�/�*�*����C���������6�"�*�X�*>�*>�#?�#?�@�@�@���������,�,�-�-�-�-�-r&c�R�|�|j|j|j��dSr))rZr$r2rs r$�test_move_filezTestMove.test_move_file�s&�����d�m�T�]�D�M�J�J�J�J�Jr&c�R�|�|j|j|j��dSr))rZr$r>r2rs r$�test_move_file_to_dirzTestMove.test_move_file_to_dir�s&�����d�m�T�\�4�=�I�I�I�I�Ir&c�z�tj|j��}|�||j|j��dSr))rorpr$rZr>r2)r�rzs  r$�"test_move_file_to_dir_pathlike_srcz+TestMove.test_move_file_to_dir_pathlike_src�s5���l�4�=�)�)�����c�4�<���?�?�?�?�?r&c�z�tj|j��}|�|j||j��dSr))rorpr>rZr$r2�r�r{s  r$�"test_move_file_to_dir_pathlike_dstz+TestMove.test_move_file_to_dir_pathlike_dst�s5���l�4�<�(�(�����d�m�S�$�-�@�@�@�@�@r&c�.�|���dSr))r^rs r$�test_move_file_other_fsz TestMove.test_move_file_other_fs�s��	
�������r&c�.�|���dSr))r`rs r$�test_move_file_to_dir_other_fsz'TestMove.test_move_file_to_dir_other_fs�s��	
�"�"�$�$�$�$�$r&c���tj|������}	|�|j||��tj|��dS#tj|��wxYwr)rsr�r�r\r=rr��r�r>s  r$�
test_move_dirzTestMove.test_move_dir�si���/�d�l�l�n�n�5�5�5��	&�� � ���w��@�@�@���W�%�%�%�%�%��I��W�%�%�%�%���s�A�A1c�.�|���dSr))rlrs r$�test_move_dir_other_fszTestMove.test_move_dir_other_fs�s��	
�������r&c
���|�|j|jtj�|jtj�|j������dSr))r\r=r>r*r:r;rHrs r$�test_move_dir_to_dirzTestMove.test_move_dir_to_dirsX�����T�\�4�<��G�L�L���r�w�'7�'7���'E�'E�F�F�	H�	H�	H�	H�	Hr&c�.�|���dSr))rprs r$�test_move_dir_to_dir_other_fsz&TestMove.test_move_dir_to_dir_other_fss��	
�!�!�#�#�#�#�#r&c
��|�|jtjjz|jtj�|jtj�|j������dSr))r\r=r*r:�sepr>r;rHrs r$�test_move_dir_sep_to_dirz!TestMove.test_move_dir_sep_to_dir
sa�����T�\�B�G�K�7����G�L�L���r�w�'7�'7���'E�'E�F�F�	H�	H�	H�	H�	Hr&zrequires os.path.altsepc
��|�|jtjjz|jtj�|jtj�|j������dSr))r\r=r*r:�altsepr>r;rHrs r$�test_move_dir_altsep_to_dirz$TestMove.test_move_dir_altsep_to_dirsa�����T�\�B�G�N�:�D�L��G�L�L���r�w�'7�'7���'E�'E�F�F�	H�	H�	H�	H�	Hr&c���t|jd��5	ddd��n#1swxYwY|�tjtj|j|j��dS)Nr3)r<r2r�r�rrWr$r>rs r$�"test_existing_file_inside_dest_dirz+TestMove.test_existing_file_inside_dest_dirs���
�$�-��
&�
&�	�	��	�	�	�	�	�	�	�	�	�	�	����	�	�	�	����&�,���T�]�D�L�Q�Q�Q�Q�Qs�$�(�(c��tj�|jd��}|�t
jt
j|j|��dS�Nr�)r*r:r;r=r�r�rrWrds  r$�test_dont_move_dir_in_itselfz%TestMove.test_dont_move_dir_in_itselfs?���g�l�l�4�<��/�/�����&�,���T�\�3�G�G�G�G�Gr&c	��tjt��	dD]�\}}tj�t|��}tj�t|��}|�t
j||��d|�d|�d������	tj	t��dS#tj	t��wxYw)N))�srcdirzsrcdir/dest�)_destinsrc() wrongly concluded that dst (z) is not in src (�)�r�)
r*r�rr:r;r�r��
_destinsrcrr�r%s   r$�test_destinsrc_false_negativez&TestMove.test_destinsrc_false_negatives���
������	%�7�
I�
I���S��g�l�l�6�3�/�/���g�l�l�6�3�/�/������ 1�#�s� ;� ;� ;�>A�c�c�3�3�3�"H� �I�I�I�I�
I�
��V�$�$�$�$�$��I��V�$�$�$�$�����BB:�:Cc	��tjt��	dD]�\}}tj�t|��}tj�t|��}|�t
j||��d|�d|�d������	tj	t��dS#tj	t��wxYw)N))rzsrc/dest)rz
srcdir.newr�z
) is in src (r�r�)
r*r�rr:r;r�r�r�rr�r%s   r$�test_destinsrc_false_positivez&TestMove.test_destinsrc_false_positive*s���
������	%�N�
D�
D���S��g�l�l�6�3�/�/���g�l�l�6�3�/�/��� � ��!2�3��!<�!<�!<�9<���c�c�c�!C�!�D�D�D�D�
D�
��V�$�$�$�$�$��I��V�$�$�$�$���r�c��tj�|jd��}tj|j|��t
j||j��|�	tj�
|j����|�	tj�|j|j����dSr|)r*r:r;r=r�r$r�rWr2r�re�samefilerds  r$�test_move_file_symlinkzTestMove.test_move_file_symlink6s����g�l�l�4�<��/�/��
�
�4�=�#�&�&�&���C���'�'�'��������t�}�5�5�6�6�6������(�(����
�F�F�G�G�G�G�Gr&c���d}tj�|j|��}tj|j|��t
j||j��tj�|j|��}|�	tj�
|����|�	tj�|j|����dSr|)r*r:r;r=r�r$r�rWr>r�rer�)r�r�r{�
final_links    r$�test_move_file_symlink_to_dirz&TestMove.test_move_file_symlink_to_dir?s������g�l�l�4�<��2�2��
�
�4�=�#�&�&�&���C���&�&�&��W�\�\�$�,��9�9�
��������z�2�2�3�3�3������(�(���
�C�C�D�D�D�D�Dr&c�<�tj�|jd��}tj�|jd��}tj||��tj�|jd��}t
j||��|�tj�	|����|�
tj�|��tj�|����dS�Nr�r�r�)r*r:r;r=r�r>r�rWr�rer��realpath�r�rzr{rVs    r$�test_move_dangling_symlinkz#TestMove.test_move_dangling_symlinkJs����g�l�l�4�<��/�/���g�l�l�4�<��/�/��
�
�3������7�<�<���f�5�5����C��"�"�"��������x�0�0�1�1�1������)�)�#�.�.���0@�0@��0J�0J�K�K�K�K�Kr&c�*�tj�|jd��}tj�|jd��}tj|��tj||��tj�|jd��}tj||��|�	tj�
|����|�	tj�||����dSr�)r*r:r;r=r�r�r>r�rWr�rer�r�s    r$�test_move_dir_symlinkzTestMove.test_move_dir_symlinkUs����g�l�l�4�<��/�/���g�l�l�4�<��/�/��
���
�
�
�
�
�3������7�<�<���f�5�5����C��"�"�"��������x�0�0�1�1�1������(�(��h�7�7�8�8�8�8�8r&c	��tj|j|j��}|�|t
j�|jt
j�|j������dSr))	r�rWr$r>r�r*r:r;rHrs  r$�test_move_return_valuezTestMove.test_move_return_valueasg��
�[�����
5�
5����������T�\�2�7�+;�+;�D�M�+J�+J�K�K�	M�	M�	M�	M�	Mr&c���tj|jtj�|jd����}|�|tj�|jd����dSr|)r�rWr$r*r:r;r>r�rs  r$� test_move_as_rename_return_valuez)TestMove.test_move_as_rename_return_valuefsU��
�[�������T�\�5�(I�(I�
J�
J������R�W�\�\�$�,��>�>�?�?�?�?�?r&c���g��fd�}tj|j|j|���|�t���d��dS)Nc�6����||f��dSr)r��rzr{�moveds  �r$r�z7TestMove.test_move_file_special_function.<locals>._copym�����L�L�#�s��$�$�$�$�$r&r�r�)r�rWr$r>r�r��r�r�r�s  @r$�test_move_file_special_functionz(TestMove.test_move_file_special_functionjs^�����	%�	%�	%�	%�	%���D�M�4�<�u�E�E�E�E�����U���Q�'�'�'�'�'r&c�z��g��fd�}tjtj�|jd����tjtj�|jd����t
j|j|j|���|�	t���d��dS)Nc�6����||f��dSr)r�r�s  �r$r�z6TestMove.test_move_dir_special_function.<locals>._copyur�r&�child�child1r�r)rr�r*r:r;r=r�rWr>r�r�r�s  @r$�test_move_dir_special_functionz'TestMove.test_move_dir_special_functionrs������	%�	%�	%�	%�	%��#�B�G�L�L���w�$G�$G�H�H�H��#�B�G�L�L���x�$H�$H�I�I�I���D�L�$�,�e�D�D�D�D�����U���Q�'�'�'�'�'r&c�N�|���|_tj�tj�|j��tj�|j�������}|�|j|��	tj
|j|��|�tj�|����tj
|��dS#tj
|��wxYwr))r�r=r*r:r;r9rH�upperr�r�rWr�rdr�rks  r$�test_move_dir_caseinsensitivez&TestMove.test_move_dir_caseinsensitive|s����|�|�~�~����'�,�,�������-�-��� � ���.�.�4�4�6�6�8�8��	
���D�L�'�2�2�2�	��K���g�.�.�.��O�O�B�G�M�M�'�2�2�3�3�3��H�W�������B�H�W�������s
�,AD�D$rI�SF_IMMUTABLE�	UF_OPAQUEzrequires lchflagsc��	tjt��tjttj��|�ttj	tt��|�ttj��v��tjttj
��tjtj�td����tjttj��|�ttj	tt��|�ttj��v��tj�t��r=tjttj
��tjt��tj�t��r?tjttj
��tjt��dSdS#tj�t��r=tjttj
��tjt��tj�t��r>tjttj
��tjt��wwxYw)Nr�)r*r��
TESTFN_SRCrIr�r�r�ryr�rW�
TESTFN_DSTr�rcr�rr�r:r;r�r�rs r$�test_move_dir_permission_deniedz(TestMove.test_move_dir_permission_denied�s���	-��H�Z� � � ��K�
�D�$5�6�6�6�
���o�v�{�J�
�S�S�S����Z�2�:�<�<�7�8�8�8�
�K�
�D�N�3�3�3��'�����Z��(I�(I�J�J�J��K�
�D�$5�6�6�6�
���o�v�{�J�
�S�S�S����Z�2�:�<�<�7�8�8�8��w�~�~�j�)�)�
-���J���7�7�7�� ��,�,�,��w�~�~�j�)�)�
-���J���7�7�7�� ��,�,�,�,�,�
-�
-���w�~�~�j�)�)�
-���J���7�7�7�� ��,�,�,��w�~�~�j�)�)�
-���J���7�7�7�� ��,�,�,�,�
-���s
�E8I�CLN)+r�r�r�rrZr\r^r`rbrer1rgrirlrnrprrrur+r,r*r:rwrxrzr}r�r�rr*r�r�r�r�r�r�r�r�r�r;rrr�r�rEr&r$rSrS�s(���������.�.�.�.�.�.�K�K�K�J�J�J�@�@�@�
A�A�A�
����[���%�%��[�%�&�&�&�����[��H�H�H�
�$�$��[�$�H�H�H��X�����)B�C�C�H�H�D�C�H�R�R�R�H�H�H�

%�
%�
%�
%�
%�
%��"��H�H��[�#�"�H��"��E�E��[�#�"�E��"��L�L��[�#�"�L��"��9�9��[�#�"�9�M�M�M�
@�@�@��(�(��[�(��(�(��[�(����"�'��X�����Z�0�0�8�$�W�T�>�:�:�8�$�W�T�;�7�7�,�.�.�-�-�	.�.�(�'�
-�-�-r&rSc���eZdZGd�de��Zd�Zejed��d���Z	ejed��d���Z
ejed��d���ZdS)	�TestCopyFilec�4�eZdZdZdZdZdd�Zd�Zd�Zd�Z	dS)	�TestCopyFile.FauxFNTc�"�||_||_dSr))�_raise_in_exit�_suppress_at_exit)r��
raise_in_exit�suppress_at_exits   r$�__init__zTestCopyFile.Faux.__init__�s��"/�D��%5�D�"�"�"r&c��dS)Nr�rE)r�r"s  r$r^zTestCopyFile.Faux.read�s���2r&c��d|_dS)NT)�_enteredrs r$�	__enter__zTestCopyFile.Faux.__enter__�s
�� �D�M�M�Mr&c�^�|||f|_|jrd|_td���|jS)NT�Cannot close)�_exited_withr��_raisedrr�)r��exc_type�exc_val�exc_tbs    r$�__exit__zTestCopyFile.Faux.__exit__�s:�� (�'�6� 9�D���"�
.�#����n�-�-�-��)�)r&)FT)
r�r�r�r�r�r�r�r^r�r�rEr&r$�Fauxr��sd������������	6�	6�	6�	6�	�	�	�	!�	!�	!�	*�	*�	*�	*�	*r&r�c��dd�}tjtd|��5|�t��5tjdd��ddd��n#1swxYwYddd��dS#1swxYwYdS)Nr]c�0�|dkrtd���J�)N�srcfilezCannot open "srcfile"r�)r�r@s  r$�_openz4TestCopyFile.test_w_source_open_fails.<locals>._open�s!���9�$�$��5�6�6�6��Hr&r<r��destfile�r])rr�r�r�rr&)r�r�s  r$�test_w_source_open_failsz%TestCopyFile.test_w_source_open_fails�s��	�	�	�	�
�
�v�v�u�
5�
5�	7�	7��"�"�7�+�+�
7�
7���	�:�6�6�6�
7�
7�
7�
7�
7�
7�
7�
7�
7�
7�
7����
7�
7�
7�
7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7����	7�	7�	7�	7�	7�	7s4�A5�A�A5�A!	�!A5�$A!	�%A5�5A9�<A9zskipped on macOSc���|����d	�fd�	}tjtd|��5tjdd��ddd��n#1swxYwY|��j��|��jdtu��|�	�jdj
d��dS)
Nr]c�B��|dkr�S|dkrtd���J�)Nr�r��Cannot open "destfile"r�)r�r@r�s  �r$r�z2TestCopyFile.test_w_dest_open_fails.<locals>._open�s2����9�$�$����:�%�%��6�7�7�7��Hr&r<r�r�rr�)r�r�)r�rr�r�r&r�r�r�rr�r")r�r�r�s  @r$�test_w_dest_open_failsz#TestCopyFile.test_w_dest_open_fails�s����)�)�+�+��	�	�	�	�	�	��
�v�v�u�
5�
5�	3�	3��O�I�z�2�2�2�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3����	3�	3�	3�	3�����(�)�)�)�����,�Q�/�7�:�;�;�;�����-�a�0�5�4�	6�	6�	6�	6�	6s�A�A� Ac�0���|����|�d���d
��fd�	}tjtd|��5tjdd��ddd��n#1swxYwY|��j��|��j��|��j��|��jdtu��|�
�jdjd	��dS)NTr]c�(��|dkr�S|dkr�SJ��Nr�r�rE�r�r@r�r�s  ��r$r�z3TestCopyFile.test_w_dest_close_fails.<locals>._open��(����9�$�$����:�%�%����Hr&r<r�r�rr�)r�r�)r�rr�r�r&r�r�r�r�rr�r"�r�r�r�r�s  @@r$�test_w_dest_close_failsz$TestCopyFile.test_w_dest_close_fails�sQ�����)�)�+�+���9�9�T�?�?��	�	�	�	�	�	�	��
�v�v�u�
5�
5�	3�	3��O�I�z�2�2�2�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3����	3�	3�	3�	3�����(�)�)�)�����)�*�*�*�����(�)�)�)�����,�Q�/�7�:�;�;�;�����-�a�0�5�*�	,�	,�	,�	,�	,s�A0�0A4�7A4c�r���|�d���|����d��fd�	}tjtd|��5|�t
��5tjdd��ddd��n#1swxYwYddd��n#1swxYwY|��j��|��j��|�	�j
��|��jddu��|��j
��dS)	NTr]c�(��|dkr�S|dkr�SJ�r�rEr�s  ��r$r�z5TestCopyFile.test_w_source_close_fails.<locals>._open�r�r&r<r�r�rr�)r�rr�r�r�rr&r�r�r�r�r�r�s  @@r$�test_w_source_close_failsz&TestCopyFile.test_w_source_close_fails�s������)�)�D�/�/���9�9�;�;��	�	�	�	�	�	�	��
�v�v�u�
5�
5�	7�	7��"�"�7�+�+�
7�
7���	�:�6�6�6�
7�
7�
7�
7�
7�
7�
7�
7�
7�
7�
7����
7�
7�
7�
7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7����	7�	7�	7�	7�	
����(�)�)�)�����)�*�*�*�����)�*�*�*�����,�Q�/�4�7�8�8�8������(�(�(�(�(s6�B"�)B�?B"�B	�B"�B	�B"�"B&�)B&N)r�r�r��objectr�r�r+r-r<r�r�r�rEr&r$r�r��s�������*�*�*�*�*�v�*�*�*�$7�7�7��X�_�U�.�/�/�6�6�0�/�6�"�X�_�U�.�/�/�,�,�0�/�,�(�X�_�U�.�/�/�)�)�0�/�)�)�)r&r�c���eZdZdZed���Zed���Zd�Zej	d���Z
d�Zd�Zd�Z
d	�Zejejd
kd��d���Zd
S)�TestCopyFileObji c�:�tt|j��dSr))rZr�FILESIZE��clss r$�
setUpClasszTestCopyFileObj.setUpClass	s������-�-�-�-�-r&c�j�tjt��tjt��dSr))rrwrr�r�s r$�
tearDownClasszTestCopyFileObj.tearDownClass	s*����� � � ����!�!�!�!�!r&c�8�tjt��dSr)�rrwr�rs r$�tearDownzTestCopyFileObj.tearDown	������!�!�!�!�!r&c#��K�ttd��5}ttd��5}||fV�ddd��n#1swxYwYddd��dS#1swxYwYdS�Nr\r3�r<rr�r%s   r$�	get_fileszTestCopyFileObj.get_files	������
�&�$�
�
�	!�3��g�t�$�$�
!���C�j� � � �
!�
!�
!�
!�
!�
!�
!�
!�
!�
!�
!����
!�
!�
!�
!�	!�	!�	!�	!�	!�	!�	!�	!�	!�	!�	!�	!����	!�	!�	!�	!�	!�	!�3�A�A�A�A	�A�A	�	A�A� Ac��t|d��5}t|d��5}|�|���|�����ddd��n#1swxYwYddd��dS#1swxYwYdSrV)r<r�r^)r�rzr{�fsrc�fdsts     r$�assert_files_eqzTestCopyFileObj.assert_files_eq!	s���
�#�t�_�_�	;���c�4���
;�D�� � ������d�i�i�k�k�:�:�:�
;�
;�
;�
;�
;�
;�
;�
;�
;�
;�
;����
;�
;�
;�
;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;����	;�	;�	;�	;�	;�	;s4�B�;A)�B�)A-	�-B�0A-	�1B�B�Bc���|���5\}}tj||��ddd��n#1swxYwY|�tt
��dSr))r�r��copyfileobjr�rr�r%s   r$�test_contentzTestCopyFileObj.test_content&	s���
�^�^�
�
�	)��#�s���s�C�(�(�(�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)����	)�	)�	)�	)����V�W�-�-�-�-�-s
�:�>�>c��|���5\}}tj||��|jrJ�|jrJ�	ddd��dS#1swxYwYdSr))r�r�r��closedr%s   r$�test_file_not_closedz$TestCopyFileObj.test_file_not_closed+	s���
�^�^�
�
�	"��#�s���s�C�(�(�(��z�!�!�!��z�!�!�!�!�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"�	"�	"s�+A�A�Ac�D�|���5\}}tj||��|�|���|j��|�|���|j��ddd��dS#1swxYwYdSr))r�r�r�r��tellr�r%s   r$�test_file_offsetz TestCopyFileObj.test_file_offset1	s���
�^�^�
�
�	8��#�s���s�C�(�(�(����S�X�X�Z�Z���7�7�7����S�X�X�Z�Z���7�7�7�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8����	8�	8�	8�	8�	8�	8s�A3B�B�BrMzWindows onlyc��tj�d��5}tjt
t��ddd��n#1swxYwY|jsJ�|�|j	ddd��tjtj
��d���5}|�d��ddd��n#1swxYwY|j}|�t"j|��tj�d��5}tj|t��ddd��n#1swxYwY|�|j	ddd��tjtj
��d���5}	ddd��n#1swxYwY|j}|�t"j|��tj�d��5}tj|t��ddd��n#1swxYwY|jrJ�|�|t��dS)	Nzshutil._copyfileobj_readintorrqiFrnsfoor)r+r�r�r�r&rr��calledr��	call_argsrsrtr*rur=rir�rrwr�)r��mrXr�s    r$�
test_win_implzTestCopyFileObj.test_win_impl7	s���]�
 �
 �!?�
@�
@�	-�A��O�F�G�,�,�,�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-����	-�	-�	-�	-��x����	
�����Q���*�O�<�<�<��
(�R�Y�[�[��
G�
G�
G�	�1�
�G�G�F�O�O�O�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�������	�(�%�0�0�0�
�]�
 �
 �!?�
@�
@�	,�A��O�E�7�+�+�+�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,����	,�	,�	,�	,������Q���*�A�.�.�.��
(�R�Y�[�[��
G�
G�
G�	�1��	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�������	�(�%�0�0�0�
�]�
 �
 �!?�
@�
@�	,�A��O�E�7�+�+�+�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,����	,�	,�	,�	,��8�������U�G�,�,�,�,�,sY� A�A�A�.C�C�C�!E�E�E�!F/�/F3�6F3�H'�'H+�.H+N)r�r�r�r��classmethodr�r�r��
contextlib�contextmanagerr�r�r�r�r�r+r-r*rir�rEr&r$r�r�	s��������H��.�.��[�.��"�"��[�"�"�"�"���!�!���!�
;�;�;�
.�.�.�
"�"�"�8�8�8��X�_�R�W��_�n�5�5�-�-�6�5�-�-�-r&r�c��eZdZdZdZdZdZed���Zed���Z	d�Z
ejd���Z
d	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�ZdS)�_ZeroCopyFileTestz#Tests common to all zero-copy APIs.i�r&r�c��tt|j��ttd��5}|���|_t
|j��|jksJ�	ddd��dS#1swxYwYdSrV)rZrr�r<r^�FILEDATAr�)r�rXs  r$r�z_ZeroCopyFileTest.setUpClass\	s�������-�-�-�
�&�$�
�
�	5�1��6�6�8�8�C�L��s�|�$�$���4�4�4�4�4�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5����	5�	5�	5�	5�	5�	5s�9A7�7A;�>A;c�8�tjt��dSr))rrwrr�s r$r�z_ZeroCopyFileTest.tearDownClassc	s����� � � � � r&c�8�tjt��dSr)r�rs r$r�z_ZeroCopyFileTest.tearDowng	r�r&c#��K�ttd��5}ttd��5}||fV�ddd��n#1swxYwYddd��dS#1swxYwYdSr�r�r%s   r$r�z_ZeroCopyFileTest.get_filesj	r�r�c� �td���)Nzmust be implemented in subclass)r)r�r"r#s   r$�zerocopy_funz_ZeroCopyFileTest.zerocopy_funp	s��!�"C�D�D�Dr&c��|���|���|���|���dSr))r�r�r�rrs r$�resetz_ZeroCopyFileTest.resets	sB���
�
�����������������
�
�����r&c��|���5\}}|�||��ddd��n#1swxYwY|�ttd���|j��|���5\}}tj�d��5}tj
tt��ddd��n#1swxYwY|jrJ�	ddd��dS#1swxYwYdS)NT�r?zshutil.copyfileobj)
r�rr�r_r�rr+r�r�r�r&rr�)r�rzr{r�s    r$�test_regular_copyz#_ZeroCopyFileTest.test_regular_copy{	s���
�^�^�
�
�	(��#�s����c�3�'�'�'�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(����	(�	(�	(�	(�����7�4�8�8�8�$�-�H�H�H�
�^�^�
�
�	 ��#�s���$�$�%9�:�:�
1�a�����0�0�0�
1�
1�
1�
1�
1�
1�
1�
1�
1�
1�
1����
1�
1�
1�
1��x�����	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 �	 �	 sC�;�?�?�	#C:�, C�C:�C	�C:�C	� C:�:C>�C>c��|�|j��|���5\}}|�t��5|�||��ddd��n#1swxYwYddd��n#1swxYwY|�ttd���|j	��dS)NTr)
r�r
r�r�r
rr�r_rrr%s   r$�test_same_filez _ZeroCopyFileTest.test_same_file�	s(������
�#�#�#�
�^�^�
�
�	,��#�s��"�"�9�-�-�
,�
,��!�!�#�s�+�+�+�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,����
,�
,�
,�
,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,����	,�	,�	,�	,�	
����6�$�7�7�7���G�G�G�G�Gs5�B�
A0�$B�0A4	�4B�7A4	�8B�B�Bc� �tjtj�����}|�t
��5}t
j|d��ddd��n#1swxYwY|�|j	j
|��dS)Nr��new)rsr�r*rur�r�r�r&r�r�r�)r�rir�s   r$�test_non_existent_srcz'_ZeroCopyFileTest.test_non_existent_src�	s�����2�9�;�;�/�/�/��
�
�
�0�
1�
1�	)�R��O�D�%�(�(�(�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)����	)�	)�	)�	)������.��5�5�5�5�5s�A#�#A'�*A'c����tdz�tdz�|��fd���|��fd���t�d��5	ddd��n#1swxYwYt�d��5}t�d��5}|�||��ddd��n#1swxYwYddd��n#1swxYwY|�t�d���d	��dS)
Nrzr{c�,��tj���Sr)�rrw)rxs�r$r�z3_ZeroCopyFileTest.test_empty_file.<locals>.<lambda>�	����	� 0�� 9� 9�r&c�,��tj���Sr)r)rys�r$r�z3_ZeroCopyFileTest.test_empty_file.<locals>.<lambda>�	rr&r3r\Trr&)rr�r<rr�r_)r�rzr{ryrxs   @@r$�test_empty_filez!_ZeroCopyFileTest.test_empty_file�	s������5�.���5�.�����9�9�9�9�:�:�:����9�9�9�9�:�:�:�
�'�4�
 �
 �	�	��	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��'�4�
 �
 �	,�C��g�t�$�$�
,���!�!�#�s�+�+�+�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,����
,�
,�
,�
,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,����	,�	,�	,�	,�	
����7�4�8�8�8�#�>�>�>�>�>sH�A%�%A)�,A)�C�B4�(C�4B8	�8C�;B8	�<C�C�Cc���tj�|jt���5|�ttjtt��ddd��dS#1swxYwYdS)Nr)
r+r�r��
PATCHPOINT�ZeroDivisionErrorr�r�r&rr�rs r$�test_unhandled_exceptionz*_ZeroCopyFileTest.test_unhandled_exception�	s���
�]�
 �
 ���->�!�@�@�	@�	@����/�$�o�v�w�
@�
@�
@�	@�	@�	@�	@�	@�	@�	@�	@�	@�	@�	@�	@����	@�	@�	@�	@�	@�	@s�2A+�+A/�2A/c��tj�|jt	t
jd�����5|���5\}}|�t��5|�
||��ddd��n#1swxYwYddd��n#1swxYwYddd��dS#1swxYwYdS�N�yor)r+r�r�rrr!�EINVALr�r�rrr%s   r$�test_exception_on_first_callz._ZeroCopyFileTest.test_exception_on_first_call�	s����]�
 �
 ���-4�U�\�4�-H�-H�!�J�J�	0�	0����!�!�
0�Z�c�3��&�&�'8�9�9�0�0��%�%�c�3�/�/�/�0�0�0�0�0�0�0�0�0�0�0����0�0�0�0�
0�
0�
0�
0�
0�
0�
0�
0�
0�
0�
0����
0�
0�
0�
0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0����	0�	0�	0�	0�	0�	0sY�C�B,�2B�	B,�B�B,�B�B,� C�,B0	�0C�3B0	�4C�C�Cc�V�tj�|jt	t
jd�����5|���5\}}|�t|j	||��ddd��n#1swxYwYddd��dS#1swxYwYdSr!)
r+r�r�rrr!�ENOSPCr�r�rr%s   r$�test_filesystem_fullz&_ZeroCopyFileTest.test_filesystem_full�	sA���]�
 �
 ���-4�U�\�4�-H�-H�!�J�J�	H�	H����!�!�
H�Z�c�3��!�!�'�4�+<�c�3�G�G�G�
H�
H�
H�
H�
H�
H�
H�
H�
H�
H�
H����
H�
H�
H�
H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H�	H����	H�	H�	H�	H�	H�	Hs5�B�&B�:B�B
	�
B�
B
	�B�B"�%B"N)r�r�r��__doc__r�rrrr�r�r�rrr�rr
rrrrrr$r'rEr&r$rrV	s ������-�-� �H��H��J��5�5��[�5��!�!��[�!�"�"�"���!�!���!�
E�E�E���� � � �H�H�H�6�6�6�?�?�?�@�@�@�0�0�0�H�H�H�H�Hr&rzos.sendfile() not supportedc�H�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�ZdS)�TestZeroCopySendfile�os.sendfilec�,�tj||��Sr))r��_fastcopy_sendfile)r�r�r�s   r$rz!TestZeroCopySendfile.zerocopy_fun�	s���(��t�4�4�4r&c���tj|j��5}ttd��5}|�t��5|�||��ddd��n#1swxYwYtj	||��ddd��n#1swxYwYddd��n#1swxYwY|�
ttd���|j��dS)Nr3Tr)�io�BytesIOrr<r�r�rrr�r�r�r_r%s   r$�test_non_regular_file_srcz.TestZeroCopySendfile.test_non_regular_file_src�	s���
�Z��
�
&�
&�	-�#��g�t�$�$�
-���&�&�'8�9�9�0�0��%�%�c�3�/�/�/�0�0�0�0�0�0�0�0�0�0�0����0�0�0�0��"�3��,�,�,�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-�
-����
-�
-�
-�
-�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-����	-�	-�	-�	-�	
����7�4�8�8�8�$�-�H�H�H�H�HsX�B1�B�A.�"B�.A2�2B�5A2�6B�B1�B	�B1�!B	�"B1�1B5�8B5c��ttd��5}tj��5}|�t
��5|�||��ddd��n#1swxYwYtj||��|�	d��|�
|���|j��ddd��n#1swxYwYddd��dS#1swxYwYdS)Nr\r)
r<rr/r0r�rrr�r��seekr�r^rr%s   r$�test_non_regular_file_dstz.TestZeroCopySendfile.test_non_regular_file_dst�	s���
�&�$�
�
�	<�3�����
<���&�&�'8�9�9�0�0��%�%�c�3�/�/�/�0�0�0�0�0�0�0�0�0�0�0����0�0�0�0��"�3��,�,�,��������� � ������T�]�;�;�;�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<�
<����
<�
<�
<�
<�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<����	<�	<�	<�	<�	<�	<sY�C.�C�A(�C�(A,�,C�/A,�0AC�
C.�C	�C.�C	�C.�.C2�5C2c�������fd�}g�tj�tj�dd|���5|���5\}}|�t��5}tj	||��ddd��n#1swxYwYddd��n#1swxYwYddd��n#1swxYwY�sJ�|�
|jjtj
��dS)Nc�v���s��d���|i|��Sttjd���)Nr")rfrr!�EBADF)r"r#r�
orig_sendfiles  ��r$rmzDTestZeroCopySendfile.test_exception_on_second_call.<locals>.sendfile�	sD����
1����D�!�!�!�$�}�d�5�f�5�5�5��e�k�4�0�0�0r&r+T)r6r)r*rmr+r�r�r�r�rr�r-r�r�r!r7)r�rmrzr{r�rr8s     @@r$�test_exception_on_second_callz2TestZeroCopySendfile.test_exception_on_second_call�	s�����	1�	1�	1�	1�	1�	1�����
�
�]�
 �
 ��t�-5�!�7�7�	8�	8����!�!�
8�Z�c�3��&�&�w�/�/�8�2��-�c�3�7�7�7�8�8�8�8�8�8�8�8�8�8�8����8�8�8�8�
8�
8�
8�
8�
8�
8�
8�
8�
8�
8�
8����
8�
8�
8�
8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8����	8�	8�	8�	8�
���������+�U�[�9�9�9�9�9sY�B<�B%�,B�B%�B�B%�B�B%�B<�%B)	�)B<�,B)	�-B<�<C�Cc�|�tj�dt���5}|���5\}}tj||��|jsJ�	ddd��n#1swxYwYddd��n#1swxYwY|�ttd���|j��dS)N�os.fstatrTr)r+r�r�rr�r�r-r�r�r_r�r�r�r�rzr{s    r$�test_cant_get_sizez'TestZeroCopySendfile.test_cant_get_size�	s$���]�
 �
 ���
 �
A�
A�	 �Q����!�!�
 �Z�c�3��)�#�s�3�3�3��x�����
 �
 �
 �
 �
 �
 �
 �
 �
 �
 �
 ����
 �
 �
 �
 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 �	
����7�4�8�8�8�$�-�H�H�H�H�Hs4�B�"A+�B�+A/	�/B�2A/	�3B�B�	Bc��tj���}d|_tj�d|���5}|���5\}}t
j||��|jsJ�	ddd��n#1swxYwYddd��n#1swxYwY|�	ttd���|j��dS)Nir;�r5Tr)
r+r��Mock�st_sizer�r�r�r-r�r�r_r�r�r�r�r�rzr{s     r$�test_small_chunksz&TestZeroCopySendfile.test_small_chunks�	s>��
�}�!�!�#�#�� ���
�]�
 �
 ��$�
 �
?�
?�	 �1����!�!�
 �Z�c�3��)�#�s�3�3�3��x�����
 �
 �
 �
 �
 �
 �
 �
 �
 �
 �
 ����
 �
 �
 �
 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 �	
����7�4�8�8�8�$�-�H�H�H�H�Hs6�B"�"B�?B"�B	�B"�B	�B"�"B&�)B&c���tj���}|jdz|_tj�d|���5}|���5\}}tj||��|j	sJ�	ddd��n#1swxYwYddd��n#1swxYwY|�
ttd���|j
��dS)Ni@r;r?Tr)r+r�r@r�rAr�r�r�r-r�r�r_r�rrBs     r$�test_big_chunkz#TestZeroCopySendfile.test_big_chunk�	sF��
�}�!�!�#�#���}�(9�:���
�]�
 �
 ��$�
 �
?�
?�	 �1����!�!�
 �Z�c�3��)�#�s�3�3�3��x�����
 �
 �
 �
 �
 �
 �
 �
 �
 �
 �
 ����
 �
 �
 �
 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 �	
����7�4�8�8�8�$�-�H�H�H�H�Hs6�B*�$"B�B*�B	�B*�B	�B*�*B.�1B.c���tj�dt���5}|�tt
jtt��|j	dd}|�
|tj�
t����tjt��t!tdd���|�tjtdz��|�tt
jttdz��|j	dd}|�
|d	��ddd��dS#1swxYwYdS)
Nr+rrrshelloTr�3i�)r+r�r�rr�r�r&rr�r�r�r*r:rTrrwrBr�)r�r��	blocksizes   r$�test_blocksize_argz'TestZeroCopySendfile.test_blocksize_arg	
sw��
�]�
 �
 ��->�!�@�@�	1�CD����/�$�o�v�w�
@�
@�
@���A��q�)�I�
���Y������(?�(?�@�@�@���W�%�%�%��w���6�6�6�6��O�O�I�,�g��m�<�<�<����/�$�o�w��#�
�
G�
G�
G���A��q�)�I����Y��0�0�0�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1����	1�	1�	1�	1�	1�	1s�D2E&�&E*�-E*c���tjsJ�	tj�|jt
tjd�����5}|�	��5\}}|�
t��5tj||��ddd��n#1swxYwYddd��n#1swxYwY|j
sJ�	ddd��n#1swxYwYtjrJ�tj�|j��5}tjtt ��|j
rJ�	ddd��n#1swxYwYdt_dS#dt_wxYw)Nr"rT)r��_USE_CP_SENDFILEr+r�r�rrr!�ENOTSOCKr�r�rr-r�r&rr�r<s    r$�test_file2file_not_supportedz1TestZeroCopySendfile.test_file2file_not_supported
sP���&�&�&�&�	+���$�$��O� '���� =� =�%�?�?�
 �BC��^�^�%�%�<��#�s��*�*�+<�=�=�<�<��1�#�s�;�;�;�<�<�<�<�<�<�<�<�<�<�<����<�<�<�<�<�<�<�<�<�<�<�<�<�<�<����<�<�<�<��x�����

 �
 �
 �
 �
 �
 �
 �
 �
 �
 �
 ����
 �
 �
 �
 ��.�.�.�.���$�$�T�_�5�5�
$������0�0�0��8�#�#�#�#�
$�
$�
$�
$�
$�
$�
$�
$�
$�
$�
$����
$�
$�
$�
$�'+�F�#�#�#��d�F�#�*�*�*�*s��>E'�C�#B:�B#�B:�#B'�'B:�*B'�+B:�.C�:B>	�>C�B>	�C�E'�C�E'�"C�#5E'�)E�E'�E�E'�E�E'�'E5N)
r�r�r�rrr1r4r9r=rCrErIrMrEr&r$r*r*�	s��������J�5�5�5�I�I�I�<�<�<�:�:�:�$I�I�I�I�I�I�I�I�I�1�1�1�$+�+�+�+�+r&r*z
macOS onlyc��eZdZdZd�ZdS)�TestZeroCopyMACOSzposix._fcopyfilec�B�tj||tj��Sr))r��_fastcopy_fcopyfile�posix�_COPYFILE_DATAr%s   r$rzTestZeroCopyMACOS.zerocopy_fun5
s���)�#�s�E�4H�I�I�Ir&N)r�r�r�rrrEr&r$rOrO1
s-������#�J�J�J�J�J�Jr&rOc��eZdZd�Zd�Zd�Zejej	e
j�����d��eje
ed��d��d�����Zejejd��d	���Zd
S)�TestGetTerminalSizec��tj��}|�|jd��|�|jd��dS)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_sizer��columns�lines)r�rUs  r$�test_does_not_crashz'TestGetTerminalSize.test_does_not_crash:
sH���'�)�)�������a�0�0�0�����
�A�.�.�.�.�.r&c��tj��5}d|d<|d=tj��}ddd��n#1swxYwY|�|jd��tj��5}|d=d|d<tj��}ddd��n#1swxYwY|�|jd��dS)z.Check if environment variables have precedence�777�COLUMNS�LINESNi	�888ix)rr.r�rWr�rXrY�r�r0rUs   r$�test_os_environ_firstz)TestGetTerminalSize.test_os_environ_firstD
s<���
*�
,�
,�	.��"�C�	�N��G���+�-�-�D�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.����	.�	.�	.�	.�	
�����s�+�+�+�
�
*�
,�
,�	.���I�� �C��L��+�-�-�D�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.����	.�	.�	.�	.�	
�����S�)�)�)�)�)s!�<�A�A�5B�B!�$B!c��tj��5}d|d<d|d<tj��}ddd��n#1swxYwY|�|jd��|�|jd��dS)Nr�r]�yyyr^r)rr.r�rWr�rXrYr`s   r$�test_bad_environz$TestGetTerminalSize.test_bad_environS
s���
�
*�
,�
,�	.��"�C�	�N� �C��L��+�-�-�D�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.����	.�	.�	.�	.�	
�����a�0�0�0�����
�A�.�.�.�.�.s�>�A�Az
not on ttyrWzneed os.get_terminal_size()c���	tjddg��������}n7#tt
tjf$r|�d��YnwxYwt|d��t|d��f}tj
��5}|d=|d=tj��}ddd��n#1swxYwY|�
||��dS)	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.
        �sttyrUzstty invocation failedr�rr^r]N)r�r�r�r�r�ryr�r�r�rr.r�rWr�)r�rUr�r0r?s     r$�test_stty_matchz#TestGetTerminalSize.test_stty_match[
s2��	4��*�F�F�+;�<�<�C�C�E�E�K�K�M�M�D�D��!�?��-�/�	4�	4�	4��M�M�2�3�3�3�3�3�	4������Q��L�L�#�d�1�g�,�,�/��
�
*�
,�
,�	0���G���I���-�/�/�F�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0����	0�	0�	0�	0�
	
����6�*�*�*�*�*s!�:=�1A1�0A1�1C�C�CzWASI has no /dev/nullc���tj��5}|d=|d=tjtdd��5tjd���}ddd��n#1swxYwY|�|jd��|�|j	d��ttjdd	�
��5}tjtd|��5tjd���}ddd��n#1swxYwYddd��n#1swxYwY|�|jd��|�|j	d
��ddd��dS#1swxYwYdS)Nr^r]�
__stdout__)�
�)�fallbackrjrkr4r5r6)��(rmrn)
rr.rr�r�r�rWr�rXrYr<r*�devnull)r�r0rUrXs    r$�
test_fallbackz!TestGetTerminalSize.test_fallbacks
s{��
�
*�
,�
,�	-���G���I���"�3��d�;�;�
C�
C��/��B�B�B��
C�
C�
C�
C�
C�
C�
C�
C�
C�
C�
C����
C�
C�
C�
C����T�\�2�.�.�.����T�Z��,�,�,��b�j�#��8�8�8�
C�A��"�3��a�8�8�
C�
C��/��B�B�B��
C�
C�
C�
C�
C�
C�
C�
C�
C�
C�
C����
C�
C�
C�
C�
C�
C�
C�
C�
C�
C�
C�
C�
C�
C�
C����
C�
C�
C�
C�
���T�\�2�.�.�.����T�Z��,�,�,�!	-�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-����	-�	-�	-�	-�	-�	-s}�"E�A�E�A	�E�A	� AE�5D
�C3�'D
�3C7�7D
�:C7�;D
�>E�
D	�E�D	�9E�E�EN)r�r�r�rZrardr+r,r*�isattyr�rirvrrrgr-r�is_wasirprEr&r$rUrU9
s�������/�/�/�
*�
*�
*�/�/�/��X�����3�>�#8�#8�#:�#:�;�;�\�J�J��X�����%8�9�9�6�8�8�+�+�8�8�K�J�+�*�X�_�W�_�&=�>�>�-�-�?�>�-�-�-r&rUc��eZdZdZd�ZdS)�PublicAPITestsz>Ensures that the correct values are exposed in the public API.c�F�|�ttd����gd�}ttd��stjdkr|�d��|�ttj��t|����dS)N�__all__)r�r&r�r�r	rr:rWr�rr.�	ExecErrorrrrrrr	rrrcr�r�rWr
�statvfsrMr�)	r�rrr�r*rirfr�rkrv)r��
target_apis  r$�test_module_all_attributez(PublicAPITests.test_module_all_attribute�
s��������	�2�2�3�3�3�<�<�<�
��2�y�!�!�	,�R�W��_�_����l�+�+�+�����V�^�,�,�c�*�o�o�>�>�>�>�>r&N)r�r�r�r(rzrEr&r$rtrt�
s)������H�H�?�?�?�?�?r&rt�__main__)F)Ur+�
unittest.mockr�rsr�r�r*�os.pathr!r/ror�rJrLrr/rrrrrrr	r
rrr
rrLrsrR�ImportErrorr�r�test.supportr�test.support.os_helperrrr�r�r�r.rRr<r=r�r�r�r�r�r�r��AssertionErrorrJr%r1rBrZr_rgr~�SUPPORTS_SENDFILEr�r��TestCaser�r2r�r?r�rrPrSr�r�r�rr-r*rOrUrtr��mainrEr&r$�<module>r�s����������
�
�
�
�����
�
�
�
�����	�	�	�	���������������������
�
�
�
�
�
�
�
�����	�	�	�	�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�6�����������L�L�L�L�������E�E�E�����������"�"�"�"�"�"�3�3�3�3�3�3�3�3�
�3�,��
�f�_�
�
�f�_�
������)�)��

�,�
!�
!�'�
*�
*��	�l�2�A�2��%�����J�J�J��J�J�J��O�O�������O�O�O�������N�N�N�N�������G�G�G������=���z�"�N�#>�?�?��A�A��L�L�L�	�	�	�����)�)�)�$����
�
�
�&�&�&�:0�/�1�1�����	�	�	�	�	�	�	�	�W6�W6�W6�W6�W6��8�,�W6�W6�W6�t`2�`2�`2�`2�`2�8�X�.�`2�`2�`2�D@?�@?�@?�@?�@?�x��*�@?�@?�@?�Fn8�n8�n8�n8�n8�8�X�.�n8�n8�n8�bM+�M+�M+�M+�M+�x��*�M+�M+�M+�`w4�w4�w4�w4�w4��(�+�w4�w4�w4�t)�)�)�)�)�Y�)�)�)�o-�o-�o-�o-�o-�x��*�o-�o-�o-�dY)�Y)�Y)�Y)�Y)�8�$�Y)�Y)�Y)�xG-�G-�G-�G-�G-�h�'�G-�G-�G-�TaH�aH�aH�aH�aH��aH�aH�aH�H���&�&�(E�F�F�s+�s+�s+�s+�s+�,�h�.?�s+�s+�G�F�s+�l���U��L�)�)�J�J�J�J�J�)�8�+<�J�J�*�)�J�L-�L-�L-�L-�L-�(�+�L-�L-�L-�^?�?�?�?�?�X�&�?�?�?�$�z����H�M�O�O�O�O�O��s6�&A+�+A5�4A5�#
C.�.C8�7C8�<D�D�
D