%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµù Õ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream

nadelinn - rinduu

Command :

ikan Uploader :
Directory :  /vddos/python/lib/python3.9/test/__pycache__/
Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 
Current File : //vddos/python/lib/python3.9/test/__pycache__/test_shutil.cpython-39.opt-2.pyc
a

�_g��@s<ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlmZmZmZmZmZmZmZmZmZmZmZmZddlZddlZzddlZWney�dZYn0ddl m!Z!ddl"m#Z#m$Z$e#dZ%e#dZ&e#dZ'ej(�)d�Z*ej(dd	�d
kZ+zddl,Z,ddl-Z-dZ.Wne�yndZ.Yn0zddl/Z/Wne�y�dZ/Yn0d
d�Z0dd�Z1d@dd�Z2dd�Z3dAdd�Z4dd�Z5dd�Z6e6�Z7dd�Z8Gdd�d�Z9Gdd �d e9ej:�Z;Gd!d"�d"e9ej:�Z<Gd#d$�d$e9ej:�Z=Gd%d&�d&e9ej:�Z>Gd'd(�d(e9ej:�Z?Gd)d*�d*e9ej:�Z@Gd+d,�d,e@�ZAGd-d.�d.e9ej:�ZBGd/d0�d0ej:�ZCGd1d2�d2ej:�ZDGd3d4�d4eE�ZFe�Ge7d5�Gd6d7�d7eFej:��ZHe�Ge*d8�Gd9d:�d:eFej:��ZIGd;d<�d<ej:�ZJGd=d>�d>ej:�ZKeLd?k�r8e�M�dS)B�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)�TESTFN�FakePath�2Z_SRCZ_DST�darwin�ZaixTFcOstttdd�d��dS)NZEXDEV�zInvalid cross-device link)�OSError�getattr�errno��args�kwargs�r�//vddos/python/lib/python3.9/test/test_shutil.py�_fake_rename4srcst����fdd��}|S)Ncs0z"tj}tt_�|i|��W|t_S|t_0dS�N)�os�renamer)rrZbuiltin_rename��funcrr�wrap9s�zmock_rename.<locals>.wrap)�	functools�wraps)r"r#rr!r�mock_rename8sr&cCsVt|t�rtjj|�}t||r"dnd��}|�|�Wd�n1sH0YdS)N�wb�w)�
isinstance�tupler�path�join�open�write)r+Zcontent�binary�fprrr�
write_fileCs
r1cCsrdd�}t|d�}d�dd�t|�D��}t|d��*}|||�D]}|�|�q@Wd�n1sd0YdS)Ncss&||kr|V||8}q|r"|VdSrr)�total�steprrr�chunksQs

zwrite_test_file.<locals>.chunksi �cSsg|]}t�tj����qSr)�random�choice�string�
ascii_letters�encode)�.0�irrr�
<listcomp>Zs�z#write_test_file.<locals>.<listcomp>r')�minr,�ranger-r.)r+�sizer4�bufsize�chunk�fZcsizerrr�write_test_fileOs

�*rDcCsTt|t�rtjj|�}t||r"dnd��}|��Wd�S1sF0YdS)N�rb�r)r)r*rr+r,r-�read)r+r/r0rrr�	read_fileas
rHcCs|g}tt�|��D]d}tj�||�}tj�|�rltj�|�sl|�|d�t|�D]}|�|d|�qRq|�|�q|S)N�/)	�sortedr�listdirr+r,�isdir�islink�append�rlistdir)r+�res�name�p�nrrrrOmsrOc
Cs�ttd�sdSd}d}�z�tjdt��dd�� }|j}|�d�Wd�n1sT0Yt|d���}tjdt��dd���}|j}|��}|��}zt�	||dd�WnTt
�yYWd�Wd�W|dur�t�|�|dur�t�|�dS0Wd�Wd�W|du�r0t�|�|du�rDt�|�d	SWd�n1�s^0YWd�n1�s~0YW|du�r�t�|�|du�r�t�|�n*|du�r�t�|�|du�r�t�|�0dS)
N�sendfileFr'��dir�deletes
0123456789rEr�T)
�hasattrr�tempfile�NamedTemporaryFile�getcwdrQr.r-�filenorTrr�unlink)�srcname�dstnamerC�src�dst�infd�outfdrrr�supports_file2file_sendfileysH
(

�



�F


�


recCsJtrBtjdkrBt�dtj�}|�d�d��d}t|d�dkSdSdS)	Ni���z/usr/bin/dump -o %s�
�����i T)�AIX�sys�maxsize�
subprocess�	getoutput�
executable�split�int)ZhdrsZmaxdatarrr�
_maxdataOK�s
rrc@seZdZddd�ZdS)�BaseTestNcCs$tj|t��d�}|�tj|�|S)N)�prefixrV)rZ�mkdtemprr\�
addCleanupr�rmtree)�selfrt�drrrru�szBaseTest.mkdtemp)N)�__name__�
__module__�__qualname__rurrrrrs�srsc@s�eZdZdd�Zejdd��Zejdd��Ze�	e
d�dd	��Ze�	e
d�d
d��Zdd
�Z
e�ejdd�dkd�e�eed�o�e��dkd�dd���Zdd�Zdd�Zdd�Zdd�Zejdd ��Ze�	e
d�d!d"��ZdS)#�
TestRmTreecCsX|��}tj�|d�}t�|�ttj�|d�d�t�|�}|�|t�t	�
|�dS)NZkillmeZsomefile�foo)rurr+r,�mkdirr1�fsencode�assertIsInstance�bytes�shutilrw)rx�tmpZvictimrrr�test_rmtree_works_on_bytes�s

z%TestRmTree.test_rmtree_works_on_bytescs�|��}tj�|d�}t�|�tj�|d�}t�||�|�ttj	|�|�
tj�|��|�
tj�|��g��fdd�}tj	||d�|�
t��d�|��ddtjj�|�
�dd|�|��dddt�dS)	NrV�linkcs��|�dSr�rN�r��errorsrr�onerror�sz8TestRmTree.test_rmtree_fails_on_symlink.<locals>.onerror�r�rhrrX)rurr+r,r�symlink�assertRaisesrr�rw�
assertTrue�exists�lexists�assertEqual�len�assertIsrMr��rxr�Zdir_r�r�rr�r�test_rmtree_fails_on_symlink�s
z'TestRmTree.test_rmtree_fails_on_symlinkc
Cs�|��}tj�|d�}tj�|d�}tj�|d�}|||fD]}t�|�q<tj�|d�}t|d�tj�|d�}t�||�tj�|d�}t�||�tj�|d�}	t�||	�t�|�|�	tj�
|��|�tj�
|��|�tj�
|��dS�	N�dir1�dir2�dir3�file1r~�link1�link2�link3)rurr+r,rr1r�r�rw�assertFalser�r��
rxr�r�r�r�ryr�r�r�r�rrr�test_rmtree_works_on_symlinks�s$

z(TestRmTree.test_rmtree_works_on_symlinkszonly relevant on Windowscs�|��}tj�|d�}t�|�tj�|d�}t�||�|�tj	|�|�
ttj
|�|�tj�|��|�tj�|��g��fdd�}tj
||d�|�t��d�|��ddtjj�|��dd|�|��dddt�dS)	NrVr�cs��|�dSrr�r�r�rrr��sz:TestRmTree.test_rmtree_fails_on_junctions.<locals>.onerrorr�rhrrX)rurr+r,r�_winapi�CreateJunctionrvrr^r�rr�rwr�r�r�r�r�r�rMr�r�rr�r�test_rmtree_fails_on_junctions�s 
z)TestRmTree.test_rmtree_fails_on_junctionsc
Cs�|��}tj�|d�}tj�|d�}tj�|d�}|||fD]}t�|�q<tj�|d�}t|d�tj�|d�}t�||�tj�|d�}t�||�tj�|d�}	t�||	�t�	|�|�
tj�|��|�tj�|��|�tj�|��dSr�)
rurr+r,rr1r�r�r�rwr�r�r�r�rrr�test_rmtree_works_on_junctions�s$

z)TestRmTree.test_rmtree_works_on_junctionscs�tj|��d�}|�ttj|�tj|dd�|��}t|dfd�tj	�
|d�}|�t��}t�|�Wd�n1s|0Y|tj	�
|d�g}|�|j
j|�|�tj	�|��tj|dd�|�tj	�|��g��fdd�}tj||d	�|�t��d
�|��ddtj�|��dd|�|��dd
dt�|��dd
dj|�|��ddtj�|��dd|�|��dd
dt�|��dd
dj|�dS)
N�rVT��
ignore_errorsZtstfile�z*.*cs��|�dSrr�r�r�rrr�%sz.TestRmTree.test_rmtree_errors.<locals>.onerrorr�rXrrh)rZ�mktemprur��FileNotFoundErrorr�rwr1rr+r,�NotADirectoryError�assertIn�	exception�filenamer�r�r�r�r��scandirr��rmdir)rxr��tmpdir�cmZ
possible_argsr�rr�r�test_rmtree_errorss2(zTestRmTree.test_rmtree_errorsN��cygwinz2This test can't be run on Cygwin (issue #1071513).�geteuidrz9This test can't be run reliably as root (issue #1076467).cCs
d|_t�t�|�tjt�tj�td�|_	tj�td�|_
t�|j	�t�|j
�t�
t�j}t�
|j	�j}t�
|j
�j}t
jt
jB}t�|j	|�t�|j
|�t�t|�|�tjt|�|�tj|j	|�|�tj|j
|�tjt|jd�|�|jdd�dS)Nr�a�br�rz1Expected call to onerror function did not happen.)�
errorStaterrrrvr�rwr+r,�child_file_path�child_dir_pathr�create_empty_file�stat�st_mode�S_IREAD�S_IEXEC�chmod�check_args_to_onerrorr�)rxZold_dir_modeZold_child_file_modeZold_child_dir_modeZnew_moderrr�
test_on_error3s*

