Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.11/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.11/test/__pycache__/test_shutil.cpython-311.opt-2.pyc

�

SԚg�����ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZmZmZmZmZmZmZmZmZmZmZmZddlZddlZ	ddlZn
#e$rdZYnwxYwddl m!Z!ddl"m#Z#ddl$m%Z%m&Z&ddl"m'Z'e%dzZ(e%dzZ)e%d	zZ*ej+�,d
��Z-ej+�,d��Z.ej+dd�d
kZ/	ddl0Z0ddl1Z1dZ2n
#e$rdZ2YnwxYw	ddl3Z3n
#e$rdZ3YnwxYwej4�5de6d�����Z7d�Z8d�Z9d>d�Z:d�Z;d>d�Z<d�Z=d�Z>e>��Z?d�Z@Gd�d��ZAGd�deAejB��ZCGd�d eAejB��ZDGd!�d"eAejB��ZEGd#�d$eAejB��ZFGd%�d&eAejB��ZGGd'�d(eAejB��ZHGd)�d*eH��ZIGd+�d,eAejB��ZJGd-�d.ejB��ZKGd/�d0ejB��ZLGd1�d2eM��ZNejOe?d3��Gd4�d5eNejB����ZPejOe-d6��Gd7�d8eNejB����ZQGd9�d:ejB��ZRGd;�d<ejB��ZSeTd=krejU��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)�warnings_helper�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/lib/python3.11/test/test_shutil.py�_fake_renamer&:s��
�'�%��"�-�-�/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_renamer2>s8����_�T���'�'�'�'���'��Kr'c���	t|t��rtjj|�}|rdnd}|rdnd}t|||���5}|�|��ddd��dS#1swxYwYdS)N�wb�w�utf-8��encoding)�
isinstance�tupler+�path�join�open�write)r;�content�binary�moder8�fps      r%�
write_filerCIs�����$����#��w�|�T�"���"�4�4�s�D��*�t�t�7�H�	
�d�D�8�	,�	,�	,���
���������������������������s�A+�+A/�2A/c�"�	d�}t|d��}d�d�t|��D����}t|d��5}|||��D]}|�|���	ddd��dS#1swxYwYdS)Nc3�DK�||kr|V�||z}||k�|r|V�dSdSr*�)�total�steps  r%�chunkszwrite_test_file.<locals>.chunksYsM�����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�������3SrF)�random�choice�string�
ascii_letters�encode)�.0�is  r%�
<listcomp>z#write_test_file.<locals>.<listcomp>bsA��/�/�/���m�F�$8�9�9�@�@�B�B�/�/�/r'r4)�minr<�ranger=r>)r;�sizerI�bufsize�chunk�f�csizes       r%�write_test_filerZWs���L�����$��o�o�G��H�H�/�/�$�W�~�~�/�/�/�
0�
0�E�	
�d�D�	�	��Q��V�D�'�*�*�	�	�E�
�G�G�E�N�N�N�N�	���������������������s�%B�B�Bc���	t|t��rtjj|�}|rdnd}|rdnd}t|||���5}|���cddd��S#1swxYwYdS)N�rb�rr6r7)r9r:r+r;r<r=�read)r;r@rAr8rBs     r%�	read_filer_is�����$����#��w�|�T�"���"�4�4�s�D��*�t�t�7�H�	
�d�D�8�	,�	,�	,����w�w�y�y���������������������s�A)�)A-�0A-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%rgrgws���
�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�sendfileFr4��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)N)�prefixro)rs�mkdtempr+ru�
addCleanupr�rmtree)�selfr��ds   r%r�zBaseTest.mkdtemp�s@��	�
��F��	���<�<�<�����	�(�!�,�,�,��r'r*)�__name__�
__module__�__qualname__r�rFr'r%r�r��s(�����������r'r�c��eZdZd�Zejd���Zejd���Zej	e
d��d���Zej	e
d��d���Zd�Z
ejejdd	�d
kd��ejejd�������Zd
�Zd�Zd�Zej	ejd��d���Zej	ejd��d���Zejejd��d���Zd�Zejd���Zej	e
d��d���Zej	ee d��d��ejejdkd��d�����Z!dS)�
TestRmTreec�x�|���}tj�|d��}tj|��ttj�|d��d��tj|��}|�|t��tj
|��dS)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�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�assertRaisesr r�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�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�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�r r�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�rCr�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�rCr+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_error:s���
���
����������
�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_onerrorYs"���?�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>.raiserws#�����<�<�!�)�)�O�%�:�b�>�>�)r'r�)r+�lstatr�rrCr�r�)r�r�r�s  @r%�+test_rmtree_does_not_choke_on_failing_lstatz6TestRmTree.test_rmtree_does_not_choke_on_failing_lstatts����
	"���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�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�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)zrequires safe rmtreec�����|���}tj�|d��}tj|��tj�|d��}tj|����fd�}d�tjtd|��5�|�t��5tj
