Your IP : 216.73.216.85


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_os.cpython-310.opt-2.pyc

o

0�i���	@s$	ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddl$m%Z%e�&��e�'d	e(�ddl)Z)ddl*Z*Wd�n1s�wYzddl+Z+Wne,y�dZ+Ynwzddl-Z-Wne,y�dZ-Ynwzddl.Z.Wne,y�dZ.Ynwzddl/Z/d
d�e/�0�D�Z1Wne,e2f�ygZ1Ynwz
ddl3m4Z4m5Z5Wne,�y)ej6Z4Z5Ynwdd
l7m8Z8ddlm9Z9ddl:m;Z;dZ<e=e	d��rJe	�>�dkZ<e=ed��r]ej?j@�r]ej?j@�Ad�ZBndZBej$�Ad��oke	�C�dkZDdd�ZEd�dd�ZFe�Gej$�Ad�d�ZHGdd�dejI�ZJGdd�dejI�ZKGd d!�d!ejI�ZLGd"d#�d#ejI�ZMdd$lmNZNGd%d&�d&eNjO�ZPGd'd(�d(ejI�ZQe�Re=e	d)�d*�Gd+d,�d,eQ��ZSGd-d.�d.eQ�ZTe�Re=e	d)�d*�Gd/d0�d0eS��ZUGd1d2�d2ejI�ZVe�Re=e	d3�d4�Gd5d6�d6ejI��ZWGd7d8�d8ejI�ZXGd9d:�d:ejI�ZYGd;d<�d<ejI�ZZe�Re=e	d=�d>�Gd?d@�d@ejI��Z[e�\dA�dBk�pCe�\dC�dBk�pCe�\dD�dBkZ]e�Ge]dE�e�Gej$dFkdG�GdHdI�dIejI���Z^ej_d�dJdK��Z`e�Re=e	dL�dM�GdNdO�dOejI��Zae�Rej$dPkdQ�GdRdS�dSejI��ZbGdTdU�dUejI�ZcGdVdW�dWejI�Zde�Gej$dPkdX�GdYdZ�dZejI��Zee�Gej$dPkdX�Gd[d\�d\ejI��Zfe�Rej$dPkdQ�Gd]d^�d^ejI��Zge�Rej$dPkdQ�Gd_d`�d`ejI��Zhe�Re=e	da�db�Gdcdd�ddejI��Zie�Rej$dPkdQ�e jjGdedf�dfejI���Zke�Rej$dPkdQ�Gdgdh�dhejI��Zle�Rej$dPkdQ�Gdidj�djejI��Zme jjGdkdl�dlejI��ZnGdmdn�dnejI�ZoGdodp�dpejI�ZpGdqdr�drejI�ZqGdsdt�dtejI�Zre�sdu�e�Re=e	dv�dw�Gdxdy�dyejI���Zte�Re=e	dz��o�e=e	d{�d|�Gd}d~�d~ejI��ZuGdd��d�e*jvejw�Zxe�Re=e	d��d��Gd�d��d�ejI��Zyd�d��Zze�Rez�d��e�{d�d�d��Gd�d��d�ejI���Z|e�Re=e	d��d��Gd�d��d�ejI��Z}e�Re=e	d��d��e�{d�d��Gd�d��d�ejI���Z~e�Re=e	d��d��e�{d�d�d��Gd�d��d�ejI���ZGd�d��d�ejI�Z�Gd�d��d�ejI�Z�Gd�d��d�ejI�Z�Gd�d��d�ejI�Z�e�Re=e	d��d��Gd�d��d�ejI��Z�Gd�d��d�ejI�Z�Gd�d��d�ejI�Z�Gd�d��d�ejI�Z�Gd�d��d�ejI�Z�Gd�d��d�ejI�Z�eEd��Gd�d��d�ejI��Z�e=e	d���r�Gd�d��d�e��Z�e�d�k�r�e���dSdS)��N)�support)�
import_helper)�	os_helper)�
socket_helper)�threading_helper)�warnings_helper)�win32_is_iot�ignorecC�g|]}|j�qS�)Zpw_uid)�.0�urr�3/opt/alt/python310/lib64/python3.10/test/test_os.py�
<listcomp><�r)�INT_MAX�PY_SSIZE_T_MAX��assert_python_ok)�
unix_shell)�FakePathF�geteuid�thread_infoZlinuxthreadsZfreebsdcCst�tt|�d|�S)Nzrequires os.%s)�unittest�
skipUnless�hasattr�os��namerrr�requires_os_func[�r�contentcCs<t|dd��}|�|�Wd�dS1swYdS)N�xbr)�open�write)�filenameZcontent�fprrr�create_file_s"�r'Zaixz%on AIX, splice() only accepts socketsc@�$eZdZdd�Zdd�Zdd�ZdS)�	MiscTestscCst��}|�|t�dS�N)r�getcwd�assertIsInstance�str��self�cwdrrr�test_getcwdj�zMiscTests.test_getcwdc
Cszd}tjdkr	d}d}d}|d|t|�}t����}t�|��z}|}	t��}|�	||�|t|�ttj
j�}|dkr@nHt|�|krP|dkrP|d|�}tj
�||�}zt�
|�t�|�Wn!tylYnty�}	z
|	jtjkrWYd}	~	n	�d}	~	ww|}q%tjr�td	t|����Wd�n1s�wYWd�dSWd�dS1s�wYdS)
Ni��vxworks����Zpython_test_dir_�aTrz!Tested current directory length: )�sys�platform�len�tempfileZTemporaryDirectoryrZ
change_cwdrr+�assertEqual�path�sep�join�mkdir�chdir�FileNotFoundError�OSError�errnoZENAMETOOLONGr�verbose�print)
r/Zmin_lenZdirlen�dirnameZtmpdirr<�expectedr0Zneed�excrrr�test_getcwd_long_pathnsL


������"�zMiscTests.test_getcwd_long_pathcCs.t��}|�|t�|�t�|�t���dSr*)r�getcwdbr,�bytesr;�fsdecoder+r.rrr�test_getcwdb�szMiscTests.test_getcwdbN)�__name__�
__module__�__qualname__r1rIrMrrrrr)is9r)c@s�eZdZdd�ZeZdd�Zdd�Zejdd��Z	d	d
�Z
eje�e
ekd�eje
dd
dd�dd����Zdd�Zdd�Ze�ejdkd�dd��Zdd�Zdd�Zdd�Zd d!�Zd"d#�Ze�eed$�d%�d&d'��Ze�eed$�d%�d(d)��Ze�eed$�d%�d*d+��Ze�eed,�d-�d.d/��Z e�eed,�d-�e!d0d1���Z"e�eed,�d-�e!d2d3���Z#e�eed,�d-�e!d4d5���Z$d6S)7�	FileTestscCs"tj�tj�rt�tj�dSdSr*)rr<�lexistsr�TESTFN�unlink�r/rrr�setUp���zFileTests.setUpcCs:t�tjtjtjB�}t�|�|�t�tjtj	��dSr*)
rr#rrS�O_CREAT�O_RDWR�close�
assertTrue�access�W_OK�r/�frrr�test_access�s
zFileTests.test_accessc	Cs�t�tjtjtjB�}t�|�}z/d}||dkr9t�|�|d7}|dkr+|�d�|t�|�}}||dksWt�|�nt�|�wt�	||d�|�
ttj|d�dS)Nr��
z%couldn't allocate two consecutive fds��a)
rr#rrSrXrY�duprZ�skipTest�
closerange�assertRaisesrBr$)r/�first�secondZretriesrrr�test_closerange�s


��zFileTests.test_closerangecCs<tj}t�|�}|�ttj|d�t�|�}|�||�dS�Nr)	rrSr7�getrefcountrh�	TypeErrorr�renamer;)r/r<�old�newrrr�test_rename�s


zFileTests.test_renamecCs�ttjd��1}|�d�|��|��}t�|dd�t�|d�}|�	t
|�t�|�	|d�Wd�dS1s:wYdS)N�w+b�spamr�)r#rrSr$�flush�filenor�lseek�readr;�typerK)r/�fobj�fd�srrr�	test_read�s
"�zFileTests.test_readzneeds INT_MAX < PY_SSIZE_T_MAXrbraF)�sizeZmemuseZdry_runcCsh|�tjtj�ttjd�ttjd��}t�|��|�}Wd�n1s'wY|�	|d�dS)Nstest�rb)
�
addCleanuprrTrSr'r#rryrwr;)r/rr&�datarrr�test_large_read�s�zFileTests.test_large_readcCs�t�tjtjtjB�}|�ttj|d�t�|d�t�|t	d��t�|t
d��t�|�ttjd��}|�|�
���gd��Wd�dS1sMwYdS)N�beanssbacon
seggs
sspam
r�)sbaconseggsrt)rr#rrSrX�O_WRONLYrhrnr$�	bytearray�
memoryviewrZr;ry�
splitlines)r/r|r{rrr�
test_write�s
�"�zFileTests.test_writecGs"tj|tjdd�}|�|d�dS)NT)�
creationflags�shellr)�
subprocessZcallZCREATE_NEW_CONSOLEr;)r/�argsZretcoderrr�write_windows_console�s
�zFileTests.write_windows_console�win32z$test specific to the Windows consolecCs*d}|�tjd|�|�tjdd|�dS)Nzprint('x' * 100000)�-cz-u)r�r7�
executable�r/�coderrr�test_write_windows_consolesz$FileTests.test_write_windows_consolecGs4t�tjtj�}tj|g|�Rddi�}|��dS)N�encoding�utf-8)rr#rrS�O_RDONLY�fdopenrZ)r/r�r|r_rrr�
fdopen_helperszFileTests.fdopen_helpercCsBt�tjtjtjB�}t�|�|��|�d�|�dd�dS)N�r�d)rr#rrSrXrYrZr��r/r|rrr�test_fdopens


zFileTests.test_fdopencCs�tjd}|�tjtj�|�tj|�ttjd�t|d�t�tj|�|�ttj	tj�t
|ddd��}|�|��d�Wd�dS1sJwYdS)Nz.2�1�2r�r��r��1)
rrSr�rTr'r�replacerhrA�statr#r;ry)r/�TESTFN2r_rrr�test_replaces

"�zFileTests.test_replacecCs"tjttjddd�}t�|�dS)N�)r<�flags�mode�dir_fd)rr#�__file__r�rZr^rrr�test_open_keywords,s�zFileTests.test_open_keywordsc	Cs>t�td�}z|dtjddd�WdSttfyYdSw)N�symlink�targetF)�src�dst�target_is_directoryr�)rZ
get_attributerrrS�NotImplementedErrorrB)r/r�rrr�test_symlink_keywords1s��zFileTests.test_symlink_keywords�copy_file_rangeztest needs os.copy_file_range()cC�>|�t��t�ddd�Wd�dS1swYdS�Nrrai����)rh�
ValueErrorrr�rUrrr�#test_copy_file_range_invalid_values9�"�z-FileTests.test_copy_file_range_invalid_valuesc	
Cs"tjd}d}ttj|�|�tjtj�ttjd�}|�|j�|��}t|d�}|�tj|�|�|j�|��}z	t�	||d�}Wnt
yc}z|jtjkrS�|�
|�WYd}~dSd}~ww|�|tdd��t|d��}|�|��|d|��Wd�dS1s�wYdS)N�.3�
0123456789r�rs�r�)rrSr'r�rTr#rZrwrr�rBrC�ENOSYSrf�assertIn�ranger;ry)	r/r�r��in_file�in_fd�out_file�out_fd�i�errr�test_copy_file_range>s.

��
"�zFileTests.test_copy_file_rangec

Cs^tjd}d}d}d}d}ttj|�|�tjtj�ttjd�}|�|j�|��}t|d�}|�tj|�|�|j�|��}	ztj	||	|||d�}
Wnt
yl}z|jtjkr\�|�
|�WYd}~dSd}~ww|�|
td	|d
��t|d��}|��}Wd�n1s�wY|�|d|�d|�|�||d�||||
��dS)N�.4r�r��r�r�rs)�
offset_src�
offset_dstrra�)rrSr'r�rTr#rZrwrr�rBrCr�rfr�r�ryr;)
r/�TESTFN4r��
bytes_to_copy�in_skip�out_seekr�r�r�r�r�r�ryrrr�test_copy_file_range_offset`sB



���

��z%FileTests.test_copy_file_range_offset�spliceztest needs os.splice()cCr�r�)rhr�rr�rUrrr�test_splice_invalid_values�r�z$FileTests.test_splice_invalid_valuesc
s�tjd}d}ttj|�|�tjtj�ttjd�}|�|j�|��}t�	�\��|��fdd��|��fdd��z	t�
|�d�}Wntye}z|jtj
krU�|�|�WYd}~dSd}~ww|�|tdd	��|�t��d
�|d|��dS)Nr�r�r�c�
t���Sr*�rrZr��read_fdrr�<lambda>��
z'FileTests.test_splice.<locals>.<lambda>cr�r*r�r��write_fdrrr��r�r�rr�r�)rrSr'r�rTr#rZrwr�piper�rBrCr�rfr�r�r;ry)r/r�r�r�r�r�r�r�r�r�r�test_splice�s(
��
 zFileTests.test_splicec

stjd}d}d}d}ttj|�|�tjtj�ttjd�}|�|j�|��}t�	�\��|��fdd��|��fdd��ztj
|�||d	�}Wntyk}z|jtj
kr[�|�|�WYd}~dSd}~ww|�|td
|d��t��d�}	|�|	||||��dS)
Nr�r�r�r�r�cr�r*r�rr�rrr��r�z1FileTests.test_splice_offset_in.<locals>.<lambda>cr�r*r�rr�rrr��r�)r�rrar�)rrSr'r�rTr#rZrwrr�r�rBrCr�rfr�r�ryr;)
r/r�r�r�r�r�r�r�r�ryrr�r�test_splice_offset_in�s.
��
zFileTests.test_splice_offset_inc
sptjd}d}d}d}ttj|�|�tjtj�t��\��|��fdd��|��fdd��t��|�t|d�}|�tj|�|�|j	�|�
�}ztj�|||d	�}Wntyw}z|j
t
jkrg�|�|�WYd}~dSd}~ww|�|td
|d��t|d��}	|	��}
Wd�n1s�wY|�|
d|�d
|�|�|
|d�|d|��dS)Nr�r�r�r�cr�r*r�rr�rrr��r�z2FileTests.test_splice_offset_out.<locals>.<lambda>cr�r*r�rr�rrr��r�rs)r�rrar�r�)rrSr'r�rTrr�r$r#rZrwr�rBrCr�rfr�r�ryr;)r/r�r�r�r�r�r�r�r�r�ryrr�r�test_splice_offset_out�s8

��

� z FileTests.test_splice_offset_outN)%rNrOrPrV�tearDownr`rkr�cpython_onlyrrr~rrrrZ
bigmemtestr�r�r�r7r8r�r�r�r�r�r�rrr�r�r�r��requires_splice_piper�r�r�rrrrrQ�sT


�
�
	


!
,
$rQc@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�	e
ed�d�d
d��Ze�	e
ed�d�dd��Z
e�	ejdkd�dd��Ze�	ejdkd�e�	e
ed�d�dd���Zdd�Ze�	ejdkd�dd��Ze�	ejdkd�dd ��Ze�	ejdkd�d!d"��Zd#S)$�StatAttributeTestscCs(tj|_|�tj|j�t|jd�dS)N�ABC)rrS�fnamer�rTr'rUrrrrVszStatAttributeTests.setUpc
	Cs�t�|�}|�|tjd�|�|jd�t|�}tt�D]2}|dd�dkrO|��}|�d�r5dd�}ndd�}|�|t||��|tt|��|�	||�qd�
�D]}tt||�d�}t||d	�d
}|j||dd�qTz|d
|�
d�Wn	ty�Ynwz
d|_|�
d�Wn	ty�Ynwz
d|_|�
d�Wnttfy�Ynwz
d|_|�
d�Wn	ty�Ynwzt�d�}	|�
d�Wn	ty�Ynwzt�d�}	WdSty�YdSw)Nr�ZST_ZTIMEcSst|�Sr*)�int��xrrr�truncsz7StatAttributeTests.check_stat_attributes.<locals>.trunccSs|Sr*rr�rrrr��zst_atime st_mtime st_ctimei��Z_nsi'rc��deltar5�No exception raisedra�rb�rrarcr�rur�r����	rb���
�)rr�r;�ST_SIZE�st_size�dir�lower�endswith�getattrr��splitr��assertAlmostEqual�fail�
IndexError�st_mode�AttributeError�st_rdevrn�parrot�stat_result)
r/r��result�membersr�attrr�ZfloatyZnanosecondy�result2rrr�check_stat_attributessl