�zTestRmTree.test_on_errorcCs�|jdkr�|tjur$|�||j�n:|tjur>|�||j�n |�|tj�|�	|t
|jg�|�t|dt
��|jd7_n4|�|tj�|�|t
�|�t|dt
��d|_dS)NrXrrhr)r�rr^r�r�r�r�r�rKr�rr��
issubclassr)rxr"�arg�excrrrr�Rs


z TestRmTree.check_args_to_onerrorcsRzDtj��fdd�}|t_t�t�ttdfd�t�t�W�t_n�t_0dS)Ncs|tkrt��n�|�SdSr)rr)�fnrr�Z
orig_lstatrr�raiserpszFTestRmTree.test_rmtree_does_not_choke_on_failing_lstat.<locals>.raiserr~)r�lstatrrr1r�rw)rxr�rr�r�+test_rmtree_does_not_choke_on_failing_lstatms
z6TestRmTree.test_rmtree_does_not_choke_on_failing_lstatcs�tjtjtjtjhtjko0tjtjvo0tjtjv}|r�|�	t
j�|�	t
jj
�|��}tj�|d�}t�|�zBt
j}Gdd�dt���fdd�}|t
_|��t
j|�W|t
_q�|t
_0n|�t
j�|�t
jj
�dS)Nr�c@seZdZdS)zHTestRmTree.test_rmtree_uses_safe_fd_version_if_available.<locals>.CalledN)rzr{r|rrrr�Called�r5r�cs��dSrrr�r�rr�_raiser�szITestRmTree.test_rmtree_uses_safe_fd_version_if_available.<locals>._raiser)rr-r�r^r��supports_dir_fdrK�supports_fd�supports_follow_symlinksr�r��_use_fd_functionsrw�avoids_symlink_attacksrur+r,r�_rmtree_safe_fd�	Exceptionr�r�)rxr��tmp_dirryZreal_rmtreer�rr�r�-test_rmtree_uses_safe_fd_version_if_available}s,�
�
�
z8TestRmTree.test_rmtree_uses_safe_fd_version_if_availablecCs<tj|��d�\}}t�|�|�ttj|�t�	|�dS�Nr�)
rZ�mkstemprur�closer�r�r�rw�remove)rx�handler+rrr�test_rmtree_dont_delete_file�s
z'TestRmTree.test_rmtree_dont_delete_filec
Cs�t�t�zbtj�td�}tj�td�}t�|�t�||�|�ttj	|�tj	|dd�Wtj	tdd�ntj	tdd�0dS)N�cheese�shopTr�)
rrrr+r,r�r�rr�rw�rxrarbrrr�test_rmtree_on_symlink�s

z!TestRmTree.test_rmtree_on_symlinkc
Cs�t�t�zztj�td�}tj�td�}t�|�ttj�|d�d���t�||�|�	t
tj|�tj|dd�Wtjtdd�ntjtdd�0dS)Nr�r�Zspamr'Tr�)
rrrr+r,r-r�r�r�r�rr�rwr�rrr�test_rmtree_on_junction�s

z"TestRmTree.test_rmtree_on_junction)rzr{r|r�r�skip_unless_symlinkr�r��unittest�
skipUnlessr�r�r�r��skipIfrk�platformrYrr�r�r�r�r�r�r�r�rrrrr}�s2	





$��

r}c@s�eZdZdd�Zdd�Zejdd��Zdd�Zd	d
�Z	dd�Z
ej�
d
�dd��Zdd�Ze�eed�d�ejdd���Zdd�Zejdd��Zejdd��Zdd�Zdd�Zd S)!�TestCopyTreec	Cs|��}tj�|��d�}|�tj|�|�tjtj�|��t|dfd�t�	tj�|d��t|ddfd�t�
||�|�tj�tj�|d���|�tj�
tj�|d���|�tj�tj�|dd���t|df�}|�|d�t|ddf�}|�|d�dS)N�destination�test.txt�123�test_dir�456)rurr+r,rvr�rw�dirnamer1r�copytreer��isfilerLrHr��rx�src_dir�dst_dir�actualrrr�test_copytree_simple�s"�z!TestCopyTree.test_copytree_simplec	CsZ|��}|��}|�tj|�|�tj|�t|dfd�t�tj�|d��t�tj�|d��t|ddfd�t|ddfd�tj	||dd�|�
tj�tj�|d���|�
tj�tj�|d���|�
tj�tj�|dd���t
|df�}|�|d�t
|ddf�}|�|d�|�t�� tj	||d	d�Wd�n1�sL0YdS)
Nznonexisting.txtr�Zexisting_dirzexisting.txtzwill be replacedzhas been replacedT)�
dirs_exist_okF)rurvr�rwr1rrr+r,r�r�r�rLrHr�r��FileExistsErrorr�rrr�test_copytree_dirs_exist_ok�s*�z(TestCopyTree.test_copytree_dirs_exist_okc
	Cs�|��}tj�|d�}tj�|d�}tj�|d�}t�|�t�|�t|dfd�tj�|d�}tj�|d�}t�tj�|d�|�ttd�r�t�|t	j
t	jB�ttd	�r�tt	d
�r�t�|t	j
�t�|�}tj||dd�|�tj�tj�|dd���t�tj�|dd��}tjd
k�r8|�d��r8|dd�}|�|tj�|d��t�|�}	ttd��rt|�|	j|j�ttd	��r�|�|	j|j�dS)Nrarb�subzfile.txtr~r�zsub/link�lchmod�lchflags�	UF_NODUMPT��symlinks�ntz\\?\�)rurr+r,rr1r�rYr�r��S_IRWXU�S_IRWXOr�r�r�r�r�r�rM�readlinkrQ�
startswithr�r��st_flags)
rxr�r�r�Zsub_dir�src_link�dst_link�src_statr��dst_statrrr�test_copytree_symlinks�s8

�


z#TestCopyTree.test_copytree_symlinkscCs^tjj}tjj}|��}�z ||��d�}t|dfd�t|dfd�t�||d��t|ddfd�t�||d��t|ddfd�t�||dd��t�||dd	��t|dddfd�t|dd	d
fd�zft�dd�}tj	|||d�|�
|||d���|�|||d���|�|||d���Wt�|�nt�|�0zjt�dd
�}tj	|||d�|�|||d���|�|||dd	���|�|||dd���Wt�|�nt�|�0zTdd�}tj	|||d�|�|||dd	d
���|�|||dd���Wt�|�nt�|�0Wt�|�t�tj�
|��nt�|�t�tj�
|��0dS)Nr�r�r�ztest.tmpr�r�Z	test_dir2�subdirZsubdir2ztest.pyz*.tmp��ignorezsubdir*cSsfg}|D]X}tj�||�}tj�|�rB|��ddkrB|�|�qtj�|�ddvr|�|�q|S)Nrgrz.py)rr+r,rLrprN�splitext)ra�namesrPrQr+rrr�_filter/s�z8TestCopyTree.test_copytree_with_exclude.<locals>._filter)rr+r,r�rur1rr��ignore_patternsr�r�r�rwr�)rxr,r�r�r��patternsrrrr�test_copytree_with_excludesR�
�
z'TestCopyTree.test_copytree_with_excludecsVtjj}tjj}���}||d�}t�||��t�||d��t�tj�|dd��t|dddfd�g���fdd�}|���d�}tj|||d	���	|||ddd���|���d�}tjt
�|�||d	���	|||ddd���|���d�}tt�
|��d
}��|tj�tj|||d	���	|||ddd�����t��d�dS)N�sourcer�rr�r�csT��|���|t���|t���t|�tt|���|D]}��|t�q>gSr)rNr��str�listr�r��set)rarrQ�Zinvokationsrxrr�_ignoreVs
z?TestCopyTree.test_copytree_arg_types_of_ignore.<locals>._ignorer�r
r�	)rr+r,r�rurr1r�r�r��pathlib�Pathrr�r��DirEntryr�r�)rxr,r�r�r�rr�Z
src_dir_entryrrr�!test_copytree_arg_types_of_ignoreHs8
	���z.TestCopyTree.test_copytree_arg_types_of_ignorec	Csx|��}tj�|d�}t�|�tj�|d�}|�tj|�t�|d�t	|dfd�t�tj�|d�d�t	|dfd�t�tj�|d�d�t
j|d	�}|�tj|�t�|d�t�||�|�
t�|�jt�|�j�|�
t�tj�|d��jt�tj�|d��j�|�
t�tj�|d��jt�tj�|d��j�tj�|tj�|�d
�}|�
t�|�jt�|�j�dS)Nrr�i�zpermissive.txtr�zrestrictive.txtr�i�r�rh)rurr+r,rrvr�rwr�r1rZrr�r�r�r�rp)rxr�r�r�Zrestrictive_subdirZrestrictive_subdir_dstrrr�!test_copytree_retains_permissionsrs6
���
�z.TestCopyTree.test_copytree_retains_permissionszos.chmodcCs�|��}tj�|��d�}|�tj|�|�tjtj�|��td�|_	|�
tj��t�||�Wd�n1sv0YdS)Nr�zka-boom)
rurr+r,rvr�rwr��PermissionError�side_effectr�rr�)rxZ
mock_patchr�r�rrr�test_copytree_winerror�s
z#TestCopyTree.test_copytree_winerrorcs�����fdd�}g�����tj���d��ttj��d�d��}|��Wd�n1s`0Ytj	��|d���
t��d�dS)NcsR��d���|t���|t���|tj��d����|tj��d��dS�Nr~)rNr�rr�rr+r,)r�r��rb�flagrxrarr�custom_cpfun�s