|��ddd��n#1swxYwYddd��n#1swxYwY|�tj�|����|�
�d��d�g��fd�}tjtd|��5�tj
||���ddd��n#1swxYwY|�
t���d��|��dd|��|�
�dd	|��|��d	d|��|�
�d	d	|��|�
�d��dS)
Nr�r�c�2���|���dz
�t�)Nr��r )�fd�close_count�
orig_closes ��r%�closez4TestRmTree.test_rmtree_fails_on_close.<locals>.close�s����J�r�N�N�N��1��K��Mr'rrrqc�2����|��dSr*r�r�s �r%r�z6TestRmTree.test_rmtree_fails_on_close.<locals>.onerror�r�r'r�r�)r�r+r;r<r�r�	swap_attrr�r r�r�r�rdr�r�r�)	r�r�r�r�rr�rr�rs	      @@@r%�test_rmtree_fails_on_closez%TestRmTree.test_rmtree_fails_on_close�s�������l�l�n�n���w�|�|�C��(�(��
�������w�|�|�D�&�)�)��
������	�	�	�	�	�	���
�
�r�7�E�
2�
2�	$�j��"�"�7�+�+�
$�
$��
�d�#�#�#�
$�
$�
$�
$�
$�
$�
$�
$�
$�
$�
$����
$�
$�
$�
$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$����	$�	$�	$�	$�	
�����
�
�d�+�+�,�,�,�����a�(�(�(�����	 �	 �	 �	 �	 �
�
�r�7�E�
2�
2�	1�j��M�$��0�0�0�0�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1����	1�	1�	1�	1�����V���a�(�(�(��
�
�f�Q�i��l�E�*�*�*�������1��t�,�,�,��
�
�f�Q�i��l�E�*�*�*�������1��t�,�,�,�����a�(�(�(�(�(sH�#C6�>C�C6�C#	�#C6�&C#	�'C6�6C:�=C:�-F�F�Fzdir_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�rr�rCr�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�r r�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-�spamr4Tr�)
r+r�rr;r<r=rr�r�r�r r�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�mkfifo�requires os.mkfifo()�vxworks�%fifo requires special path on VxWorksc���tjt��	|�t��5tjt��ddd��n#1swxYwY|�tj�	t����tj
t��n#tj
t��wxYwtjt��tjtj�td����tjt��|�
tj�	t����dS)N�mypipe)r+r3rr�r�r�r�r�r;r�rwr�r<r��r�s r%�test_rmtree_on_named_pipez$TestRmTree.test_rmtree_on_named_pipe�sD��	�	�&����	��"�"�#5�6�6�
&�
&��
�f�%�%�%�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&�
&����
&�
&�
&�
&��O�O�B�G�N�N�6�2�2�3�3�3��I�f������B�I�f��������
������
�	�"�'�,�,�v�x�0�0�1�1�1��
�f������������/�/�0�0�0�0�0s.�B7�A�B7�A�B7�"A�#:B7�7C)"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
rr!r$r*r/r2rrr+r:rFr'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�3I�J�J� )� )�K�J� )�D�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��X�����X�.�.�0F�G�G��X�_�S�\�Y�.�;�=�=�1�1�=�=�H�G�1�1�1r'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��dirnamerCr��copytreer��isfilerdr_r��r��src_dir�dst_dir�actuals    r%�test_copytree_simplez!TestCopyTree.test_copytree_simples����,�,�.�.���'�,�,�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.txtrG�existing_dirzexisting.txtzwill be replacedzhas been replacedT)�
dirs_exist_okF)r�r�r�r�rCr+r�r;r<rKr�rLrdr_r�r��FileExistsErrorrMs    r%�test_copytree_dirs_exist_okz(TestCopyTree.test_copytree_dirs_exist_oks����,�,�.�.���,�,�.�.������
�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�rCr�rrrYr��S_IRWXU�S_IRWXOrZr[r�r�rKr�re�readlinkri�
startswithr�r��st_flags)
r�rrNrO�sub_dir�src_link�dst_link�src_statrP�dst_stats
          r%�test_copytree_symlinksz#TestCopyTree.test_copytree_symlinks7s����,�,�.�.���'�,�,�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)NrErFrGztest.tmprHrI�	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>._filters����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�rCr�r��ignore_patternsrKr�r�r�rJ)r�r<r�rNrO�patternsrss       r%�test_copytree_with_excludez'TestCopyTree.test_copytree_with_excludeWs���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�sourcerHrrFrIc�X����|����|t����|t����t|��tt
|������|D]}��|t���gSr*)rfr��str�listr�r��set)rzrrri�invokationsr�s   ��r%�_ignorez?TestCopyTree.test_copytree_arg_types_of_ignore.<locals>._ignore�s�������s�#�#�#��!�!�#�s�+�+�+��!�!�%��.�.�.����S��Z�Z��S��Z�Z���9�9�9��
1�
1���%�%�d�C�0�0�0�0��Ir'rErnr�	)r+r;r<r�r�r�rCr�rKr��pathlib�Pathr{r�r��DirEntryr�r�)	r�r<r�rrNr~rO�
src_dir_entryr}s	`       @r%�!test_copytree_arg_types_of_ignorez.TestCopyTree.test_copytree_arg_types_of_ignore�sq�����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)NrxrEi�zpermissive.txtrGzrestrictive.txtrIi�r�r�)r�r+r;r<r�r�r�r�r�rCrsrrKr�r�r�r�)r�rrNrO�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)NrEzka-boom)
r�r+r;r<r�r�r�rJ�PermissionErrorrr�rrK)r��
mock_patchrNrOs    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�rzr�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�r5r6r7��
copy_functionr�)r�rsr�r=r+r;r<rr�rKr�r�)r�r�rXr{r�rzs`  @@@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�"Br3r4r5r6c��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)
Nrr8�os.mkfifo(): %sz$shutil.Error should have been raisedrr�z`%s` is a named pipeTr�)r+r�rr;r<r3r��skipTestr�rK�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)	NrErFrGrHrIc�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<rCr�r�rKr�r�)r�rNrOr�r�s    @r%�test_copytree_special_funcz'TestCopyTree.test_copytree_special_funcs�����,�,�.�.���'�,�,�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)
NrF�abc�dir_a�
IDONTEXIST�broken�validrE�destination2T)�ignore_dangling_symlinks�destination3r\)r�r+r;r<rCr�r�r�rr�rK�walk�assertNotInr�rc)	r�rN�
valid_filer�r�rO�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)NrE�real_dirrFr4�link_to_dirT��target_is_directoryFr\r�)r�r+r;r<r�r=r�r�rKr�rer�rcr�)r�rNrOs   r%�test_copytree_symlink_dirz&TestCopyTree.test_copytree_symlink_dirAs���,�,�.�.���'�,�,�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<rCrKr�rc)r�rNrOrz�rvs     r%�test_copytree_return_valuez'TestCopyTree.test_copytree_return_valueUs����,�,�.�.���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<�makedirsrCrKr�rc)r��base_dirrNrOrzr�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�rQrVrr;rjrvr�r�r<�mock�patchr�r�r=rrr+r>r�r?r�r�r�r�r�r�rFr'r%rCrC	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'rCc�l�eZdZejd���Zejee	d��p
e	j
dkd��ejd�����Zejee	d��d��ejd�����Z
ejd���Zejee	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���Z ejd ���Z!ejee	d!��d"��eje"j#d#kd$��d%�����Z$d&�Z%d'�Z&eje'pe(pe)d(��eje*d)��d*�����Z+d+�Z,d,S)-�TestCopyc�b�|���}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��tj|tj
��tj||��|�tj|��jtj|��j��tj|tj
��tj||��|�tj|��jtj|��j��tj|tj
��tj||��|�tj|��jtj|��j��dS)Nr��bar�baz�quux)r�r+r;r<rCr�r�r�r`�S_IRWXGra�assertNotEqualr�r��copymoder��r�rrzr{rfrgs      r%�test_copymode_follow_symlinksz&TestCopy.test_copymode_follow_symlinksos>���,�,�.�.���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�	���d�l�#�#�#����#�&�&�&���������-�r�w�s�|�|�/C�D�D�D�
���d�l�#�#�#����X�&�&�&���������-�r�w�s�|�|�/C�D�D�D�
���d�l�#�#�#����(�+�+�+���������-�r�w�s�|�|�/C�D�D�D�D�Dr'rYr^zrequires os.lchmodc� �tjdkrtjntj}|���}tj�|d��}tj�|d��}tj�|d��}tj�|d��}t|d��t|d��tj||��tj||��tj|tj
tjz��tj|tj
��||tjtjz��||tj��tj	|��j
}tj||d���|�tj|��j
tj|��j
��|�tj	|��j
|��||tj��tj||d���|�tj	|��j
tj	|��j
��||tj��tj||d���|�tj	|��j
tj	|��j
��dS)Nr^r�r�r�r�F��follow_symlinks)r+rir�rYr�r;r<rCr�r�r`r�rar�r�r�r�r�)r��_lchmodrrzr{rfrg�old_modes        r%� test_copymode_symlink_to_symlinkz)TestCopy.test_copymode_symlink_to_symlink�sQ��!�g��o�o�"�(�(�2�9���,�,�.�.���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�#�#�#����$�,�t�|�3�4�4�4����$�,�'�'�'��7�3�<�<�'�����(�E�B�B�B�B������(�+�+�3���(�+�+�3�	5�	5�	5���������-�x�8�8�8����$�,�'�'�'����#�u�=�=�=�=���������-�r�w�s�|�|�/C�D�D�D����$�,�'�'�'����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���dS)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_lchmod�s����,�,�.�.���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��|���}tj�|d��}tj�|d��}tj�|d��}tj�|d��}t	|d��tj|��}tj||j|jdz
f��t	|d��|�	tj|��jtj|��j��tj
||��tj
||��ttd��r tj|t
j
��n/tjdkrtj|t
j
��ttd��r4tt
d	��rtj|t
j��tj|��}ttd��stjdkrIt'j||d
���|�	|jtj|��j��t'j||d���tj|��}tjtjvr:d
D]7}	|�t1||	��t1||	��dz���8ttd��stjdkr |�|j|j��ttd��r0t|d��r |�|j|j��t'j||d���|�t9tj|��jtj|��jz
��dk��dS)Nr�r�r��quxgE@rYr^rZr[Tr�F��st_atime�st_mtimer�rdg�������?)r�r+r;r<rCr��utimer�r�r�r�rrrYrarir�rZr[r�r��copystatr�r	�assertLessEqualr!r�rdr��abs)
r�rrzr{rfrgrh�
src_link_stat�
dst_link_stat�attrs
          r%�test_copystat_symlinkszTestCopy.test_copystat_symlinks�sU���,�,�.�.���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���-�-�-�-�
�W��_�_��H�X�t�|�,�,�,��2�z�"�"�	2�w�t�[�'A�'A�	2��K��$�.�1�1�1����*�*�
��2�x� � �	M�B�G�t�O�O��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�B�G�t�O�O����]�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<rCr�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�rF)�fnamer��valr$�
orig_setxattr�os_errors    ��r%�_raise_on_user_fooz3TestCopy.test_copyxattr.<locals>._raise_on_user_foos5����z�!�!����
�e�T�3�9�9�&�9�9�9�9�9r'Tr�c�^��|�krttjd����||���S)NzOperation not supportedr�)r r"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<rCr��
_copyxattr�setxattrr�rb�	listxattr�getxattrr(r r"r�r�r�r�)r�rr{rr�srcro�dstrorr�r�rzs       @@@@r%�test_copyxattrzTestCopy.test_copyxattrs��������,�,�.�.���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<rCr�r	r�rr�rr�r )r�rrzrfr{rgs      r%�test_copyxattr_symlinksz TestCopy.test_copyxattr_symlinksHsr���,�,�.�.���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)NrFr�)r�rCr+r;r<)r��methodr�r�r��tmpdir2r�s       r%�
_copy_filezTestCopy._copy_filebs{�����������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_copylsk�����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�rYTr�F)r�r+r;r<rCr�rrrYr�r`rar�rr�rer�r_r(r�rbr�r�)r�rrzr{rfs     r%�test_copy_symlinkszTestCopy.test_copy_symlinksrs����,�,�.�.���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�rd)
rr��copy2r�r+r;r�r�r�r�r�r!rr)r�r�r��
file1_stat�
file2_statr�s      r%�
test_copy2zTestCopy.test_copy2�s3�����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�rYrZr[Tr�Fr�r�rd)r�r+r;r<rCr�rrrYr�r`rarZr[r�r�rr�rer�r_r(r�rbr�r	r�r!r�r�rd)	r�rrzr{rfrhr�rir�s	         r%�test_copy2_symlinkszTestCopy.test_copy2_symlinks�s����,�,�.�.���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<rCr	r�rr�rr()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�rrr�r+r;r<rCr�)r�r�rNrOrzr�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�rr9s r%�
test_copy_dirzTestCopy.test_copy_dir�s�����F�K�(�(�(�(�(r'c�D�|�tj��dSr*)r&r�rr9s 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<rCr�r?r��IsADirectoryErrorr�)r��	copy_funcrN�src_filer�r{r�s       r%r&zTestCopy._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{rgr�r�Fr�)
r�r+r;r<rCr�r��copyfiler�rer�rbr�)r�rrzr{rgr�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-r5r6r7�cheddarz
os.link(): %sr]Tr�)r+r�rr;r<r=r>r�r�r�r�r�r
r2r�r^r(r�)r�rzr{rXr�s     r%�'test_dont_copy_file_onto_link_to_itselfz0TestCopy.test_dont_copy_file_onto_link_to_itselfs��	�������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-r5r6r7r5r]Tr�)r+r�rr;r<r=r>r�r�r�r
r2r�r^r(r�)r�rzr{rXs    r%�*test_dont_copy_file_onto_symlink_to_itselfz3TestCopy.test_dont_copy_file_onto_symlink_to_itselfs���	�������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(�(Fr3r4r5r6c���	tjt��n/#t$r"}|�d|z��Yd}~nd}~wwxYw	|�tjtjtt��|�tjtjtt��tjt��dS#tjt��wxYw)Nr�)r+r3rr�r�r�r��SpecialFileErrorr2r��__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<rCr�r2r�r�r�r_)r�rNrO�dst_filer0r�s      r%�test_copyfile_return_valuez#TestCopy.test_copyfile_return_value:s����,�,�.�.���,�,�.�.���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<rCr�r
r�r2rr�r_)r�rNr0s   r%�test_copyfile_same_filez TestCopy.test_copyfile_same_fileEs����,�,�.�.���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<rCr�r�r�r2)r�rNr0r{s    r%�test_copyfile_nonexistent_dirz&TestCopy.test_copyfile_nonexistent_dirQso���,�,�.�.���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<rCr�r?r�r.r�r�r2)r�rNr0r�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+rir�r>r�r�r"r��skip_unless_xattrr�skip_unless_dac_overriderrrrrr r"r$r'r)r&r3r6r8r�r?r<r?rA�MACOS�SOLARISr�r�rCrErFr'r%r�r�ks�������"�E�E�#�"�E�<�X�����X�.�.�A�"�'�T�/�CW�X�X��"�E�E�#�"�Y�X�E�<�X�_�W�W�R��*�*�,N�O�O��"�
C�
C�#�"�P�O�
C��"�(!�(!�#�"�(!�T�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�Zej��d���Zd�Zd�Zd�Zd�Zej��d���Zej��d���Z ej!��ej"e#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)rOz./subz./sub2z./file1z./file2z./sub/file3�tar�.tarr])�
_create_filesr�r+r�r;rJr<�basenamer�
change_cwd�no_chdir�abspathrr�r�rL�tarfile�
is_tarfiler=�assertCountEqual�getnames)	r��root_dirr�r�work_dir�
rel_base_name�	base_name�tarball�tfs	         r%�test_make_tarballzTestArchives.test_make_tarballus���"�/�/��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*)rXr=r[�sortr:)r�r;rQrrs    r%�_tarinfozTestArchives._tarinfo�s���
�\�$�
�
�	 �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�rX�file3�sub2�outer)r�r+r;r<r�rCr�)r�r�r\rfs    r%rSzTestArchives._create_files�s����<�<�>�>���w�|�|�H�h�/�/��
��D�4�(�(�(�(��D�'�?�E�*�*�*��D�'�?�E�*�*�*�
������d�E�*�*�+�+�+��D�%��)�5�1�1�1�
������d�F�+�+�,�,�,��	3���'�*�E�2�2�2���!�!r'rQzNeed the tar command to runc���|���\}}tj�|���d��}t
5t
|d||��}ddd��n#1swxYwY|�||dz��|�tj�	|����tj�|d��}ddd|g}tjdkr^ddl}t|�
��d�d	��d��d
kr|�dd��t!j||t j�
��|�tj�	|����|�|�|��|�|����t
5t
|d||��}ddd��n#1swxYwY|�||dz��|�tj�	|����t
5t
|d||d���}ddd��n#1swxYwY|�||dz��|�tj�	|����dS)NrMrNrPzarchive2.tarrQz-cfrrrO�r�z--no-mac-metadata��cwd�stdoutrRT��dry_run)rSr+r;r<r�rVrr�r�rLr�r?r��mac_verr��insertr��
check_call�DEVNULLre)r�r\r�r_r`�tarball2�tar_cmdr?s        r%�test_tarfile_vs_tarz TestArchives.test_tarfile_vs_tar�sk��"�/�/�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���%���:���<�8�#�#�
�O�O�O��8�#�#�%�%�a�(�.�.�s�3�3�A�6�7�7�2�=�=����q�"5�6�6�6���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�0H�H�H�,J
�
J�Jc�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)NrM�zip�.zip)�dist/�	dist/sub/�
dist/sub2/�
dist/file1�
dist/file2�dist/sub/file3rk)r}r~rr�r�r�)rSr�r+r�r;rJr<rTrrUrVrWrr�r�rL�zipfile�
is_zipfile�ZipFilerZ�namelist)	r�r\r�rr]r^r_rh�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� Lr{zNeed 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)NrMr{r|zarchive2.zipz-qz-rrn)rSr+r;r<r�rVrr�r�rLr�rurvr�r�r�rb)
r�r\r�r_rM�archive2�zip_cmdr�rr�names2s
          r%�test_zipfile_vs_zipz TestArchives.test_zipfile_vs_zipsf��"�/�/�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)NrMr{r|r�z-t)�stderr�replace)r�zunrecognized option: tzunzip doesn't support -tz{}

**Unzip Output**
{})rSr+r;r<r�rVrr�r�rLrrUr��check_output�STDOUT�CalledProcessError�output�decoder�r��format)	r�r\r�r_rMr�r��details�msgs	         r%�test_unzip_zipfilezTestArchives.test_unzip_zipfiles#��"�/�/�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)NrMr�)r�r+r;r<r��
ValueErrorr)r�r�r_s   r%�test_make_archivezTestArchives.test_make_archive5sD���������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�rMr{��owner�grouprQ�	kjhkjhkjg�oihohoh)
�UID_GID_SUPPORT�grp�getgrgid�pwd�getpwuidrSr+r;r<r�rr�rL)r�r�r�r\r�r_rhs       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)NrMrrNrfr�)rSr+r;r<r�r�r�r�r�rrUrVrr�rLrXr=�
getmembersr��uid�gidr)	r�r\r�r_r�r��archive_namerM�members	         r%�test_tarfile_root_ownerz$TestArchives.test_tarfile_root_ownerVs��"�/�/�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>._breaksps���.�.� r'c�H����|���|��dSr*r�)r;r��
orig_chdirs ��r%�_chdirz2TestArchives.test_make_archive_cwd.<locals>._chdirss+����K�K������J�t�����r'r��xxx file�chdir)r\)
r+rur�rrrrr
r�r)r��current_dirr\r�r�r�r�s     @@r%�test_make_archive_cwdz"TestArchives.test_make_archive_cwdmso�����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�testrQztest.tar�
r�rrUrVr�rr�r+r;rL�r�r\s  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�r{ztest.zipr�r�s  r%�test_make_zipfile_in_curdirz(TestArchives.test_make_zipfile_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�	8r�c���|�ttdd��|�ttdd�d��|�ttdd�ddg��tdd�dgd��d	�t��D��}|�d|��td��d
�t��D��}|�d|��dS)Nr�r�c��tSr*��xrFr'r%�<lambda>z;TestArchives.test_register_archive_format.<locals>.<lambda>����Q�r'c��tSr*r�rFr'r%r�z;TestArchives.test_register_archive_format.<locals>.<lambda>�r�r')r�rq)r�rqrc��tSr*r�rFr'r%r�z;TestArchives.test_register_archive_format.<locals>.<lambda>�s��q�r'r�c��g|]\}}|��SrFrF�rPri�paramss   r%rRz=TestArchives.test_register_archive_format.<locals>.<listcomp>����B�B�B�L�D�&�4�B�B�Br'c��g|]\}}|��SrFrFr�s   r%rRz=TestArchives.test_register_archive_format.<locals>.<listcomp>�r�r')r��	TypeErrorrrr�rr�)r��formatss  r%�test_register_archive_formatz)TestArchives.test_register_archive_format�s������)�%<�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	��|�tjt�d���dD�]-}|�|���5|���}tj�|d��}|�	t��5}ttd||���ddd��n#1swxYwY|�|j
jtj��|�|j
j|��|�tj�t�d�����t'j|���\}}t
j|��|�	t,��5}ttd||���ddd��n#1swxYwY|�|j
jtj��|�|j
j|��|�tj�t�d�����ddd��n#1swxYwY��/dS)NrR�FTrq�nonexistingrQr��r�rrwr�subTestr�r+r;r<r�r�rr�r�r"�ENOENTr�r�r�rsr'rr��ENOTDIR�r�rrr�nonexisting_filer��tmp_fd�tmp_files       r%�test_make_tarfile_rootdir_nodirz,TestArchives.test_make_tarfile_rootdir_nodir�s������	�(�V�/�/�/�:�:�:�$�	B�	B�G����g��.�.�
B�
B��,�,�.�.��#%�7�<�<���#G�#G� ��&�&�'8�9�9�S�R� ���0@�'�R�R�R�R�S�S�S�S�S�S�S�S�S�S�S����S�S�S�S�� � ���!3�U�\�B�B�B�� � ���!6�8H�I�I�I�� � �����6����!@�!@�A�A�A�#+�#3��#@�#@�#@� ������ � � ��&�&�'9�:�:�K�b� ����'�J�J�J�J�K�K�K�K�K�K�K�K�K�K�K����K�K�K�K�� � ���!3�U�]�C�C�C�� � ���!6��A�A�A�� � �����6����!@�!@�A�A�A�
B�
B�
B�
B�
B�
B�
B�
B�
B�
B�
B����
B�
B�
B�
B��	B�	B�]�AI
�B8�,I
�8B<�<I
�?B<�C
I
�
F2�&I
�2F6�6I
�9F6�:BI
�
I	�I	c	��|�tjt�d���dD�]-}|�|���5|���}tj�|d��}|�	t��5}ttd||���ddd��n#1swxYwY|�|j
jtj��|�|j
j|��|�tj�t�d�����t'j|���\}}t
j|��|�	t,��5}ttd||���ddd��n#1swxYwY|�|j
jtj��|�|j
j|��|�tj�t�d�����ddd��n#1swxYwY��/dS)Nr|r�rqr�r{r�r�r�s       r%�test_make_zipfile_rootdir_nodirz,TestArchives.test_make_zipfile_rootdir_nodir�s���	
���	�(�V�/�/�/�:�:�:�$�	B�	B�G����g��.�.�
B�
B��,�,�.�.��#%�7�<�<���#G�#G� ��&�&�'8�9�9�S�R� ���0@�'�R�R�R�R�S�S�S�S�S�S�S�S�S�S�S����S�S�S�S�� � ���!3�U�\�B�B�B�� � ���!6�8H�I�I�I�� � �����6����!@�!@�A�A�A�#+�#3��#@�#@�#@� ������ � � ��&�&�'9�:�:�K�b� ����'�J�J�J�J�K�K�K�K�K�K�K�K�K�K�K����K�K�K�K�� � ���!3�U�]�C�C�C�� � ���!6��A�A�A�� � �����6����!@�!@�A�A�A�
B�
B�
B�
B�
B�
B�
B�
B�
B�
B�
B����
B�
B�
B�
B��	B�	Br�c��|j|d�fi|��|j|tjfi|��|j|tfi|��dS)Nc��|Sr*rF�r;s r%r�z3TestArchives.check_unpack_archive.<locals>.<lambda>�s���r')�#check_unpack_archive_with_converterr�r�r)r�r�r$s   r%�check_unpack_archivez!TestArchives.check_unpack_archive�s}��0��0��%�%�	1�	1�)/�	1�	1�	1�0��0��G�L�	,�	,�$*�	,�	,�	,�0��0���L�L�V�L�L�L�L�Lr'c��|���\}}t|��}|�d��tj�|���d��}t||||��}|���}	t||��||	��fi|��|�	t|	��|��|���}
t||��||
��fd|i|��|�	t|
��|��|�
tj��5t|t��fi|��ddd��n#1swxYwY|�
t��5t|t��fddi|��ddd��dS#1swxYwYdS)NrkrMr�r�)rSrgr(r+r;r<r�rrr�r�r��	ReadErrorrr�)r�r��	converterr$r\r��expectedr_r�r�tmpdir3s           r%r�z0TestArchives.check_unpack_archive_with_converter�sh��!�/�/�1�1���(��H�%�%������ � � ��G�L�L�������;�;�	��	�6�8�X�F�F���,�,�.�.���y�y��*�*�I�I�g�,>�,>�I�I�&�I�I�I�����'�*�*�H�5�5�5��,�,�.�.���y�y��*�*�I�I�g�,>�,>�	!�	!�v�	!��	!�	!�	!�����'�*�*�H�5�5�5�
�
�
�v�/�
0�
0�	8�	8��9�9�V�,�,�7�7��7�7�7�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8�	8����	8�	8�	8�	8�
�
�
�z�
*�
*�	F�	F��9�9�V�,�,�E�E�U�E�f�E�E�E�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F����	F�	F�	F�	F�	F�	Fs$�E7�7E;�>E;�G�G�Gc���|�|d���|�|d���tj|��5|�|��ddd��dS#1swxYwYdS)N�
fully_trusted��filter�data)r�r�check_no_warnings)r�r�s  r%�check_unpack_tarballz!TestArchives.check_unpack_tarball�s����!�!�&��!�A�A�A��!�!�&��!�8�8�8�
�
.�t�
4�
4�	.�	.��%�%�f�-�-�-�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.����	.�	.�	.�	.�	.�	.s�A&�&A*�-A*c�0�|�d��dS)NrQ�r�r9s r%�test_unpack_archive_tarz$TestArchives.test_unpack_archive_tar�s���!�!�%�(�(�(�(�(r'c�0�|�d��dS)NrNr�r9s r%�test_unpack_archive_gztarz&TestArchives.test_unpack_archive_gztar�����!�!�'�*�*�*�*�*r'c�0�|�d��dS)N�bztarr�r9s 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�r9s r%�test_unpack_archive_xztarz&TestArchives.test_unpack_archive_xztar�s��	
�!�!�'�*�*�*�*�*r'c���|�d��|�t��5|�dd���ddd��dS#1swxYwYdS)Nr{r�r�)r�r�r�r9s r%�test_unpack_archive_zipz$TestArchives.test_unpack_archive_zips����!�!�%�(�(�(�
�
�
�y�
)�
)�	<�	<��%�%�e�F�%�;�;�;�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<����	<�	<�	<�	<�	<�	<s�A�A�Ac���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>._boosK������U�A�&�&�&����X�{�3�3�3����[�$�/�/�/�/�/r'�Booz.booz.b2)r	r�rr�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)rf)(r�r�r�r�
requires_zlibrbrerSr<r=r��whichryr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��requires_bz2r��
requires_lzmar>r�r�rrr
rFr'r%rKrKqs��������W����!H�!H���!H�F � � �"�"�"�"��W�����X�����e�,�,�6�8�8�*1�*1�8�8���*1�X�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�)�)�)� B�B�B�*�W����B�B���B�.M�M�M�F�F�F�0.�.�.�)�)�)��W����+�+���+��W����+�+���+��W�����X�_�S�-�����-�/Y�Z�Z�+�+�[�Z���+��W����<�<���<�
8�8�8�8�8r'rKc���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)rG�used�freer)r�rr+r;rJr;r�r!r��
assertGreaterrGr�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_chownOsY������!�!�A���� � ��a�h�/�/�/���� � ��a�h�/�/�/�/�/��r')r�r)NN)r�rsr�rCr�r�r�r�LookupErrorr�r+�getuid�getgidr�r�r�r��KeyError)r�rJr�r�r$rr�r�s`      @r%�
test_chownzTestMisc.test_chown6s������,�,�.�.���?�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�rr�r+r)rFr'r%rr%s��������X������6�6�D�F�F�$�$�F�F�$��X���*H�I�I��X�����W�-�-�/B�C�C�:+�:+�D�C�J�I�:+�:+�:+r'rc�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�extr9s r%�setUpzTestWhich.setUpws������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�rr3ror�r1ri�r�r�s  r%�
test_basiczTestWhich.test_basic�s;��
�\�$�)�$�(�
3�
3�
3������T�^�0�1�1�1�1�1r'c��tj|jj|j���}|�||jj��dSr9)r�rr1rir0r�r:s  r%�test_absolute_cmdzTestWhich.test_absolute_cmd�s@���\�$�.�-�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#1swxYwYdSr9)
r+r;r�ror<r3rrUr�rr0r��assertIsNone)r�r��tail_dir�relpathr�s     r%�test_relative_cmdzTestWhich.test_relative_cmd�sn�� �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;rJrorrUr�rr3r�r?r�r<r5r?)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;rA)r+r�r1rir�r��access�W_OKr�r�rr3ror?r:s  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#1swxYwYdSr9)r+r;r�rorrUr�rr3r�r<)r�r�r@r�s    r%�test_relative_pathzTestWhich.test_relative_path�s����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�rror?r:s  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�rr3ror�r1rir6r:s  r%�test_pathext_checkingzTestWhich.test_pathext_checking�sU��
�\�$�)�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�EnvironmentVarGuardr4r�rr3r�r1ri�r��envr�s   r%�test_environ_pathzTestWhich.test_environ_path�s���
�
*�
,�
,�	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�rR�
os.confstrT��return_value�create�defpath)rrSr<r�r�rorrr+rUr�rr3r?rTs   r%�test_environ_path_emptyz!TestWhich.test_environ_path_empty�s���
�
*�
,�
,�	&���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-rRrXTrYr\)r+r;rTr1rir�r?r5r9r�r�r<rrS�pathsepr<r�r�rorrr�rr3r?rUr�)r��expected_cwdr5rUr�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)NrRrXT)rr[r\rYr�)rrS�popr<r�r�r�rrr+ror�rr3r�r1rirTs   r%�test_environ_path_missingz#TestWhich.test_environ_path_missing�s���
�
*�
,�
,�	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�rRr�)r+r;rJrorrUrSr4r�rr3r?)r�r�rUr�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#1swxYwYdSrQ)rrSrcr�rr3r?rTs   r%�test_empty_path_no_PATHz!TestWhich.test_empty_path_no_PATHs���
�
*�
,�
,�	"���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�)rsrtr0r+r�rir�r2r�rr;rTrqrrSr�rr��r�r6�temp_filexyz�programrUr�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)Nrjrkr.r�;rlr�)rsrtr0r�rr+r;rTrirqrrSr�rr�rms      r%�test_pathext_with_empty_strz%TestWhich.test_pathext_with_empty_strs!�����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�r7r;r=rBrDrr@rHrJrLr<r=r�r?rOrVr]rardrfrhrprsrFr'r%r+r+us����������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'r+c��eZdZd�ZdS)�TestWhichBytesc�z�t�|��tj|j��|_tj|j��|_tj|jj��|j_tj|j��|_tj|j	��|_	dSr*)
r+r7r+r�ror3r1rir5r6r9s r%r7zTestWhichBytes.setUp0s}����������;�t�x�(�(����K��	�*�*��	� �k�$�.�*=�>�>�����k�$�+�.�.����;�t�x�(�(����r'N)r�r�r�r7rFr'r%ruru/s#������)�)�)�)�)r'ruc���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&e
d���Z'ejd���Z(ejd ���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�r4r)
r�rNrOr+r;r<r0r>r=r>)r�r�rXs   r%r7zTestMove.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_fileDs)��
�#�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�r|r�r�r;r�)r�rzr{r}r~s     r%�_check_move_dirzTestMove._check_move_dirLsy���"�*�S�/�/�*�*����C���������6�"�*�X�*>�*>�#?�#?�@�@�@���������,�,�-�-�-�-�-r'c�R�|�|j|j|j��dSr*)rr0r>r9s r%�test_move_filezTestMove.test_move_fileRs&�����d�m�T�]�D�M�J�J�J�J�Jr'c�R�|�|j|j|j��dSr*)rr0rOr>r9s r%�test_move_file_to_dirzTestMove.test_move_file_to_dirVs&�����d�m�T�\�4�=�I�I�I�I�Ir'c�z�tj|j��}|�||j|j��dSr*)r�r�r0rrOr>)r�rzs  r%�"test_move_file_to_dir_pathlike_srcz+TestMove.test_move_file_to_dir_pathlike_srcZs5���l�4�=�)�)�����c�4�<���?�?�?�?�?r'c�z�tj|j��}|�|j||j��dSr*)r�r�rOrr0r>�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�r9s r%�test_move_file_other_fsz TestMove.test_move_file_other_fsds��	
�������r'c�.�|���dSr*)r�r9s r%�test_move_file_to_dir_other_fsz'TestMove.test_move_file_to_dir_other_fsis��	
�"�"�$�$�$�$�$r'c���tj|������}	|�|j||��tj|��dS#tj|��wxYwr&)rsr�r�r�rNrr��r�rOs  r%�
test_move_dirzTestMove.test_move_dirnsi���/�d�l�l�n�n�5�5�5��	&�� � ���w��@�@�@���W�%�%�%�%�%��I��W�%�%�%�%���s�A�A1c�.�|���dSr*)r�r9s r%�test_move_dir_other_fszTestMove.test_move_dir_other_fsvs��	
�������r'c
���|�|j|jtj�|jtj�|j������dSr*)r�rNrOr+r;r<rTr9s r%�test_move_dir_to_dirzTestMove.test_move_dir_to_dir{sX�����T�\�4�<��G�L�L���r�w�'7�'7���'E�'E�F�F�	H�	H�	H�	H�	Hr'c�.�|���dSr*)r�r9s r%�test_move_dir_to_dir_other_fsz&TestMove.test_move_dir_to_dir_other_fs�s��	
�!�!�#�#�#�#�#r'c
��|�|jtjjz|jtj�|jtj�|j������dSr*)r�rNr+r;�seprOr<rTr9s 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�rNr+r;�altseprOr<rTr9s r%�test_move_dir_altsep_to_dirz$TestMove.test_move_dir_altsep_to_dir�sa�����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)Nr4)r=r>r�r�rr|r0rOr9s r%�"test_existing_file_inside_dest_dirz+TestMove.test_existing_file_inside_dest_dir�s���
�$�-��
&�
&�	�	��	�	�	�	�	�	�	�	�	�	�	����	�	�	�	����&�,���T�]�D�L�Q�Q�Q�Q�Qs�$�(�(c��tj�|jd��}|�t
jt
j|j|��dS�Nr�)r+r;r<rNr�r�rr|r�s  r%�test_dont_move_dir_in_itselfz%TestMove.test_dont_move_dir_in_itself�s?���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_negative�s���
������	%�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))r�zsrc/dest)r�z
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<rNr�r0r�r|r>r�re�samefiler�s  r%�test_move_file_symlinkzTestMove.test_move_file_symlink�s����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<rNr�r0r�r|rOr�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<rNr�rOr�r|r�rer��realpath�r�rzr{rgs    r%�test_move_dangling_symlinkz#TestMove.test_move_dangling_symlink�s����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<rNr�r�rOr�r|r�rer�r�s    r%�test_move_dir_symlinkzTestMove.test_move_dir_symlink�s����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�r|r0rOr�r+r;r<rTr:s  r%�test_move_return_valuezTestMove.test_move_return_value�sg��
�[�����
5�
5����������T�\�2�7�+;�+;�D�M�+J�+J�K�K�	M�	M�	M�	M�	Mr'c���tj|jtj�|jd����}|�|tj�|jd����dSr�)r�r|r0r+r;r<rOr�r:s  r%� test_move_as_rename_return_valuez)TestMove.test_move_as_rename_return_value�sU��
�[�������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>._copy������L�L�#�s��$�$�$�$�$r'r�r�)r�r|r0rOr�r��r�r�r�s  @r%�test_move_file_special_functionz(TestMove.test_move_file_special_function�s^�����	%�	%�	%�	%�	%���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>._copy�r�r'�child�child1r�r)rr�r+r;r<rNr�r|rOr�r�r�s  @r%�test_move_dir_special_functionz'TestMove.test_move_dir_special_function�s������	%�	%�	%�	%�	%��#�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�rNr+r;r<rJrT�upperr�r�r|r�rdr�r�s  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$c���tj�|jd��}tj�|jd��}tj|j|d���t
j||��|�tj�	|����|�tj�
|j|����|�tj�|����tj|j|d���|�
tj��5t
j||��ddd��n#1swxYwY|�tj�
|j|����|�tj�|����dS)N�	linktodirTr�)r+r;r<rNrOr�r�r|r�rer�r�r�r�r)r�r{rzrgs    r%�"_test_move_symlink_to_dir_into_dirz+TestMove._test_move_symlink_to_dir_into_dir		s����g�l�l�4�<��5�5���7�<�<���k�:�:��
�
�4�<��$�?�?�?�?���C������������x�0�0�1�1�1������(�(���x�@�@�A�A�A���������,�,�-�-�-�	�
�4�<��$�?�?�?�?�
�
�
�v�|�
,�
,�	"�	"��K��S�!�!�!�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"������(�(���x�@�@�A�A�A��������s�+�+�,�,�,�,�,s�E5�5E9�<E9c�:�|�|j��dSr*)r�rOr9s r%�!test_move_symlink_to_dir_into_dirz*TestMove.test_move_symlink_to_dir_into_dir	s���/�/���=�=�=�=�=r'c��tj�|jd��}tj|j|d���|�|��dS)N�otherlinktodirTr�)r+r;r<rNr�rOr�r�s  r%�,test_move_symlink_to_dir_into_symlink_to_dirz5TestMove.test_move_symlink_to_dir_into_symlink_to_dir	sM���g�l�l�4�<�)9�:�:��
�
�4�<��$�?�?�?�?��/�/��4�4�4�4�4r'rZ�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_SRCrZr�r�r�r�r�r|�
TESTFN_DSTr�rcr�rr�r;r<r�r�r9s 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�r7rr�r�r�r�r�r2r�r�r�r�r�r�r�r<r=r+r;r�r�r�r�r�r�rr;r�r�r�r�r�r�r�r�r�r�r�r�rGrrr�r�rFr'r%rxrx9s����������.�.�.�.�.�.�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�
@�@�@��(�(��[�(��(�(��[�(����$�-�-��[�-�"�"�>�>�#�"�>��"�5�5�#�"�5�
�'��X�����Z�0�0�8�$�W�T�>�:�:�8�$�W�T�;�7�7�,�.�.�-�-�	.�.�(�'�
-�-�-r'rxc���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__N	s��"/�D��%5�D�"�"�"r'c��dS)Nr�rF)r�r#s  r%r^zTestCopyFile.Faux.readQ	s���2r'c��d|_dS)NT)�_enteredr9s r%�	__enter__zTestCopyFile.Faux.__enter__S	s
�� �D�M�M�Mr'c�^�|||f|_|jrd|_td���|jS)NT�Cannot close)�_exited_withr��_raisedr r�)r��exc_type�exc_val�exc_tbs    r%�__exit__zTestCopyFile.Faux.__exit__U	s:�� (�'�6� 9�D���"�
.�#����n�-�-�-��)�)r'r�)
r�r�r�r�r�r�r�r^r�r�rFr'r%�Fauxr�J	sd������������	6�	6�	6�	6�	�	�	�	!�	!�	!�	*�	*�	*�	*�	*r'r�c��dd�}tjtd|��5|�t��5tjdd��ddd��n#1swxYwYddd��dS#1swxYwYdS)Nr]c�0�|dkrtd���dS)N�srcfilezCannot open "srcfile"r)r�rAs  r%�_openz4TestCopyFile.test_w_source_open_fails.<locals>._open]	s$���9�$�$��5�6�6�6�%�$r'r=r��destfile�r])rrr�r�r r2)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���dS)Nr�r��Cannot open "destfile"r)r�rAr�s  �r%r�z2TestCopyFile.test_w_dest_open_fails.<locals>._openj	s5����9�$�$����:�%�%��6�7�7�7�&�%r'r=r�r�rr�)r�r�)r�rrr�r2r�r�r�r r�r#)r�r�r�s  @r%�test_w_dest_open_failsz#TestCopyFile.test_w_dest_open_failsf	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�SdS�Nr�r�rF�r�rAr�r�s  ��r%r�z3TestCopyFile.test_w_dest_close_fails.<locals>._open}	�+����9�$�$����:�%�%���&�%r'r=r�r�rr�)r�r�)r�rrr�r2r�r�r�r�r r�r#�r�r�r�r�s  @@r%�test_w_dest_close_failsz$TestCopyFile.test_w_dest_close_failsx	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�SdSr�rFrs  ��r%r�z5TestCopyFile.test_w_source_close_fails.<locals>._open�	rr'r=r�r�rr�)r�rrr�r�r r2r�r�r�r�r�rs  @@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>rHr�rrrFr'r%r�r�H	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�r9s r%�tearDownzTestCopyFileObj.tearDown�	������!�!�!�!�!r'c#��K�ttd��5}ttd��5}||fV�ddd��n#1swxYwYddd��dS#1swxYwYdS�Nr\r4�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#1swxYwYdSr{)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*)rr��copyfileobjrrr�r.s   r%�test_contentzTestCopyFileObj.test_content�	s���
�^�^�
�
�	)��#�s���s�C�(�(�(�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)�	)����	)�	)�	)�	)����V�W�-�-�-�-�-s
�:�>�>c��|���5\}}tj||��ddd��dS#1swxYwYdSr*)rr�r r.s   r%�test_file_not_closedz$TestCopyFileObj.test_file_not_closed�	s���
�^�^�
�
�	"��#�s���s�C�(�(�(�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"�	"����	"�	"�	"�	"�	"�	"s
�;�?�?c�D�|���5\}}tj||��|�|���|j��|�|���|j��ddd��dS#1swxYwYdSr*)rr�r r��tellrr.s   r%�test_file_offsetz TestCopyFileObj.test_file_offset�	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�Br^zWindows onlyc��tj�d��5}tjt
t��ddd��n#1swxYwY|�|jddd��tj
tj��d���5}|�
d��ddd��n#1swxYwY|j}|�t j|��tj�d��5}tj|t��ddd��n#1swxYwY|�|jddd��tj
tj��d���5}	ddd��n#1swxYwY|j}|�t j|��tj�d��5}tj|t��ddd��n#1swxYwY|�|t��dS)	Nzshutil._copyfileobj_readintorrqiFrnsfoor)r<r�r�r�r2rr�r��	call_argsrsrtr+rur>rir�rrwr)r��mrXr�s    r%�
test_win_implzTestCopyFileObj.test_win_impl�	s���]�
 �
 �!?�
@�
@�	-�A��O�F�G�,�,�,�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-����	-�	-�	-�	-�
	
�����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�+�+�+�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,����	,�	,�	,�	,�	
���U�G�,�,�,�,�,sY� A�A�A�%C�C�C�D?�?E�E�F&�&F*�-F*�7H�H"�%H"N)r�r�r�r�classmethodrrr�
contextlib�contextmanagerrrr!r#r&r<r>r+rir*rFr'r%r	r	�	s��������H��.�.��[�.��"�"��[�"�"�"�"���!�!���!�
;�;�;�
.�.�.�
"�"�"�8�8�8��X�_�R�W��_�n�5�5�-�-�6�5�-�-�-r'r	c��eZdZ	dZdZdZed���Zed���Zd�Z	e
jd���Zd�Z
d	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�ZdS)�_ZeroCopyFileTesti�r'r�c���tt|j��ttd��5}|���|_ddd��dS#1swxYwYdSr{)rZrrr=r^�FILEDATA)r
rXs  r%rz_ZeroCopyFileTest.setUpClass�	s�������-�-�-�
�&�$�
�
�	5�1��6�6�8�8�C�L�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5����	5�	5�	5�	5�	5�	5s�A�A�Ac�8�tjt��dSr*)rrwrrs r%rz_ZeroCopyFileTest.tearDownClass�	s����� � � � � r'c�8�tjt��dSr*rr9s r%rz_ZeroCopyFileTest.tearDown�	rr'c#��K�ttd��5}ttd��5}||fV�ddd��n#1swxYwYddd��dS#1swxYwYdSrrr.s   r%rz_ZeroCopyFileTest.get_files
rrc� �td���)Nzmust be implemented in subclass)r#)r�r#r$s   r%�zerocopy_funz_ZeroCopyFileTest.zerocopy_fun
s��!�"C�D�D�Dr'c��|���|���|���|���dSr*)rrrr7r9s r%�resetz_ZeroCopyFileTest.reset
sB���
�
�����������������
�
�����r'c��|���5\}}|�||��ddd��n#1swxYwY|�ttd���|j��|���5\}}tj�d��5}tj
tt��ddd��n#1swxYwYddd��dS#1swxYwYdS)NT�r@zshutil.copyfileobj)rr6r�r_r�r1r<r�r�r�r2r)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�	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 �	 �	 sC�;�?�?�	#C0�, C�C0�C	�C0�C	� C0�0C4�7C4c��|�|j��|���5\}}|�tt
f��5|�||��ddd��n#1swxYwYddd��n#1swxYwY|�ttd���|j
��dS)NTr:)r�r8rr�r rr6r�r_rr1r.s   r%�test_same_filez _ZeroCopyFileTest.test_same_file
s.������
�#�#�#�
�^�^�
�
�	,��#�s��"�"�G�->�#?�@�@�
,�
,��!�!�#�s�+�+�+�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,�
,����
,�
,�
,�
,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,����	,�	,�	,�	,�	
����6�$�7�7�7���G�G�G�G�Gs5�%B�A7�+B�7A;	�;B�>A;	�?B�B�Bc� �tjtj�����}|�t
��5}t
j|d��ddd��n#1swxYwY|�|j	j
|��dS)Nr��new)rsr�r+rur�r�r�r2r�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*rC)rys�r%r�z3_ZeroCopyFileTest.test_empty_file.<locals>.<lambda>/
rDr'r4r\Tr:r')rr�r=r6r�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�r2rr�r9s r%�test_unhandled_exceptionz*_ZeroCopyFileTest.test_unhandled_exception9
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�rHr r"�EINVALrr�rr6r.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#1swxYwYdSrL)
r<r�r�rHr r"�ENOSPCrr�r6r.s   r%�test_filesystem_fullz&_ZeroCopyFileTest.test_filesystem_fullI
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�rr1rHr+rrrr,r-rr6r8r;r=r@rFrJrOrRrFr'r%r/r/�	s������-� �H��H��J��5�5��[�5��!�!��[�!�"�"�"���!�!���!�
E�E�E���� � � �H�H�H�6�6�6�?�?�?�@�@�@�0�0�0�H�H�H�H�Hr'r/zos.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�rrs   r%r6z!TestZeroCopySendfile.zerocopy_funV
s���(��t�4�4�4r'c���tj|j��5}ttd��5}|�t��5|�||��ddd��n#1swxYwYtj	||��ddd��n#1swxYwYddd��n#1swxYwY|�
ttd���|j��dS)Nr4Tr:)�io�BytesIOr1r=r�r�rr6r�r r�r_r.s   r%�test_non_regular_file_srcz.TestZeroCopySendfile.test_non_regular_file_srcY
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=rrYrZr�rr6r�r �seekr�r^r1r.s   r%�test_non_regular_file_dstz.TestZeroCopySendfile.test_non_regular_file_dstb
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|�
|jjtj
��dS)Nc�v���s��d���|i|��Sttjd���)NrM)rfr r"�EBADF)r#r$r��
orig_sendfiles  ��r%rmzDTestZeroCopySendfile.test_exception_on_second_call.<locals>.sendfilel
sD����
1����D�!�!�!�$�}�d�5�f�5�5�5��e�k�4�0�0�0r'rUT)r[r)r+rmr<r�r�rr�r r�rWr�r�r"ra)r�rmrzr{r�r�rbs     @@r%�test_exception_on_second_callz2TestZeroCopySendfile.test_exception_on_second_callk
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�h�tj�dt���5}|���5\}}tj||��ddd��n#1swxYwYddd��n#1swxYwY|�ttd���|j
��dS)N�os.fstatrTr:)r<r�r�r rr�rWr�r_r�r1�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�
 �
 �
 �
 �
 �
 �
 �
 �
 �
 �
 ����
 �
 �
 �
 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 �	