������
��z(StatAttributeTests.check_stat_attributescCs|�|j�dSr*)r
r�rUrrr�test_stat_attributesM�z'StatAttributeTests.test_stat_attributescCsFz
|j�t���}Wnty|�d|j�Ynw|�|�dS)Nz#cannot encode %a for the filesystem)r��encoder7�getfilesystemencoding�UnicodeEncodeErrorrfr
)r/r�rrr�test_stat_attributes_bytesPs�z-StatAttributeTests.test_stat_attributes_bytescC�ft�|j�}ttjd�D]#}t�||�}|�d|�|dkr%|�d|�t�|�}|�	||�q
dS)Nrasstat_resultruscos
stat_result
)
rr�r�r��pickle�HIGHEST_PROTOCOL�dumpsr��loadsr;�r/r�proto�pZ	unpickledrrr�test_stat_result_pickleWs
�z*StatAttributeTests.test_stat_result_pickle�statvfsztest needs os.statvfs()cCst�|j�}|�|j|d�d}t|�D]\}}|�t|d|�||�q|�t|j	t
��|�t|�d�z
d|_|�d�Wn	t
yKYnwz
d|_|�d�Wn	t
y_Ynwzt�d�}|�d�Wn	tyuYnwzt�d�}WdSty�YdSw)	Nr�)
ZbsizeZfrsizeZblocksZbfreeZbavail�filesZffreeZfavail�flagZnamemaxZf_rbrar�r�r�)rrr�r;�f_bfree�	enumerater�r[�
isinstance�f_fsidr�r9r�rr�statvfs_resultrn)r/rr�value�memberr	rrr�test_statvfs_attributesas<��
��z*StatAttributeTests.test_statvfs_attributes�need os.statvfs()cCr)Nrasstatvfs_resultruscos
statvfs_result
)
rrr�r�rrrr�rr;rrrr�test_statvfs_result_pickle�s
�z-StatAttributeTests.test_statvfs_result_pickler��Win32 specific testsc
Cs^zt�d�WdSty|�d�YdSty.}z|�d�WYd}~dSd}~ww)Nzc:\pagefile.syszc:\pagefile.sys does not existzCould not stat pagefile.sys)rr�rArfrBr��r/r�rrr�test_1686475�s��zStatAttributeTests.test_1686475r�zrequires os.pipe()c	Cs�t��\}}zt�|�Wt�|�t�|�nt�|�t�|�w|�t��
}t�|�Wd�n1s8wY|�|jjtj	�dSr*)
rr�r�rZrhrBr;�	exceptionrC�EBADF)r/r��w�ctxrrr�
test_15261�s

��zStatAttributeTests.test_15261cCsL|�t|d��|�t|jt��|�d|jko dk�dS�dS)N�st_file_attributesr���)r[rrr/r�)r/rrrr�check_file_attributes�s*z(StatAttributeTests.check_file_attributesz$st_file_attributes is Win32 specificcCszt�|j�}|�|�|�|jtj@d�tjd}t�	|�|�
tj|�t�|�}|�|�|�|jtj@tj�dS)Nrr�)rr�r�r1r;r/�FILE_ATTRIBUTE_DIRECTORYrrSr?r��rmdir)r/rrFrrr�test_file_attributes�s

�




�z'StatAttributeTests.test_file_attributescCsdtj�tjd|j�}|�tj|�t|d�d}t	j
d|ddg|d�t�|�}|�|j
d�dS)	NZTEMPr�r�z
icacls.exez/denyz*S-1-5-32-545:(S)�r�r)rr<r>�environr�r�rrTr'r��
check_callr��assertNotEqualr�)r/r�ZDETACHED_PROCESSrrrr�test_access_denied�s

�
z%StatAttributeTests.test_access_deniedcCs6dtj�t���d}t�|�}|�|jtj�dS)Nz//./r)rr<�
splitdriver+r�r;r�S_IFBLK)r/r�rrrr�test_stat_block_device�s
z)StatAttributeTests.test_stat_block_deviceN)rNrOrPrVr
rrrrrrrr$r&r7r8r)r.r1r4r9r<rrrrr�s4A

+�

	�

r�c@s�eZdZdd�Zdd�Zd)dd�Zdd	�Zed
d��Zdd
�Z	dd�Z
e�e
je
jvd�dd��Ze�e
je
jvd�dd��Ze�e
je
jvd�dd��Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zejd'd(��ZdS)*�
UtimeTestscCsDtj|_tj�|jd�|_|�tj|j�t�	|j�t
|j�dS)N�f1)rrSrFrr<r>r�r��rmtreer?r'rUrrrrV�s
zUtimeTests.setUpcCs4t�|�}|j|dkp|j|dkp|j|dkS)Nr�r�r�)rr��st_atime�st_mtime�st_ctime)r/r%�strrr�support_subsecond�s
��zUtimeTests.support_subsecondNcCs�|s|j}|�|�}|rd}d}nd}d}||||f�t�|�}|r:|j|j|ddd�|j|j|ddd�n|�|j|d�|�|j|d�|�|j|�|�|j	|�dS)Ni8Z�;l�
o]�rTlP�9��&�.>g���ư>r�)
r�rDrr�r�r@rAr;�st_atime_ns�st_mtime_ns)r/�set_timer%rD�atime_ns�mtime_nsrCrrr�_test_utime�s"

zUtimeTests._test_utimecC�dd�}|�|�dS)NcS�tj||d�dS�N��ns�r�utime�r%rQrrrrI�z'UtimeTests.test_utime.<locals>.set_time�rL�r/rIrrr�
test_utimeszUtimeTests.test_utimecCs|ddS)NrFg��&�.>rrPrrr�	ns_to_sec szUtimeTests.ns_to_secc��fdd�}��|�dS)Ncs0|\}}��|�}��|�}t�|||f�dSr*�rYrrS�r%rQrJrKZatime�mtimerUrrrI)s

z2UtimeTests.test_utime_by_indexed.<locals>.set_timerVrWrrUr�test_utime_by_indexed'sz UtimeTests.test_utime_by_indexedcrZ)Ncs2|\}}��|�}��|�}tj|||fd�dS)N)�timesr[r\rUrrrI3s

z0UtimeTests.test_utime_by_times.<locals>.set_timerVrWrrUr�test_utime_by_times2szUtimeTests.test_utime_by_timesz9follow_symlinks support for utime required for this test.cCrM)NcSstj||dd�dS)NF)rQ�follow_symlinksrRrTrrrrI?sz9UtimeTests.test_utime_nofollow_symlinks.<locals>.set_timerVrWrrr�test_utime_nofollow_symlinks;sz'UtimeTests.test_utime_nofollow_symlinksz,fd support for utime required for this test.cCrM)NcSsDt|dd��}tj|��|d�Wd�dS1swYdS)N�wbrrP)r#rrSrw)r%rQr&rrrrIHs"�z*UtimeTests.test_utime_fd.<locals>.set_timerVrWrrr�
test_utime_fdE�zUtimeTests.test_utime_fdz0dir_fd support for utime required for this test.cCrM)NcSsPtj�|�\}}t�|��}tj|||d�Wd�dS1s!wYdS)N)r�rQ)rr<r�r�open_dir_fdrS)r%rQrFr�dirfdrrrrIRs"�z.UtimeTests.test_utime_dir_fd.<locals>.set_timerVrWrrr�test_utime_dir_fdOrezUtimeTests.test_utime_dir_fdcCsdd�}|j||jd�dS)NcSrNrOrRrTrrrrIZrUz1UtimeTests.test_utime_directory.<locals>.set_time�r%)rLrFrWrrr�test_utime_directoryYszUtimeTests.test_utime_directorycCsbt��}||j�|�|j�sd}nd}t�|j�}d|j||j|f}|j|j|||d�dS)Ng�?g�������?zst_time=%r, current=%r, dt=%r)r��msg)�timer�rDrr�rAr�)r/rIZcurrentr�rCrkrrr�_test_utime_current_s
�

�zUtimeTests._test_utime_currentcrZ)Ncst��j�dSr*�rrSr�rirUrrrIv�z/UtimeTests.test_utime_current.<locals>.set_time�rmrWrrUr�test_utime_currentu�zUtimeTests.test_utime_currentcrZ)Ncst��jd�dSr*rnrirUrrrI|rUz3UtimeTests.test_utime_current_old.<locals>.set_timerprWrrUr�test_utime_current_old{rrz!UtimeTests.test_utime_current_oldcCsptjdkr4tj�tj�|��dd}ddl}|jj}|�	dd�}|�
|ddddd|t|��}|r6|jSdSdS)Nr�r�\�r�)
r7r8rr<r:�abspath�ctypes�windll�kernel32Zcreate_unicode_bufferZGetVolumeInformationWr9r")r/r<�rootrwry�buf�okrrr�get_file_system�s

��zUtimeTests.get_file_systemcCsJ|�|j�dkr
|�d�d}t�|j||f�|�t�|j�j|�dS)NZNTFSz
requires NTFSrE)	r}rFrfrrSr�r;r�rA)r/Zlargerrr�test_large_time�s

zUtimeTests.test_large_timec	Cs�|�t��tj|jddd�Wd�n1swY|�t��t�|jddg�Wd�n1s7wY|�t��t�|jd�Wd�n1sSwY|�t��t�|jd�Wd�n1sowY|�t��tj|jddgd�Wd�n1s�wY|�t��tj|jdd�Wd�n1s�wY|�t��tj|jdd�Wd�n1s�wYtjtjvr�|�t��tj|jddd�Wd�n1s�wYtjtjv�r.t	|jdd	��&}|�t��t�|�
�d�Wd�n	1�swYWd�n	1�s)wYtjtjv�rW|�t��tj|jdd	d
�Wd�dS1�sPwYdSdS)N)r�r�rPr�)r�)r�r�r�F�rarcr�r�)rhr�rrSr�rn�supports_follow_symlinksr��supports_fdr#rw�supports_dir_fd)r/r&rrr�test_utime_invalid_arguments�sJ�����������$��z'UtimeTests.test_utime_invalid_argumentscCs�dd�}|�t��tj|j|d�dfd�Wd�n1s wY|�t��tj|j|d�dfd�Wd�n1sAwY|�t��tj|j|d�dfd�Wd�dS1scwYdS)NcsG�fdd�d�}|�S)NcseZdZ�fdd�ZdS)z?UtimeTests.test_issue31577.<locals>.get_bad_int.<locals>.BadIntcs�Sr*r)r���divmod_ret_valrr�
__divmod__��zJUtimeTests.test_issue31577.<locals>.get_bad_int.<locals>.BadInt.__divmod__N)rNrOrPr�rr�rr�BadInt�sr�r)r�r�rr�r�get_bad_int�sz/UtimeTests.test_issue31577.<locals>.get_bad_int�*rarPr)rarcr�)rhrnrrSr�)r/r�rrr�test_issue31577�s��"�zUtimeTests.test_issue31577r*)rNrOrPrVrDrLrX�staticmethodrYr^r`rrrrSr�rbr�rdr�rhrjrmrqrsr}r~r�rr�r�rrrrr=�s<

	�
�
�


r=)�
mapping_testsc@s@eZdZ	dZdd�Zdd�Zdd�Zdd	�Ze�	e
o ej�
e
�d
�e�	eed�d�d
d���Ze�	e
o9ej�
e
�d
�e�	eed�d�dd���Zdd�Zdd�Zdd�Zdd�Ze�	ejd�dd��Zdd�Ze�dd�d d!��Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Z d.d/�Z!d0d1�Z"d2d3�Z#d4d5�Z$d6d7�Z%dS)8�EnvironTestsNcCsBttj�|_tjrttj�|_|����D]	\}}|tj|<qdSr*)	�dictrr6�_EnvironTests__save�supports_bytes_environ�environb�_EnvironTests__saveb�
_reference�items�r/�keyr"rrrrV�s�zEnvironTests.setUpcCs>tj��tj�|j�tjrtj��tj�|j�dSdSr*)rr6�clear�updater�r�r�r�rUrrrr��s

�zEnvironTests.tearDowncCsdddd�S)NZVALUE1ZVALUE2ZVALUE3)ZKEY1ZKEY2ZKEY3rrUrrrr���zEnvironTests._referencecCstj��tjSr*)rr6r�rUrrr�_empty_mapping�s
zEnvironTests._empty_mappingzrequires a shell�popenzneeds os.popen()cCsdtj��tjjdd�t�dt��}|����}|�|d�Wd�dS1s+wYdS)NZWorld)ZHELLOz%s -c 'echo $HELLO')	rr6r�r�r�rry�stripr;)r/r�r"rrr�test_update2�s
"�zEnvironTests.test_update2cCszt�dt��,}t|�}|�t|�d�|�t|�d�|�t|�d�|�tt|�Wd�dS1s6wYdS)Nz %s -c 'echo "line1
line2
line3"'zline1
zline2
zline3
)rr�r�iterr;�nextrh�
StopIteration)r/r��itrrr�test_os_popen_iter�s�"�zEnvironTests.test_os_popen_itercCs8tj��D]\}}|�t|�t�|�t|�t�qdSr*)rr6r�r;rzr-)r/r��valrrr�test_keyvalue_types�s�z EnvironTests.test_keyvalue_typescCs.|����D]\}}|�tj�|�|�qdSr*)r�r�r;rr6�getr�rrr�
test_items�s�zEnvironTests.test_itemsc
Cs6	tj}|�t|�d�d�dd�|��D����dS)Nzenviron({{{}}})z, css �|]\}}d�||�VqdS)z
{!r}: {!r}N��format)rr�r"rrr�	<genexpr>s
�
�
�z-EnvironTests.test___repr__.<locals>.<genexpr>)rr6r;�reprr�r>r�)r/�envrrr�
test___repr__s
�zEnvironTests.test___repr__cCs\tj�tj�}gd�}dtj�|�i}tj}zt|�t_|�|t���|�|tjdd��W|t_n|t_w|�|t�i��|�dt�ddi��|�|t�|��tj	r�zt
jdd��
dd	d
�}Wd�n1snwYWn	ty}Yn	w|�
ttj|�|�t�ddi�d
g�|�t�dd
i�d
g�|�t�ddi�d
g�dSdS)N)z/montyz/pythonruz/flying/circus�PATH�r��ruruT)�recordr�r�)r��PATHr��abc�abc)r�defpathr��pathsepr>r6r��assertSequenceEqual�
get_exec_pathr��warnings�catch_warnings�BytesWarningrhr�)r/Zdefpath_listZ	test_pathZtest_envZ
saved_environZ	mixed_envrrr�test_get_exec_path
s@
�������zEnvironTests.test_get_exec_pathz#os.environb required for this test.cCs�d}z
|�t��d�}Wnty!dt��f}|�|�Ynw|tjd<|�tjd|�|�tjd|�d}|tjd<|�tjd|�|�	t��d�}|�tjd|�dS)	Nueuro€�surrogateescapez'U+20AC character is not encodable to %sZunicodesunicode��sbytesrK)
r
r7rrrfrr6r;r��decode)r/r"Zvalue_bytesrkZ	value_strrrr�
test_environb3s&
���

zEnvironTests.test_environbcCs�d}d}d|�d�}t���L}|�|d�t�||�tjtjd|gdtj	dd�}|�
|j��t
|��t�|�tjtjd|gdtj	dd�}|�
|j��t
d��Wd�dS1s]wYdS)NZ
PYTHONTESTVARZ	testvaluez%import os; print(repr(os.environ.get(z)))r�T)�check�stdout�text)rZEnvironmentVarGuard�popr�putenvr��runr7r��PIPEr;r��rstripr��unsetenv)r/rr"r�r��procrrr�test_putenv_unsetenvJs 
�
�"�z!EnvironTests.test_putenv_unsetenvrbr�cCs�dD]}|�ttftj|d�|�ttftj|�qtjdkr?dd}|�ttj|d�|�ttjd|�|�ttj|�dSdS)N)ruz=namezna=mezname=znameznamer"r�r���r��X)rhrBr�rr�r�r7r8)r/rZlongstrrrr�test_putenv_unsetenv_error]s
�z'EnvironTests.test_putenv_unsetenv_errorcCs�d}|�|tj�|�t��
}tj|Wd�n1swY|�|jjd|�|�|jj	�|�t��}tj|=Wd�n1sHwY|�|jjd|�|�|jj	�dS)NZ
missingkeyr)
�assertNotInrr6rh�KeyError�assertIsr*r�r[�__suppress_context__)r/Zmissing�cmrrr�
test_key_typems�
�zEnvironTests.test_key_typecCsRt|�}d}t|�dtj|<zt|�|�tj|d�Wtj|=dStj|=w)NZ__new_key__Ztest_environ_iteration)r�r�rr6r;)r/Z
collection�iteratorZnew_keyrrr�_test_environ_iteration{s
z$EnvironTests._test_environ_iterationcC�|�tj�dSr*)r�rr6rUrrr�(test_iter_error_when_changing_os_environ�rz5EnvironTests.test_iter_error_when_changing_os_environcC�|�tj���dSr*)r�rr6r�rUrrr�.test_iter_error_when_changing_os_environ_items��z;EnvironTests.test_iter_error_when_changing_os_environ_itemscCr�r*)r�rr6�valuesrUrrr�/test_iter_error_when_changing_os_environ_values�r�z<EnvironTests.test_iter_error_when_changing_os_environ_valuescCsftrtj�t�s
dSt�t�d|�d���}|����}Wd�n1s&wY|�||�dS)Nz -c 'echo $�')rrr<�existsr�ryr�r;)r/�varrGr�r"rrr�_test_underlying_process_env�s�z)EnvironTests._test_underlying_process_envcCs�d}d}|tj|<dddd|di}ttj�}|�|�tj|B}|�||�|�d||�|��}|�ttj�	|��|�
dd�|�
||�dS�	N�
_TEST_VAR_�original_value�_A_r��_B_�2�3ru)rr6r�r��assertDictEqualr;r�r��NotImplemented�__or__r��r/�overridden_keyr��
new_vars_dictrG�actual�new_vars_itemsrrr�test_or_operator�s