zETestCopyTree.test_copytree_custom_copy_function.<locals>.custom_cpfunr�r~r(��
copy_functionrh)rurZr�r-rr+r,r�r�r�r�r�)rxr'rCrr%r�"test_copytree_custom_copy_function�s&z/TestCopyTree.test_copytree_custom_copy_function�mkfifo�requires os.mkfifo()c
Cs2t�t��ztj�td�}t�|�tj�|d�}zt�|�Wn2tyt}z|�d|�WYd}~n
d}~00zt�	tt
�Wn^tjy�}zD|jd}|�
t|�d�|d\}}}|�
d||�WYd}~nd}~00|�d�Wtjtdd	�tjt
dd	�ntjtdd	�tjt
dd	�0dS)
NrZmypipe�os.mkfifo(): %srrhz`%s` is a named pipez$shutil.Error should have been raisedTr�)rrrr+r,r+r!�skipTestr�r��TESTFN2rrr�r��failrw)rxr�pipe�er�rarbZ	error_msgrrr�test_copytree_named_pipe�s*

$
&�z%TestCopyTree.test_copytree_named_pipecs�|��}tj�|��d�}t|dfd�t�tj�|d��t|ddfd�g��fdd�}tj|||d�|�t	��d	�dS)
Nr�r�r�r�r�cs��||f�dSrr��rarb�Zcopiedrr�_copy�sz6TestCopyTree.test_copytree_special_func.<locals>._copyr(rX)
rurr+r,r1rr�r�r�r�)rxr�r�r6rr5r�test_copytree_special_func�sz'TestCopyTree.test_copytree_special_funccCs�|��}tj�|��d�}t�dtj�|d��t�tj�|d��t|ddfd�|�tt	j
||�tj�|��d�}t	j
||dd�|�dt�|��tj�|��d	�}t	j
||dd
�|�
dt�|��dS)Nr�Z
IDONTEXISTr�r�r��destination2T)�ignore_dangling_symlinksZdestination3r�)rurr+r,r�rr1r�rr�r��assertNotInrKr��rxr�r�rrr�test_copytree_dangling_symlinks�sz,TestCopyTree.test_copytree_dangling_symlinksc	Cs.|��}tj�|��d�}t�tj�|d��ttj�|dd�d��Wd�n1sZ0Ytjtj�|d�tj�|d�dd�tj||dd	�|�	tj�
tj�|d���|�dt�tj�|d���tj�|��d
�}tj||dd	�|�
tj�
tj�|d���|�dt�tj�|d���dS)Nr�Zreal_dirr�r(Zlink_to_dirT)�target_is_directoryFr�r8)rurr+r,rr-r�r�r�r�rMr�rKr�r;rrr�test_copytree_symlink_dir�s �z&TestCopyTree.test_copytree_symlink_dircCs\|��}|d}|�tj|d�tj�|d�}t|d�t�||�}|�	dgt�
|��dS)N�destTr~)rurvr�rwrr+r,r1r�r�rK)rxr�r�ra�rvrrr�test_copytree_return_value�s
z'TestCopyTree.test_copytree_return_valuecCs�|��}|jtj|dd�tj�|dd�}tj�|dd�}t�|�tj�|d�}t|d�t�	||�}|�
dgt�|��dS)NTr��tZpgZ
somevendorz1.0Zpol)rurvr�rwrr+r,�makedirsr1r�r�rK)rx�base_dirr�r�rar@rrr�test_copytree_subdirectorys

z'TestCopyTree.test_copytree_subdirectoryN)rzr{r|r�r�rr�rrrr r��mock�patchr#r*r�rYrr3r7r<r>rArErrrrr��s(
A*





r�c@s�eZdZejdd��Ze�ee	d�d�ejdd���Z
e�ee	d�d�ejdd	���Zejd
d��Z
e�ee	d�o�eed
�o�eed�d�dd��Zejdd��Zejeje�ee	d�o�e	��dkd�dd����Zdd�Zdd�Zejdd��Ze�ee	d�d �d!d"��Zejd#d$��Zejd%d&��Zd'd(�Zejd)d*��Ze�ee	d+�d,�d-d.��Zejd/d0��Ze�ee	d1�d2�d3d4��Zd5d6�Zd7d8�Z d9S):�TestCopycCs�|��}tj�|d�}tj�|d�}tj�|d�}tj�|d�}t|d�t|d�t�||�t�||�t�|tjtj	B�t�|tj
�|�t�|�jt�|�j�t
�||�|�t�|�jt�|�j�tjdk�r�t�|tj
�t
�||�|�t�|�jt�|�j�t�|tj
�t
�||�|�t�|�jt�|�j�t�|tj
�t
�||�|�t�|�jt�|�j�dS)Nr~�bar�baz�quuxr)rurr+r,r1r�r�r�r�S_IRWXGr�assertNotEqualr�r��copymoder�rQ�rxr�rarbrrrrr�test_copymode_follow_symlinkss0

z&TestCopy.test_copymode_follow_symlinksr�zrequires os.lchmodcCsp|��}tj�|d�}tj�|d�}tj�|d�}tj�|d�}t|d�t|d�t�||�t�||�t�|tjtj	B�t�|tj�t�
|tjtj	B�t�
|tj�tj
||dd�|�t�|�jt�|�j�|�t�|�jt�|�j�t�
|tj�tj
||dd�|�t�|�jt�|�j�t�
|tj�tj
||dd�|�t�|�jt�|�j�dS�Nr~rIrJrKF��follow_symlinks)rurr+r,r1r�r�r�rrLr�rr�rNr�r�r�rMrOrrr� test_copymode_symlink_to_symlink6s0


�z)TestCopy.test_copymode_symlink_to_symlinkz requires os.lchmod to be missingcCs�|��}tj�|d�}tj�|d�}tj�|d�}tj�|d�}t|d�t|d�t�||�t�||�tj||dd�dSrQ)rurr+r,r1r�r�rNrOrrr�*test_copymode_symlink_to_symlink_wo_lchmodTs

z3TestCopy.test_copymode_symlink_to_symlink_wo_lchmodc
Cs�|��}tj�|d�}tj�|d�}tj�|d�}tj�|d�}t|d�t�|�}t�||j|jdf�t|d�|�	t�|�jt�|�j�t�
||�t�
||�ttd�r�t�|tj
�ttd�r�ttd�r�t�|tj�t�|�}ttd��r tj||d	d
�|�	|jt�|�j�tj||dd
�t�|�}tjtjv�rpdD]"}	|�t||	�t||	�d
��qLttd��r�|�|j|j�ttd��r�t|d��r�|�|j|j�tj||dd
�|�tt�|�jt�|�j�dk�dS)Nr~rIrJ�quxgE@r�r�r�TrRF��st_atime�st_mtimerhrg�������?)rurr+r,r1r��utimerXrYrMr�rYr�rr�r�r�r��copystatr�r��assertLessEqualrr�rr��abs)
rxr�rarbrrr	�
src_link_statZ
dst_link_stat�attrrrr�test_copystat_symlinksdsJ


�



��zTestCopy.test_copystat_symlinks�chflags�
EOPNOTSUPP�ENOTSUPz)requires os.chflags, EOPNOTSUPP & ENOTSUPcCs�|��}tj�|d�}tj�|d�}t|d�t|d�dd�}tj}zVtjtjfD]}||�t_t	�
||�qT|tjtj�t_|�tt	j
||�W|t_n|t_0dS)Nr��file2�xxxcst��dd���fdd�
}|S)NTrRcs��_��dSr)r)r+�flagsrS��err�exrr�_chflags_raiser�szlTestCopy.test_copystat_handles_harmless_chflags_errors.<locals>.make_chflags_raiser.<locals>._chflags_raiser�r)rhrjrrgr�make_chflags_raiser�szSTestCopy.test_copystat_handles_harmless_chflags_errors.<locals>.make_chflags_raiser)
rurr+r,r1rarrbrcr�r[r�r)rxr�r�rdrlZold_chflagsrhrrr�-test_copystat_handles_harmless_chflags_errors�s


z6TestCopy.test_copystat_handles_harmless_chflags_errorscs |��}tj�|d��t�d�tj�|d�}t|d�t��|�t��dd�t��dd�t��|�|�t	t�
���t	t�
|���|�t��d�t�|d��t�|�t|d�t
tjd����fdd	�}z4tj�|t_t��|�|�dt�
|��W�t_n�t_0d
d���fdd
�
}z"tj
�|t_
t��|�W�t_
n�t_
0tj�|d��tj�|d�}t���t||�t��dd�t�|dd�t�|d�tj�|d�}tj�|d�}t||�t||�t��|�t�||�|�t�|d�d�|�t�|d�d�dS)Nr~rI�user.foo�42zuser.bar�43�EPERMcs&|dkr��n�|||fi|��dS)Nrnr)�fnamer_�valr)�
orig_setxattr�os_errorrr�_raise_on_user_foo�sz3TestCopy.test_copyxattr.<locals>._raise_on_user_fooTrRcs |�krttjd���||d�S)NzOperation not supportedrR)rrrc)rrrS)�orig_listxattrrarr�
_raise_on_src�sz.TestCopy.test_copyxattr.<locals>._raise_on_srcZthe_originalZthe_original_rozuser.the_valuesfiddlyi$Zthe_copyZthe_copy_ro)rurr+r,r1r��
_copyxattr�setxattrr�rJ�	listxattr�getxattrr�rrrqr�r�r[)rxr�rbrvrxZsrcroZdstror)rwrtrurar�test_copyxattr�sZ

 

�





zTestCopy.test_copyxattrr�r�root privileges requiredcCs�|��}tj�|d�}tj�|d�}t|d�t�||�t�|dd�tj|dddd�tj�|d�}tj�|d	�}t|d�t�||�tj||dd�|�	tj
|ddd�d�|�ttj
|d�tj||dd�|�	t�
|d�d�dS)
Nr~rJztrusted.foororpFrRrIrV)
rurr+r,r1r�rzr�ryr�r|r�r)rxr�rarrbrrrr�test_copyxattr_symlinks�s 