����7�4�8�8�8�$�-�H�H�H�H�Hs4�A8�A!�A8�!A%	�%A8�(A%	�)A8�8A<�?A<c��tj���}d|_tj�d|���5}|���5\}}t
j||��ddd��n#1swxYwYddd��n#1swxYwY|�ttd���|j��dS)Nire�rZTr:)r<r��Mock�st_sizer�rr�rWr�r_r�r1�r�r�r)rzr{s     r%�test_small_chunksz&TestZeroCopySendfile.test_small_chunks�
s1��
�}�!�!�#�#�� ���
�]�
 �
 ��$�
 �
?�
?�	 �1����!�!�
 �Z�c�3��)�#�s�3�3�3�
 �
 �
 �
 �
 �
 �
 �
 �
 �
 �
 ����
 �
 �
 �
 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 �	
����7�4�8�8�8�$�-�H�H�H�H�Hs6�B�B�5B�B	�B�B	�	B�B�Bc��tj���}|jdz|_tj�d|���5}|���5\}}tj||��ddd��n#1swxYwYddd��n#1swxYwY|�	ttd���|j��dS)Ni@reriTr:)
r<r�rjrrkr�rr�rWr�r_r�r1rls     r%�test_big_chunkz#TestZeroCopySendfile.test_big_chunk�
s9��
�}�!�!�#�#���}�(9�:���
�]�
 �
 ��$�
 �
?�
?�	 �1����!�!�
 �Z�c�3��)�#�s�3�3�3�
 �
 �
 �
 �
 �
 �
 �
 �
 �
 �
 ����
 �
 �
 �
 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 �	
����7�4�8�8�8�$�-�H�H�H�H�Hs6�B �$B	�=B �	B
	�
B �B
	�B � B$�'B$c���tj�dt���5}|�tt
jtt��|j	dd}|�
|tj�
t����tjt��t!tdd���|�tjtdz��|�tt
jttdz��|j	dd}|�
|d	��ddd��dS#1swxYwYdS)
NrUrrrshelloTr:�3i�)r<r�r�rIr�r�r2rr�r(r�r+r;�getsizerrwrCr�)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��	tj�|jt	t
jd�����5}|���5\}}|�t��5tj||��ddd��n#1swxYwYddd��n#1swxYwYddd��n#1swxYwYtj�|j��5}tjtt��ddd��n#1swxYwYdt_dS#dt_wxYw)NrMrT)r<r�r�rHr r"�ENOTSOCKrr�rr�rWr2rr��_USE_CP_SENDFILErfs    r%�test_file2file_not_supportedz1TestZeroCopySendfile.test_file2file_not_supported�
s��
	+���$�$��O� '���� =� =�%�?�?�
 �BC��^�^�%�%�<��#�s��*�*�+<�=�=�<�<��1�#�s�;�;�;�<�<�<�<�<�<�<�<�<�<�<����<�<�<�<�<�<�<�<�<�<�<�<�<�<�<����<�<�<�<�
 �
 �
 �
 �
 �
 �
 �
 �
 �
 �
 ����
 �
 �
 �
 ���$�$�T�_�5�5�
$������0�0�0�
$�
$�
$�
$�
$�
$�
$�
$�
$�
$�
$����
$�
$�
$�
$�'+�F�#�#�#��d�F�#�*�*�*�*s��>D7�C�B,�3B�	B,�B�B,�B�B,� C�,B0	�0C�3B0	�4C�7D7�C�D7�
C�'D7�2 D�D7�D"�"D7�%D"�&D7�7EN)
r�r�r�rHr6r[r^rcrgrmrortrxrFr'r%rTrTR
s��������J�5�5�5�I�I�I�<�<�<�:�:�:�$I�I�I�I�I�I�I�I�I�1�1�1�$+�+�+�+�+r'rTz
macOS onlyc��eZdZdZd�ZdS)�TestZeroCopyMACOSzposix._fcopyfilec�B�tj||tj��Sr*)r��_fastcopy_fcopyfile�posix�_COPYFILE_DATAr.s   r%r6zTestZeroCopyMACOS.zerocopy_fun�
s���)�#�s�E�4H�I�I�Ir'N)r�r�r�rHr6rFr'r%rzrz�
s-������#�J�J�J�J�J�Jr'rzc��eZdZd�Zd�Zd�Zejej	e
j�����d��eje
ed��d��d�����Zejejd��d	���Zd
S)�TestGetTerminalSizec��	tj��}|�|jd��|�|jd��dS)Nr)r��get_terminal_sizer�columns�lines)r�rUs  r%�test_does_not_crashz'TestGetTerminalSize.test_does_not_crash�
sM��	�
�'�)�)�������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)N�777�COLUMNS�LINESi	�888ix)rrSr�r�r�r�r��r�rUrUs   r%�test_os_environ_firstz)TestGetTerminalSize.test_os_environ_first�
s=��8�
�
*�
,�
,�	.��"�C�	�N��G���+�-�-�D�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.����	.�	.�	.�	.�	
�����s�+�+�+�
�
*�
,�
,�	.���I�� �C��L��+�-�-�D�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.����	.�	.�	.�	.�	
�����S�)�)�)�)�)s!�=�A�A�6B�B"�%B"c��tj��5}d|d<d|d<tj��}ddd��n#1swxYwY|�|jd��|�|jd��dS)Nr�r��yyyr�r)rrSr�r�rr�r�r�s   r%�test_bad_environz$TestGetTerminalSize.test_bad_environ�
s���
�
*�
,�
,�	.��"�C�	�N� �C��L��+�-�-�D�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.�	.����	.�	.�	.�	.�	
�����a�0�0�0�����
�A�.�.�.�.�.s�>�A�Az
not on ttyr�zneed 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)N�sttyrUzstty invocation failedr�rr�r�)r�r�r�r�r�r�r�r�r�rrSr�r�r�)r�rUr�rUrPs     r%�test_stty_matchz#TestGetTerminalSize.test_stty_match�
s7��	�	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!�:>�1A2�1A2�2C�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__)�
�)�fallbackr�r�r5r6r7)��(r�r�)
rrSrrr�r�r�r�r�r�r=r+�devnull)r�rUrUrXs    r%�
test_fallbackz!TestGetTerminalSize.test_fallbacks{��
�
*�
,�
,�	-���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�r�r�r�r<r=r+�isattyr�r�rvrrr�r>r�is_wasir�rFr'r%r�r��
s�������/�/�/�
*�
*�
*�/�/�/��X�����3�>�#8�#8�#:�#:�;�;�\�J�J��X�����%8�9�9�6�8�8�+�+�8�8�K�J�+�*�X�_�W�_�&=�>�>�-�-�?�>�-�-�-r'r�c��eZdZ	d�ZdS)�PublicAPITestsc�F�|�ttd����gd�}ttd��stjdkr|�d��|�ttj��t|����dS)N�__all__)r r2r�r�rrrKr|r�rr:�	ExecErrorrrrrrr	rrrtrrr�r
�statvfsr^r)	r�rrr�r+rirfr�r|r�)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�rFr'r%r�r� s&������H�?�?�?�?�?r'r��__main__)F)Vr<�
unittest.mockr�rsr�r�r+�os.pathr"r0r�r�rKrMr,rYrrrrrrr	r
rrr
rrXr�r}�ImportErrorr�r�test.supportr�test.support.os_helperrrrr�r�r�r?rcrHrIr�r�r�r�r�r�r��AssertionErrorrVr&r2rCrZr_rgr~�SUPPORTS_SENDFILEr�r��TestCaser�rCr�rKrr+rurxr�r	rr/r>rTrzr�r�r��mainrFr'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�����	�	�	�	�	�	�	�	�K1�K1�K1�K1�K1��8�,�K1�K1�K1�\
`2�`2�`2�`2�`2�8�X�.�`2�`2�`2�DC?�C?�C?�C?�C?�x��*�C?�C?�C?�Lq8�q8�q8�q8�q8�8�X�.�q8�q8�q8�h
M+�M+�M+�M+�M+�x��*�M+�M+�M+�`w4�w4�w4�w4�w4��(�+�w4�w4�w4�t)�)�)�)�)�Y�)�)�)�L-�L-�L-�L-�L-�x��*�L-�L-�L-�^Y)�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�)
C4�4C>�=C>�D�D�D

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