zEnvironTests.test_or_operatorcCs|d}dtj|<dddd|di}ttj�}|�|�tj|O_|�|tj�|�dtj|�|�dd�|�|d�dS)Nr�r�r�r�r�r�r��rr6r�r�r;r�)r/r�r�rGrrr�test_ior_operator�s


zEnvironTests.test_ior_operatorcCs�tj��}|�t��ddi}tj|O_Wd�n1s wY|�t��ddi}tj|O_Wd�n1s@wY|�|tj�dS)Nrar�)rr6�copyrhrnr;)r/Zos_environ_copyZdict_with_bad_keyZdict_with_bad_valrrr�test_ior_operator_invalid_dicts�s
��z,EnvironTests.test_ior_operator_invalid_dictscCszd}dtj|<dd|dff}ttj�}|�|�tj|O_|�|tj�|�dtj|�|�dd�|�|d�dS)Nr�r�)r�r�)r�r�r�r�r�r�)r/r�r�rGrrr�$test_ior_operator_key_value_iterable�s


z1EnvironTests.test_ior_operator_key_value_iterablecCs�d}d}|tj|<dddd|di}t|�}|�tj�|tjB}|�||�|�|||�|��}|�ttj�	|��|�
dd�|�
||�dSr�)rr6r�r�r�r;r�r�r��__ror__r�r�rrr�test_ror_operator�s

zEnvironTests.test_ror_operator)&rNrOrPZ	type2testrVr�r�r�rrrrr<r�rr�r�r�r�r�r�r�r�r�rZrequires_mac_verr�r�r�r�r�r�r�r�r�r�r�r�rrrrr��sN��)�


	
r�c@sXeZdZ	dd�Zdd�Zdd�Zddd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�ZdS)�	WalkTestscKs(d|vr|�d�|d<tj|fi|��S�Nra�followlinks)r�r�walk)r/�top�kwargsrrrr��szWalkTests.walkc	Cs:tjj}|�tjtj�|tjd�|_||jd�|_||jd�|_	||jd�}||d�}||jd�}||jd�}||d�}||d�}||d	�|_
|tjd
�}|tjd
d�}	||d�}
||d
�}||d�}t�|j	�t�|�t�|�t�|�||||	|fD]"}
t|
ddd��}|�
d|
d�Wd�n1s�wYq�t��r�t�tj�|�|j
�t�d|
d�t�|dd�|d�t�|dd�|d�|dd	ggd�f|_n|dgdgf|_t�|d�zt�|�Wnt�y|�tj|tj�YdSwt�|tj�t�|�t�|�|jddd�=dS)NZTEST1�SUB1�SUB11�SUB2ZSUB21�tmp1�tmp2�tmp3�linkZTEST2�tmp4�broken_link�broken_link2�broken_link3r�r�r�zI'm z" and proud of it.  Blame test_os.
ZbrokenTZtmp5)rr	r
rrra)rr<r>r�rr?rS�	walk_path�	sub1_path�
sub11_path�	link_path�makedirsr#r$�can_symlinkr�rv�	sub2_tree�chmod�listdir�PermissionErrorr��S_IRWXUrTr3)r/r>Z	sub2_pathZ
sub21_pathZ	tmp1_pathZ	tmp2_pathZ	tmp3_pathZ	tmp5_pathZt2_pathZ	tmp4_pathZbroken_link_pathZbroken_link2_pathZbroken_link3_pathr<r_rrrrV�sZ








����

zWalkTests.setUpcCs�t|�|j��}|�t|�d�|ddddk}|dd��|dd|d��|dd|d��|�|d|jddgd	gf�|�|d||jd
gdgf�|�|d||jggf�|�|dd||j�dS)Nrurrarr�rc���rrrr)	�listr�rr;r9�sortrr
r�r/�allZflippedrrr�test_walk_topdown=s zWalkTests.test_walk_topdownNcCs�|dur|j}g}|�|�D]\}}}|�|||f�d|vr$|�d�q|�t|�d�|�|d|jdgdgf�|dd��|dd��|�|d|j�dS)Nrrcrrrrar)rr��append�remover;r9rr)r/rrrz�dirsrrrr�test_walk_pruneNs
�zWalkTests.test_walk_prunecCs|�t|j��dSr*)rrrrUrrr�test_file_like_pathar�zWalkTests.test_file_like_pathcCs�t|j|jdd��}|�t|�d|�|ddddk}|dd��|dd|d	��|dd|d��|�|d|jdd
gdgf�|�|||jggf�|�||d|jdgd
gf�|�|dd||j�dS)NF��topdownrur�rarrrcrrrrr)	rr�rr;r9rr
rrrrrr�test_walk_bottom_upds$
�

���zWalkTests.test_walk_bottom_upcCsjt��s	|�d�|j|jdd�}|D]\}}}||jkr-|�|g�|�|dg�dSq|�d�dS)Nzneed symlink supportTrrz+Didn't follow symlink with followlinks=True)rrrfr�rrr;r�)r/�walk_itrzrrrrr�test_walk_symlinkys

�zWalkTests.test_walk_symlinkc
Cs�g}|j|j|jd�}t|�\}}}|�|g�d}tj�||�}tj�||d�}t�||�z5dd�|D�}	|�	|�|�
||	�|�
||	�|D]}
|
|kr\|�tj�||
�|	�qKWt�||�dSt�||�w)N)�onerrorrz.newcSsg|]\}}}|�qSrr)rr��dr_rrrr��z/WalkTests.test_walk_bad_dir.<locals>.<listcomp>)r�rrr�r;rr<r>ror[r�r�)r/�errorsr$rzrr�dir1Zpath1Zpath1new�roots�dir2rrr�test_walk_bad_dir�s&
��zWalkTests.test_walk_bad_dircsd}tj�tjd��tjj�gdg|�R�}t�|���fdd�td�D�}t|d�D]}||r6dgnggf}|D]
}��t|�|�q<tj�	|�}q.��fdd�td�D�}�}t|d�D]"}|||krldgnggf}|D]
}��t|�|�qrtj�|d�}qbdS)	N�Zdeepr'c�g|]	}�j�dd��qS)Fr!�r��r�j��baser/rrr��z7WalkTests.test_walk_many_open_files.<locals>.<listcomp>r�racr/)Tr!r0r1r3rrr�r5)
rr<r>rrSrr�r;r�rF)r/ZdepthrZitersr�rGr�rr3r�test_walk_many_open_files�s$
�z#WalkTests.test_walk_many_open_filesr*)rNrOrPr�rVrrr r#r%r-r6rrrrr��sE
r��fwalkzTest needs os.fwalk()c@sJeZdZ	dd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dZ
dS)�
FwalkTestscks2�|j|fi|��D]\}}}}|||fVq
dSr*)r7)r/r�r�rzrrZroot_fdrrrr��s��zFwalkTests.walkcOstj|i|��Sr*)rr7�r/r�r�rrrr7�rzFwalkTests.fwalkc
Cs�	|��}|��}tjddd�D]O\}}|j||d�|j||d�i}tjdi|��D]\}}}t|�t|�f||<q,|jdi|��D]\}}}}	|�||�|�	||t|�t|�f�qDqdS)N�TFrc��repeat)r"r�)r"rar)
r��	itertools�productr�rr��setr7r�r;)
r/�walk_kwargs�fwalk_kwargsr"rarGrzrr�rootfdrrr�_compare_to_walk�s��zFwalkTests._compare_to_walkcCsdtji}|�||�dS)Nr�)rrSrC)r/r�rrr�test_compare_to_walk��
zFwalkTests.test_compare_to_walkc	CsRz"t�dtj�}dtji}|��}||d<|�||�Wt�|�dSt�|�w)N�.r�r�)rr#r�rrSr�rCrZ)r/r|r@rArrr�test_dir_fd�s
zFwalkTests.test_dir_fdcCs|tjddd�D]4\}}tj|df}|j|d|i�D]!\}}}}t�|�t�|�|�t	t�
|��t	|�t	|�B�qqdS)Nr:rcr;ra)r=r>rrSr7r�fstatr�r;r?r)r/r"rar�rzrrrBrrr�test_yields_correct_dir_fd�s

$��z%FwalkTests.test_yields_correct_dir_fdcCs\t�d�}t�|�td�D]}|�tj�D]}qqt�d�}|�tj|�|�||�dS)Nra�)	rrerZr�r7rrSr�r;)r/Zminfdr�r�Znewfdrrr�test_fd_leak�s

�
zFwalkTests.test_fd_leakN)rNrOrPr�r7rCrDrGrIrKr6rrrrr8�s
r8c@�eZdZ	dd�ZdS)�BytesWalkTestsc	ks��d|vr|�d�|d<tjt�|�fi|��D]8\}}}t�|�}tttj|��}tttj|��}|||fVtttj|��|dd�<tttj|��|dd�<qdSr�)r�rr��fsencoderLr�map)	r/r�r��broot�bdirs�bfilesrzrrrrrr��s�"
�zBytesWalkTests.walkN)rNrOrPr�rrrrrM�srMc@seZdZ	ddd�ZdS)�BytesFwalkTestsrFcos��tjt�|�g|�Ri|��D]:\}}}}t�|�}tttj|��}	tttj|��}
||	|
|fVtttj|	��|dd�<tttj|
��|dd�<qdSr*)rr7rNrLrrO)r/r�r�r�rPrQrR�topfdrzrrrrrr7
s�*
�zBytesFwalkTests.fwalkN)rF)rNrOrPr7rrrrrSsrSc@s^eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	�
ejd
kd�dd��Z
dd�ZdS)�MakedirTestscC�t�tj�dSr*�rr?rrSrUrrrrVrzMakedirTests.setUpc
Cs�tj}tj�|ddd�}t�|�tj�|dddd�}t�|�|�ttjtj�tj�|dddddtj�}t�|�tj�|dtjddddd�}t�|�dS�Nr*r,Zdir3Zdir4Zdir5Zdir6)	rrSrr<r>rrhrB�curdir)r/r4r<rrr�test_makedirs


�zMakedirTests.test_makedircCs�t�d��Wtj}tj�|d�}tj�|d�}t�|d�|�tj�|��|�tj�	|��tj
dkrT|�t�|�j
d@d�|�t�|�j
d@d�Wd�dSWd�dS1s_wYdS)Nrcr*r,im�ntr�i�)rZ
temp_umaskrSrr<r>rr[r��isdirrr;r�r)r/r4�parentr<rrr�	test_mode's
�"�zMakedirTests.test_modecCs�tj�tjd�}d}t�d�}t�||�|�ttj||�|jttj||dd�tj|ddd�tj||dd�t�|�tjtj�	d	�dd�dS)
Nr*r��F��exist_oki�T)r�ra�/)
rr<r>rrS�umaskrrhrBrv)r/r<r��old_maskrrr� test_exist_ok_existing_directory3s