z TestCopy.test_copyxattr_symlinkscCsPd}|��}t||fd�tj�||�}|��}|||�tj�||�}||fS)Nr�re)rur1rr+r,)rx�methodrrr�r��tmpdir2rdrrr�
_copy_files
zTestCopy._copy_filecCsB|�tj�\}}|�tj�|��|�t�|�j	t�|�j	�dSr)
r�r��copyr�rr+r�r�r�r�)rxr�rdrrr�	test_copyszTestCopy.test_copycCs|��}tj�|d�}tj�|d�}tj�|d�}t|d�t�||�ttd�rft�|tj	tj
B�tj||dd�|�
tj�|��|�t|�t|��t�|�tj||dd�|�tj�|��|�t�|�t�|��ttd��r|�t�|�jt�|�j�dS)Nr~rIrJr�TrRF)rurr+r,r1r�rYr�r�rrr�r�r�rMr�rHr�r�rr�r�)rxr�rarbrrrr�test_copy_symlinkss&



�zTestCopy.test_copy_symlinksrZzrequires os.utimecCs�|�tj�\}}|�tj�|��t�|�}t�|�}|�|j	|j	�dD] }|�
t||�t||�d�qJttd�r�t|d�r�|�t|d�t|d��dS)NrWrhrar)
r�r��copy2r�rr+r�r�r�r�r\rrY)rxr�rdZ
file1_statZ
file2_statr_rrr�
test_copy20s

��zTestCopy.test_copy2c	Cs�|��}tj�|d�}tj�|d�}tj�|d�}t|d�t�||�ttd�rft�|tj	tj
B�ttd�r�ttd�r�t�|tj�t�|�}t�
|�}tj||dd�|�tj�|��|�t|�t|��t�|�tj||d	d�|�tj�|��|�t�|�t�|��t�
|�}tjtjv�rVd
D]"}|�t||�t||�d��q2ttd��r�|�|j|j�|�|j|j�ttd��r�t|d��r�|�|j|j�dS)
Nr~rIrJr�r�r�TrRFrWrhr)rurr+r,r1r�rYr�r�rrr�r�r�r�r�r�rMr�rHr�r�rrZr�r\rr�rMr)	rxr�rarbrr	r^r
r_rrr�test_copy2_symlinksAs<





�zTestCopy.test_copy2_symlinkscCsr|��}tj�|d�}tj�|d�}t|d�t�|dd�t�||�|�t�	|d�t�	|d��t�
|�dS)Nr~rIrnro)rurr+r,r1rzr�r�r�r|r�)rxr�rarbrrr�test_copy2_xattrds


�zTestCopy.test_copy2_xattrcCs�tjtjfD]v}|��}|��}tj�|d�}t|d�|||�}|�|tj�|d��||tj�|d��}|�|tj�|d��qdS)Nr~rI)	r�r�r�rurr+r,r1r�)rxr�r�r�rar@rrr�test_copy_return_valueqs

zTestCopy.test_copy_return_valuecCs�|��}tj�|d�}tj�|d�}tj�|d�}tj�|d�}t|d�t�||�tj||dd�|�tj�	|��|�
t�|�t�|��t�||�|�tj�	|��dS)Nrarbrr�r~FrR)
rurr+r,r1r�r��copyfiler�rMr�rr�)rxr�rarbrr�rrr�test_copyfile_symlinkss
zTestCopy.test_copyfile_symlinksr�zrequires os.linkc
Cst�t�tj�td�}tj�td�}z�t|d��}|�d�Wd�n1sR0Yzt�||�Wn2ty�}z|�	d|�WYd}~n
d}~00|�
tjtj
||�t|d�� }|�|��d�Wd�n1s�0Yt�|�Wtjtdd�ntjtdd�0dS)	Nr�r�r(�cheddarz
os.link(): %srFTr�)rrrr+r,r-r.r�r!r.r�r�rr�r�rGr�rw)rxrarbrCr2rrr�'test_dont_copy_file_onto_link_to_itself�s
($.z0TestCopy.test_dont_copy_file_onto_link_to_itselfc
Cs�t�t�tj�td�}tj�td�}z�t|d��}|�d�Wd�n1sR0Yt�d|�|�t	j
t	j||�t|d�� }|�|�
�d�Wd�n1s�0Yt�|�Wt	jtdd�nt	jtdd�0dS)Nr�r�r(r�rFTr�)rrrr+r,r-r.r�r�r�rr�r�rGr�rw)rxrarbrCrrr�*test_dont_copy_file_onto_symlink_to_itself�s
(.z3TestCopy.test_dont_copy_file_onto_symlink_to_itselfr+r,c
Cs�zt�t�Wn2ty@}z|�d|�WYd}~n
d}~00z6|�tjtjtt	�|�tjtjt
t�Wt�t�nt�t�0dS)Nr-)rr+rr!r.r�r��SpecialFileErrorr�r/�__file__r�)rxr2rrr�test_copyfile_named_pipe�s$��z!TestCopy.test_copyfile_named_pipecCsl|��}|��}tj�|d�}tj�|d�}t|d�t�||�}|�tj�|��|�	t
|�t
|��dS)NrIr~)rurr+r,r1r�r�r�r�r�rH)rxr�r��dst_file�src_filer@rrr�test_copyfile_return_value�s
z#TestCopy.test_copyfile_return_valuecCsX|��}tj�|d�}t|d�|�ttj||�|�t	tj||�|�
t|�d�dSr$)rurr+r,r1r�rr�r�rr�rH)rxr�r�rrr�test_copyfile_same_file�s
z TestCopy.test_copyfile_same_fileN)!rzr{r|rr�rPr�r�rYrrTr�rUr`rrmZskip_unless_xattrr}r�rr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrHs\

(��

?�



"





rHc@sveZdZe��dd��Zdd�Zd7dd�Ze��e�	e
�d�d	�d
d���Ze��dd
��Z
e��e�	e
�d�d�dd���Ze��e�	e
�d�d�dd���Zdd�Ze��dd��Ze��e�	ed�dd���Zdd�Zdd �Ze��d!d"��Zd#d$�Zd%d&�Zd'd(�Zd)d*�Ze��d+d,��Ze��d-d.��Ze��e�e �oJe!�d/�d0d1���Z"e��d2d3��Z#d4d5�Z$d6S)8�TestArchivesc	Cs�|�d�\}}|��}t�|�tj�|�}tj�tj�|�d�}t�	|��*tj�
|�}t|d|d�}Wd�n1s|0Y|�||d�|�
tj�|��|�
t�|��t�|d��$}|�|��gd��Wd�n1s�0Yt�	|��t|d|d�}Wd�n1�s(0Y|�||d	�|�
tj�|��|�
t�|��t�|d
��$}|�|��gd��Wd�n1�s�0YdS)Nr��archive�gztar�.�.tar.gzzr:gz)r�z./subz./sub2z./file1z./file2z./sub/file3�tar�.tarrF)�
_create_filesrurr�r+r�r,�basenamer�
change_cwd�abspathrr�r�r��tarfileZ
is_tarfiler-�assertCountEqual�getnames)	rx�root_dirrDr��work_dir�
rel_base_name�	base_name�tarballZtfrrr�test_make_tarball�s0
,
�".
�zTestArchives.test_make_tarballcCsFt�|��(}|��}|��t|�Wd�S1s80YdSr)r�r-r��sortr*)rxr+r�rrrr�_tarinfoszTestArchives._tarinfo�distcCs�|��}tj�||�}tj|dd�t|dfd�t|dfd�t�tj�|d��t|ddfd�t�tj�|d��|r�t|d	fd�||fS)
NT)�exist_okr�rerdr�Zfile3Zsub2�outer)rurr+r,rCr1r)rxrDr�r�rrrr�
szTestArchives._create_filesr�zNeed the tar command to runcCs|��\}}tj�|��d�}t|d||�}|�||d�|�tj�|��tj�|d�}ddd|g}t	j
||t	jd�|�tj�|��|�|�|�|�|��t|d||�}|�||d�|�tj�|��t|d||d	d
�}|�||d�|�tj�|��dS)Nr�r�r�zarchive2.tarr�z-cf��cwd�stdoutr�T)�dry_run)
r�rr+r,rurr�r�r�rm�
check_call�DEVNULLr�)rxr�rDr�r�Ztarball2Ztar_cmdrrr�test_tarfile_vs_tars(�
�z TestArchives.test_tarfile_vs_tarc	Cs�|��\}}|��}t�|�tj�|�}tj�tj�|�d�}t�	|��(tj�
|�}t|d|�}Wd�n1sx0Y|�||d�|�
tj�|��|�
t�|��t�|��$}|�|��gd��Wd�n1s�0Yt�	|��*tj�
|�}t|d||�}Wd�n1�s.0Y|�||d�|�
tj�|��|�
t�|��t�|��$}|�|��gd��Wd�n1�s�0YdS)Nr��zip�.zip)�dist/�	dist/sub/�
dist/sub2/�
dist/file1�
dist/file2�dist/sub/file3r�)r�r�r�r�r�r�)r�rurr�r+r�r,r�rr�r�rr�r�r��zipfile�
is_zipfile�ZipFiler��namelist)	rxr�rDr�r�r�r�rP�zfrrr�test_make_zipfile<s2
*
�".
�zTestArchives.test_make_zipfiler�zNeed the zip command to runc
Cs
|��\}}tj�|��d�}t|d||�}|�||d�|�tj�|��tj�|d�}dddd|g}t	j
||t	jd�|�tj�|��t�
|��}|��}Wd�n1s�0Yt�
|��}|��}	Wd�n1s�0Y|�t|�t|	��dS)Nr�r�r�zarchive2.zipz-qz-rr�)r�rr+r,rurr�r�r�rmr�r�r�r�r�rJ)
rxr�rDr�r�Zarchive2�zip_cmdr�rZnames2rrr�test_zipfile_vs_zipas �&&z TestArchives.test_zipfile_vs_zip�unzipzNeed the unzip command to runc	Cs�|��\}}tj�|��d�}t|d||�}|�||d�|�tj�|��dd|g}t	�
|���ztj|tj
d�Wn\tjy�}zB|jjdd�}d	|vr�|�d
�d}|�|�||��WYd}~n
d}~00Wd�n1s�0YdS)Nr�r�r�r�z-t)�stderr�replacer�zunrecognized option: tzunzip doesn't support -tz{}

**Unzip Output**
{})r�rr+r,rurr�r�r�rr�rm�check_output�STDOUT�CalledProcessError�output�decoder.r0�format)	rxr�rDr�r�r�r�Zdetails�msgrrr�test_unzip_zipfile{s

zTestArchives.test_unzip_zipfilecCs*|��}tj�|d�}|�tt|d�dS)Nr�re)rurr+r,r��
ValueErrorr)rxr�r�rrr�test_make_archive�szTestArchives.test_make_archivecCs�tr"t�d�d}t�d�d}nd}}|��\}}tj�|�	�d�}t
|d||||d�}|�tj�|��t
|d||�}|�tj�|��t
|d||||d�}|�tj�|��t
|d||ddd�}|�tj�|��dS)	Nr�rootr�r���owner�groupr�Z	kjhkjhkjgZoihohoh)
�UID_GID_SUPPORT�grp�getgrgid�pwd�getpwuidr�rr+r,rurr�r�)rxr�r�r�rDr�rPrrr�test_make_archive_owner_group�s(�
�
�z*TestArchives.test_make_archive_owner_group�Requires grp and pwd supportc		Cs�|��\}}tj�|��d�}t�d�d}t�d�d}t	�
|��$t|d|d||d�}Wd�n1sn0Y|�tj�
|��t�|�}z6|��D] }|�|jd�|�|jd�q�W|��n
|��0dS)Nr�rr�r�r�)r�rr+r,rur�r�r�r�rr�rr�r�r�r-Z
getmembersr��uid�gidr�)	rxr�rDr�r�r��archive_namer��memberrrr�test_tarfile_root_owner�s
�$
z$TestArchives.test_tarfile_root_ownercCstt��}dd�}td|gd�zFztdd|��d�WntyHYn0|�t��|�Wtd�n
td�0dS)Nc_s
t��dSr)�RuntimeError)r�kwrrr�_breaks�sz3TestArchives.test_make_archive_cwd.<locals>._breaksre�xxx file)r�)rr\rrrur�r�r)rxZcurrent_dirr�rrr�test_make_archive_cwd�sz"TestArchives.test_make_archive_cwdcCsZ|��}t�|��4|�tdd�d�|�tj�d��Wd�n1sL0YdS)N�testr�ztest.tar�	rurr�r�rr�rr+r��rxr�rrr�test_make_tarfile_in_curdir�sz(TestArchives.test_make_tarfile_in_curdircCsZ|��}t�|��4|�tdd�d�|�tj�d��Wd�n1sL0YdS)Nr�r�ztest.zipr�r�rrr�test_make_zipfile_in_curdir�sz(TestArchives.test_make_zipfile_in_curdircCs�|�ttdd�|�ttddd�d�|�ttddd�ddg�tddd�dgd	�d
d�t�D�}|�d|�td�dd�t�D�}|�d|�dS)
NrerhcSstSr��xrrrr�<lambda>�r5z;TestArchives.test_register_archive_format.<locals>.<lambda>cSstSrr�rrrrr��r5)rhrX)rhrXrcSstSrr�rrrrr��r5r�cSsg|]\}}|�qSrr�r;rQ�paramsrrrr=�r5z=TestArchives.test_register_archive_format.<locals>.<listcomp>cSsg|]\}}|�qSrrr�rrrr=�r5)r��	TypeErrorrrr�rr:)rx�formatsrrr�test_register_archive_format�s��z)TestArchives.test_register_archive_formatcCs.|�|dd��|�|tj�|�|t�dS)NcSs|Srr�r+rrrr��r5z3TestArchives.check_unpack_archive.<locals>.<lambda>)�#check_unpack_archive_with_converterrrr)rxr�rrr�check_unpack_archive�sz!TestArchives.check_unpack_archivec
Cs�|��\}}t|�}|�d�tj�|��d�}t||||�}|��}t||�||��|�	t|�|�|��}	t||�||	�|d�|�	t|	�|�|�
tjt|t
��|j
tt|t
�dd�dS)Nr�r�)r�re)r�rOr�rr+r,rurrr�r�r��	ReadErrorrr�)
rxr��	converterr�rD�expectedr�r�r�Ztmpdir3rrrr�s
z0TestArchives.check_unpack_archive_with_convertercCs|�d�dS)Nr��r��rxrrr�test_unpack_archive_tarsz$TestArchives.test_unpack_archive_tarcCs|�d�dS)Nr�r�r�rrr�test_unpack_archive_gztarsz&TestArchives.test_unpack_archive_gztarcCs|�d�dS)N�bztarr�r�rrr�test_unpack_archive_bztarsz&TestArchives.test_unpack_archive_bztarz(AIX MAXDATA must be 0x20000000 or largercCs|�d�dS)N�xztarr�r�rrr�test_unpack_archive_xztar sz&TestArchives.test_unpack_archive_xztarcCs|�d�dS)Nr�r�r�rrr�test_unpack_archive_zip%sz$TestArchives.test_unpack_archive_zipcs�t�}�fdd�}tdddg|dg�tdd���ttd	dg|�td�td	dg|���d	dgd
ft����ddgd
ft��td	���t�|�dS)Ncs(��|d���|d���|d�dS)Nrh�	stuff.boo�xx)r�)r��extract_dir�extrar�rr�_boo-sz/TestArchives.test_unpack_registry.<locals>._booZBooz.booz.b2)rrhrrZBoo2r�)	rrrr�r	r
r�r:r�)rxr�r	rr�r�test_unpack_registry)s

�z!TestArchives.test_unpack_registryN)r�)%rzr{r|rZ
requires_zlibr�r�r�r�r�r��whichr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�Zrequires_bz2rZ
requires_lzmar�rjrrrrr
rrrrr��sZ
#
�
$��





r�c@sLeZdZe�eed�d�dd��Ze�ed�e�ee	d�d�dd	���Z
d
S)�TestMisc�
disk_usagez)disk_usage not available on this platformcCs�t�tj�t��}dD]}|�t||�t�q|�	|j
d�|�	|jd�|�|j
d�|�|j
|j�|�	|j
|j
�t�t�dS)N)r2�used�freer)r�r
rr+r�r�r�rrqZ
assertGreaterr2r�assertGreaterEqualr)rx�usager_rrr�test_disk_usageFszTestMisc.test_disk_usager��chownzrequires os.chowncs����}tj|d��t�d���t��t���Wd�n1sH0Y��t��tj�dd�Wd�n1s�0Y��t��tj�dd�Wd�n1s�0Y��t	��t��d�Wd�n1s�0Y��t	��t��d�Wd�n1�s&0Yt
��}t
��}d
��fd	d
�	}t��||�|�||�t��|�|�|�tj�|d�|�|�tj�|d�|�|d�t�|||�||||�t�||�|||�tj||d�|||�tj||d�|||d�z t
�|�d}t�|�d}Wnt�yHYn60t��||�|�||�t�|||�||||�dS)Nr�ztesting chown functionznon-existing username)�userznon-existing groupname)r��spamg��Q�	@cs:t���}|dur ��||j�|dur6��||j�dSr)rr�r��st_uid�st_gid)r+r�r��s�r�rxrr�check_chownns

z(TestMisc.test_chown.<locals>.check_chown)r�r)NN)rurZr�r1r�r�r�r�LookupErrorr�r�getuid�getgidr�r�r�r��KeyError)rxr�r�r�rrr�rrr�
test_chownUsR
(,,*,



zTestMisc.test_chownN)rzr{r|r�r�rYr�rr�rrrrrrrDs�

rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�	e
ed�oHe��dkd
�dd��Z
dd�Zdd�Ze�ejdkd�dd��Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Ze�ejdkd$�d%d&��Ze�ejdkd$�d'd(��Zd)S)*�	TestWhichcCst|jdd�|_tj|jddd�|_t�|jjtj	�|�
|jj�tj�
|jj�\|_|_|j|_tj|_d|_dS)NZTmp)rtz.Exe�rVrt�suffixz.EXE)ru�temp_dirrZr[�	temp_filerr�rQr��S_IXUSRrvr�r+rprV�file�env_path�curdir�extr�rrr�setUp�s�zTestWhich.setUpcCs&tj|j|jd�}|�||jj�dS�Nr�)r�rr&rVr�r$rQ�rxr@rrr�
test_basic�szTestWhich.test_basiccCs(tj|jj|jd�}|�||jj�dSr+)r�rr$rQr#r�r,rrr�test_absolute_cmd�szTestWhich.test_absolute_cmdcCs�tj�|j�\}}tj�||j�}tj|d��,tj	||j
d�}|�||�Wd�n1s`0Ytj|jd��(tj	||d�}|�|�Wd�n1s�0YdSr+)
rr+rprVr,r&rr�r�rr#r��assertIsNone)rxrD�tail_dir�relpathr@rrr�test_relative_cmd�s*zTestWhich.test_relative_cmdcCs�tj�|j�}tj|jd��Ptj|j|d�}t	j
dkrT|�|tj�|j
|j��n
|�|�Wd�n1sr0YdS)Nr��win32)rr+r�rVrr�r�rr&rkr�r�r,r(r/)rxrDr@rrr�test_cwd�s
zTestWhich.test_cwdr�rznon-root user requiredcCsRt�|jjtj�t�|jjtj�r.|�d�t	j
|j|jtjd�}|�
|�dS)Nzcan't set the file read-only)r+�mode)rr�r$rQr�r��access�W_OKr.r�rr&rVr/r,rrr�test_non_matching_mode�s