z-MakedirTests.test_exist_ok_existing_directoryc	Cs�tj�tjd�}tj}d}t�d�}zdt�t�	tj�j
�}zt�tj||B�Wnty4t
�d��wt�	tj�j
|@|krEt
�d��t�|||B�tj||dd�t�|t�t�	|�j
�|@�tj|||Bdd�Wt�|�dSt�|�w)Nr*r�r_zCannot set S_ISGID for dir.z No support for S_ISGID dir mode.Tr`)rr<r>rrSr��S_ISGIDrc�S_IMODE�lstatrrrr�SkipTestr)r/r<rfr�rdZexisting_testfn_moderrr�test_exist_ok_s_isgid_directoryAs(
�
�
 z,MakedirTests.test_exist_ok_s_isgid_directorycCs�tj}tj�tjd�}t|ddd��
}|�d�Wd�n1s"wY|�ttj	|�|jttj	|dd�|jttj	|dd�t�
|�dS)	Nr*r,r�r�r�Fr`T)rrSrr<r>r#r$rhrBrr)r/r4r<r_rrr�#test_exist_ok_existing_regular_file\s�z0MakedirTests.test_exist_ok_existing_regular_filer[zrequires WindowscCsdtj}tj�tj�tjd��}tj|dd�tjd|dgdd�}t�	|�|�
|��|�d��dS)	Nr�i�)r�z	cacls.exez/sZoemr�z6 "D:P(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICI;FA;;;OW)")rrSrr<rvr>r?r��check_outputr3r;r�)r/r4r<�outrrr�test_win32_mkdir_700fs
�z!MakedirTests.test_win32_mkdir_700c	Cs`tj�tjdddddd�}tj�|�s)|tjkr)tj�|�}tj�|�s)|tjkst�|�dSrX)rr<r>rrSr�rF�
removedirs�r/r<rrrr�rs��zMakedirTests.tearDownN)rNrOrPrVrZr^rerjrkrrrrrnr�rrrrrUs

rU�chownzTest needs chownc@s�eZdZedd��Zdd�Ze�ee	d�d�dd��Z
e�eo$ee
�d	kd
�dd��Ze�eo5ee
�d	kd
�dd��Zedd��ZdS)�ChownFileTestscCrVr*rW��clsrrr�
setUpClass�rozChownFileTests.setUpClasscCs�t�tj�}|j}|j}ddt�d�t�	dd�fD]}|�
ttjtj||�|�
ttjtj||�q|�
t�tj||��|�
t�tjdd��dS)Ng�y��r���rc)rr�rrS�st_uid�st_gid�decimalZDecimal�	fractionsZFractionrhrnrq�assertIsNone)r/r��uid�gidr"rrr�*test_chown_uid_gid_arguments_must_be_index�sz9ChownFileTests.test_chown_uid_gid_arguments_must_be_index�	getgroupszneed os.getgroupscCs�t��}t|�dkr|�d�|dd�\}}t�tj�j}t�tj||�t�tj�j	}|�
||�t�tj||�t�tj�j	}|�
||�dS)Nrcztest needs at least 2 groups)rrr9rfr�rrSrwrqrxr;)r/�groupsZgid_1Zgid_2r|r}rrr�test_chown_gid�s
zChownFileTests.test_chown_gidraz0test needs root privilege and more than one usercCsvtdd�\}}t�tj�j}t�tj||�t�tj�j}|�||�t�tj||�t�tj�j}|�||�dS�Nrc)	�	all_usersrr�rrSrxrqrwr;)r/�uid_1�uid_2r}r|rrr�test_chown_with_root�sz#ChownFileTests.test_chown_with_rootz2test needs non-root account and more than one usercCsntdd�\}}t�tj�j}|�t��t�tj||�t�tj||�Wd�dS1s0wYdSr�)	r�rr�rrSrxrhrrq)r/r�r�r}rrr�test_chown_without_permission�s"�z,ChownFileTests.test_chown_without_permissioncCrVr*)rr3rrSrsrrr�
tearDownClass�rozChownFileTests.tearDownClassN)rNrOrP�classmethodrur~rrrrr��
root_in_posixr9r�r�r�r�rrrrrr~s 


�

�
rrc@�4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�RemoveDirsTestscCrVr*)rrrrSrUrrrrV�rzRemoveDirsTests.setUpcCst�tj�dSr*)rr?rSrUrrrr��rzRemoveDirsTests.tearDowncCsxtj�tjd�}t�|�tj�|d�}t�|�t�|�|�tj�|��|�tj�|��|�tj�tj��dS)N�dira�dirb)	rr<r>rrSr?ro�assertFalser��r/r�r�rrr�test_remove_all�s


zRemoveDirsTests.test_remove_allcCs�tj�tjd�}t�|�tj�|d�}t�|�ttj�|d��t�|�|�tj�	|��|�
tj�	|��|�
tj�	tj��dS�Nr�r��file.txt)rr<r>rrSr?r'ror�r�r[r�rrr�test_remove_partial�s


z#RemoveDirsTests.test_remove_partialcCs�tj�tjd�}t�|�tj�|d�}t�|�ttj�|d��|�t��
t�	|�Wd�n1s7wY|�
tj�|��|�
tj�|��|�
tj�tj��dSr�)rr<r>rrSr?r'rhrBror[r�r�rrr�test_remove_nothing�s

�z#RemoveDirsTests.test_remove_nothingN)rNrOrPrVr�r�r�r�rrrrr��s
r�c@�eZdZdd�ZdS)�DevNullTestscCs�ttjdd��}|�d�|��Wd�n1swYttjd��}|�|��d�Wd�dS1s:wYdS)Nrcr�hellor��)r#r�devnullr$rZr;ryr^rrr�test_devnull�s

�"�zDevNullTests.test_devnullN)rNrOrPr�rrrrr���r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�URandomTestscCsr|�tt�d��d�|�tt�d��d�|�tt�d��d�|�tt�d��d�|�tt�d��d�dS)Nrrarbr�r4)r;r9r�urandomrUrrr�test_urandom_length�s
z URandomTests.test_urandom_lengthcCs0t�d�}|�|t�t�d�}|�||�dS�N�)rr�r,rKr8�r/Zdata1Zdata2rrr�test_urandom_value�s

zURandomTests.test_urandom_valuecCs<d�dd|ddf�}td|�}|d}|�t|�|�|S)N�
zimport os, syszdata = os.urandom(%s)zsys.stdout.buffer.write(data)zsys.stdout.buffer.flush()r�ra)r>rr;r9)r/�countr�rmr�rrr�get_urandom_subprocess�s�
z#URandomTests.get_urandom_subprocesscCs$|�d�}|�d�}|�||�dSr�)r�r8r�rrr�test_urandom_subprocess�

z$URandomTests.test_urandom_subprocessN)rNrOrPr�r�r�r�rrrrr��s
r��	getrandomzneed os.getrandom()c@s@eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�GetRandomTestsc
CsBzt�d�WdSty }z|jtjkrt�d���d}~ww)Nraz%getrandom() syscall fails with ENOSYS)rr�rBrCr�rri)rtrHrrrru
s
��zGetRandomTests.setUpClasscCs*t�d�}|�|t�|�t|�d�dSr�)rr�r,rKr;r9�r/r�rrr�test_getrandom_types
z"GetRandomTests.test_getrandom_typecCst�d�}|�|d�dS)Nrr�)rr�r;)r/�emptyrrr�test_getrandom0rEzGetRandomTests.test_getrandom0cCs|�ttd��dS)N�GRND_RANDOM)r[rrrUrrr�test_getrandom_random"r�z$GetRandomTests.test_getrandom_randomcCs*z
t�dtj�WdStyYdSw�Nra)rr��
GRND_NONBLOCK�BlockingIOErrorrUrrr�test_getrandom_nonblock(s
�z&GetRandomTests.test_getrandom_nonblockcCs$t�d�}t�d�}|�||�dSr�)rr�r8r�rrr�test_getrandom_value0r�z#GetRandomTests.test_getrandom_valueN)
rNrOrPr�rur�r�r�r�r�rrrrr�s
r�ZHAVE_GETENTROPYraZHAVE_GETRANDOMZHAVE_GETRANDOM_SYSCALLz*os.random() does not use a file descriptorr3z$VxWorks can't set RLIMIT_NOFILE to 1c@s0eZdZe�ed�dd��Zdd�Zdd�ZdS)	�URandomFDTestsz!test requires the resource modulecCsd}td|�dS)Na�if 1:
            import errno
            import os
            import resource

            soft_limit, hard_limit = resource.getrlimit(resource.RLIMIT_NOFILE)
            resource.setrlimit(resource.RLIMIT_NOFILE, (1, hard_limit))
            try:
                os.urandom(16)
            except OSError as e:
                assert e.errno == errno.EMFILE, e.errno
            else:
                raise AssertionError("OSError not raised")
            r�rr�rrr�test_urandom_failureBsz#URandomFDTests.test_urandom_failurecCsd}td|�\}}}dS)Naif 1:
            import os
            import sys
            import test.support
            os.urandom(4)
            with test.support.SuppressCrashReport():
                os.closerange(3, 256)
            sys.stdout.buffer.write(os.urandom(4))
            �-Scr)r/r��rcrm�errrrr�test_urandom_fd_closedYs	z%URandomFDTests.test_urandom_fd_closedcCs�|�tjtj�ttjd�djtjd�}td|�\}}}|�t|�d�|�	|dd�|dd��td|�\}}}|�t|�d�|�	||�dS)Nsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxa�if 1:
            import os
            import sys
            import test.support
            os.urandom(4)
            with test.support.SuppressCrashReport():
                for fd in range(3, 256):
                    try:
                        os.close(fd)
                    except OSError:
                        pass
                    else:
                        # Found the urandom fd (XXX hopefully)
                        break
                os.closerange(3, 256)
            with open({TESTFN!r}, 'rb') as f:
                new_fd = f.fileno()
                # Issue #26935: posix allows new_fd and fd to be equal but
                # some libc implementations have dup2 return an error in this
                # case.
                if new_fd != fd:
                    os.dup2(new_fd, fd)
                sys.stdout.buffer.write(os.urandom(4))
                sys.stdout.buffer.write(os.urandom(4))
            )rSr�r�rru)
r�rrTrSr'r�rr;r9r8)r/r�r�rmr�Zout2Zerr2rrr�test_urandom_fd_reopenedgs�z'URandomFDTests.test_urandom_fd_reopenedN)	rNrOrPrr�resourcer�r�r�rrrrr�=s


r�c#s��	g��fdd�}�fdd�}z%tj}tj}tj}|t_|t_|dur'|t_�VW|t_|t_|t_dS|t_|t_|t_w)Ncs��d||f�td��)N�execvzexecv called)r�RuntimeError�rr���callsrr�
mock_execv�sz#_execvpe_mockup.<locals>.mock_execvcs��d||f�ttjd��)N�execvez
execve called)rrBrCZENOTDIRr�r�rr�mock_execve�sz$_execvpe_mockup.<locals>.mock_execve)rr�r�r�)r�r�r�Z
orig_execvZorig_execveZorig_defpathrr�r�_execvpe_mockup�s(�
�r�r�zneed os.execv()c@steZdZe�ed�dd��Zdd�Zdd�Ze�	e
ed�d	�d
d��Zdd
�Z
dd�Ze�	ejdkd�dd��ZdS)�	ExecTestsz4avoid triggering a linuxthreads bug: see issue #4970cCs|�ttjddgd�dS)Nzno such app-)rhrBr�execvperUrrr�test_execvpe_with_bad_program�s�z'ExecTests.test_execvpe_with_bad_programcCsN|�ttjdd�|�ttjdg�|�ttjdd�|�ttjddg�dS)N�notepadrr�ru)rhr�rr�rUrrr�test_execv_with_bad_arglist�sz%ExecTests.test_execv_with_bad_arglistcCsB|�ttjdgd�|�ttjdgi�|�ttjddgi�dS)Nr�ru)rhr�rr�rUrrr�test_execvpe_with_bad_arglist�sz'ExecTests.test_execvpe_with_bad_arglist�_execvpez)No internal os._execvpe function to test.c
Cs�tjd}|turd}tj�t�|�|�}|}gd�}nd}gd�}tj�||�}tjdkr4t�|�}n|}ddi}t��%}|�t	tj
||�|�t|�d	�|�|d
d||ff�Wd�n1sewYt|d��(}|jt
tj
|||d
�|�t|�d	�|�|d
d|||ff�Wd�n1s�wYt��:}|��}	|tur�||	d<n||	d<|jt
tj
|||	d
�|�t|�d	�|�|d
d|||	ff�Wd�dS1s�wYdS)NZabsolutepaths
executable)sprogname�arg1�arg2r�)Zprognamer�r�r[Zspamr�rarr�)r�r�r�r�r�)rr=rKr<r>rNrr�rhr�r�r;r9rBr�r�)
r/Z	test_typeZprogram_pathZprogram�fullpathZnative_fullpathZ	argumentsr�r�Zenv_pathrrr�_test_internal_execvpe�sT


��
�
��	

�
�"�z ExecTests._test_internal_execvpecCs&|�t�tjdkr|�t�dSdS)Nr[)r�r-rrrKrUrrr�test_internal_execvpe_str�s

�z#ExecTests.test_internal_execvpe_strcCs�tjddg}tj��}d|d<|�t��t�|d||�Wd�n1s(wYtj��}d|d<|�t��t�|d||�Wd�n1sOwYtj��}d|d	<|�t��t�|d||�Wd�dS1swwYdS)
Nr��pass�cabbage�FRUITVEGETABLEr�orangeVEGETABLE=cabbage�FRUIT�lemon�FRUIT=ORANGE)r7r�rr6r�rhr�r�)r/r��newenvrrr�test_execve_invalid_env�s 
�
�
"�z!ExecTests.test_execve_invalid_envr�zWin32-specific testc
Csdz
t�ddgi�Wn ty*}z|�|jdup|jdk�WYd}~dSd}~ww|�d�dS)Nru�argrzNo OSError raised)rr�rBr[Zwinerrorr�r(rrr�test_execve_with_empty_paths(��z%ExecTests.test_execve_with_empty_pathN)rNrOrPr�skipIf�USING_LINUXTHREADSr�r�r�rrrr�r�r�r7r8r�rrrrr��s�
�
/r�r�r'c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�Win32ErrorTestsc
Cszzt�tj�Wn*tyd}YdSty2}zd}|�dtj|f�WYd}~dSd}~ww|�dtj�dS)NFTz.file %s must not exist; os.stat failed with %szfile %s must not exist)rr�rrSrArBr�)r/r�rHrrrrVs
���zWin32ErrorTests.setUpcCs|�ttjtjtjd�dS)Nz.bak)rhrBrrorrSrUrrrrr'szWin32ErrorTests.test_renamecC�|�ttjtj�dSr*)rhrBrrrrSrUrrr�test_remove*r zWin32ErrorTests.test_removecCr�r*)rhrBrr@rrSrUrrr�
test_chdir-r zWin32ErrorTests.test_chdircCsT|�tjtj�ttjd��}|�ttjtj�Wd�dS1s#wYdS)Nr�)	r�rrTrSr#rhrBrr?r^rrr�
test_mkdir0s"�zWin32ErrorTests.test_mkdircCs|�ttjtjd�dSr*)rhrBrrSrrSrUrrrrX6�zWin32ErrorTests.test_utimecCs|�ttjtjd�dSrl)rhrBrrrrSrUrrr�
test_chmod9r�zWin32ErrorTests.test_chmodN)
rNrOrPrVrrr�r�r�rXr�rrrrr�sr�c@s�eZdZgd�Zdd�ZeD]Zee�e�de<qdd�Zdd�Ze	�
eed	�d
�dd��Z
e	�
eed
�d�dd��Ze	�
eed�d�dd��Ze	�
eed�d�dd��Ze	�
eed�d�dd��Ze	�
eed�d�dd��Ze	�
eed�d �d!d"��Ze	�
eed#�d$�d%d&��Ze	�
eed'�d(�d)d*��Ze	�
eed+�d,�d-d.��Ze	�
eed/�d0�d1d2��Ze	�
eed3�d4�d5d6��Ze	�
eed7�d8�d9d:��Ze	�
eed;�d<�d=d>��Zd?d@�Ze	�
eedA�dB�dCdD��ZdES)F�
TestInvalidFD)�fchdirre�	fdatasyncrH�fstatvfs�fsync�	tcgetpgrp�ttynamecs�fdd�}|S)Ncs"tt��r|�tt���dSdSr*)rrr�r�rU�r_rr�helperCs
�z(TestInvalidFD.get_single.<locals>.helperr)r_r�rr�r�
get_singleBszTestInvalidFD.get_singleZtest_c
Oshz|t��g|�Ri|��Wnty*}z|�|jtj�WYd}~dSd}~ww|�d|�dS)Nz5%r didn't raise an OSError with a bad file descriptor)r�make_bad_fdrBr;rCr+r�)r/r_r�r�r�rrrr�Js��
�zTestInvalidFD.checkcCs|jtjdd�dS)Nr�r�)r�rr�rUrrrr�Sr�zTestInvalidFD.test_fdopen�isattyztest needs os.isatty()cCs|�t�t���d�dS�NF)r;rr�rr�rUrrr�test_isattyVszTestInvalidFD.test_isattyrgztest needs os.closerange()c	Csnt��}td�D]}z	t�||�Wn	tyYqw|dkr't�d��|�t�	|||d�d�dS)Nrbrcz5Unable to acquire a range of invalid file descriptorsra)
rr�r�rrHrBrrir;rg)r/r|r�rrrrkZs�� zTestInvalidFD.test_closerange�dup2ztest needs os.dup2()cC�|�tjd�dS)N�)r�rr�rUrrr�	test_dup2jrUzTestInvalidFD.test_dup2c
Cs�t�ttj�}|�tj|�|ddg}tj|dd�D]C\}}||kr]|j||d��,|�	t
��}t�||�Wd�n1s@wY|�|j
jtj�Wd�n1sXwYqdS)Nri�rcr;)r|�fd2)rr#r�r�r�rZr=r>�subTestrhrBr�r;r*rCr+)r/Zvalid_fdZfdsr|r�r-rrr�test_dup2_negative_fdns �����z#TestInvalidFD.test_dup2_negative_fd�fchmodztest needs os.fchmod()cCr�rl)r�rr�rUrrr�test_fchmod~rUzTestInvalidFD.test_fchmod�fchownztest needs os.fchown()cC�|�tjdd�dS)Nr)r�rr�rUrrr�test_fchown��zTestInvalidFD.test_fchown�	fpathconfztest needs os.fpathconf()cC� |�tjd�|�tjd�dS)N�PC_NAME_MAX)r�r�pathconfrrUrrr�test_fpathconf��zTestInvalidFD.test_fpathconf�	ftruncateztest needs os.ftruncate()cCrrl)r�r�truncaterrUrrr�test_ftruncate�rzTestInvalidFD.test_ftruncaterxztest needs os.lseek()cCr�rl)r�rrxrUrrr�
test_lseek�rzTestInvalidFD.test_lseekryztest needs os.read()cCr�r�)r�rryrUrrrr~�rUzTestInvalidFD.test_read�readvztest needs os.readv()cCstd�}|�tj|g�dS)Nrb)r�r�rr)r/r{rrr�
test_readv�szTestInvalidFD.test_readv�	tcsetpgrpztest needs os.tcsetpgrp()cCr�rl)r�rrrUrrr�test_tcsetpgrpt�rUzTestInvalidFD.test_tcsetpgrptr$ztest needs os.write()cCr�)N� )r�rr$rUrrrr��rUzTestInvalidFD.test_write�writevztest needs os.writev()cCs|�tjdg�dS)Nr�)r�rrrUrrr�test_writev�rzTestInvalidFD.test_writevcC�|�tj�|�tjd�dS�NT)r�r�get_inheritable�set_inheritablerUrrr�test_inheritable��zTestInvalidFD.test_inheritable�get_blocking�-needs os.get_blocking() and os.set_blocking()cCrr)r�rr�set_blockingrUrrr�
test_blocking�szTestInvalidFD.test_blockingN)rNrOrPZsinglesr�r_�localsr�r�rrrrr�rkr�r�r�rrr
rr~r
rr�rrrrrrrr�=sP	













�r�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�	LinkTestscCs tj|_tj�tjd�|_dS)Nr�)rrS�file1rr<r>�file2rUrrrrV��zLinkTests.setUpcCs,|j|jfD]
}tj�|�rt�|�qdSr*)rr rr<r�rT)r/�filerrrr��s

��zLinkTests.tearDownc
Cs�t|�zt�||�Wnty%}z
|�d|�WYd}~nd}~wwt|d��4}t|d��}|�tj�|�	�|�	���Wd�n1sJwYWd�dSWd�dS1sbwYdS)N�
os.link(): %sr�)
r'rrrrfr#r[r<�sameopenfilerw)r/rr r�r>�f2rrr�
_test_link�s��P�zLinkTests._test_linkcCs|�|j|j�dSr*)r&rr rUrrr�	test_link�r�zLinkTests.test_linkcCs(|�t|jt���t|jt����dSr*)r&rKrr7rr rUrrr�test_link_bytes�s�zLinkTests.test_link_bytescCsVzt�d�Wntyt�d��w|jd7_|jd|_|�|j|j�dS)N�ñz#Unable to encode for this platform.r�)rrN�UnicodeErrorrrirr r&rUrrr�test_unicode_name�s
�zLinkTests.test_unicode_nameN)	rNrOrPrVr�r&r'r(r+rrrrr�s
rzPosix specific testsc@s�eZdZdZdZe�eed�d�dd��Z	e�eed�d�dd	��Z
e�eed
�d�dd
��Ze�eed�d�dd��Ze�eed�d�dd��Z
e�eed�d�dd��Ze�eed�d�dd��Ze�eed�d�dd��ZdS)�PosixUidGidTests��setuidztest needs os.setuid()cCsBt��dkr|�ttjd�|�ttjd�|�ttj|j�dS�Nrz
not an int)r�getuidrhrBr.rn�
OverflowError�UID_OVERFLOWrUrrr�test_setuid��zPosixUidGidTests.test_setuid�setgidztest needs os.setgid()cC�Ft��dkrts|�ttjd�|�ttjd�|�ttj|j�dSr/)	rr0�HAVE_WHEEL_GROUPrhrBr5rnr1�GID_OVERFLOWrUrrr�test_setgid��zPosixUidGidTests.test_setgid�seteuidztest needs os.seteuid()cCsBt��dkr|�ttjd�|�ttjd�|�ttj|j�dSr/)	rr0rhrBr;rn�setegidr1r2rUrrr�test_seteuid�r4zPosixUidGidTests.test_seteuidr<ztest needs os.setegid()cCr6r/)	rr0r7rhrBr<rnr1r8rUrrr�test_setegid�r:zPosixUidGidTests.test_setegid�setreuidztest needs os.setreuid()cCsnt��dkr|�ttjdd�|�ttjdd�|�ttjdd�|�ttj|jd�|�ttjd|j�dSr/)rr0rhrBr?rnr1r2rUrrr�
test_setreuid�szPosixUidGidTests.test_setreuidcC�t�tjddg�dS)Nr�z,import os,sys;os.setreuid(-1,-1);sys.exit(0)�r�r7r7r�rUrrr�test_setreuid_neg1	�
�z#PosixUidGidTests.test_setreuid_neg1�setregidztest needs os.setregid()cCsrt��dkrts|�ttjdd�|�ttjdd�|�ttjdd�|�ttj|jd�|�ttjd|j�dSr/)	rr0r7rhrBrErnr1r8rUrrr�
test_setregid	szPosixUidGidTests.test_setregidcCrA)Nr�z,import os,sys;os.setregid(-1,-1);sys.exit(0)rBrUrrr�test_setregid_neg1	rDz#PosixUidGidTests.test_setregid_neg1N)rNrOrPr2r8rrrrr3r9r=r>r@rCrFrGrrrrr,�s&






r,c@sNeZdZdd�Zdd�Zdd�Zdd�Ze�e	e
d	�d
�dd��Zd
d�ZdS)�Pep383Testscs�tjrtj|_ntjrtj|_ntj|_t�|j�|_g��fdd�}|tj�tjr0|tj�tjr8|tj��s?|�	d�t
�|_t�|j�z'�D]!}t�
tj�|j|��t�|�}||jvrgtd��|j�|�qLWdSt�|j��)Ncs2zt�|�}Wn
tyYdSw��|�dSr*)rrNrr)�fn��bytesfnrr�add_filename)	s�z'Pep383Tests.setUp.<locals>.add_filenamez&couldn't create any non-ascii filenamezduplicate filename)r�TESTFN_UNENCODABLEr�ZTESTFN_NONASCIIrSrrNZbdirZTESTFN_UNICODErfr?�	unicodefnr?Zcreate_empty_filer<r>rLr��add�shutilr?)r/rLrIrrJrrV	s8







�zPep383Tests.setUpcCst�|j�dSr*)rPr?r�rUrrrr�D	rzPep383Tests.tearDownc	Cst|j}tt�|j��}|�||�t��}zt�tj�|�tt���tt�tj���Wt�|�dSt�|�wr*)	rNr?rrr�r;r+r@r=)r/rG�foundZcurrent_directoryrrr�test_listdirG	s"zPep383Tests.test_listdircCs.|jD]}ttj�|j|�d�}|��qdS�Nr�)rNr#rr<r>r�rZ)r/rIr_rrr�	test_openS	s

�zPep383Tests.test_openrr%cCs*|jD]}tj�|j|�}t�|�qdSr*)rNrr<r>r�r)r/rI�fullnamerrr�test_statvfsX	s
�zPep383Tests.test_statvfscCs&|jD]
}t�tj�|j|��qdSr*)rNrr�r<r>r�)r/rIrrr�	test_stata	s
�zPep383Tests.test_statN)
rNrOrPrVr�rRrTrrrrrVrWrrrrrH	s%�
rHc@sFeZdZdd�Zdd�Zdd�Zdd�Ze�d	�d
d��Z	dd
�Z
dS)�Win32KillTestscCs�ddl}ddlm}ddl}|jjj}|j|_|j|�	|j
�|j|�	|j�|�	|j�|�	|j�f|_d}t
jtjdd�|�gt
jt
jt
jd�}|�|jj�|�|jj�|�|jj�d\}}	||	kr�|��dur�|�t|��}
||�|j���|
|�|
�ddd�}|�|dd�|
jr�|� ||
j�!��nt"�#d	�|d
7}||	kr�|��dusj|�$d�t%�&|j'|�|� |�(�|�dS)Nr��wintypes�runningr�z<import sys;sys.stdout.write('{}');sys.stdout.flush();input())r��stderr�stdin�rr�zPeekNamedPipe failed皙�����?raz1Did not receive communication from the subprocess))rwrZ�msvcrtrxry�
PeekNamedPipe�BOOL�restype�HANDLE�POINTERZc_char�DWORD�argtypesr��Popenr7r�r�r�r�r�rZr\r]�pollZcreate_string_bufferr9Z
get_osfhandlerwZsizeofr8r"r;r�rl�sleepr�r�kill�pid�wait)r/ZsigrwrZr`rarkr�r��maxr{Zrsltrrr�_killg	sP




�
���
�
zWin32KillTests._killcCr�r*)ro�signal�SIGTERMrUrrr�test_kill_sigterm�	roz Win32KillTests.test_kill_sigtermcCs|�d�dS)Nr�)rorUrrr�
test_kill_int�	szWin32KillTests.test_kill_intcCs�dt��}t�dd|�}d|d<tjtjtj�	tj�
t�d�|gtjd�}d\}}||krN|�
�durN|ddkr;n t�d�|d7}||krN|�
�dus4t�|jtj�|�d	�t�|j|�t�d
�|�
�s}t�|jtj�|�d�|��dSdS)Nz
test_os_%srrarzwin_console_handler.pyr5r^r_z'Subprocess didn't finish initializationg�?zsubprocess did not stop on {})�uuidZuuid1�mmapr�rhr7r�rr<r>rFr�ZCREATE_NEW_PROCESS_GROUPrirlrjrkrlrp�SIGINTr�r�)r/ZeventrZtagname�mr�r�rnrrr�_kill_with_event�	s4���
�

�zWin32KillTests._kill_with_eventz.subprocesses aren't inheriting Ctrl+C propertycCsdddlm}ddl}|�|j��}|jjj}|�|j�|jf|_|j|_	||d�|�
tjd�dS)NrrY�CTRL_C_EVENT)
rwrZreZc_intrxry�SetConsoleCtrlHandlerrbrgrcrxrpry)r/rZrwZNULLrzrrr�test_CTRL_C_EVENT�	s

�
z Win32KillTests.test_CTRL_C_EVENTcCr�)N�CTRL_BREAK_EVENT)rxrpr|rUrrr�test_CTRL_BREAK_EVENT�	�z$Win32KillTests.test_CTRL_BREAK_EVENTN)rNrOrProrrrsrxr�skipr{r}rrrrrXe	s6
rXc@s.eZdZ	dd�Zdd�Zdd�Zdd�Zd	S)
�Win32ListdirTestsc	Cs�g|_td�D]E}d|}tj�tj|�}d|}tj�tj|�}t�|�t|ddd��}|�	d|�Wd�n1s?wY|j�
||g�q|j��dS)NrczSUB%dzFILE%dr,r�r�z'I'm %s and proud of it. Blame test_os.
)�
created_pathsr�rr<r>rrSrr#r$�extendr)r/r�Zdir_nameZdir_path�	file_nameZ	file_pathr_rrrrV�	s
�zWin32ListdirTests.setUpcCrVr*)rPr?rrSrUrrrr��	rzWin32ListdirTests.tearDowncCsJ	|�tt�tj��|j�|�tt�t�tj���dd�|jD��dS)NcS�g|]}t�|��qSr�rrN�rr<rrrr�	r(zCWin32ListdirTests.test_listdir_no_extended_path.<locals>.<listcomp>)r;�sortedrrrrSr�rNrUrrr�test_listdir_no_extended_path�	s��z/Win32ListdirTests.test_listdir_no_extended_pathcCsj	dtj�tj�}|�tt�|��|j�dt�	tj�tj��}|�tt�|��dd�|jD��dS)N�\\?\�\\?\cSr�rr�r�rrrr
r(z@Win32ListdirTests.test_listdir_extended_path.<locals>.<listcomp>)
rr<rvrrSr;r�rr�rNrprrr�test_listdir_extended_path�	s��z,Win32ListdirTests.test_listdir_extended_pathN)rNrOrPrVr�r�r�rrrrr��	s
r��readlinkzneeds os.readlink()c@szeZdZdZej�e�Ze�	e�Z
e�	e�Zdd�Zdd�Z
dd�Zdd	�Zejd
d��Zejdd
��Zejdd��ZdS)�
ReadlinkTestsZreadlinktestcCsbtj�|�}tj�|�}tjdkr)dd�}||�r|dd�}||�r)|dd�}|�||�dS)Nr�cSs|�t|t�r
d�Sd�S)Nr�r�)�
startswithrrK)rrrrr�
s
��z/ReadlinkTests.assertPathEqual.<locals>.<lambda>ru)rr<�normcaser7r8r;)r/�left�rightZ
has_prefixrrr�assertPathEqual
s
zReadlinkTests.assertPathEqualcCsT|�tj�|j��|�tj�|j��|�tj�|j��|�tj�|j��dSr*)	r[rr<r��filelink_target�filelinkb_targetr��filelink�	filelinkbrUrrrrV
szReadlinkTests.setUpcCs0t|j�}|�ttj|j�|�ttj|�dSr*)rr�rhrBrr�)r/r�rrr�test_not_symlink$
s
zReadlinkTests.test_not_symlinkcCs(|�ttjd�|�ttjtd��dS)Nzmissing-link)rhrArr�rrUrrr�test_missing_link)
s
�zReadlinkTests.test_missing_linkcCsBt�|j|j�|�tj|j�t|j�}|�t�	|�|j�dSr*)
rr�r�r�r�rrTrr�r�)r/r�rrr�
test_pathlike.
s
zReadlinkTests.test_pathlikecCsNt�|j|j�|�tj|j�t�t|j��}|�	||j�|�
|t�dSr*)rr�r�r�r�rrTr�rr�r,rKrprrr�test_pathlike_bytes5
s
z!ReadlinkTests.test_pathlike_bytescCsJt�|j|j�|�tj|j�t�|j�}|�||j�|�	|t
�dSr*)rr�r�r�r�rrTr�r�r,rKrprrr�
test_bytes=
s
zReadlinkTests.test_bytesN)rNrOrPr�rr<rvr�r�rNr�r�r�rVr�r�r�skip_unless_symlinkr�r�r�rrrrr�	
s



r�c@s�eZdZdZej�e�ZdZ	ej�
e�ZdZdd�Z
dd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Ze�ej�d�oKej�d�d�dd��Zdd�Zdd �Zd!S)"�Win32SymlinkTestsZfilelinktestZdirlinktestzmissing linkcC�dSr*rrUrrrrVO
r�zWin32SymlinkTests.setUpcCsVtj�|j�r
t�|j�tj�|j�rt�|j�tj�|j�r)t�|j�dSdSr*)	rr<r�r�r�dirlinkr3rR�missing_linkrUrrrr�V
s�zWin32SymlinkTests.tearDowncC�`t�|j|j�|�tj�|j��|�tj�|j��|�tj�|j��|�	|j|j�dSr*)
rr��dirlink_targetr�r[r<r�r\�islink�
check_statrUrrr�test_directory_link^
�
z%Win32SymlinkTests.test_directory_linkcCr�r*)
rr�r�r�r[r<r��isfiler�r�rUrrr�test_file_linke
r�z Win32SymlinkTests.test_file_linkcCs8	|j}tj�|�rt�|�d}d}t�|||�dS)Nz"c:\\target does not exist.29r3c740T)r�rr<rRrr�)r/Zlinknamer�Z
target_is_dirrrr�_create_missing_dir_linkl
s
z*Win32SymlinkTests._create_missing_dir_linkcC�|��t�|j�dSr*)r�rrr�rUrrr�,test_remove_directory_link_to_missing_targetv
sz>Win32SymlinkTests.test_remove_directory_link_to_missing_targetcCs |��|�tj�|j��dSr*)r�r�rr<r\r�rUrrr�.test_isdir_on_directory_link_to_missing_target}
r!z@Win32SymlinkTests.test_isdir_on_directory_link_to_missing_targetcCr�r*)r�rr3r�rUrrr�.test_rmdir_on_directory_link_to_missing_target�
r2z@Win32SymlinkTests.test_rmdir_on_directory_link_to_missing_targetcCsn|�t�|�t�|��|�t�|�t�|��t�|�}|�t�|�t�|��|�t�|�t�|��dSr*)r;rr�r8rhrN)r/rr�Z
bytes_linkrrrr��
s

zWin32SymlinkTests.check_statc	CsHtj�tj�}tj�|d�}tj�|d�}|�tj|�t�|�t�|�t�|�tj�tj�|d��}t	|�t�
�}z_t�|�tj�|d�}t�tj�
|�d�|�dt�t�
���|�t�|�t�d��t�|�|�t�|�t�tj�
|���t�|�|�t�|�t�tj�
|���Wt�|�dSt�|�w)N�level2�level3rr)rr<rvrrSr>r�r?r?r'r+r@r��relpathr�rr;r�)r/Zlevel1r�r�rZorig_dirrrrr�
test_12084�
s2




�
�zWin32SymlinkTests.test_12084�C:\Users\All Users�C:\ProgramDatazTest directories not foundcCs"t�d�}|�tj�|d��dS)Nr�r�)rr�r[r<�samefile)r/r�rrr�
test_29248�
s
zWin32SymlinkTests.test_29248c	Cs�d}tjj|gd�}d||f||f|dd�|dd�fg}|D]O\}}zt�||�Wn	ty7Ynwzt�|�Wn	tyHYnwzt�t�|�t�|��Wn	ty`Yq"wzt�|�Wq"tyqYq"wdS)NZXXXXXXXXXXXXXXXXXXXXXXXXXXXrbrt�)rr<r>r�rArrBrN)r/Zsegmentr<Z
test_casesr��destrrr�test_buffer_overflow�
s8
������z&Win32SymlinkTests.test_buffer_overflowcs�tj�d��tj���s|�d��fdd�t�t���d�D�}|D].}tj	r0t
�t
d|�t�|�}|�|t�
|��|�t
�|j��|�|jt
j�dS|�d�dS)Nz$%LOCALAPPDATA%\Microsoft\WindowsAppsz%test requires a WindowsApps directorycsg|]	}tj��|��qSr)rr<r>�rr6�rzrrr�
s�z6Win32SymlinkTests.test_appexeclink.<locals>.<listcomp>z*.exezTesting withz$test requires an app execution alias)rr<�
expandvarsr\rf�fnmatch�filterrrrDrErhr;r�r��S_ISLNKrZst_reparse_tagZIO_REPARSE_TAG_APPEXECLINK)r/�aliases�aliasrCrr�r�test_appexeclink�
s 

�

z"Win32SymlinkTests.test_appexeclinkN)rNrOrPr�rr<rvr�r�r�rFr�r�rVr�r�r�r�r�r�r�r�r�rrrRr�r�r�r�rrrrr�F
s.
#
�
#r�c@sDeZdZdZej�ej�e��Z	dd�Z
dd�Zdd�Zdd	�Z
d
S)�Win32JunctionTestsZjunctiontestcCr�r*rrUrrrrV�
r�zWin32JunctionTests.setUpcCs"tj�|j�rt�|j�dSdSr*)rr<rR�junctionrTrUrrrr�rWzWin32JunctionTests.tearDowncCs�t�|j|j�|�tj�|j��|�tj�|j��|�tj�	|j��|�
t�|j�t�|j��|�
t�|j�t�|j��|�tj�|j��|�
tj�d|j�tj�t�|j���dS)Nr�)�_winapi�CreateJunction�junction_targetr�r[rr<rRr�r\r8r�rhr;r�r�r�r�rUrrr�test_create_junctions�z'Win32JunctionTests.test_create_junctioncCs\t�|j|j�|�tj�|j��|�tj�|j��t�	|j�|�
tj�|j��dSr*)r�r�r�r�r[rr<r�rRrTr�rUrrr�test_unlink_removes_junctions
z/Win32JunctionTests.test_unlink_removes_junctionN)rNrOrPr�rr<rFrvr�r�rVr�r�r�rrrrr��
s
r�c@�eZdZdd�Zdd�ZdS)�Win32NtTestsc
Cs*t�d�}t�d�}ddl}|jddd�}|jj|j_|jj|j	_|jj|jj
f|j	_|��}|j��}|�	||�
|��}|�d|�|j}dd	d
tg}td�D](}	|D]#}
z|�|
�Wn	tyfYnwzt�|
�WqTtywYqTwqP|�	||�
|��}|�d|�|j|}|�d|�dS)Nr[rwrzKernel32.dllT)Zuse_last_errorraz\\?\C:z\\?\NULz	\\?\CONINrb)r�
import_moduleZctypes.wintypesZWinDLLrZrdZGetCurrentProcessrcrbZGetProcessHandleCountZLPDWORDrgrfZbyrefr;r"r�r�Z_getfinalpathname�	Exceptionrr�)r/r[rwZkernelZhprocZhandle_countr|Zbefore_count�	filenames�_rZhandle_deltarrr�test_getfinalpathname_handlessH