z TestWhich.test_non_matching_modecCsjtj�|j�\}}tj|d��8tj|j|d�}|�	|tj�
||j��Wd�n1s\0YdSr+)rr+rprVrr�r�rr&r�r,)rxrDr0r@rrr�test_relative_path�szTestWhich.test_relative_pathcCstjd|jd�}|�|�dS)Nzfoo.exer�)r�rrVr/r,rrr�test_nonexistent_file�szTestWhich.test_nonexistent_filer3zpathext check is Windows-onlycCs<tj|jdd�|jd�}|�||jjdd�|j�dS)N���r�)r�rr&rVr�r$rQr)r,rrr�test_pathext_checking�szTestWhich.test_pathext_checkingcCsRt���6}|j|d<t�|j�}|�||jj�Wd�n1sD0YdS�N�PATH)	r�EnvironmentVarGuardr'r�rr&r�r$rQ�rx�envr@rrr�test_environ_path�s

zTestWhich.test_environ_pathcCs�t����}d|d<tjjd|jdd���t�td|j��Rt�|j��&t	�
|j�}|�|�Wd�n1sr0YWd�n1s�0YWd�n1s�0YWd�n1s�0YdS)Nr�r>�
os.confstrT��return_value�create�defpath)
rr?r�rFrGrV�	swap_attrrr�r�rr&r/r@rrr�test_environ_path_empty�s
��
�z!TestWhich.test_environ_path_emptycCs:tj�|jj�}tjdkrBtj}t|t	�r4t�
|�}tj�||�}t�
���}tj|d<tjjd|jdd���t�td|j��jt�|j�}|�|�t�|j��(t�|j�}|�||�Wd�n1s�0YWd�n1s�0YWd�n1�s0YWd�n1�s,0YdS)Nr3r>rCTrDrG)rr+r�r$rQrkr�r(r)r�r�r,rr?�pathsepr�rFrGrVrHr�rr&r/r�r�)rxZexpected_cwdr(rAr@rrr�test_environ_path_cwd�s$




��
zTestWhich.test_environ_path_cwdc
Cs8t����}|�dd�tjjdtdd��Lt�td|j	��t
�|j�}Wd�n1s^0YWd�n1s|0Y|�
||jj�tjjd|j	dd��Jt�tdd��t
�|j�}Wd�n1s�0YWd�n1s�0Y|�
||jj�Wd�n1�s*0YdS)Nr>rCT)r"rFrGrDr�)rr?�popr�rFrGr�rHrrVr�rr&r�r$rQr@rrr�test_environ_path_missings 
��H��Hz#TestWhich.test_environ_path_missingc	Cs�tj�|j�}tj|jd��\t���4}|j|d<tj	|j
dd�}|�|�Wd�n1s`0YWd�n1s~0YdS)Nr�r>r�)rr+r�rVrr�r?r'r�rr&r/)rxrDrAr@rrr�test_empty_paths�
zTestWhich.test_empty_pathcCsNt���2}|�dd�t�|j�}|�|�Wd�n1s@0YdSr=)rr?rLr�rr&r/r@rrr�test_empty_path_no_PATH&s
z!TestWhich.test_empty_path_no_PATHztest specific to WindowscCs�d}tj|jd|d�}t�|jtj�|�|j	�tj
�|j�}tj
�|�d}t
���6}||d<tj||jd�}|�||j�Wd�n1s�0YdS)N�.xyz�Tmp2r!r�PATHEXTr�)rZr[r#rr�rQr�r%rvr�r+r�rrr?r�rr��rxr)Ztemp_filexyzZprogramrAr@rrr�test_pathext,s�
zTestWhich.test_pathextcCs�d}tj|jd|d�}|�|j�tj�|j�}tj�	|�d}t
���<}|�d�|d<tj
||jd�}|�||j�Wd�n1s�0YdS)NrPrQr!r�;rRr�)rZr[r#rvr�rr+r�rQrrr?r�rr�rSrrr�test_pathext_with_empty_str>s�
z%TestWhich.test_pathext_with_empty_strN)rzr{r|r*r-r.r2r4r�r�rYrr�r8r9r:r�rkr�r<rBrIrKrMrNrOrTrVrrrrr �s2
�
�

r c@seZdZdd�ZdS)�TestWhichBytescCsXt�|�t�|j�|_t�|j�|_t�|jj�|j_t�|j�|_t�|j	�|_	dSr)
r r*rr�rVr&r$rQr(r)r�rrrr*Ps
zTestWhichBytes.setUpN)rzr{r|r*rrrrrWOsrWc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
dd��Ze
dd��Zdd�Z
e
dd��Zdd�Ze
dd��Zdd�Ze�ejjd�dd��Zd d!�Zd"d#�Zd$d%�Zd&d'�Zeje
d(d)���Zeje
d*d+���Zeje
d,d-���Z eje
d.d/���Z!d0d1�Z"d2d3�Z#e
d4d5��Z$e
d6d7��Z%d8d9�Z&e�e'ed:��ove�(�d;k�ove'ed<��ove'e)d=��ove'e)d>�d?�d@dA��Z*dBS)C�TestMovecCsvd}|��|_|��|_tj�|j|�|_tj�|j|�|_t|jd��}|�	d�Wd�n1sh0YdS)Nr~r'r)
rur�r�rr+r,r�r�r-r.)rxr�rCrrrr*[s

zTestMove.setUpcCs�t|d��}|��}Wd�n1s(0Yt�||�t|d�� }|�||���Wd�n1sn0Y|�tj�|��dS�NrE)	r-rGr��mover�r�rr+r�)rxrarb�real_dstrC�contentsrrr�_check_move_fileds&.zTestMove._check_move_filecCsFtt�|��}t�||�|�|tt�|���|�tj�|��dSr)	rJrrKr�rZr�r�r+r�)rxrarbr[r\rrr�_check_move_dirlszTestMove._check_move_dircCs|�|j|j|j�dSr)r]r�r�r�rrr�test_move_filerszTestMove.test_move_filecCs|�|j|j|j�dSr)r]r�r�r�r�rrr�test_move_file_to_dirvszTestMove.test_move_file_to_dircCs"t�|j�}|�||j|j�dSr)rrr�r]r�r�)rxrarrr�"test_move_file_to_dir_pathlike_srczsz+TestMove.test_move_file_to_dir_pathlike_srccCs"t�|j�}|�|j||j�dSr)rrr�r]r�r��rxrbrrr�"test_move_file_to_dir_pathlike_dstsz+TestMove.test_move_file_to_dir_pathlike_dstcCs|��dSr)r_r�rrr�test_move_file_other_fs�sz TestMove.test_move_file_other_fscCs|��dSr)r`r�rrr�test_move_file_to_dir_other_fs�sz'TestMove.test_move_file_to_dir_other_fsc	Cs@tj|��d�}z|�|j||�Wt�|�nt�|�0dSr�)rZr�rur^r�rrw�rxr�rrr�
test_move_dir�szTestMove.test_move_dircCs|��dSr)rgr�rrr�test_move_dir_other_fs�szTestMove.test_move_dir_other_fsc
Cs,|�|j|jtj�|jtj�|j���dSr)r^r�r�rr+r,r�r�rrr�test_move_dir_to_dir�s�zTestMove.test_move_dir_to_dircCs|��dSr)rir�rrr�test_move_dir_to_dir_other_fs�sz&TestMove.test_move_dir_to_dir_other_fsc
Cs4|�|jtjj|jtj�|jtj�|j���dSr)r^r�rr+�sepr�r,r�r�rrr�test_move_dir_sep_to_dir�s�z!TestMove.test_move_dir_sep_to_dirzrequires os.path.altsepc
Cs4|�|jtjj|jtj�|jtj�|j���dSr)r^r�rr+�altsepr�r,r�r�rrr�test_move_dir_altsep_to_dir�s�z$TestMove.test_move_dir_altsep_to_dircCsHt|jd��Wd�n1s"0Y|�tjtj|j|j�dS)Nr')r-r�r�r�rrZr�r�r�rrr�"test_existing_file_inside_dest_dir�sz+TestMove.test_existing_file_inside_dest_dircCs*tj�|jd�}|�tjtj|j|�dS�NrI)rr+r,r�r�r�rrZrbrrr�test_dont_move_dir_in_itself�sz%TestMove.test_dont_move_dir_in_itselfc	Csrt�t�zVdD]B\}}tj�t|�}tj�t|�}|jt�||�d||fd�qWt�	t�nt�	t�0dS)N))�srcdirzsrcdir/destz?_destinsrc() wrongly concluded that dst (%s) is not in src (%s)�r�)
rrrr+r,r�r��
_destinsrcrrwr�rrr�test_destinsrc_false_negative�s
��
z&TestMove.test_destinsrc_false_negativec	Csrt�t�zVdD]B\}}tj�t|�}tj�t|�}|jt�||�d||fd�qWt�	t�nt�	t�0dS)N))rrzsrc/dest)rrz
srcdir.newz;_destinsrc() wrongly concluded that dst (%s) is in src (%s)rs)
rrrr+r,r�r�rtrrwr�rrr�test_destinsrc_false_positive�s
��
z&TestMove.test_destinsrc_false_positivecCs\tj�|jd�}t�|j|�t�||j�|�	tj�
|j��|�	tj�|j|j��dSrp)rr+r,r�r�r�r�rZr�r�rM�samefilerbrrr�test_move_file_symlink�s
zTestMove.test_move_file_symlinkcCsld}tj�|j|�}t�|j|�t�||j�tj�|j|�}|�	tj�
|��|�	tj�|j|��dSrp)rr+r,r�r�r�r�rZr�r�rMrw)rxr�rbZ
final_linkrrr�test_move_file_symlink_to_dir�sz&TestMove.test_move_file_symlink_to_dircCsztj�|jd�}tj�|jd�}t�||�tj�|jd�}t�||�|�tj�	|��|�
tj�|�tj�|��dS�NrJrIrK)rr+r,r�r�r�r�rZr�rMr��realpath�rxrarbrrrr�test_move_dangling_symlink�sz#TestMove.test_move_dangling_symlinkcCs|tj�|jd�}tj�|jd�}t�|�t�||�tj�|jd�}t�||�|�	tj�
|��|�	tj�||��dSrz)rr+r,r�rr�r�r�rZr�rMrwr|rrr�test_move_dir_symlink�s
zTestMove.test_move_dir_symlinkc	Cs6t�|j|j�}|�|tj�|jtj�|j���dSr)	r�rZr�r�r�rr+r,r�r,rrr�test_move_return_value�s�zTestMove.test_move_return_valuecCs6t�|jtj�|jd��}|�|tj�|jd��dSrp)r�rZr�rr+r,r�r�r,rrr� test_move_as_rename_return_valuesz)TestMove.test_move_as_rename_return_valuecs8g��fdd�}tj|j|j|d�|�t��d�dS)Ncs��||f�dSrr�r4�Zmovedrrr6sz7TestMove.test_move_file_special_function.<locals>._copyr(rh)r�rZr�r�r�r��rxr6rr�r�test_move_file_special_functionsz(TestMove.test_move_file_special_functioncsdg��fdd�}t�tj�|jd��t�tj�|jd��tj|j|j|d�|�	t
��d�dS)Ncs��||f�dSrr�r4r�rrr6sz6TestMove.test_move_dir_special_function.<locals>._copy�childZchild1r(r)rr�rr+r,r�r�rZr�r�r�r�rr�r�test_move_dir_special_function
sz'TestMove.test_move_dir_special_functionc	Cs~|��|_tj�tj�|j�tj�|j����}|�|j|�z.t	�
|j|�|�tj�|��Wt�
|�nt�
|�0dSr)rur�rr+r,r�r��upperrMr�rZr�rLr�rfrrr�test_move_dir_caseinsensitives
�z&TestMove.test_move_dir_caseinsensitiver�rr��SF_IMMUTABLE�	UF_OPAQUEr~c
Cs0z�t�t�t�ttj�|�ttj	tt
�|�t
t��v�t�ttj
�t�tj�td��t�ttj�|�ttj	tt
�|�t
t��v�Wtj�t�r�t�ttj
�t�t�tj�t
�r�t�t
tj
�t�t
�nNtj�t��rt�ttj
�t�t�tj�t
��r*t�t
tj
�t�t
�0dS)Nr�)rr�
TESTFN_SRCr�r�r�r�r!r�rZ�
TESTFN_DSTr�rKr�Z	os_helperr�r+r,r�rwr�rrr�test_move_dir_permission_denied(s,

�
z(TestMove.test_move_dir_permission_deniedN)+rzr{r|r*r]r^r_r`rarcr&rdrergrhrirjrlr�r�rr+rmrnrorqrurvrr�rxryr}r~rr�r�r�r�rYr�r�r�rrrrrXYsh	




		


	���rXc@s`eZdZGdd�de�Zdd�Ze�ed�dd��Z	e�ed�dd	��Z
e�ed�d
d��ZdS)
�TestCopyFilec@s:eZdZdZdZdZddd�Zdd�Zdd	�Zd
d�Z	dS)
zTestCopyFile.FauxFNTcCs||_||_dSr)�_raise_in_exit�_suppress_at_exit)rxZ
raise_in_exitZsuppress_at_exitrrr�__init__QszTestCopyFile.Faux.__init__cGsdS)Nr�r)rxrrrrrGTszTestCopyFile.Faux.readcCs
d|_dS)NT)�_enteredr�rrr�	__enter__VszTestCopyFile.Faux.__enter__cCs&|||f|_|jr d|_td��|jS)NT�Cannot close)�_exited_withr��_raisedrr�)rx�exc_type�exc_val�exc_tbrrr�__exit__Xs
zTestCopyFile.Faux.__exit__)FT)
rzr{r|r�r�r�r�rGr�r�rrrr�FauxMs
r�c	Csrddd�}t�td|��F|�t��t�dd�Wd�n1sF0YWd�n1sd0YdS)NrFcSs|dkrtd��dS)N�srcfilezCannot open "srcfile"rk�r�r5rrr�_open`sz4TestCopyFile.test_w_source_open_fails.<locals>._openr-r��destfile)rF)rrHr�r�rr��rxr�rrr�test_w_source_open_fails_s
z%TestCopyFile.test_w_source_open_failszskipped on macOScs�|���d
�fdd�	}t�td|��t�dd�Wd�n1sF0Y|��j�|��jdtu�|�	�jdj
d	�dS)NrFcs |dkr�S|dkrtd��dS)Nr�r��Cannot open "destfile"rkr��r�rrr�ms
z2TestCopyFile.test_w_dest_open_fails.<locals>._openr-r�r�rrh)r�)rF)r�rrHr�r�r�r�r�rr�rr�rr�r�test_w_dest_open_failsis*�z#TestCopyFile.test_w_dest_open_failscs�|���|�d��d��fdd�	}t�td|��t�dd�Wd�n1sR0Y|��j�|��j�|��j�|��jdt	u�|�
�jd	jd
�dS)NTrFcs|dkr�S|dkr�SdS�Nr�r�rr��r�r�rrr��s
z3TestCopyFile.test_w_dest_close_fails.<locals>._openr-r�r�rrh)r�)rF)r�rrHr�r�r�r�r�r�rr�rr�rr�r�test_w_dest_close_fails{s
*�z$TestCopyFile.test_w_dest_close_failsc	s�|�d��|���d	��fdd�	}t�td|��F|�t��t�dd�Wd�n1s^0YWd�n1s|0Y|��j�|��j�|�	�j
�|��jddu�|��j
�dS)
NTrFcs|dkr�S|dkr�SdSr�rr�r�rrr��s
z5TestCopyFile.test_w_source_close_fails.<locals>._openr-r�r�r)rF)r�rrHr�r�rr�r�r�r�r�r�r�rr�r�test_w_source_close_fails�s
Hz&TestCopyFile.test_w_source_close_failsN)rzr{r|�objectr�r�r�r��MACOSr�r�r�rrrrr�Ks





r�c@sxeZdZdZedd��Zedd��Zdd�Zej	dd	��Z
d
d�Zdd
�Zdd�Z
dd�Ze�ejdkd�dd��ZdS)�TestCopyFileObji cCstt|j�dSr)rDr�FILESIZE��clsrrr�
setUpClass�szTestCopyFileObj.setUpClasscCst�t�t�t�dSr)rr^rr/r�rrr�
tearDownClass�s
zTestCopyFileObj.tearDownClasscCst�t�dSr�rr^r/r�rrr�tearDown�szTestCopyFileObj.tearDownc	csbttd��D}ttd��}||fVWd�n1s60YWd�n1sT0YdS�NrEr'�r-rr/r�rrr�	get_files�szTestCopyFileObj.get_filesc	Cslt|d��N}t|d��$}|�|��|���Wd�n1s@0YWd�n1s^0YdSrY)r-r�rG)rxrarb�fsrc�fdstrrr�assert_files_eq�szTestCopyFileObj.assert_files_eqcCsH|��� \}}t�||�Wd�n1s.0Y|�tt�dSr)r�r��copyfileobjr�rr/r�rrr�test_content�s*zTestCopyFileObj.test_contentcCs<|��� \}}t�||�Wd�n1s.0YdSr)r�r�r�r�rrr�test_file_not_closed�sz$TestCopyFileObj.test_file_not_closedcCs`|���D\}}t�||�|�|��|j�|�|��|j�Wd�n1sR0YdSr)r�r�r�r��tellr�r�rrr�test_file_offset�sz TestCopyFileObj.test_file_offsetrzWindows onlycCs~tj�d��}t�tt�Wd�n1s.0Y|�|jddd�t	j
t��dd��}|�
d�Wd�n1s�0Y|j}|�tj|�tj�d��}t�|t�Wd�n1s�0Y|�|jddd�t	j
t��dd��}Wd�n1�s0Y|j}|�tj|�tj�d��}t�|t�Wd�n1�sd0Y|�|t�dS)	Nzshutil._copyfileobj_readintorrXiFrUsfoor)r�rFrGr�r�rr/r��	call_argsrZr[rr\r.rQrvrr^r�)rx�mrCrrrrr�
test_win_impl�s"*(* ,zTestCopyFileObj.test_win_implN)rzr{r|r��classmethodr�r�r��
contextlib�contextmanagerr�r�r�r�r�r�r�rrQr�rrrrr��s


r�c@s�eZdZdZdZdZedd��Zedd��Zdd	�Z	e
jd
d��Zdd
�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZdS)�_ZeroCopyFileTesti�r5r�cCsDtt|j�ttd��}|��|_Wd�n1s60YdSrY)rDrr�r-rG�FILEDATA)r�rCrrrr��s
z_ZeroCopyFileTest.setUpClasscCst�t�dSr)rr^rr�rrrr��sz_ZeroCopyFileTest.tearDownClasscCst�t�dSrr�r�rrrr�	sz_ZeroCopyFileTest.tearDownc	csbttd��D}ttd��}||fVWd�n1s60YWd�n1sT0YdSr�r�r�rrrr�	sz_ZeroCopyFileTest.get_filescOstd��dS)Nzmust be implemented in subclass)�NotImplementedError)rxrrrrr�zerocopy_fun	sz_ZeroCopyFileTest.zerocopy_funcCs$|��|��|��|��dSr)r�r�r�r*r�rrr�reset	sz_ZeroCopyFileTest.resetc	Cs�|��� \}}|�||�Wd�n1s.0Y|�ttdd�|j�|���L\}}tj�d��}t	�
tt�Wd�n1s�0YWd�n1s�0YdS)NT�r/zshutil.copyfileobj)r�r�r�rHr/r�r�rFrGr�r�r)rxrarbr�rrr�test_regular_copy	s**z#_ZeroCopyFileTest.test_regular_copyc	Cs�|�|j�|���J\}}|�t��|�||�Wd�n1sF0YWd�n1sd0Y|�ttdd�|j	�dS)NTr�)
rvr�r�r�r�r�r�rHrr�r�rrr�test_same_file 	s
Hz _ZeroCopyFileTest.test_same_filecCsZtjt��d�}|�t��}t�|d�Wd�n1s<0Y|�|j	j
|�dS)Nr��new)rZr�rr\r�r�r�r�r�r�r�)rxrQr�rrr�test_non_existent_src(	s*z'_ZeroCopyFileTest.test_non_existent_srcc	s�td�td�|��fdd��|��fdd��t�d��Wd�n1sT0Yt�d��F}t�d��}|�||�Wd�n1s�0YWd�n1s�0Y|�t�dd	�d
�dS)Nrarbcs
t���Sr�rr^r)r_rrr�1	r5z3_ZeroCopyFileTest.test_empty_file.<locals>.<lambda>cs
t���Srr�r)r`rrr�2	r5r'rETr�r5)rrvr-r�r�rHr�r)r`r_r�test_empty_file.	sHz!_ZeroCopyFileTest.test_empty_filecCsHtjj|jtd��"|�ttjtt	�Wd�n1s:0YdS)N�r")
r�rFrG�
PATCHPOINT�ZeroDivisionErrorr�r�r�rr/r�rrr�test_unhandled_exception<	s
��z*_ZeroCopyFileTest.test_unhandled_exceptionc
Cs�tjj|jttjd�d��r|���J\}}|�t	��|�
||�Wd�n1sV0YWd�n1st0YWd�n1s�0YdS�N�yor�)r�rFrGr�rr�EINVALr�r�r
r�r�rrr�test_exception_on_first_callB	s

�z._ZeroCopyFileTest.test_exception_on_first_callc	Cs|tjj|jttjd�d��N|���&\}}|�t|j	||�Wd�n1sP0YWd�n1sn0YdSr�)
r�rFrGr�rr�ENOSPCr�r�r�r�rrr�test_filesystem_fullL	s


�z&_ZeroCopyFileTest.test_filesystem_fullN)rzr{r|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��s&




r�zos.sendfile() not supportedc@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�TestZeroCopySendfile�os.sendfilecCst�||�Sr)r��_fastcopy_sendfile)rxr�r�rrrr�Y	sz!TestZeroCopySendfile.zerocopy_func
Cs�t�|j��|}ttd��R}|�t��|�||�Wd�n1sF0Yt�	||�Wd�n1sp0YWd�n1s�0Y|�
ttdd�|j�dS)Nr'Tr�)�io�BytesIOr�r-r/r�r
r�r�r�r�rHr�rrr�test_non_regular_file_src\	s*Hz.TestZeroCopySendfile.test_non_regular_file_srcc
Cs�ttd���}t���n}|�t��|�||�Wd�n1sB0Yt�||�|�	d�|�
|��|j�Wd�n1s�0YWd�n1s�0YdS)NrEr)
r-rr�r�r�r
r�r�r��seekr�rGr�r�rrr�test_non_regular_file_dste	s
*
z.TestZeroCopySendfile.test_non_regular_file_dstc
s���fdd�}g�tj�tjjdd|d��r|���J\}}|�t��}t�	||�Wd�n1sf0YWd�n1s�0YWd�n1s�0Y|�
|jjtj
�dS)Ncs,�s��d��|i|��Sttjd��dS)Nr�)rNrr�EBADFr�r&Z
orig_sendfilerrrTo	s
zDTestZeroCopySendfile.test_exception_on_second_call.<locals>.sendfiler�T)rFr")rrTr�rFrGr�r�rr�r�r�r�rr�)rxrTrarbr�rr�r�test_exception_on_second_calln	s
�fz2TestZeroCopySendfile.test_exception_on_second_callc	Cs�tjjdtd��H}|��� \}}t�||�Wd�n1s@0YWd�n1s^0Y|�tt	dd�|j
�dS)N�os.fstatr�Tr�)r�rFrGrr�r�r�r�rHr/r��rxr�rarbrrr�test_cant_get_size�	s
<z'TestZeroCopySendfile.test_cant_get_sizec	Cs�tj��}d|_tjjd|d��H}|��� \}}t�||�Wd�n1sP0YWd�n1sn0Y|�t	t
dd�|j�dS)Nir��rETr�)r�rF�Mock�st_sizerGr�r�r�r�rHr/r��rxrFr�rarbrrr�test_small_chunks�	s
<z&TestZeroCopySendfile.test_small_chunksc	Cs�tj��}|jd|_tjjd|d��H}|��� \}}t�||�Wd�n1sV0YWd�n1st0Y|�	t
tdd�|j�dS)Ni@r�r�Tr�)
r�rFr�r�r�rGr�r�r�r�rHr/r�r�rrr�test_big_chunk�	s
<z#TestZeroCopySendfile.test_big_chunkcCs�tjjdtd���}|�ttjtt�|j	dd}|�
|tj�
t��t�t�ttddd�|�tjtd�|�ttjttd�|j	dd}|�
|d	�Wd�n1s�0YdS)
Nr�r�rrshelloTr��3i�)r�rFrGr�r�r�r�rr/r�r�rr+�getsizerr^r1rv)rxr��	blocksizerrr�test_blocksize_arg�	s"��
�z'TestZeroCopySendfile.test_blocksize_argc
Cs�z�tjj|jttjd�d��r}|���J\}}|�t	��t
�||�Wd�n1sX0YWd�n1sv0YWd�n1s�0Ytj�|j��}t
�t
t�Wd�n1s�0YWdt
_ndt
_0dS)Nr�r�T)r�rFrGr�rr�ENOTSOCKr�r�r
r�r�r�rr/�_USE_CP_SENDFILEr�rrr�test_file2file_not_supported�	s
�H z1TestZeroCopySendfile.test_file2file_not_supportedN)
rzr{r|r�r�r�r�r�r�r�r�r�r�rrrrr�U	s		


r�z
macOS onlyc@seZdZdZdd�ZdS)�TestZeroCopyMACOSzposix._fcopyfilecCst�||tj�Sr)r��_fastcopy_fcopyfile�posix�_COPYFILE_DATAr�rrrr��	szTestZeroCopyMACOS.zerocopy_funN)rzr{r|r�r�rrrrr��	sr�c@s^eZdZdd�Zdd�Zdd�Ze�e�	e
j���d�e�e
ed�d	�d
d���Zdd
�ZdS)�TestGetTerminalSizecCs(t��}|�|jd�|�|jd�dS)Nr)r��get_terminal_sizer�columns�lines)rxr@rrr�test_does_not_crash�	sz'TestGetTerminalSize.test_does_not_crashcCs�t���&}d|d<|d=t��}Wd�n1s40Y|�|jd�t���&}|d=d|d<t��}Wd�n1s�0Y|�|jd�dS)NZ777�COLUMNS�LINESi	Z888ix)rr?r�r�r�r�r��rxrAr@rrr�test_os_environ_first�	s
&
&z)TestGetTerminalSize.test_os_environ_firstcCs`t���(}d|d<d|d<t��}Wd�n1s60Y|�|jd�|�|jd�dS)Nrer�Zyyyr�r)rr?r�r�rr�r�r�rrr�test_bad_environ�	s
&z$TestGetTerminalSize.test_bad_environz
not on ttyr�zneed os.get_terminal_size()c
Cs�zt�ddg�����}Wn$tttjfy>|�d�Yn0t|d�t|d�f}t	�
��$}|d=|d=t��}Wd�n1s�0Y|�
||�dS)NZsttyr@zstty invocation failedrhrr�r�)rmr�r�rpr�r!r�r.rqrr?r�r�r�)rxr@r�rAr�rrr�test_stty_match�	s
�

&z#TestGetTerminalSize.test_stty_matchc
Cst����}|d=|d=t�tdd��tjdd�}Wd�n1sF0Y|�|jd�|�|jd�t	t
jd��J}t�td|��tjd	d�}Wd�n1s�0YWd�n1s�0Y|�|jd
�|�|jd�Wd�n1�s0YdS)Nr�r��
__stdout__)�
�)�fallbackrrr()��(rr)rr?rHrkr�r�r�r�r�r-r�devnull)rxrAr@rCrrr�
test_fallback
s
*�Hz!TestGetTerminalSize.test_fallbackN)rzr{r|r�rrr�r�r�isattyrkrr]rYrr
rrrrr��	s
�r�c@seZdZdd�ZdS)�PublicAPITestscCsP|�ttd��gd�}ttd�s,tjdkr6|�d�|�ttj�t|��dS)N�__all__)r�r�rNr[r�r�r�rZrwrr��	ExecErrorrrrrrrr
rrrrr�r�statvfsrr
)	r�rYr�rrQrNr�rr
)rxZ
target_apirrr�test_module_all_attribute%
s

z(PublicAPITests.test_module_all_attributeN)rzr{r|rrrrrr"
sr�__main__)F)F)Nr�Z
unittest.mockr�rZrkr�rZos.pathrr$rrmr6r8r�r�rrrrrrrr	r
rrr
r�r�r��ImportErrorr�rZtest.supportrrr/r�r�r�rr�rjr�r�r�r�rr&r1rDrHrOreZSUPPORTS_SENDFILErrrsZTestCaser}r�rHr�rr rWrXr�r�r�r�r�r�r�r�rrz�mainrrrr�<module>s�8




	
[PgP<
s\JdvN


Kontol Shell Bypass