�
����
z*Win32NtTests.test_getfinalpathname_handlescCs�tj}|�tj|�t��d}t�d�}t�t	j
d||t|�g��M}t��|krIzt�
|�WntyB}zWYd}~nd}~wwt��|ks)z|�d�Wntjy^|��Yn	wWd�dSWd�dS1srwYdS)Nr�a�            import os
            import sys
            import time

            filename = sys.argv[1]
            deadline = float(sys.argv[2])

            while time.time() < deadline:
                try:
                    with open(filename, "w") as f:
                        pass
                except OSError:
                    pass
                try:
                    os.remove(filename)
                except OSError:
                    pass
            r�ra)rrSr�rTrl�textwrap�dedentr�rhr7r�r-rr�rArmZTimeoutExpiredZ	terminate)r/r%ZdeadlineZcommandr�r�rrr�test_stat_unlink_raceKs*
�����	"�z"Win32NtTests.test_stat_unlink_raceN)rNrOrPr�r�rrrrr�s0r�c@r()�NonLocalSymlinkTestscCs	t�d�dS)Nz
base/some_dir)rrrUrrrrVxszNonLocalSymlinkTests.setUpcCst�d�dS)Nr4)rPr?rUrrrr��szNonLocalSymlinkTests.tearDowncCs 	tj�dd�}t�d|�dS)Nr4Z	some_linkZsome_dir)rr<r>r�)r/r�rrr�test_directory_link_nonlocal�sz1NonLocalSymlinkTests.test_directory_link_nonlocalN)rNrOrPrVr�r�rrrrr�us	r�c@r�)�FSEncodingTestscCs(|�t�d�d�|�t�d�d�dS)Nsabc�uabcŁ)r;rrNrLrUrrr�test_nop�szFSEncodingTests.test_nopc	CsBdD]}zt�|�}Wn	tyYqw|�t�|�|�qdS)N)u	unicodeŁulatiné�ascii)rrNrr;rL)r/rIrKrrr�
test_identity�s��zFSEncodingTests.test_identityN)rNrOrPr�r�rrrrr��sr�c@sVeZdZdd�Ze�e�d�o"e�o"e	j
�d�p"ee
d�o"ee
d�d�dd	��Zd
S)�DeviceEncodingTestscCs|�t�d��dS)Ni@�)r{r�device_encodingrUrrr�test_bad_fd�rzDeviceEncodingTests.test_bad_fdr�win�nl_langinfo�CODESETz>test requires a tty and either Windows or nl_langinfo(CODESET)cCs(t�d�}|�|�|�t�|��dSrl)rr�ZassertIsNotNoner[�codecs�lookup)r/r�rrr�test_device_encoding�s

z(DeviceEncodingTests.test_device_encodingN)rNrOrPr�rrrr�rr7r8r�r�localer�rrrrr��s"�r�c@s�eZdZe�eed�d�dd��Zddd�Zdd	�Z	d
d�Z
e�ejdkd
�dd��Z
e�ejdkd
�dd��Ze�eed�d�dd��ZdS)�PidTests�getppidztest needs os.getppidcCs<tjtjddgtjd�}|��\}}|�t|�t�	��dS)Nr�zimport os; print(os.getppid()))r�)
r�rhr7r�r�Zcommunicater;r�r�getpid)r/rr�r�rrr�test_getppid�s
��zPidTests.test_getppidNcCs�tjdkrdtj�d�dd|�d�g}ntjd|g}t�tjtj|�}|dur+||�t�|d�\}}|�t�|�|�|�||�dS)Nr��"r�r)	r7r8r�r�spawnv�P_NOWAIT�waitpidr;�waitstatus_to_exitcode)r/r��exitcode�callbackr�rlZpid2Zstatusrrr�
check_waitpid�s
zPidTests.check_waitpidcCs|jddd�dS)Nr�r)r�r��r�rUrrr�test_waitpid�r~zPidTests.test_waitpidcCsXd}d|�d�}|j||d�|�t��t�d�Wd�dS1s%wYdS)N�zimport sys; sys.exit(�)�r�g)r�rhrnrr�)r/r�r�rrr�test_waitstatus_to_exitcode�s"�z$PidTests.test_waitstatus_to_exitcoder��win32-specific testcCs"d}d|�d�}|j||d�dS)Nl:z$import _winapi; _winapi.ExitProcess(r�r�r�)r/ZSTATUS_CONTROL_C_EXITr�rrr�test_waitpid_windows�szPidTests.test_waitpid_windowscCs�d}ddd|fD]
}|�t�|d>�|�q|�t��t�|dd>�Wd�n1s/wY|�t��t�d�Wd�dS1sJwYdS)Nr0rrar�r�r)r;rr�rhr�r1)r/Zmax_exitcoder�rrr�#test_waitstatus_to_exitcode_windows�s��"�z,PidTests.test_waitstatus_to_exitcode_windows�SIGKILLzneed signal.SIGKILLcs6dtj�d�}tj��fdd�}|j|�|d�dS)Nzimport time; time.sleep(r�cst�|��dSr*)rrk)rl�Zsignumrr�kill_process�rz?PidTests.test_waitstatus_to_exitcode_kill.<locals>.kill_process)r�r�)rZLONG_TIMEOUTrpr�r�)r/r�r�rr�r� test_waitstatus_to_exitcode_kill�sz)PidTests.test_waitstatus_to_exitcode_killr*)rNrOrPrrrrr�r�r�r�r7r8r�r�rpr�rrrrr��s




r�c@s$eZdZddd�dd�Zed�dd��Zed�d	d
��Zed�dd
��Zed�dd��Zed�dd��Z	ed�dd��Z
ed�dd��Zed�dd��Zed�dd��Z
ed�dd ��Zed�d!d"��Zed�d#d$��Zed�d%d&��Zed�d'd(��Zd)d*�Zed�d+d,��Zed�d-d.��Zd/S)0�
SpawnTestsF��with_env�	use_bytescCs�d|_tj}|�tj|�|sd|j}nttj�|_t	t
���|_|j|j|j<d|j|jf}t
|ddd��
}|�|�Wd�n1sHwYtj|g}|rfdd�|D�}d	d
�|j��D�|_|S)N�zimport sys; sys.exit(%s)z4import sys, os; magic = os.environ[%r]; sys.exit(%s)r,r�r�cSr�rr�r�rrrrr(z*SpawnTests.create_args.<locals>.<listcomp>cSs"i|]
\}}t�|�t�|��qSrr�)r�k�vrrr�
<dictcomp>s�z*SpawnTests.create_args.<locals>.<dictcomp>)r�rrSr�rTr�rr6r�r-rtZuuid4r�r#r$r7r�r�)r/r�r�r%r�r&r�rrr�create_args�s*
��
�zSpawnTests.create_args�spawnlcC�4|��}tjtj|dg|�R�}|�||j�dSrl)rrr�P_WAITr;r��r/r�r�rrr�test_spawnl�zSpawnTests.test_spawnl�spawnlecC�>|jdd�}tjtj|dg|�|j�R�}|�||j�dS�NT)r�r)rrrrr�r;r�rrrr�test_spawnle� zSpawnTests.test_spawnle�spawnlpcCrrl)rrrrr;r�rrrr�test_spawnlp%r
zSpawnTests.test_spawnlp�spawnlpecCrr
)rrrrr�r;r�rrrr�
test_spawnlpe+rzSpawnTests.test_spawnlper�cCsT|��}t�tj|d|�}|�||j�t�tjt|d�|�}|�||j�dSrl)rrr�rr;r�rrrrr�test_spawnv1s
zSpawnTests.test_spawnv�spawnvecC�6|jdd�}t�tj|d||j�}|�||j�dSr
�rrrrr�r;r�rrrr�test_spawnve;�zSpawnTests.test_spawnve�spawnvpcCs.|��}t�tj|d|�}|�||j�dSrl)rrrrr;r�rrrr�test_spawnvpAszSpawnTests.test_spawnvp�spawnvpecCrr
)rrrrr�r;r�rrrr�
test_spawnvpeGrzSpawnTests.test_spawnvpecCs0|��}t�tj|d|�}tj||jd�dS)Nrr�)rrr�r�rZwait_processr�)r/r�rlrrr�test_nowaitMszSpawnTests.test_nowaitcCs8|jddd�}t�tj|d||j�}|�||j�dS)NTr�rrrrrr�test_spawnve_bytesSszSpawnTests.test_spawnve_bytescCs>|��}|�ttjtj|d�|�ttjtj|dd�dS�Nrru)rrhr�rrr��r/r�rrr�test_spawnl_noargsZszSpawnTests.test_spawnl_noargscCsB|��}|�ttjtj|di�|�ttjtj|ddi�dSr )rrhr�rrr�r!rrr�test_spawnle_noargs`s zSpawnTests.test_spawnle_noargscCsv|��}|�ttjtj|dd�|�ttjtj|dg�|�ttjtj|dd�|�ttjtj|ddg�dS�Nrrr�ru)rrhr�rr�r�r!rrr�test_spawnv_noargsfs
 zSpawnTests.test_spawnv_noargscCs~|��}|�ttjtj|ddi�|�ttjtj|dgi�|�ttjtj|ddi�|�ttjtj|ddgi�dSr$)rrhr�rrr�r!rrr�test_spawnve_noargsns
"zSpawnTests.test_spawnve_noargscCsvtjddg}tj��}d|d<z|tj|d||�}Wn	ty$Ynw|�|d�tj��}d|d<z|tj|d||�}Wn	tyIYnw|�|d�tj��}d	|d
<z|tj|d||�}Wn	tynYnw|�|d�tj	}|�
tj|�t|ddd
��
}|�
d�Wd�n1s�wYtj|g}tj��}d|d<|tj|d||�}|�|d�dS)Nr�r�r�r�r�r�r�r�r�r,r�r�zPimport sys, os
if os.getenv("FRUIT") != "orange=lemon":
    raise AssertionErrorzorange=lemon)r7r�rr6r�rr�r;rrSr�rTr#r$)r/Zspawnr�r�r�r%r&rrr�_test_invalid_envvsF
�
�
��

zSpawnTests._test_invalid_envcCr�r*)r(rrrUrrr�test_spawnve_invalid_env�roz#SpawnTests.test_spawnve_invalid_envcCr�r*)r(rrrUrrr�test_spawnvpe_invalid_env�roz$SpawnTests.test_spawnvpe_invalid_envN)rNrOrPrrr	rrrrrrrrrr"r#r%r&r(r)r*rrrrr��sF




	








.
r�z>Skip due to platform/environment differences on *NIX buildbots�getloginztest needs os.getloginc@r�)�
LoginTestscCst��}|�t|�d�dSrl)rr+r8r9)r/Z	user_namerrr�
test_getlogin��zLoginTests.test_getloginN)rNrOrPr-rrrrr,��r,�getpriority�setpriorityz'needs os.getpriority and os.setpriorityc@rL)�ProgramPriorityTestscCs
t�tjt���}t�tjt��|d�zIt�tjt���}|dkr.|dkr.t�d|��|�||d�Wz
t�tjt��|�WdSty^}z|j	t	j
krS�WYd}~dSd}~wwzt�tjt��|�Wwty�}z
|j	t	j
krz�WYd}~wd}~ww)Nra�z?unable to reliably test setpriority at current nice level of %s)rr0�PRIO_PROCESSr�r1rrir;rBrCZEACCES)r/r4Znew_prior�rrr�test_set_get_priority�s2��������z*ProgramPriorityTests.test_set_get_priorityN)rNrOrPr5rrrrr2�sr2c@sveZdZGdd�dej�Zdd�Zedd��Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�ZeZdd�Zdd�ZdS)�SendfileTestServerc@r�)zSendfileTestServer.HandlercCs.tj�||�g|_d|_d|_|�d�dS)NTFs220 ready
)�asynchat�
async_chat�__init__�	in_buffer�
accumulate�closed�push)r/�connrrrr9�s
z#SendfileTestServer.Handler.__init__cCs$|�d�}|jr|j�|�dSdS)N�)�recvr;r:rr�rrr�handle_read�s
�z&SendfileTestServer.Handler.handle_readcCsd�|j�S)Nr�)r>r:rUrrr�get_data�r�z#SendfileTestServer.Handler.get_datacCs|��d|_dSr)rZr<rUrrr�handle_close�s
z'SendfileTestServer.Handler.handle_closecC��r*rrUrrr�handle_error��z'SendfileTestServer.Handler.handle_errorN)rNrOrPr9rArBrCrErrrr�Handler�srGcCsptj�|�tj�|�|�tjtj�|�	|�|�
d�|j��dd�\|_|_
d|_d|_t��|_dS)Nr�rcF)�	threading�Threadr9�asyncore�
dispatcherZ
create_socket�socketZAF_INETZSOCK_STREAMZbindZlistenZgetsockname�host�port�handler_instance�_activeZLock�_active_lock)r/Zaddressrrrr9�s

zSendfileTestServer.__init__cCs|jSr*)rPrUrrrr[�szSendfileTestServer.runningcCs$t��|_tj�|�|j��dSr*)rHZEvent�_SendfileTestServer__flagrI�startrmrUrrrrS�s
zSendfileTestServer.startcCsd|_|��dSr�)rPr>rUrrr�stop
szSendfileTestServer.stopcCs2t|jdd�st�d�t|jdd�r|��dS)Nr<F���MbP?)r�rOrlrjrTrUrrrrm
s
�zSendfileTestServer.waitcCsVd|_|j��|jr%tjr%|j��tjddd�|j��|jr%tjst�	�dS)NTrUra)Ztimeoutr�)
rPrRr?rJZ
socket_maprQ�acquireZloop�releaseZ	close_allrUrrrr�

s


�zSendfileTestServer.runcCs|��\}}|�|�|_dSr*)ZacceptrGrO)r/r>Zaddrrrr�
handle_accept
sz SendfileTestServer.handle_acceptcCs|��dSr*)rZrUrrr�handle_connect
r�z!SendfileTestServer.handle_connectcCsdSrlrrUrrr�writable
r�zSendfileTestServer.writablecCrDr*rrUrrrrE!
rFzSendfileTestServer.handle_errorN)rNrOrPr7r8rGr9�propertyr[rSrTrmr�rXrYrArZrErrrrr6�s
	r6�sendfileztest needs os.sendfile()c@s
eZdZddZej�d�oej�d�oej�d�Ze�	ed�Z
e�	ejdkd�Ze
d	d
��Ze
dd��Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Ze
dd��Ze
dd ��Ze
ed!d"���Ze
ed#d$���Ze
e�	eed%�d&�d'd(���Zd)S)*�TestSendfiles�12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde12345abcde�ZlinuxZsolarisZsunosz%requires headers and trailers supportr-z(test is only meaningful on 32-bit buildscCst��|_ttj|j�dSr*)rZthreading_setupr�r'rrS�DATArsrrrru1
s
zTestSendfile.setUpClasscCstj|j�t�tj�dSr*)rZthreading_cleanupr�rrTrSrsrrrr�6
szTestSendfile.tearDownClasscCs~ttjdf�|_|j��t��|_|j�|jj|jj	f�|j�
d�|j�d�|j��|_
ttjd�|_|j��|_dS)Nrrar^r�)r6rZHOST�serverrSrL�clientZconnectrMrNZ
settimeoutr@rw�socknor#rrSr"rUrrrrV;
s

zTestSendfile.setUpcCs0|j��|j��|jjr|j��d|_dSr*)r"rZrar`r[rTrUrrrr�G
s




zTestSendfile.tearDownc
Os^		z	tj|i|��WSty.}z|jtjkr�|jtjtjfvr)WYd}~q�d}~wwr*)rr\rBrCZ
ECONNRESET�EAGAIN�EBUSY)r/r�r�r�rrr�sendfile_wrapperN
s��zTestSendfile.sendfile_wrappercCs�d}d}d}|t|j�kr8|�|j|j||�}|dkrn||7}||7}|�||k�|�||�|t|j�ks
|�|t|j��|j�t	j
�|j��|j�
�|jj��}|�t|�t|j��|�||j�dS)Nrr?)r9r_rerbrwr[r;ra�shutdownrL�	SHUT_RDWRrZr`rmrOrB)r/�
total_sent�offset�nbytes�sentr�rrr�test_send_whole_file_
s&�	

z!TestSendfile.test_send_whole_filecCs�d}t|j�d}t|j�|}d}||kr8|�|j|j||�}|dkr%n||7}||7}|�||k�||ks|j�tj	�|j�
�|j��|jj
��}|jt|j�dd�}|�|t|��|�t|�t|��|�||�dS)Nrrcr?)r9r_rerbrwr[rarfrLrgrZr`rmrOrBr;)r/rhriZ	must_sendrjrkr�rGrrr�test_send_at_certain_offsetu
s(�

z(TestSendfile.test_send_at_certain_offsetc
Cs�t|j�d}zt�|j|j|d�}Wnty,}z
|jtjkr"�WYd}~nd}~ww|�	|d�|j
�tj
�|j
��|j��|jj��}|�	|d�dS)Nr?rr�)r9r_rr\rbrwrBrC�EINVALr;rarfrLrgrZr`rmrOrB)r/rirkr�r�rrr�test_offset_overflow�
s���

z!TestSendfile.test_offset_overflowcCsT|�t��}t�|j|jdd�Wd�n1swY|�|jjtj	�dS)Nrr?)
rhrBrr\rbrwr;r*rCrn�r/r�rrr�test_invalid_offset�
s�z TestSendfile.test_invalid_offsetc	Cs@tj|j|jddd�|jrtj|j|jdddddd�dSdS)Nrr?)r�r�rir�r)r�r�rir��headers�trailersr�)rr\rbrw�SUPPORT_HEADERS_TRAILERSrUrrr�
test_keywords�
s�
��zTestSendfile.test_keywordscCs�d}d|jdd�}tj|j|jddddgd�}|�|d�||7}d}|t|�krWtt|�|d�}|�|j|j||�}|dkrCn|�||�||7}||7}|t|�ks+|�	|t|��|j
��|j�
�|jj��}|�	t|�t|��dS)	Nrsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyrr?sxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy�rri)r_rr\rbrwZassertLessEqualr9�minrer;rarZr`rmrOrB�hash)r/rhZ
expected_datarkrirjr�rrr�test_headers�
s0���


zTestSendfile.test_headerscCs�tjd}d}|�tj|�t||�t|d��.}tj|j|�	�ddddgd�|j
��|j�
�|jj��}|�|d	�Wd�dS1sIwYdS)
Nr�sabcdefr�rr�s123456s789�rssabcde123456789)rrSr�rTr'r#rr\rbrwrarZr`rmrOrBr;)r/r�Z	file_datar_r�rrr�
test_trailers�
s

�

"�zTestSendfile.test_trailerscC�ld|jj_|�t��}tj|j|jddddgdd�Wd�n1s&wY|�	|j
jtj�dS)NFr�x�r�rv�
r`rOr;rhrBrr\rbrwr;r*rCrnrprrr�test_headers_overflow_32bits�
�
��z)TestSendfile.test_headers_overflow_32bitscCr|)NFrr}r~r�rzrrprrr�test_trailers_overflow_32bits�
r�z*TestSendfile.test_trailers_overflow_32bits�SF_NODISKIOztest needs os.SF_NODISKIOc
Cs\ztj|j|jddtjd�WdSty-}z|jtjtjfvr"�WYd}~dSd}~ww)Nrr?)r�)	rr\rbrwr�rBrCrdrc)r/r�rrr�
test_flags�
s����zTestSendfile.test_flagsN)rNrOrPr_r7r8r�rtrrZrequires_headers_trailers�maxsizeZrequires_32br�rur�rVr�rerlrmrorqruryr{r�r�rrr�rrrrr]%
sP����



�r]c	Cs�ttd�sdSzLttjdd��+}zt�|��dd�Wnty2YWd�Wt�tj�dSwWd�n1s=wYWt�tj�dSWt�tj�dSt�tj�w)N�setxattrFr"r�	user.testr�T)	rrr#rrSr�rwrBrT)r&rrr�supports_extended_attributes�
s&
������r�z(no non-broken extended attribute supportrcr��'c@r�)�ExtendedAttributeTestsc
KsFtj}|�tj|�t|�|�t��}|||d�fi|��Wd�n1s)wY|�|jj	t	j
�||�}	|�|	t�|||d�dfi|��t
|	�}
|
�d�|�t
||��|
�|�||dfi|��d�|||d�dtjfi|��|�||dfi|��d�|�t��}|||d�dtjfi|��Wd�n1s�wY|�|jj	t	j�|�t��}|||d�dtjfi|��Wd�n1s�wY|�|jj	t	j
�|||d�dtjfi|��|
�d�|�t
||��|
�|||d�fi|��|�t��}|||d�fi|��Wd�n	1�s$wY|�|jj	t	j
�|
�d�|�t
||��|
�|�|||d�fi|��d�|||d�dfi|��|�|||d�fi|��d�|||d�fi|��td	d
�td�D��}|D]
}|||dfi|���q�|�t
||��t
|	�t
|�B�dS)
N�	user.testr�r�r�sbyez
user.test2sfoosaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacss�|]}d�|�VqdS)zuser.test{}Nr�)rr�rrrr�5��z;ExtendedAttributeTests._check_xattrs_str.<locals>.<genexpr>r�r})rrSr�rTr'rhrBr;r*rCZENODATAr,rr?rOr�
XATTR_REPLACE�XATTR_CREATEZEEXISTrr�r�)
r/r}�getxattrr��removexattr�	listxattrr�rIr�Z
init_xattrZxattr�many�thingrrr�_check_xattrs_str
sT�
��
�
$z(ExtendedAttributeTests._check_xattrs_strcOsN|jtg|�Ri|��t�tj�|jtjg|�Ri|��t�tj�dSr*)r�r-rrTrSrrNr9rrr�
_check_xattrs:sz$ExtendedAttributeTests._check_xattrscCs|�tjtjtjtj�dSr*�r�rr�r�r�r�rUrrr�test_simpleAs�z"ExtendedAttributeTests.test_simplecCs |jtjtjtjtjdd�dS)NFrr�rUrrr�
test_lpathEs
�z!ExtendedAttributeTests.test_lpathcCs4dd�}dd�}dd�}dd�}|�||||�dS)	NcW�Dt|d��}tj|��g|�R�Wd�S1swYdSrS)r#rr�rw�r<r�r&rrrr�J�$�z1ExtendedAttributeTests.test_fds.<locals>.getxattrcW�Ht|dd��}tj|��g|�R�Wd�dS1swYdS�Nrcr)r#rr�rwr�rrrr�M�"�z1ExtendedAttributeTests.test_fds.<locals>.setxattrcWr�r�)r#rr�rwr�rrrr�Pr�z4ExtendedAttributeTests.test_fds.<locals>.removexattrcWr�rS)r#rr�rwr�rrrr�Sr�z2ExtendedAttributeTests.test_fds.<locals>.listxattr)r�)r/r�r�r�r�rrr�test_fdsIs
zExtendedAttributeTests.test_fdsN)rNrOrPr�r�r�r�r�rrrrr�s0r��get_terminal_sizezrequires os.get_terminal_sizec@r�)�
TermsizeTestsc
Csp	zt��}Wn ty'}ztjdks|jtjtjfvr"|�d��d}~ww|�	|j
d�|�	|jd�dS)Nr��failed to query terminal sizer)rr�rBr7r8rCrn�ENOTTYrfZassertGreaterEqual�columns�lines)r/rr�rrr�test_does_not_crash[s
��z!TermsizeTests.test_does_not_crashc
Cs�	ztjddgtjdd���}Wnttjtfy"|�d�Ynwt|d�t|d�f}z
t	�
tj�
��}Wn tyY}ztjdksO|jtjtjfvrT|�d	��d}~ww|�||�dS)
NZsttyrT)r\r�zstty invocation failedrarr�r�)r�rlZDEVNULLr�rAZCalledProcessErrorrrfr�rr�r7�	__stdin__rwrBr8rCrnr�r;)r/rrGr�r�rrr�test_stty_matchms,��
��
��zTermsizeTests.test_stty_matchN)rNrOrPr�r�rrrrr�Ysr��memfd_createzrequires os.memfd_creater�rc@r�)�MemfdCreateTestscCs�t�dtj�}|�|d�|�tj|�|�t�|��t|ddd��}|�	d�|�
|��d�Wd�n1s;wYt�d�}|�tj|�|�t�|��dS)NZHirrcF)�closefdsmemfd_creater�)rr��MFD_CLOEXECr8r�rZr�rr#r$r;�tell)r/r|r_r�rrr�test_memfd_create�s
�
z"MemfdCreateTests.test_memfd_createN)rNrOrPr�rrrrr��r/r��eventfdzrequires os.eventfdr.c@r()�EventfdTestscCs�dd�}d}d}t�|�}|�|d�|�tj|�|�t�|��t�||�}|�|||��t�	||d��t�||�}|�||d��t�	||d��t�	||d��t�||�}|�||d��t�
|d	�t�
|d
�t�|�}|�|d�dS)NcSs	t�d|�S)Nz@Q)�struct�pack)r"rrrr��sz/EventfdTests.test_eventfd_initval.<locals>.packr�r�rr��(rcr�r�)rr�r8r�rZr�rryr;r$�
eventfd_write�eventfd_read)r/r�r�initvalr|�resrrr�test_eventfd_initval�s(

z!EventfdTests.test_eventfd_initvalcCs.d}tjtjBtjB}t�||�}|�|d�|�tj|�t�|�}|�	|d�t�|�}|�	|d�|�
t��
t�|�Wd�n1sIwY|�
t��t�|d�Wd�n1sdwYt�
|d�t�|�}|�	|d�|�
t��t�|�Wd�dS1s�wYdS)Nrcrrar�)r�EFD_CLOEXEC�
EFD_SEMAPHORE�EFD_NONBLOCKr�r8r�rZr�r;rhr�ryr�)r/r�r�r|r�rrr�test_eventfd_semaphore�s*

��
"�z#EventfdTests.test_eventfd_semaphorecCstjtjB}t�d|�}|�|d�|�tj|�t�|g|g|gd�\}}}|�|||fg|ggf�t�	|d�t�|g|g|gd�\}}}|�|||f|g|ggf�|�t�
|�d�t�	|d�t�|g|g|gd�\}}}|�|||f|gggf�t�
|�dS)Nrrr�l����)rr�r�r�r8r�rZ�selectr;r�r�)r/r�r|�rfd�wfdZxfdrrr�test_eventfd_select�sz EventfdTests.test_eventfd_selectN)rNrOrPr�r�r�rrrrr��sr�c@r�)�OSErrorTestscCs�Gdd�dt�}g|_g|_tjdurtj}ntj}|j�|�|j�||��tjdur1tj}nt�	tj�}|j�|�|j�t
|��|j�t|��|j|j|_dS)Nc@�eZdZdS)zOSErrorTests.setUp.<locals>.StrN�rNrOrPrrrr�Str��r�)
r-�bytes_filenames�unicode_filenamesrrMrSrZTESTFN_UNDECODABLErrNr�r�r�)r/r�ZdecodedZencodedrrrrV�s

zOSErrorTests.setUpcCs@|jtjf|jtjdf|jtjf|jtjtjf|jtjf|jtjf|jtj	fg}t
jdkrP|�|j
tjdf|j
tjdf|jtjdf|jtjdf|jtjff�n|�|jtjf|jtjdf|jtjdff�ttd�rv|�|jtjddf�ttd�r�|�|jtjddf�ttd�r�|�|jtjdf�ttd	�r�|�|jtjdf�ttd
�r�|�|jtjdf�ttd�r�|�|jtjf�ttd�r�t
jdkr�|�|j
tjdf�|�|jtjdf�n
|�|jtjdf�ttd
��r
|�|jtjf|jtjdf|jtjddf|jtjdff�ttd��r|�|jtjdf�ttd��r,|�|jtj f�|D]o^}}}|D]f}z2t!|t"t#f��rI||g|�R�n|�$t%d��||g|�R�Wd�n	1�scwYWn(t&�y�}z|�'|j(|t"|��WYd}~�q5d}~wt)�y�Y�q5w|�*d�+|���q5�q.dS)Nr�r�sdstr�rqr�lchownr	�chflags�lchflags�chrootrr�r�suser�lchmodr�z	should bezNo exception thrown by {}),r�rr@rrhr#r�r3r�rTr7r8r�r�ror�r�rrrrqr�r	r�r�r�rr�r�r�r�r�r�rr-rKZassertWarnsRegex�DeprecationWarningrBr�r%�UnicodeDecodeErrorr�r�)r/Zfuncsr��funcZ	func_argsrr�rrr�test_oserror_filenames�




�
	
�
�








���"����z"OSErrorTests.test_oserror_filenameN)rNrOrPrVr�rrrrr��sr�c@r�)�
CPUCountTestscCs:t��}|dur|�|t�|�|d�dS|�d�dS)Nrz&Could not determine the number of CPUs)r�	cpu_countr,r��
assertGreaterrf)r/Zcpusrrr�test_cpu_countLs
zCPUCountTests.test_cpu_countN)rNrOrPr�rrrrr�Kr�r�c@s�eZdZdd�Ze�edud�dd��Ze�edud�dd��Ze�	e
ed	�d
�dd��Zd
d�Z
dd�Ze�	e
ed�d�dd��Zdd�Zdd�Ze�	ejdkd�dd��Ze�	e
ed�d�dd ��Ze�	e
ed!�d"�d#d$��ZdS)%�FDInheritanceTestscCsPt�ttj�}|�tj|�|�t�|�d�t�|d�|�t�|�d�dS�NFT)	rr#r�r�r�rZr;rrr�rrr�test_get_set_inheritableVs
z+FDInheritanceTests.test_get_set_inheritableNz
need fcntlcCsnt�ttj�}|�tj|�|�t�|�d�t�|tj	�}|tj
M}t�|tj|�|�t�|�d�dSr�)rr#r�r�r�rZr;r�fcntl�F_GETFD�
FD_CLOEXECZF_SETFD)r/r|r�rrr�test_get_inheritable_cloexec^sz/FDInheritanceTests.test_get_inheritable_cloexeccCsft�ttj�}|�tj|�|�t�|tj�tj	@tj	�t�
|d�|�t�|tj�tj	@d�dS)NTr)rr#r�r�r�rZr;r�r�r�rr�rrr�test_set_inheritable_cloexecks��z/FDInheritanceTests.test_set_inheritable_cloexec�O_PATHzneed os.O_PATHcC�nt�ttj�}|�tj|�|�t�|�d�t�|d�|�t�|�d�t�|d�|�t�|�d�dSr�)	rr#r�r�r�rZr;rrr�rrr�test_get_set_inheritable_o_pathvsz2FDInheritanceTests.test_get_set_inheritable_o_pathcCs�t��}|�t��
}t�|�Wd�n1swY|�|jjtj	�|�t��}t�
|d�Wd�n1s=wY|�|jjtj	�|�t��}t�
|d�Wd�n1sawY|�|jjtj	�dS�NTF)rr�rhrBrrr;r*rCr+r)r/r|r-rrr�test_get_set_inheritable_badf�s���z0FDInheritanceTests.test_get_set_inheritable_badfcCs2t�ttj�}|�tj|�|�t�|�d�dSr�)rr#r�r�r�rZr;rr�rrrrT�szFDInheritanceTests.test_openr�zneed os.pipe()cC�Pt��\}}|�tj|�|�tj|�|�t�|�d�|�t�|�d�dSr�)rr�r�rZr;r)r/r�r�rrr�	test_pipe��
zFDInheritanceTests.test_pipecCsJt�ttj�}|�tj|�t�|�}|�tj|�|�t�|�d�dSr�)	rr#r�r�r�rZrer;r�r/Zfd1r�rrr�test_dup�s

zFDInheritanceTests.test_dupcCs(t�d�}|�tj|�|�|d�dS�Nrar)rrer�rZr�r�rrr�test_dup_standard_stream�s
z+FDInheritanceTests.test_dup_standard_streamr�r�cCsHt�dtj�}|�tj|�t�|�}|�tj|�|�t�|��dS)NZNUL)rr#r�r�rZrer�rr�rrr�test_dup_nul�s

zFDInheritanceTests.test_dup_nulr�zneed os.dup2()cCs�t�ttj�}|�tj|�t�ttj�}|�tj|�|�t�||�|�|�t�	|��t�ttj�}|�tj|�|�tj||dd�|�|�
t�	|��dS)NF)Zinheritable)rr#r�r�r�rZr;r�r[rr�)r/r|r�Zfd3rrrr��szFDInheritanceTests.test_dup2�openptyzneed os.openpty()cCr�r�)rr�r�rZr;r)r/Z	master_fdZslave_fdrrr�test_openpty�r�zFDInheritanceTests.test_openpty)rNrOrPr�rr�r�r�r�rrrr�r�rTr�r�r�r7r8r�r�r�rrrrr�Us(






r�c@sHeZdZddddejfdfddddd	eed
d�fgZdd�Zd
d�ZdS)�PathTConverterTests)r�TrN)rhFrNr\FN)r�F�rN)r�Fr�Nr#r�rZcCs�tj}tjdkr
d}}n
t�tj�}t|�}t�t|�tjtjB�}|�	tj
tj�|�	tj|�t|�}t|�}|jD]�\}}}	}
|j
|d���ztt|�}Wnty`YWd�q=w||||fD].}|durnqg|j
||d��||g|	�R�}
|
dur�|
|
�Wd�n1s�wYqg|�td��||g|	�R�Wd�n1s�wY|r�||g|	�R�}
|
dur�|
|
�n|�td��||g|	�R�Wd�n1s�wYWd�n1s�wYq=dS)Nr[r)rr<zto return str or byteszos.PathLike)rrSrrrNrr#r�rXr�rTrZ�	functionsr�r�r�assertRaisesRegexrn)r/Zstr_filenameZbytes_fspath�bytes_filenamer|Z
int_fspathZ
str_fspathrZallow_fdZ
extra_argsZ
cleanup_fnrIr<rrrr�test_path_t_converter�sd

��������������z)PathTConverterTests.test_path_t_convertercCs�d}|�t|d��t�td��Wd�n1swY|�t|d��t�td��Wd�n1s;wY|�t|d��t�tt���Wd�dS1s\wYdS)Nz-__fspath__\(\) to return str or bytes, not %sr�rc�floatg���Q�@�object)r�rnrr�rr�)r/rkrrr�&test_path_t_converter_and_custom_classs��"�z:PathTConverterTests.test_path_t_converter_and_custom_class)	rNrOrPr�F_OKr�r�r�r�rrrrr��s�	,r�rrc@r�)�
BlockingTestscCr�r�)	rr#r�r�r�rZr;rrr�rrrrszBlockingTests.test_blockingN)rNrOrPrrrrrr�r/r�c@r�)�ExportsTestscCs |�dtj�|�dtj�dS)Nr#r�)r�r�__all__rUrrr�test_os_all!szExportsTests.test_os_allN)rNrOrPr�rrrrr� r�r�c@r()�TestDirEntrycCs0tj�tj�|_|�tj|j�t�|j�dSr*)rr<�realpathrrSr�r?r?rUrrrrV'szTestDirEntry.setUpcCs|�ttj�dSr*)rhrnr�DirEntryrUrrr�test_uninstantiable,r~z TestDirEntry.test_uninstantiablecCsjttj�|jd�d�}dd�t�|j�D���}|�|tj�|�|j	d�ddl
}|�t|j
||�dS)Nr��pythoncSsg|]}|�qSrr�r�entryrrrr1sz0TestDirEntry.test_unpickable.<locals>.<listcomp>r)r'rr<r>�scandirr�r,r�r;rrrhrnr)r/r%rrrrr�test_unpickable/szTestDirEntry.test_unpickableN)rNrOrPrVr�rrrrrr�&sr�c@s
eZdZejZdd�Zd<dd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
d<dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Ze�ejejvd(�d)d*��Zd+d,�Zd-d.�Zd/d0�Z d1d2�Z!d3d4�Z"d5d6�Z#d7d8�Z$d9d:�Z%d;S)=�TestScandircCs>tj�tj�|_t�|j�|_|�tj|j�t�	|j�dSr*)
rr<r�rrSrN�
bytes_pathr�r?r?rUrrrrV;szTestScandir.setUpr�cCs2t|t�r|jn|j}tj�||�}t|d�|S)Nr�)rrKrr<rr>r')r/rr<r%rrrr'As
zTestScandir.create_filecCs2tdd�t�|j�D��}|�t|���|�|S)Ncs��|]}|j|fVqdSr*rr�rrrr�Hs��z*TestScandir.get_entries.<locals>.<genexpr>)r�rrr<r;r��keys)r/�names�entriesrrr�get_entriesGs

�zTestScandir.get_entriescCs\|r&t|�D]}|�d�sq|dvrq|�t||�t||�|||f�qdS|�||�dS)NZst_)�st_dev�st_ino�st_nlink)r�r�r;r�)r/Zstat1Zstat2Zskip_fieldsrrrr�assert_stat_equalMs
��	zTestScandir.assert_stat_equalcCs(t�|j�}|�tt|��|��dSr*)rrr<rhrnrzrZ)r/�scandir_iterrrrr�ZszTestScandir.test_uninstantiablecCs<|�d�}t�|j�}ddl}|�t|j||�|��dS)Nr�r)	r'rrr<rrhrnrrZ)r/r%rrrrrr_s

zTestScandir.test_unpickablecCs0|�|tj�|�|j|�|�|jtj�|j|��|�|��tj|jdd�j	�t�|j�}|�|�
�t�|j��|�|�
�t�|j��|�|��tj�|j��tj|jdd�}|�|j
dd�t�|j��|�|j
dd�t�|j��|�|��|tjdko�|�|�|jdd�|tjdk�dS)NFrr[)r,rr�r;rr<r>�inoder�r�is_dir�S_ISDIRr�is_file�S_ISREG�
is_symlinkr�r
)r/rrrrrZ
entry_statZentry_lstatrrr�check_entryfs>
�

�

�
�
�
�
��zTestScandir.check_entryc	
Cs�ttd�}t��}tj�|jd�}t�|�|�d�}|rEzt�|tj�|jd��Wnt	yD}z
|�
d|�WYd}~nd}~ww|ratj|tj�|jd�dd�t�|tj�|jd	��ddg}|rl|�d�|rs|�
d
�|�|�}|d}|�|dddd�|d}|�|dddd�|r�|d}|�|dddd�|r�|d}|�|dddd�|d	}|�|d	ddd�dSdS)Nrr�r�z
link_file.txtr#�symlink_dirT)r��symlink_file.txt)rrF)rrrrr<r>r?r'rrrfr�rr�r	r)	r/rr�rFr%r�rrrrrr�test_attributes�sH


���


�zTestScandir.test_attributescCsNt|t�r|jn|j}tt�|��}|�t|�d�|d}|�|j	|�|Sr�)
rrKrr<rrrr;r9r)r/rr<rrrrr�	get_entry�szTestScandir.get_entrycCs|j|d�}|�tj�|��S)Nr)r'rrr<�basename)r/rr%rrr�create_file_entry�rzTestScandir.create_file_entryc	Csn|��}t��}z(t�|j�tdd�t��D��}|�t|�	��tj�
|�g�Wt�|�dSt�|�w)Ncsrr*rr�rrrr��r�z5TestScandir.test_current_directory.<locals>.<genexpr>)r'rr+r@r<r�rr;r�rr)r/r%Zold_dirrrrr�test_current_directory�s�z"TestScandir.test_current_directorycCs|��}|�t|�d�dS)Nz<DirEntry 'file.txt'>)rr;r��r/rrrr�	test_repr�r.zTestScandir.test_reprcCs*|��}|�t�|�tj�|jd��dS)Nr�)rr;r�fspathr<r>rrrr�test_fspath_protocol�s"z TestScandir.test_fspath_protocolcCsNt�d�}|j|d�}t�|�}|�|t�|�|tj�t�|j�|��dS)Nz
bytesfile.txtr)	rrNrrr,rKr;r<r>)r/r�Zbytes_entryrrrr�test_fspath_protocol_bytes�s

�z&TestScandir.test_fspath_protocol_bytescCs�tj�|jd�}t�|�|�d�}t�|�tjdkr#|�|���|�	|�
��|�	|���tjdkrI|�t
|j�|��|jdd�dS|�|��d�|�t
|j�|jt
|jdd�dS)Nr�r[Frr)rr<r>r?rr3rr[rr�rrrhrArr�r�)r/r<rrrr�test_removed_dir�s




zTestScandir.test_removed_dircCs�|��}t�|j�|�|���tjdkr|�|���|�|�	��tjdkr<|�
t|j�|�
�|j
dd�dS|�|��d�|�
t|j
�|j
t|j
dd�dS)Nr[Frr)rrrTr<r�rrr[rrrhrArr�r�rrrr�test_removed_file�s

zTestScandir.test_removed_filecCs�t��s	|�d�S|�d�}t�|tj�|jd��|�ddg�}|d}t�	|�|�
|��d�|�|�
��|�|���|�|j
dd��|�|jdd��|�|���|�t|j�|jdd�dS)Nzcannot create symbolic linkr�zsymlink.txtrFr)rrrfr'rr�r<r>r	rTr�rr�rrr[rrhrAr�)r/r%rrrrr�test_broken_symlink�s"

�
zTestScandir.test_broken_symlinkc	Csp|�d�t�|j�}tt�|��}|�t|�d|�|d}|�|jd�|�|jt�tj�	|jd���dS�Nr�rarsfile.txt)
r'rrNr<rrr;r9rr>)r/�
path_bytesrrrrrr�s
�zTestScandir.test_bytesc
Cs�|�d�ttfD]\}|t�|j��}|�t��tt�	|��}Wd�n1s*wY|�
t|�d|�|d}|�
|jd�|�
|jt�tj�
|jd���|�t|j�t�|�t|j�t�q	dSr%)r'r�r�rrNr<�assertWarnsr�rrr;r9rr>r�rzrK)r/rtr&rrrrr�test_bytes_like s
���zTestScandir.test_bytes_likez.fd support for listdir required for this test.c	Cst|�tjtj�|�d�dg}t��r%t�dtj�	|jd��|�
d�t�|j���}t�|��}t|�}Wd�n1s@wYdd�|D�}|�
t|�|�|�
|t�|��|D]H}|�
|j|j�|�
t�|�|j�|�
|��|jdk�tjtjvr�tj|j|d�}|�
|��|�tj|j|dd�}|�
|jdd�|�q_Wd�dS1s�wYdS)	Nr�rcSr
rrr�rrrr=rz'TestScandir.test_fd.<locals>.<listcomp>r�F)r�rar)r�rrr�r'rrr�r<r>rrfrr;r�rrrrr�r�)r/Zexpected_namesr|r�rrrrCrrr�test_fd0s2


���"�zTestScandir.test_fdcCs|�ttjd�dS)Nru)rhrArrrUrrr�test_empty_pathJr�zTestScandir.test_empty_pathcCsN|�d�t�|j�}t|�}|�t|�d|�t|�}|�t|�d|�dS)Nr�rar)r'rrr<rr;r9)r/r�rZentries2rrr�test_consume_iterator_twiceMs
z'TestScandir.test_consume_iterator_twicecCs$digfD]
}|�ttj|�qdS)NgX9��v��?)rhrnrr)r/�objrrr�test_bad_path_typeXs�zTestScandir.test_bad_path_typecCsh|�d�|�d�t�|j�}t|�|��|��|���
~Wd�dS1s-wYdS�Nr��	file2.txt)r'rrr<r�rZ�check_no_resource_warning�r/r�rrr�
test_close\s


"�zTestScandir.test_closecCsx|�d�|�d�t�|j��}t|�Wd�n1swY|���
~Wd�dS1s5wYdSr.)r'rrr<r�r0r1rrr�test_context_managergs


�
"�z TestScandir.test_context_managercCsV|�d�|�d�t�|j��}t|�|��Wd�dS1s$wYdSr.)r'rrr<r�rZr1rrr�test_context_manager_closeos


"�z&TestScandir.test_context_manager_closec	Cs�|�d�|�d�|�t��&t�|j��}t|�ddWd�n1s)wYWd�n1s8wY|���
~Wd�dS1sNwYdS)Nr�r/rar)r'rh�ZeroDivisionErrorrrr<r�r0r1rrr�test_context_manager_exceptionvs


���
"�z*TestScandir.test_context_manager_exceptioncCs�|�d�|�d�t�|j�}t|�|�t��
~t��Wd�n1s)wYt�|j�}t	|�|�
��
~Wd�dS1sIwYdSr.)r'rrr<r�r'�ResourceWarningrZ
gc_collectrr0r1rrr�test_resource_warning�s


�
"�z!TestScandir.test_resource_warningN)r�)&rNrOrPrr0rVr'r	r
r�rrrrrrrr r!r"r#r$r�r(rrrrr�r)r*r+r-r2r3r4r6r8rrrrr8sB

)
	�

rc@s^eZdZeej�Zdd�Zdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�ZdS)�
TestPEP519cC� dD]}|�||�|��qdS)N)r�sgoodbyessome/path/and/file�r;r)r/�brrr�test_return_bytes���zTestPEP519.test_return_bytescCr:)N)ZhelloZgoodbyezsome/path/and/filer;)r/r}rrr�test_return_string�r>zTestPEP519.test_return_stringcCsLdD]!}t|�}|�||�|��|�dt�|��|�dt�|��qdS)N)�path/like/object�path/like/objectrAr@)rr;rrrNrL)r/rZpathlikerrr�test_fsencode_fsdecode�s�z!TestPEP519.test_fsencode_fsdecodecCsB|�d|�td���|�tttj��|�ttd�tj��dS)Nz#feelthegilr�)r;rrr[�
issubclassr�PathLikerrUrrrr��szTestPEP519.test_pathlikecCs4tddi�}ttt|�fD]
}|�t|j|�q
dS)NZblahr)rzr�rrhrnr)r/Zvapor�orrr�test_garbage_in_exception_out�s�z(TestPEP519.test_garbage_in_exception_outcCs|�t|j�dSr*)rhrnrrUrrr�test_argument_required�r~z!TestPEP519.test_argument_requiredcCsR|�t|jtd��tddi�}d|_|�t|j|��|�t|jtt���dS)Nr�Zfoorra)rhrnrrrz�
__fspath__r5)r/�crrr�test_bad_pathlike�s
�zTestPEP519.test_bad_pathlikecCs8Gdd�dtj�}|�tt|��|�tttj��dS)Nc@r�)z0TestPEP519.test_pathlike_subclasshook.<locals>.ANr�rrrr�A�r�rK)rrDr�rCrr[)r/rKrrr�test_pathlike_subclasshook�sz%TestPEP519.test_pathlike_subclasshookcCs|�tjttj�dSr*)r,rrDrK�types�GenericAliasrUrrr�test_pathlike_class_getitem�r�z&TestPEP519.test_pathlike_class_getitemN)rNrOrPr�rrr=r?rBr�rFrGrJrLrOrrrrr9�s
r9c@r�)�
TimesTestscCsrt��}|�|tj�dD]
}t||�}|�|t�q
tjdkr7|�|jd�|�|j	d�|�|j
d�dSdS)N)�user�system�
children_user�children_system�elapsedr[r)rr_r,�times_resultr�r�rr;rSrTrU)r/r_Zfieldr"rrr�
test_times�s

�zTimesTests.test_timesN)rNrOrPrWrrrrrP�r�rP�forkc@r�)�	ForkTestscCs d}td|�td|dd�dS)Nz�if 1:
            import os
            from test import support
            pid = os.fork()
            if pid != 0:
                support.wait_process(pid, exitcode=0)
        r�Zmalloc_debug)ZPYTHONMALLOCrr�rrr�	test_fork�s
zForkTests.test_forkN)rNrOrPrZrrrrrY�srY�_fspathc@seZdZ	eej�ZdS)�TestPEP519PurePythonN)rNrOrPr�rr[rrrrrr\�sr\�__main__)r!r*)�r��
contextlibryrCr�rzr=r�rurrr�rPrprLr�r�r�r7Z	sysconfigr:r�rHrlrMrrtr��testrZtest.supportrrrrrr8rr��simplefilterr�r7rJr��ImportErrorr�r��pwdZgetpwallr�rZ	_testcapirrr�Ztest.support.script_helperrrZtest.support.os_helperrr�rrr�versionr�r��getgidr7rr'r�r�ZTestCaser)rQr�r=r�ZBasicTestMappingProtocolr�r�rr8rMrSrUrrr�r�r�r�Zget_config_varZOS_URANDOM_DONT_USE_FDr��contextmanagerr�r�r�r�rr,rHrXr�r�r�r�r�r�r�r�r�r�r�rr,r2rKrIr6r]r�Zrequires_linux_versionr�r�r�r�r�r�r�r�r�r�r�rr9rPrYr\rN�mainrrrr�<module>s�

������
�EZe\)EG
j;)	-����M �h#w%CGs/<0![H4�VO�Q0
Q]
yB�Y:
