HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.10/test/__pycache__/test_os.cpython-310.opt-2.pyc
o

�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�)�pw_uid)�.0�urr�)/usr/local/lib/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�tempfile�TemporaryDirectoryrZ
change_cwdrr,�assertEqual�path�sep�join�mkdir�chdir�FileNotFoundError�OSError�errnoZENAMETOOLONGr�verbose�print)
r0Zmin_lenZdirlen�dirnameZtmpdirr>�expectedr1Zneed�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__r2rKrOrrrrr*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�r0rrr�setUp���zFileTests.setUpcCs:t�tjtjtjB�}t�|�|�t�tjtj	��dSr+)
rr$rrU�O_CREAT�O_RDWR�close�
assertTrue�access�W_OK�r0�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$rrUrZr[�dupr\�skipTest�
closerange�assertRaisesrDr%)r0�first�secondZretriesrrr�test_closerange�s


��zFileTests.test_closerangecCs<tj}t�|�}|�ttj|d�t�|�}|�||�dS�Nr)	rrUr8�getrefcountrj�	TypeErrorr�renamer=)r0r>�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$rrUr%�flush�filenor�lseek�readr=�typerM)r0�fobj�fd�srrr�	test_read�s
"�zFileTests.test_readzneeds INT_MAX < PY_SSIZE_T_MAXrdrcF)�sizeZmemuse�dry_runcCsh|�tjtj�ttjd�ttjd��}t�|��|�}Wd�n1s'wY|�	|d�dS)Nstest�rb)
�
addCleanuprrVrUr(r$rr{ryr=)r0r�r'�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�)sbaconseggsrv)rr$rrUrZ�O_WRONLYrjrpr%�	bytearray�
memoryviewr\r=r{�
splitlines)r0r~r}rrr�
test_write�s
�"�zFileTests.test_writecGs"tj|tjdd�}|�|d�dS)NT)�
creationflags�shellr)�
subprocess�callZCREATE_NEW_CONSOLEr=)r0�args�retcoderrr�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�r8�
executable�r0�coderrr�test_write_windows_consolesz$FileTests.test_write_windows_consolecGs4t�tjtj�}tj|g|�Rddi�}|��dS)N�encoding�utf-8)rr$rrU�O_RDONLY�fdopenr\)r0r�r~rarrr�
fdopen_helperszFileTests.fdopen_helpercCsBt�tjtjtjB�}t�|�|��|�d�|�dd�dS)N�r�d)rr$rrUrZr[r\r��r0r~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)
rrUr�rVr(r�replacerjrC�statr$r=r{)r0�TESTFN2rarrr�test_replaces

"�zFileTests.test_replacecCs"tjttjddd�}t�|�dS)N�)r>�flags�mode�dir_fd)rr$�__file__r�r\r`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_attributerrrU�NotImplementedErrorrD)r0r�rrr�test_symlink_keywords1s��zFileTests.test_symlink_keywords�copy_file_rangeztest needs os.copy_file_range()cC�>|�t��t�ddd�Wd�dS1swYdS�Nrrci����)rj�
ValueErrorrr�rWrrr�#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�ru�r�)rrUr(r�rVr$r\ryrr�rDrE�ENOSYSrh�assertIn�ranger=r{)	r0r�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�ru)�
offset_src�
offset_dstrrc�)rrUr(r�rVr$r\ryrr�rDrEr�rhr�r�r{r=)
r0�TESTFN4r��
bytes_to_copy�in_skip�out_seekr�r�r�r�r�r�r{rrr�test_copy_file_range_offset`sB



���

��z%FileTests.test_copy_file_range_offset�spliceztest needs os.splice()cCr�r�)rjr�rr�rWrrr�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+�rr\r��read_fdrr�<lambda>��
z'FileTests.test_splice.<locals>.<lambda>cr�r+r�r��write_fdrrr��r�r�rr�r�)rrUr(r�rVr$r\ryr�piper�rDrEr�rhr�r�r=r{)r0r�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�rrcr�)rrUr(r�rVr$r\ryrr�r�rDrEr�rhr�r�r{r=)
r0r�r�r�r�r�r�r�r�r{rr�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�ru)r�rrcr�r�)rrUr(r�rVrr�r%r$r\ryr�rDrEr�rhr�r�r{r=)r0r�r�r�r�r�r�r�r�r�r{rr�r�test_splice_offset_out�s8

��

� z FileTests.test_splice_offset_outN)%rPrQrRrX�tearDownrbrmr�cpython_onlyrtr�rrrrZ
bigmemtestr�r�r�r8r9r�r�r�r�r�r�rrr�r�r�r��requires_splice_piper�r�r�rrrrrS�sT


�
�
	


!
,
$rSc@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)rrU�fnamer�rVr(rWrrrrXszStatAttributeTests.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're��deltar6�No exception raisedrc�rd�rrcrer�rwr�r����	rd���
�)rr�r=�ST_SIZE�st_size�dir�lower�endswith�getattrr��splitr��assertAlmostEqual�fail�
IndexError�st_mode�AttributeError�st_rdevrp�parrot�stat_result)
r0r��result�membersr�attrr�ZfloatyZnanosecondy�result2rrr�check_stat_attributessl


������
��z(StatAttributeTests.check_stat_attributescCs|�|j�dSr+)rr�rWrrr�test_stat_attributesM�z'StatAttributeTests.test_stat_attributescCsFz
|j�t���}Wnty|�d|j�Ynw|�|�dS)Nz#cannot encode %a for the filesystem)r��encoder8�getfilesystemencoding�UnicodeEncodeErrorrhr)r0r�rrr�test_stat_attributes_bytesPs�z-StatAttributeTests.test_stat_attributes_bytescC�ft�|j�}ttjd�D]#}t�||�}|�d|�|dkr%|�d|�t�|�}|�	||�q
dS)Nrcsstat_resultrwscos
stat_result
)
rr�r�r��pickle�HIGHEST_PROTOCOL�dumpsr��loadsr=�r0r�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_rdrcr�r�r�)rrr�r=�f_bfree�	enumeraterr]�
isinstance�f_fsidr�r:rrr	�statvfs_resultrp)r0rr�value�memberrrrr�test_statvfs_attributesas<��
��z*StatAttributeTests.test_statvfs_attributes�need os.statvfs()cCr)Nrcsstatvfs_resultrwscos
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�rCrhrDr�r0r�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�r\rjrDr=�	exceptionrE�EBADF)r0r��w�ctxrrr�
test_15261�s

��zStatAttributeTests.test_15261cCsL|�t|d��|�t|jt��|�d|jko dk�dS�dS)N�st_file_attributesr���)r]rr$r4r�)r0rrrr�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�r6r=r4�FILE_ATTRIBUTE_DIRECTORYrrUrAr��rmdir)r0rrHrrr�test_file_attributes�s

�




�z'StatAttributeTests.test_file_attributescCsdtj�tjd|j�}|�tj|�t|d�d}t	j
d|ddg|d�t�|�}|�|j
d�dS)	N�TEMPr�r�z
icacls.exez/denyz*S-1-5-32-545:(S)�r�r)rr>r@�environr�r�rrVr(r��
check_callr��assertNotEqualr�)r0r�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)r0r�rrrr�test_stat_block_device�s
z)StatAttributeTests.test_stat_block_deviceN)rPrQrRrXrrrrrrrrr)r+r8r9r.r3r6r9r?rBrrrrr�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)rrUrHrr>r@r�r��rmtreerAr(rWrrrrX�s
zUtimeTests.setUpcCs4t�|�}|j|dkp|j|dkp|j|dkS)Nr�r�r�)rr��st_atime�st_mtime�st_ctime)r0r&�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�rJrr�rrFrGr=�st_atime_ns�st_mtime_ns)r0�set_timer&rJ�atime_ns�mtime_nsrIrrr�_test_utime�s"

zUtimeTests._test_utimecC�dd�}|�|�dS)NcS�tj||d�dS�N��ns�r�utime�r&rWrrrrO�z'UtimeTests.test_utime.<locals>.set_time�rR�r0rOrrr�
test_utimeszUtimeTests.test_utimecCs|ddS)NrLg��&�.>rrVrrr�	ns_to_sec szUtimeTests.ns_to_secc��fdd�}��|�dS)Ncs0|\}}��|�}��|�}t�|||f�dSr+�r_rrY�r&rWrPrQZatime�mtimerWrrrO)s

z2UtimeTests.test_utime_by_indexed.<locals>.set_timer\r]rrWr�test_utime_by_indexed'sz UtimeTests.test_utime_by_indexedcr`)Ncs2|\}}��|�}��|�}tj|||fd�dS)N)�timesrarbrWrrrO3s

z0UtimeTests.test_utime_by_times.<locals>.set_timer\r]rrWr�test_utime_by_times2szUtimeTests.test_utime_by_timesz9follow_symlinks support for utime required for this test.cCrS)NcSstj||dd�dS)NF)rW�follow_symlinksrXrZrrrrO?sz9UtimeTests.test_utime_nofollow_symlinks.<locals>.set_timer\r]rrr�test_utime_nofollow_symlinks;sz'UtimeTests.test_utime_nofollow_symlinksz,fd support for utime required for this test.cCrS)NcSsDt|dd��}tj|��|d�Wd�dS1swYdS)N�wbrrV)r$rrYry)r&rWr'rrrrOHs"�z*UtimeTests.test_utime_fd.<locals>.set_timer\r]rrr�
test_utime_fdE�zUtimeTests.test_utime_fdz0dir_fd support for utime required for this test.cCrS)NcSsPtj�|�\}}t�|��}tj|||d�Wd�dS1s!wYdS)N)r�rW)rr>rr�open_dir_fdrY)r&rWrHr�dirfdrrrrORs"�z.UtimeTests.test_utime_dir_fd.<locals>.set_timer\r]rrr�test_utime_dir_fdOrkzUtimeTests.test_utime_dir_fdcCsdd�}|j||jd�dS)NcSrTrUrXrZrrrrOZr[z1UtimeTests.test_utime_directory.<locals>.set_time�r&)rRrHr]rrr�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�rJrr�rGr)r0rO�currentr�rIrqrrr�_test_utime_current_s
�

�zUtimeTests._test_utime_currentcr`)Ncst��j�dSr+�rrYr�rorWrrrOv�z/UtimeTests.test_utime_current.<locals>.set_time�rtr]rrWr�test_utime_currentu�zUtimeTests.test_utime_currentcr`)Ncst��jd�dSr+rurorWrrrO|r[z3UtimeTests.test_utime_current_old.<locals>.set_timerwr]rrWr�test_utime_current_old{ryz!UtimeTests.test_utime_current_oldcCsptjdkr4tj�tj�|��dd}ddl}|jj}|�	dd�}|�
|ddddd|t|��}|r6|jSdSdS)Nr�r�\�r�)
r8r9rr>r@�abspath�ctypes�windll�kernel32Zcreate_unicode_bufferZGetVolumeInformationWr:r')r0r>�rootr~r��buf�okrrr�get_file_system�s

��zUtimeTests.get_file_systemcCsJ|�|j�dkr
|�d�d}t�|j||f�|�t�|j�j|�dS)NZNTFSz
requires NTFSrK)	r�rHrhrrYr�r=r�rG)r0Zlargerrr�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�rVr�)r�)r�r�r�F�rgrir�r�)rjr�rrYr�rp�supports_follow_symlinksr��supports_fdr$ry�supports_dir_fd)r0r'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)rPrQrRr�rr�rr�BadInt�sr�r)r�r�rr�r�get_bad_int�sz/UtimeTests.test_issue31577.<locals>.get_bad_int�*rcrVr)rcrer�)rjrprrYr�)r0r�rrr�test_issue31577�s��"�zUtimeTests.test_issue31577r+)rPrQrRrXrJrRr^�staticmethodr_rdrfrrrrYr�rhr�rjr�rnrprtrxrzr�r�r�rr�r�rrrrrC�s<

	�
�
�


rC)�
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+)	�dictrr<�_EnvironTests__save�supports_bytes_environ�environb�_EnvironTests__saveb�
_reference�items�r0�keyr'rrrrX�s�zEnvironTests.setUpcCs>tj��tj�|j�tjrtj��tj�|j�dSdSr+)rr<�clear�updater�r�r�r�rWrrrr��s

�zEnvironTests.tearDowncCsdddd�S)NZVALUE1ZVALUE2ZVALUE3)ZKEY1ZKEY2ZKEY3rrWrrrr���zEnvironTests._referencecCstj��tjSr+)rr<r�rWrrr�_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')	rr<r�r�r�rr{�stripr=)r0r�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=�nextrj�
StopIteration)r0r��itrrr�test_os_popen_iter�s�"�zEnvironTests.test_os_popen_itercCs8tj��D]\}}|�t|�t�|�t|�t�qdSr+)rr<r�r=r|r.)r0r��valrrr�test_keyvalue_types�s�z EnvironTests.test_keyvalue_typescCs.|����D]\}}|�tj�|�|�qdSr+)r�r�r=rr<�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>)rr<r=�reprr�r@r�)r0�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/pythonr|z/flying/circus�PATH�r��r|r|T)�recordr�r�)r��PATHr��abc�abc)r�defpathr�pathsepr@r<r��assertSequenceEqual�
get_exec_pathr��warnings�catch_warnings�BytesWarningrjr�)r0Z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 %s�unicodesunicode��sbytesrM)
rr8rrrhrr<r=r��decode)r0r'Zvalue_bytesrqZ	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��runr8r��PIPEr=r��rstripr��unsetenv)r0rr'r�r��procrrr�test_putenv_unsetenvJs 
�
�"�z!EnvironTests.test_putenv_unsetenvrdr�cCs�dD]}|�ttftj|d�|�ttftj|�qtjdkr?dd}|�ttj|d�|�ttjd|�|�ttj|�dSdS)N)r|z=namezna=mezname=znameznamer'r�r���r��X)rjrDr�rr�r�r8r9)r0rZlongstrrrr�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)
�assertNotInrr<rj�KeyError�assertIsr/r�r]�__suppress_context__)r0�missing�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�rr<r=)r0Z
collection�iteratorZnew_keyrrr�_test_environ_iteration{s
z$EnvironTests._test_environ_iterationcC�|�tj�dSr+)r�rr<rWrrr�(test_iter_error_when_changing_os_environ�rz5EnvironTests.test_iter_error_when_changing_os_environcC�|�tj���dSr+)r�rr<r�rWrrr�.test_iter_error_when_changing_os_environ_items��z;EnvironTests.test_iter_error_when_changing_os_environ_itemscCr�r+)r�rr<�valuesrWrrr�/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�r{r�r=)r0�varrIr�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�3r|)rr<r�r��assertDictEqualr=r�r��NotImplemented�__or__r��r0�overridden_keyr��
new_vars_dictrI�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��rr<r�r�r=r�)r0r�r�rIrrr�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)Nrcr�)rr<�copyrjrpr=)r0Zos_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�)r0r�r�rIrrr�$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�)rr<r�r�r�r=r�r�r��__ror__r�r�rrr�test_ror_operator�s

zEnvironTests.test_ror_operator)&rPrQrRZ	type2testrXr�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�rrrrrrr��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�Nrg�followlinks)r�r�walk)r0�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.
�brokenTZtmp5)rrrrrrc)rr>r@r�rrErU�	walk_path�	sub1_path�
sub11_path�	link_path�makedirsr$r%�can_symlinkr�r}�	sub2_tree�chmod�listdir�PermissionErrorr��S_IRWXUrVr8)r0r@Z	sub2_pathZ
sub21_pathZ	tmp1_pathZ	tmp2_pathZ	tmp3_pathZ	tmp5_pathZt2_pathZ	tmp4_pathZbroken_link_pathZbroken_link2_pathZbroken_link3_pathr>rarrrrX�sZ








����

zWalkTests.setUpcCs�t|�|j��}|�t|�d�|ddddk}|dd��|dd|d��|dd|d��|�|d|jddgd	gf�|�|d||jd
gdgf�|�|d||jggf�|�|dd||j�dS)Nrwrrcr	r�re���rrr
r
)	�listrrr=r:�sortrrr�r0�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)Nr	rerrrrcr )rr�append�remover=r:r"r)r0rr$r��dirsr rrr�test_walk_pruneNs
�zWalkTests.test_walk_prunecCs|�t|j��dSr+)r)rrrWrrr�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��topdownrwr�rcrr	rer rrr
r
)	r!rrr=r:r"rrrr#rrr�test_walk_bottom_upds$
�

���zWalkTests.test_walk_bottom_upcCsjt��s	|�d�|j|jdd�}|D]\}}}||jkr-|�|g�|�|dg�dSq|�d�dS)Nzneed symlink supportTr�rz+Didn't follow symlink with followlinks=True)rrrhrrrr=r)r0�walk_itr�r(r rrr�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)�onerrorr	z.newcSsg|]\}}}|�qSrr)r
r��drarrrr��z/WalkTests.test_walk_bad_dir.<locals>.<listcomp>)rrr&r�r=rr>r@rqr]r�r�)r0�errorsr.r�r(r �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�Zdeepr1c�g|]	}�j�dd��qS)Fr+�r�r
�j��baser0rrr��z7WalkTests.test_walk_many_open_files.<locals>.<listcomp>r�rccr9)Tr+r:r;r=rrr�r?)
rr>r@rrUrr�r=r�rH)r0�depthrZitersr�rIr�rr=r�test_walk_many_open_files�s$
�z#WalkTests.test_walk_many_open_filesr+)rPrQrRrrXr%r)r*r-r/r7rArrrrr�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+)rB)r0rrr�r(r Zroot_fdrrrr�s��zFwalkTests.walkcOstj|i|��Sr+)rrB�r0r�rrrrrB�rzFwalkTests.fwalkc
Cs�	|��}|��}tjddd�D]O\}}|j||d�|j||d�i}tjdi|��D]\}}}t|�t|�f||<q,|jdi|��D]\}}}}	|�||�|�	||t|�t|�f�qDqdS)N�TFre��repeat)r,r)r,rgr)
r��	itertools�productr�rr�setrBr�r=)
r0�walk_kwargs�fwalk_kwargsr,rgrIr�r(r �rootfdrrr�_compare_to_walk�s��zFwalkTests._compare_to_walkcCsdtji}|�||�dS)Nr)rrUrN)r0rrrr�test_compare_to_walk��
zFwalkTests.test_compare_to_walkc	CsRz"t�dtj�}dtji}|��}||d<|�||�Wt�|�dSt�|�w)N�.rr�)rr$r�rrUr�rNr\)r0r~rKrLrrr�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)NrErerFrg)rHrIrrUrBr�fstatr�r=rJr)r0r,rgr�r�r(r rMrrr�test_yields_correct_dir_fd�s

$��z%FwalkTests.test_yields_correct_dir_fdcCs\t�d�}t�|�td�D]}|�tj�D]}qqt�d�}|�tj|�|�||�dS)Nrc�)	rrgr\r�rBrrUr�r=)r0Zminfdr�r�Znewfdrrr�test_fd_leak�s

�
zFwalkTests.test_fd_leakN)rPrQrRrrBrNrOrRrTrVrArrrrrC�s
rCc@�eZdZ	dd�ZdS)�BytesWalkTestsc	ks��d|vr|�d�|d<tjt�|�fi|��D]8\}}}t�|�}tttj|��}tttj|��}|||fVtttj|��|dd�<tttj|��|dd�<qdSr)r�rr�fsencoderNr!�map)	r0rr�broot�bdirs�bfilesr�r(r rrrr�s�"
�zBytesWalkTests.walkN)rPrQrRrrrrrrX�srXc@seZdZ	ddd�ZdS)�BytesFwalkTestsrQcos��tjt�|�g|�Ri|��D]:\}}}}t�|�}tttj|��}	tttj|��}
||	|
|fVtttj|	��|dd�<tttj|
��|dd�<qdSr+)rrBrYrNr!rZ)r0rr�rr[r\r]�topfdr�r(r rrrrB
s�*
�zBytesFwalkTests.fwalkN)rQ)rPrQrRrBrrrrr^sr^c@�DeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�MakedirTestscC�t�tj�dSr+�rrArrUrWrrrrXrzMakedirTests.setUpc
Cs�tj}tj�|ddd�}t�|�tj�|dddd�}t�|�|�ttjtj�tj�|dddddtj�}t�|�tj�|dtjddddd�}t�|�dS�Nr4r6Zdir3Zdir4Zdir5Zdir6)	rrUrr>r@rrjrD�curdir)r0r>r>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)Nrer4r6im�ntr�i�)rZ
temp_umaskrUrr>r@rr]r��isdirrr=r�r)r0r>�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)
Nr4r��F��exist_oki�T)r�rm�/)
rr>r@rrU�umaskrrjrDr})r0r>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)Nr4r�rkzCannot set S_ISGID for dir.z No support for S_ISGID dir mode.Trl)rr>r@rrUr��S_ISGIDro�S_IMODE�lstatrrrr�SkipTestr)r0r>rrr�rpZexisting_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)	Nr4r1r�r�r�FrlT)rrUrr>r@r$r%rjrDrr')r0r>r>rarrr�#test_exist_ok_existing_regular_file\s�z0MakedirTests.test_exist_ok_existing_regular_filec	Cs`tj�tjdddddd�}tj�|�s)|tjkr)tj�|�}tj�|�s)|tjkst�|�dSrd)rr>r@rrUr�rH�
removedirs�r0r>rrrr�fs��zMakedirTests.tearDownN)
rPrQrRrXrfrjrqrvrwr�rrrrras
ra�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)�ChownFileTestscCrbr+rc��clsrrr�
setUpClassurvzChownFileTests.setUpClasscCs�t�tj�}|j}|j}ddt�d�t�	dd�fD]}|�
ttjtj||�|�
ttjtj||�q|�
t�tj||��|�
t�tjdd��dS)Ng�y��r ���re)rr�rrU�st_uid�st_gid�decimalZDecimal�	fractionsZFractionrjrprz�assertIsNone)r0r��uid�gidr'rrr�*test_chown_uid_gid_arguments_must_be_indexys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)Nreztest needs at least 2 groups)rr�r:rhr�rrUr�rzr�r=)r0�groupsZgid_1Zgid_2r�r�rrr�test_chown_gid�s
zChownFileTests.test_chown_gidrcz0test needs root privilege and more than one usercCsvtdd�\}}t�tj�j}t�tj||�t�tj�j}|�||�t�tj||�t�tj�j}|�||�dS�Nre)	�	all_usersrr�rrUr�rzr�r=)r0�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�rrUr�rjrrz)r0r�r�r�rrr�test_chown_without_permission�s"�z,ChownFileTests.test_chown_without_permissioncCrbr+)rr8rrUr|rrr�
tearDownClass�rvzChownFileTests.tearDownClassN)rPrQrR�classmethodr~r�rrrrr��
root_in_posixr:r�r�r�r�rrrrr{rs 


�

�
r{c@�4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�RemoveDirsTestscCrbr+)rrrrUrWrrrrX�rzRemoveDirsTests.setUpcCst�tj�dSr+)rrErUrWrrrr��rzRemoveDirsTests.tearDowncCsxtj�tjd�}t�|�tj�|d�}t�|�t�|�|�tj�|��|�tj�|��|�tj�tj��dS)N�dira�dirb)	rr>r@rrUrArx�assertFalser��r0r�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@rrUrAr(rxr�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@rrUrAr(rjrDrxr]r�r�rrr�test_remove_nothing�s

�z#RemoveDirsTests.test_remove_nothingN)rPrQrRrXr�r�r�r�rrrrr��s
r�c@�eZdZdd�ZdS)�DevNullTestscCs�ttjdd��}|�d�|��Wd�n1swYttjd��}|�|��d�Wd�dS1s:wYdS)Nrir�hellor��)r$r�devnullr%r\r=r{r`rrr�test_devnull�s

�"�zDevNullTests.test_devnullN)rPrQrRr�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)Nrrcrdr�r5)r=r:r�urandomrWrrr�test_urandom_length�s
z URandomTests.test_urandom_lengthcCs0t�d�}|�|t�t�d�}|�||�dS�N�)rr�r-rMr>�r0Zdata1Zdata2rrr�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�rc)r@rr=r:)r0�countr��outr�rrr�get_urandom_subprocess�s�
z#URandomTests.get_urandom_subprocesscCs$|�d�}|�d�}|�||�dSr�)r�r>r�rrr�test_urandom_subprocess��

z$URandomTests.test_urandom_subprocessN)rPrQrRr�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)Nrcz%getrandom() syscall fails with ENOSYS)rr�rDrEr�rru)r}rJrrrr~s
��zGetRandomTests.setUpClasscCs*t�d�}|�|t�|�t|�d�dSr�)rr�r-rMr=r:�r0r�rrr�test_getrandom_type
s
z"GetRandomTests.test_getrandom_typecCst�d�}|�|d�dS)Nrr�)rr�r=)r0�emptyrrr�test_getrandom0rPzGetRandomTests.test_getrandom0cCs|�ttd��dS)N�GRND_RANDOM)r]rrrWrrr�test_getrandom_randomr�z$GetRandomTests.test_getrandom_randomcCs*z
t�dtj�WdStyYdSw�Nrc)rr��
GRND_NONBLOCK�BlockingIOErrorrWrrr�test_getrandom_nonblocks
�z&GetRandomTests.test_getrandom_nonblockcCs$t�d�}t�d�}|�||�dSr�)rr�r>r�rrr�test_getrandom_value$r�z#GetRandomTests.test_getrandom_valueN)
rPrQrRr�r~r�r�r�r�r�rrrrr��s
r�ZHAVE_GETENTROPYrcZHAVE_GETRANDOMZHAVE_GETRANDOM_SYSCALLz*os.random() does not use a file descriptorr4z$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_failure6sz#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)r0r��rcr��errrrr�test_urandom_fd_closedMs	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))
            )rUr�r�rrw)
r�rrVrUr(r�rr=r:r>)r0r�r�r�r�Zout2Zerr2rrr�test_urandom_fd_reopened[s�z'URandomFDTests.test_urandom_fd_reopenedN)	rPrQrRrr�resourcer�r�r�rrrrr�1s


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)r&rDrE�ENOTDIRr�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-)rjrDr�execvperWrrr�test_execvpe_with_bad_program�s�z'ExecTests.test_execvpe_with_bad_programcCsN|�ttjdd�|�ttjdg�|�ttjdd�|�ttjddg�dS)N�notepadrr�r|)rjr�rr�rWrrr�test_execv_with_bad_arglist�sz%ExecTests.test_execv_with_bad_arglistcCsB|�ttjdgd�|�ttjdgi�|�ttjddgi�dS)Nr�r|)rjr�rr�rWrrr�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�rgZspamr�rcrr�)r�r�r�r�r�)rr?rMr>r@rYrr�rjr�r�r=r:rDr�r�)
r0Z	test_typeZprogram_pathZprogram�fullpathZnative_fullpathZ	argumentsr�r�Zenv_pathrrr�_test_internal_execvpe�sT


��
�
��	

�
�"�z ExecTests._test_internal_execvpecCs&|�t�tjdkr|�t�dSdS)Nrg)r�r.rrrMrWrrr�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)r8r�rr<r�rjr�r�)r0r��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)Nr|�argrzNo OSError raised)rr�rDr]�winerrorrr-rrr�test_execve_with_empty_paths(��z%ExecTests.test_execve_with_empty_pathN)rPrQrRr�skipIf�USING_LINUXTHREADSr�r�r�rrrr�r�r�r8r9r�rrrrr��s�
�
/r�r�r,c@r`)�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�rrUrCrDr)r0r�rJrrrrXs
���zWin32ErrorTests.setUpcCs|�ttjtjtjd�dS)Nz.bak)rjrDrrqrrUrWrrrrtszWin32ErrorTests.test_renamecC�|�ttjtj�dSr+)rjrDrr'rrUrWrrr�test_remover!zWin32ErrorTests.test_removecCr�r+)rjrDrrBrrUrWrrr�
test_chdir!r!zWin32ErrorTests.test_chdircCsT|�tjtj�ttjd��}|�ttjtj�Wd�dS1s#wYdS)Nr�)	r�rrVrUr$rjrDrrAr`rrr�
test_mkdir$s"�zWin32ErrorTests.test_mkdircCs|�ttjtjd�dSr+)rjrDrrYrrUrWrrrr^*�zWin32ErrorTests.test_utimecCs|�ttjtjd�dSrn)rjrDrrrrUrWrrr�
test_chmod-r�zWin32ErrorTests.test_chmodN)
rPrQrRrXrtr�r�r�r^r�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)�fchdirrg�	fdatasyncrS�fstatvfs�fsync�	tcgetpgrp�ttynamecs�fdd�}|S)Ncs"tt��r|�tt���dSdSr+)rrr�rrW�rarr�helper7s
�z(TestInvalidFD.get_single.<locals>.helperr)rar�rr�r�
get_single6s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_fdrDr=rEr0r)r0rar�rr�rrrr�>s��
�zTestInvalidFD.checkcCs|jtjdd�dS)Nr�r�)r�rr�rWrrrr�Gr�zTestInvalidFD.test_fdopen�isattyztest needs os.isatty()cCs|�t�t���d�dS�NF)r=rr�rr�rWrrr�test_isattyJszTestInvalidFD.test_isattyriztest needs os.closerange()c	Csnt��}td�D]}z	t�||�Wn	tyYqw|dkr't�d��|�t�	|||d�d�dS)Nrdrez5Unable to acquire a range of invalid file descriptorsrc)
rr�r�rrSrDrrur=ri)r0r~r�rrrrmNs�� zTestInvalidFD.test_closerange�dup2ztest needs os.dup2()cC�|�tjd�dS)N�)r�rrrWrrr�	test_dup2^r[zTestInvalidFD.test_dup2c
Cs�t�ttj�}|�tj|�|ddg}tj|dd�D]C\}}||kr]|j||d��,|�	t
��}t�||�Wd�n1s@wY|�|j
jtj�Wd�n1sXwYqdS)Nr i�rerF)r~�fd2)rr$r�r�r�r\rHrI�subTestrjrDrr=r/rEr0)r0Zvalid_fd�fdsr~rr2rrr�test_dup2_negative_fdbs �����z#TestInvalidFD.test_dup2_negative_fd�fchmodztest needs os.fchmod()cCrrn)r�rr	rWrrr�test_fchmodrr[zTestInvalidFD.test_fchmod�fchownztest needs os.fchown()cC�|�tjdd�dS)Nr )r�rrrWrrr�test_fchownv�zTestInvalidFD.test_fchown�	fpathconfztest needs os.fpathconf()cC� |�tjd�|�tjd�dS)N�PC_NAME_MAX)r�r�pathconfrrWrrr�test_fpathconfz�zTestInvalidFD.test_fpathconf�	ftruncateztest needs os.ftruncate()cCrrn)r�r�truncaterrWrrr�test_ftruncaterzTestInvalidFD.test_ftruncaterzztest needs os.lseek()cCrrn)r�rrzrWrrr�
test_lseek�rzTestInvalidFD.test_lseekr{ztest needs os.read()cCrr�)r�rr{rWrrrr��r[zTestInvalidFD.test_read�readvztest needs os.readv()cCstd�}|�tj|g�dS)Nrd)r�r�rr)r0r�rrr�
test_readv�szTestInvalidFD.test_readv�	tcsetpgrpztest needs os.tcsetpgrp()cCrrn)r�rrrWrrr�test_tcsetpgrpt�r[zTestInvalidFD.test_tcsetpgrptr%ztest needs os.write()cCr)N� )r�rr%rWrrrr��r[zTestInvalidFD.test_write�writevztest needs os.writev()cCs|�tjdg�dS)Nr�)r�rrrWrrr�test_writev�rzTestInvalidFD.test_writevcC�|�tj�|�tjd�dS�NT)r�r�get_inheritable�set_inheritablerWrrr�test_inheritable��zTestInvalidFD.test_inheritable�get_blocking�-needs os.get_blocking() and os.set_blocking()cCr r!)r�rr&�set_blockingrWrrr�
test_blocking�szTestInvalidFD.test_blockingN)rPrQrRZsinglesr�ra�localsr�r�rrrrrrmrrr
r
rrrr�rrr�rr$r)rrrrr�1sP	













�r�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�	LinkTestscCs tj|_tj�tjd�|_dS)Nr�)rrU�file1rr>r@�file2rWrrrrX��zLinkTests.setUpcCs,|j|jfD]
}tj�|�rt�|�qdSr+)r,r-rr>r�rV)r0�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(rrrrhr$r]r>�sameopenfilery)r0r,r-r�rD�f2rrr�
_test_link�s��P�zLinkTests._test_linkcCs|�|j|j�dSr+)r3r,r-rWrrr�	test_link�r�zLinkTests.test_linkcCs(|�t|jt���t|jt����dSr+)r3rMr,r8rr-rWrrr�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�)rrY�UnicodeErrorrrur,r-r3rWrrr�test_unicode_name�s
�zLinkTests.test_unicode_nameN)	rPrQrRrXr�r3r4r5r8rrrrr+�s
r+zPosix 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�getuidrjrDr;rp�
OverflowError�UID_OVERFLOWrWrrr�test_setuid��zPosixUidGidTests.test_setuid�setgidztest needs os.setgid()cC�Ft��dkrts|�ttjd�|�ttjd�|�ttj|j�dSr<)	rr=�HAVE_WHEEL_GROUPrjrDrBrpr>�GID_OVERFLOWrWrrr�test_setgid��zPosixUidGidTests.test_setgid�seteuidztest needs os.seteuid()cCsBt��dkr|�ttjd�|�ttjd�|�ttj|j�dSr<)	rr=rjrDrHrp�setegidr>r?rWrrr�test_seteuid�rAzPosixUidGidTests.test_seteuidrIztest needs os.setegid()cCrCr<)	rr=rDrjrDrIrpr>rErWrrr�test_setegid�rGzPosixUidGidTests.test_setegid�setreuidztest needs os.setreuid()cCsnt��dkr|�ttjdd�|�ttjdd�|�ttjdd�|�ttj|jd�|�ttjd|j�dSr<)rr=rjrDrLrpr>r?rWrrr�
test_setreuid�szPosixUidGidTests.test_setreuidcC�t�tjddg�dS)Nr�z,import os,sys;os.setreuid(-1,-1);sys.exit(0)�r�r=r8r�rWrrr�test_setreuid_neg1��
�z#PosixUidGidTests.test_setreuid_neg1�setregidztest needs os.setregid()cCsrt��dkrts|�ttjdd�|�ttjdd�|�ttjdd�|�ttj|jd�|�ttjd|j�dSr<)	rr=rDrjrDrRrpr>rErWrrr�
test_setregid	szPosixUidGidTests.test_setregidcCrN)Nr�z,import os,sys;os.setregid(-1,-1);sys.exit(0)rOrWrrr�test_setregid_neg1		rQz#PosixUidGidTests.test_setregid_neg1N)rPrQrRr?rErrrrr@rFrJrKrMrPrSrTrrrrr9�s&






r9c@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+)rrYrr&)�fn��bytesfnrr�add_filename	s�z'Pep383Tests.setUp.<locals>.add_filenamez&couldn't create any non-ascii filenamezduplicate filename)r�TESTFN_UNENCODABLEr�ZTESTFN_NONASCIIrUrrYZbdirZTESTFN_UNICODErhrJ�	unicodefnrAZcreate_empty_filer>r@rNr��add�shutilrE)r0rYrVrrWrrX	s8







�zPep383Tests.setUpcCst�|j�dSr+)r]rEr�rWrrrr�8	rzPep383Tests.tearDownc	Cst|j}tt�|j��}|�||�t��}zt�tj�|�tt���tt�tj���Wt�|�dSt�|�wr+)	r[rJrrr�r=r,rBr?)r0rI�foundZcurrent_directoryrrr�test_listdir;	s"zPep383Tests.test_listdircCs.|jD]}ttj�|j|�d�}|��qdS�Nr�)r[r$rr>r@r�r\)r0rVrarrr�	test_openG	s

�zPep383Tests.test_openrr*cCs*|jD]}tj�|j|�}t�|�qdSr+)r[rr>r@r�r)r0rV�fullnamerrr�test_statvfsL	s
�zPep383Tests.test_statvfscCs&|jD]
}t�tj�|j|��qdSr+)r[rr�r>r@r�)r0rVrrr�	test_statU	s
�zPep383Tests.test_statN)
rPrQrRrXr�r_rarrrrrcrdrrrrrU	s%�
rUc@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皙�����?rcz1Did not receive communication from the subprocess))r~rg�msvcrtrr��
PeekNamedPipe�BOOL�restype�HANDLE�POINTERZc_char�DWORD�argtypesr��Popenr8r�r�r�r�r�r\rirj�pollZcreate_string_bufferr:Z
get_osfhandleryZsizeofr>r'r=r�rr�sleeprr�kill�pid�wait)r0�sigr~rgrmrnrqr�r��maxr�Zrsltrrr�_kill[	sP




�
���
�
zWin32KillTests._killcCr�r+)r}�signal�SIGTERMrWrrr�test_kill_sigterm�	rvz Win32KillTests.test_kill_sigtermcCs|�d�dS)Nr�)r}rWrrr�
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_%sr rcrzwin_console_handler.pyr;rkrlz'Subprocess didn't finish initializationg�?zsubprocess did not stop on {})�uuidZuuid1�mmapr�rur8r�rr>r@rHr�ZCREATE_NEW_PROCESS_GROUPrvrrrwrxryr~�SIGINTrr�)r0�eventrZtagname�mr�r�r|rrr�_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)Nrrf�CTRL_C_EVENT)
r~rgrrZc_intrr��SetConsoleCtrlHandlerrortrpr�r~r�)r0rgr~ZNULLr�rrr�test_CTRL_C_EVENT�	s

�
z Win32KillTests.test_CTRL_C_EVENTcCr)N�CTRL_BREAK_EVENT)r�r~r�rWrrr�test_CTRL_BREAK_EVENT�	�z$Win32KillTests.test_CTRL_BREAK_EVENTN)rPrQrRr}r�r�r�r�skipr�r�rrrrreY	s6
rec@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)NrezSUB%dzFILE%dr1r�r�z'I'm %s and proud of it. Blame test_os.
)�
created_pathsr�rr>r@rrUrr$r%�extendr")r0r�Zdir_nameZdir_path�	file_nameZ	file_pathrarrrrX�	s
�zWin32ListdirTests.setUpcCrbr+)r]rErrUrWrrrr��	rzWin32ListdirTests.tearDowncCsJ	|�tt�tj��|j�|�tt�t�tj���dd�|jD��dS)NcS�g|]}t�|��qSr�rrY�r
r>rrrr�	r2zCWin32ListdirTests.test_listdir_no_extended_path.<locals>.<listcomp>)r=�sortedrrrrUr�rYrWrrr�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�	r2z@Win32ListdirTests.test_listdir_extended_path.<locals>.<listcomp>)
rr>r}rrUr=r�rr�rYryrrr�test_listdir_extended_path�	s��z,Win32ListdirTests.test_listdir_extended_pathN)rPrQrRrXr�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�)�
startswithr$rM)rrrrr�

s
��z/ReadlinkTests.assertPathEqual.<locals>.<lambda>rw)rr>�normcaser8r9r=)r0�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�	filelinkbrWrrrrX
szReadlinkTests.setUpcCs0t|j�}|�ttj|j�|�ttj|�dSr+)rr�rjrDrr�)r0r�rrr�test_not_symlink
s
zReadlinkTests.test_not_symlinkcCs(|�ttjd�|�ttjtd��dS)Nzmissing-link)rjrCrr�rrWrrr�test_missing_link
s
�zReadlinkTests.test_missing_linkcCsBt�|j|j�|�tj|j�t|j�}|�t�	|�|j�dSr+)
rr�r�r�r�rrVrr�r�)r0r�rrr�
test_pathlike"
s
zReadlinkTests.test_pathlikecCsNt�|j|j�|�tj|j�t�t|j��}|�	||j�|�
|t�dSr+)rr�r�r�r�rrVr�rr�r-rMryrrr�test_pathlike_bytes)
s
z!ReadlinkTests.test_pathlike_bytescCsJt�|j|j�|�tj|j�t�|j�}|�||j�|�	|t
�dSr+)rr�r�r�r�rrVr�r�r-rMryrrr�
test_bytes1
s
zReadlinkTests.test_bytesN)rPrQrRr�rr>r}r�r�rYr�r�r�rXr�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+rrWrrrrXC
r�zWin32SymlinkTests.setUpcCsVtj�|j�r
t�|j�tj�|j�rt�|j�tj�|j�r)t�|j�dSdSr+)	rr>r�r�r'�dirlinkr8rT�missing_linkrWrrrr�J
s�zWin32SymlinkTests.tearDowncC�`t�|j|j�|�tj�|j��|�tj�|j��|�tj�|j��|�	|j|j�dSr+)
rr��dirlink_targetr�r]r>r�rh�islink�
check_statrWrrr�test_directory_linkR
�
z%Win32SymlinkTests.test_directory_linkcCr�r+)
rr�r�r�r]r>r��isfiler�r�rWrrr�test_file_linkY
r�z Win32SymlinkTests.test_file_linkcCs8	|j}tj�|�rt�|�d}d}t�|||�dS)Nz"c:\\target does not exist.29r3c740T)r�rr>rTr'r�)r0Zlinknamer�Z
target_is_dirrrr�_create_missing_dir_link`
s
z*Win32SymlinkTests._create_missing_dir_linkcC�|��t�|j�dSr+)r�rr'r�rWrrr�,test_remove_directory_link_to_missing_targetj
sz>Win32SymlinkTests.test_remove_directory_link_to_missing_targetcCs |��|�tj�|j��dSr+)r�r�rr>rhr�rWrrr�.test_isdir_on_directory_link_to_missing_targetq
r.z@Win32SymlinkTests.test_isdir_on_directory_link_to_missing_targetcCr�r+)r�rr8r�rWrrr�.test_rmdir_on_directory_link_to_missing_targetu
r3z@Win32SymlinkTests.test_rmdir_on_directory_link_to_missing_targetcCsn|�t�|�t�|��|�t�|�t�|��t�|�}|�t�|�t�|��|�t�|�t�|��dSr+)r=rr�r>rtrY)r0rr�Z
bytes_linkrrrr�y
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�level3r,r)rr>r}rrUr@r�rErAr(r,rBr��relpathr�rr=r�)r0Zlevel1r�r�r,Zorig_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)r0r�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)NZXXXXXXXXXXXXXXXXXXXXXXXXXXXrdr{�)rr>r@r�rCr'rDrY)r0Zsegmentr>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
r7�r�rrr�
s�z6Win32SymlinkTests.test_appexeclink.<locals>.<listcomp>z*.exezTesting withz$test requires an app execution alias)rr>�
expandvarsrhrh�fnmatch�filterrrrFrGrtr=r�r��S_ISLNKr�st_reparse_tagZIO_REPARSE_TAG_APPEXECLINK)r0�aliases�aliasrIrr�r�test_appexeclink�
s 

�

z"Win32SymlinkTests.test_appexeclinkN)rPrQrRr�rr>r}r�r�r�rHr�r�rXr�r�r�r�r�r�r�r�r�rrrTr�r�r�r�rrrrr�:
s.
#
�
#r�c@sDeZdZdZej�ej�e��Z	dd�Z
dd�Zdd�Zdd	�Z
d
S)�Win32JunctionTestsZjunctiontestcCr�r+rrWrrrrX�
r�zWin32JunctionTests.setUpcCs"tj�|j�rt�|j�dSdSr+)rr>rT�junctionrVrWrrrr��
rYzWin32JunctionTests.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>rTr�rhr>r�rtr=r�r�r�r�rWrrr�test_create_junction�
s�z'Win32JunctionTests.test_create_junctioncCs\t�|j|j�|�tj�|j��|�tj�|j��t�	|j�|�
tj�|j��dSr+)r�r�r�r�r]rr>r�rTrVr�rWrrr�test_unlink_removes_junctions
z/Win32JunctionTests.test_unlink_removes_junctionN)rPrQrRr�rr>rHr}r�r�rXr�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)Nrgr~rzKernel32.dllT)Zuse_last_errorrcz\\?\C:z\\?\NULz	\\?\CONINrd)r�
import_moduleZctypes.wintypesZWinDLLrgrqZGetCurrentProcessrproZGetProcessHandleCountZLPDWORDrtrsZbyrefr=r'r�r�Z_getfinalpathname�	Exceptionrr�)r0rgr~ZkernelZhprocZ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�rc)rrUr�rVrr�textwrap�dedentr�rur8r�r.rr�rCrz�TimeoutExpired�	terminate)r0r&�deadlineZcommandr�r�rrr�test_stat_unlink_race?s*
�����	"�z"Win32NtTests.test_stat_unlink_raceN)rPrQrRr�r�rrrrr�
s0r�c@r))�NonLocalSymlinkTestscCs	t�d�dS)Nz
base/some_dir)rrrWrrrrXlszNonLocalSymlinkTests.setUpcCst�d�dS)Nr>)r]rErWrrrr�uszNonLocalSymlinkTests.tearDowncCs 	tj�dd�}t�d|�dS)Nr>Z	some_linkZsome_dir)rr>r@r�)r0r�rrr�test_directory_link_nonlocalxsz1NonLocalSymlinkTests.test_directory_link_nonlocalN)rPrQrRrXr�r�rrrrr�is	r�c@r�)�FSEncodingTestscCs(|�t�d�d�|�t�d�d�dS)Nsabc�uabcŁ)r=rrYrNrWrrr�test_nop�szFSEncodingTests.test_nopc	CsBdD]}zt�|�}Wn	tyYqw|�t�|�|�qdS)N)u	unicodeŁulatiné�ascii)rrYrr=rN)r0rVrXrrr�
test_identity�s��zFSEncodingTests.test_identityN)rPrQrRr�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_encodingrWrrr�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�|��dSrn)rr�ZassertIsNotNoner]�codecs�lookup)r0r�rrr�test_device_encoding�s

z(DeviceEncodingTests.test_device_encodingN)rPrQrRr�rrrr�rr8r9r�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�rur8r�r��communicater=r�r�getpid)r0rr�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)	r8r9r�r�spawnv�P_NOWAIT�waitpidr=�waitstatus_to_exitcode)r0r��exitcode�callbackr�ryZpid2�statusrrr�
check_waitpid�s
zPidTests.check_waitpidcCs|jddd�dS)Nr�r)r�r�rrWrrr�test_waitpid�r�zPidTests.test_waitpidcCsXd}d|�d�}|j||d�|�t��t�d�Wd�dS1s%wYdS)N�zimport sys; sys.exit(�)�rg)rrjrprr�)r0rr�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(rrr)r0ZSTATUS_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)Nr5rrcr�r�r )r=rr�rjr�r>)r0Zmax_exitcoderrrr�#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(rcst�|��dSr+)rrx)ry��signumrr�kill_process�rz?PidTests.test_waitstatus_to_exitcode_kill.<locals>.kill_process)rr)rZLONG_TIMEOUTr~r
r)r0r�rrrr� test_waitstatus_to_exitcode_kill�sz)PidTests.test_waitstatus_to_exitcode_killr+)rPrQrRrrrrr�rrr	r8r9rrr~rrrrrr��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)r1r�r�cSr�rr�r�rrrrr2z*SpawnTests.create_args.<locals>.<listcomp>cSs"i|]
\}}t�|�t�|��qSrr�)r
�k�vrrr�
<dictcomp>s�z*SpawnTests.create_args.<locals>.<dictcomp>)rrrUr�rVr�rr<r�r.r�Zuuid4r�r$r%r8r�r�)r0rrr&r�r'r�rrr�create_args�s*
��
�zSpawnTests.create_args�spawnlcC�4|��}tjtj|dg|�R�}|�||j�dSrn)rrr�P_WAITr=r�r0r�rrrr�test_spawnl
�zSpawnTests.test_spawnl�spawnlecC�>|jdd�}tjtj|dg|�|j�R�}|�||j�dS�NT)rr)rrr!rr�r=rrrrr�test_spawnle� zSpawnTests.test_spawnle�spawnlpcCrrn)rrr&rr=rrrrr�test_spawnlpr zSpawnTests.test_spawnlp�spawnlpecCr"r#)rrr(rr�r=rrrrr�
test_spawnlper%zSpawnTests.test_spawnlper�cCsT|��}t�tj|d|�}|�||j�t�tjt|d�|�}|�||j�dSrn)rrr�rr=rrrrrr�test_spawnv%s
zSpawnTests.test_spawnv�spawnvecC�6|jdd�}t�tj|d||j�}|�||j�dSr#�rrr+rr�r=rrrrr�test_spawnve/�zSpawnTests.test_spawnve�spawnvpcCs.|��}t�tj|d|�}|�||j�dSrn)rrr0rr=rrrrr�test_spawnvp5szSpawnTests.test_spawnvp�spawnvpecCr,r#)rrr2rr�r=rrrrr�
test_spawnvpe;r/zSpawnTests.test_spawnvpecCs0|��}t�tj|d|�}tj||jd�dS)Nrr)rrr�r�rZwait_processr)r0r�ryrrr�test_nowaitAszSpawnTests.test_nowaitcCs8|jddd�}t�tj|d||j�}|�||j�dS)NTrrr-rrrr�test_spawnve_bytesGszSpawnTests.test_spawnve_bytescCs>|��}|�ttjtj|d�|�ttjtj|dd�dS�Nrr|)rrjr�rrr��r0r�rrr�test_spawnl_noargsNszSpawnTests.test_spawnl_noargscCsB|��}|�ttjtj|di�|�ttjtj|ddi�dSr6)rrjr�rr!r�r7rrr�test_spawnle_noargsTs zSpawnTests.test_spawnle_noargscCsv|��}|�ttjtj|dd�|�ttjtj|dg�|�ttjtj|dd�|�ttjtj|ddg�dS�Nrrr�r|)rrjr�rr�r�r7rrr�test_spawnv_noargsZs
 zSpawnTests.test_spawnv_noargscCs~|��}|�ttjtj|ddi�|�ttjtj|dgi�|�ttjtj|ddi�|�ttjtj|ddgi�dSr:)rrjr�rr+r�r7rrr�test_spawnve_noargsb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�r1r�r�zPimport sys, os
if os.getenv("FRUIT") != "orange=lemon":
    raise AssertionErrorzorange=lemon)r8r�rr<r�rr�r=rrUr�rVr$r%)r0�spawnr�r�rr&r'rrr�_test_invalid_envjsF
�
�
��

zSpawnTests._test_invalid_envcCr�r+)r?rr+rWrrr�test_spawnve_invalid_env�rvz#SpawnTests.test_spawnve_invalid_envcCr�r+)r?rr2rWrrr�test_spawnvpe_invalid_env�rvz$SpawnTests.test_spawnvpe_invalid_envN)rPrQrRrr rr$r'r)r*r.r1r3r4r5r8r9r;r<r?r@rArrrrr�sF




	








.
rz>Skip due to platform/environment differences on *NIX buildbots�getloginztest needs os.getloginc@r�)�
LoginTestscCst��}|�t|�d�dSrn)rrBr>r:)r0Z	user_namerrr�
test_getlogin��zLoginTests.test_getloginN)rPrQrRrDrrrrrC��rC�getpriority�setpriorityz'needs os.getpriority and os.setpriorityc@rW)�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)Nrc�z?unable to reliably test setpriority at current nice level of %s)rrG�PRIO_PROCESSr�rHrrur=rDrEZEACCES)r0r>Znew_prior�rrr�test_set_get_priority�s2��������z*ProgramPriorityTests.test_set_get_priorityN)rPrQrRrLrrrrrI�srIc@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)r0�connrrrrP�s
z#SendfileTestServer.Handler.__init__cCs$|�d�}|jr|j�|�dSdS)N�)�recvrRrQr&r�rrr�handle_read�s
�z&SendfileTestServer.Handler.handle_readcCsd�|j�S)Nr�)r@rQrWrrr�get_data�r�z#SendfileTestServer.Handler.get_datacCs|��d|_dSr!)r\rSrWrrr�handle_close�s
z'SendfileTestServer.Handler.handle_closecC��r+rrWrrr�handle_error��z'SendfileTestServer.Handler.handle_errorN)rPrQrRrPrXrYrZr\rrrr�Handler�sr^cCsptj�|�tj�|�|�tjtj�|�	|�|�
d�|j��dd�\|_|_
d|_d|_t��|_dS)Nr�reF)�	threading�ThreadrP�asyncore�
dispatcherZ
create_socket�socket�AF_INET�SOCK_STREAM�bind�listen�getsockname�host�port�handler_instance�_active�Lock�_active_lock)r0�addressrrrrP�s

zSendfileTestServer.__init__cCs|jSr+)rlrWrrrrh�szSendfileTestServer.runningcCs$t��|_tj�|�|j��dSr+)r_�Event�_SendfileTestServer__flagr`�startrzrWrrrrr�s
zSendfileTestServer.startcCsd|_|��dSr�)rlr@rWrrr�stop�szSendfileTestServer.stopcCs2t|jdd�st�d�t|jdd�r|��dS)NrSF���MbP?)rrkrrrwrsrWrrrrz�s
�zSendfileTestServer.waitcCsVd|_|j��|jr%tjr%|j��tjddd�|j��|jr%tjst�	�dS)NTrtrc)�timeoutr�)
rlrqrJraZ
socket_maprn�acquireZloop�releaseZ	close_allrWrrrr�
s


�zSendfileTestServer.runcCs|��\}}|�|�|_dSr+)�acceptr^rk)r0rU�addrrrr�
handle_accept

sz SendfileTestServer.handle_acceptcCs|��dSr+)r\rWrrr�handle_connect
r�z!SendfileTestServer.handle_connectcCsdSrnrrWrrr�writable
r�zSendfileTestServer.writablecCr[r+rrWrrrr\
r]zSendfileTestServer.handle_errorN)rPrQrRrNrOr^rP�propertyrhrrrsrzr�rzr{rXr|r\rrrrrM�s
	rM�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��linuxZsolarisZsunosz%requires headers and trailers supportr:z(test is only meaningful on 32-bit buildscCst��|_ttj|j�dSr+)rZthreading_setupr�r(rrU�DATAr|rrrr~%
s
zTestSendfile.setUpClasscCstj|j�t�tj�dSr+)rZthreading_cleanupr�rrVrUr|rrrr�*
szTestSendfile.tearDownClasscCs~ttjdf�|_|j��t��|_|j�|jj|jj	f�|j�
d�|j�d�|j��|_
ttjd�|_|j��|_dS)Nrrcr�r�)rMrZHOST�serverrrrc�client�connectrirj�
settimeoutrWry�socknor$rrUr/rWrrrrX/
s

zTestSendfile.setUpcCs0|j��|j��|jjr|j��d|_dSr+)r/r\r�r�rhrsrWrrrr�;
s




zTestSendfile.tearDownc
Os^		z	tj|i|��WSty.}z|jtjkr�|jtjtjfvr)WYd}~q�d}~wwr+)rr~rDrEZ
ECONNRESET�EAGAIN�EBUSY)r0r�rr�rrr�sendfile_wrapperB
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)NrrV)r:r�r�r�ryr]r=r��shutdownrc�	SHUT_RDWRr\r�rzrkrY)r0�
total_sent�offset�nbytes�sentr�rrr�test_send_whole_fileS
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)NrrerV)r:r�r�r�ryr]r�r�rcr�r\r�rzrkrYr=)r0r�r�Z	must_sendr�r�r�rIrrr�test_send_at_certain_offseti
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)NrVrr�)r:r�rr~r�ryrDrE�EINVALr=r�r�rcr�r\r�rzrkrY)r0r�r�r�r�rrr�test_offset_overflow�
s���

z!TestSendfile.test_offset_overflowcCsT|�t��}t�|j|jdd�Wd�n1swY|�|jjtj	�dS)Nr rV)
rjrDrr~r�ryr=r/rEr��r0r�rrr�test_invalid_offset�
s�z TestSendfile.test_invalid_offsetc	Cs@tj|j|jddd�|jrtj|j|jdddddd�dSdS)NrrV)r�r�r�r�r)r�r�r�r��headers�trailersr�)rr~r�ry�SUPPORT_HEADERS_TRAILERSrWrrr�
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)	Nrsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyr rVsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy�r�i)r�rr~r�ryZassertLessEqualr:�minr�r=r�r\r�rzrkrY�hash)r0r�Z
expected_datar�r�r�r�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�r�sabcde123456789)rrUr�rVr(r$rr~r�ryr�r\r�rzrkrYr=)r0r�Z	file_datarar�rrr�
test_trailers�
s

�

"�zTestSendfile.test_trailerscC�ld|jj_|�t��}tj|j|jddddgdd�Wd�n1s&wY|�	|j
jtj�dS)NFr�x�r�r��
r�rkrRrjrDrr~r�ryr=r/rEr�r�rrr�test_headers_overflow_32bits�
�
��z)TestSendfile.test_headers_overflow_32bitscCr�)NFrr�r�r�r�r�r�rrr�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)NrrV)r�)	rr~r�ryr�rDrEr�r�)r0r�rrr�
test_flags�
s����zTestSendfile.test_flagsN)rPrQrRr�r8r9r�r�rrZrequires_headers_trailers�maxsizeZrequires_32br�r~r�rXr�r�r�r�r�r�r�r�r�r�r�rrr�rrrrr
sP����



�rc	Cs�ttd�sdSzLttjdd��+}zt�|��dd�Wnty2YWd�Wt�tj�dSwWd�n1s=wYWt�tj�dSWt�tj�dSt�tj�w)N�setxattrFr#r�	user.testr�T)	rrr$rrUr�ryrDrV)r'rrr�supports_extended_attributes�
s&
������r�z(no non-broken extended attribute supportrer��'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�)��z;ExtendedAttributeTests._check_xattrs_str.<locals>.<genexpr>r�r�)rrUr�rVr(rjrDr=r/rE�ENODATAr-r!rJr\r�
XATTR_REPLACE�XATTR_CREATE�EEXISTr'r�r�)
r0r�getxattrr��removexattr�	listxattrrrVr�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.rrVrUrrYrDrrr�
_check_xattrs.sz$ExtendedAttributeTests._check_xattrscCs|�tjtjtjtj�dSr+�r�rr�r�r�r�rWrrr�test_simple5s�z"ExtendedAttributeTests.test_simplecCs |jtjtjtjtjdd�dS)NFr�r�rWrrr�
test_lpath9s
�z!ExtendedAttributeTests.test_lpathcCs4dd�}dd�}dd�}dd�}|�||||�dS)	NcW�Dt|d��}tj|��g|�R�Wd�S1swYdSr`)r$rr�ry�r>r�r'rrrr�>�$�z1ExtendedAttributeTests.test_fds.<locals>.getxattrcW�Ht|dd��}tj|��g|�R�Wd�dS1swYdS�Nrir)r$rr�ryr�rrrr�A�"�z1ExtendedAttributeTests.test_fds.<locals>.setxattrcWr�r�)r$rr�ryr�rrrr�Dr�z4ExtendedAttributeTests.test_fds.<locals>.removexattrcWr�r`)r$rr�ryr�rrrr�Gr�z2ExtendedAttributeTests.test_fds.<locals>.listxattr)r�)r0r�r�r�r�rrr�test_fds=s
zExtendedAttributeTests.test_fdsN)rPrQrRr�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�rDr8r9rEr��ENOTTYrhZassertGreaterEqual�columns�lines)r0r�r�rrr�test_does_not_crashOs
��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)
NZsttyr�T)rir�zstty invocation failedrcrr�r�)r��check_output�DEVNULLrrC�CalledProcessErrorrrhr�rr�r8�	__stdin__ryrDr9rEr�r�r=)r0r�rIr�r�rrr�test_stty_matchas,��
��
��zTermsizeTests.test_stty_matchN)rPrQrRr�r�rrrrr�Ms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)NZHir riF)�closefdsmemfd_creater�)rr��MFD_CLOEXECr>r�r\r�r"r$r%r=�tell)r0r~rarrrr�test_memfd_create�s
�
z"MemfdCreateTests.test_memfd_createN)rPrQrRr�rrrrr�~rFr��eventfdzrequires os.eventfdr8c@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�r r�(rerr�)rr�r>r�r\r�r"r{r=r%�
eventfd_write�eventfd_read)r0r�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)Nrer rcr�)r�EFD_CLOEXEC�
EFD_SEMAPHORE�EFD_NONBLOCKr�r>r�r\r�r=rjr�r{r�)r0r�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)Nrr rl����)rr�r�r�r>r�r\�selectr=r�r�)r0r�r~�rfd�wfdZxfdrrr�test_eventfd_select�sz EventfdTests.test_eventfd_selectN)rPrQrRr�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�rPrQrRrrrr�Str��r�)
r.�bytes_filenames�unicode_filenamesrrZrUr&ZTESTFN_UNDECODABLErrYr�r�r�)r0r�Zdecoded�encodedrrrrX�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�rzr�lchownr�chflags�lchflags�chrootrr�r�suser�lchmodr�z	should bezNo exception thrown by {}),r�rrBrrtr$r�r8r�rVr8r9r�r�rqr�r�rrr&rzr�rr�r�r�rr�r�r�r�r�r�r$r.rMZassertWarnsRegex�DeprecationWarningrDr�r&�UnicodeDecodeErrorrr�)r0Zfuncsr��funcZ	func_argsrr�rrr�test_oserror_filename�s�




�
	
�
�








���"����z"OSErrorTests.test_oserror_filenameN)rPrQrRrXr�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��
assertGreaterrh)r0Zcpusrrr�test_cpu_count@s
zCPUCountTests.test_cpu_countN)rPrQrRr�rrrrr�?r�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�r\r=r"r#r�rrr�test_get_set_inheritableJs
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�r\r=r"�fcntl�F_GETFD�
FD_CLOEXEC�F_SETFD)r0r~r�rrr�test_get_inheritable_cloexecRsz/FDInheritanceTests.test_get_inheritable_cloexeccCsft�ttj�}|�tj|�|�t�|tj�tj	@tj	�t�
|d�|�t�|tj�tj	@d�dS)NTr)rr$r�r�r�r\r=rrrr#r�rrr�test_set_inheritable_cloexec_s��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�r\r=r"r#r�rrr�test_get_set_inheritable_o_pathjs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�rjrDrr"r=r/rEr0r#)r0r~r2rrr�test_get_set_inheritable_badfvs���z0FDInheritanceTests.test_get_set_inheritable_badfcCs2t�ttj�}|�tj|�|�t�|�d�dSr�)rr$r�r�r�r\r=r"r�rrrra�szFDInheritanceTests.test_openr�zneed os.pipe()cC�Pt��\}}|�tj|�|�tj|�|�t�|�d�|�t�|�d�dSr�)rr�r�r\r=r")r0r�r�rrr�	test_pipe��
zFDInheritanceTests.test_pipecCsJt�ttj�}|�tj|�t�|�}|�tj|�|�t�|�d�dSr�)	rr$r�r�r�r\rgr=r"�r0�fd1rrrr�test_dup�s

zFDInheritanceTests.test_dupcCs(t�d�}|�tj|�|�|d�dS�Nrcr)rrgr�r\r�r�rrr�test_dup_standard_stream�s
z+FDInheritanceTests.test_dup_standard_streamr�r
cCsHt�dtj�}|�tj|�t�|�}|�tj|�|�t�|��dS)N�NUL)rr$r�r�r\rgr�r"rrrr�test_dup_nul�s

zFDInheritanceTests.test_dup_nulrzneed os.dup2()cCs�t�ttj�}|�tj|�t�ttj�}|�tj|�|�t�||�|�|�t�	|��t�ttj�}|�tj|�|�tj||dd�|�|�
t�	|��dS)NF)�inheritable)rr$r�r�r�r\r=rr]r"r�)r0r~rZfd3rrrr�szFDInheritanceTests.test_dup2�openptyzneed os.openpty()cCrr�)rrr�r\r=r")r0Z	master_fdZslave_fdrrr�test_openpty�rzFDInheritanceTests.test_openpty)rPrQrRrrr�rrrrrrrr
rarrrr8r9rrrrrrrrIs(






rc@sHeZdZddddejfdfddddd	eed
d�fgZdd�Zd
d�ZdS)�PathTConverterTests)r�TrN)rtFrNr^FN)r�F�rN)r�FrNr$rr\cCs�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)Nrgr)rr>zto return str or byteszos.PathLike)rrUrrrYrr$r�rZr�rVr\�	functionsrrr�assertRaisesRegexrp)r0Zstr_filenameZbytes_fspath�bytes_filenamer~Z
int_fspathZ
str_fspathrZallow_fd�
extra_argsZ
cleanup_fnrVr>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�re�floatg���Q�@�object)rrprr�rr#)r0rqrrr�&test_path_t_converter_and_custom_class�s��"�z:PathTConverterTests.test_path_t_converter_and_custom_class)	rPrQrRr�F_OKrrr!r$rrrrr�s�	,rr&r'c@r�)�
BlockingTestscCr
r)	rr$r�r�r�r\r=r&r(r�rrrr)szBlockingTests.test_blockingN)rPrQrRr)rrrrr&rFr&c@r�)�ExportsTestscCs |�dtj�|�dtj�dS)Nr$r)r�r�__all__rWrrr�test_os_allszExportsTests.test_os_allN)rPrQrRr)rrrrr'r�r'c@r))�TestDirEntrycCs0tj�tj�|_|�tj|j�t�|j�dSr+)rr>�realpathrrUr�rErArWrrrrXszTestDirEntry.setUpcCs|�ttj�dSr+)rjrpr�DirEntryrWrrr�test_uninstantiable r�z TestDirEntry.test_uninstantiablecCsjttj�|jd�d�}dd�t�|j�D���}|�|tj�|�|j	d�ddl
}|�t|j
||�dS)Nr��pythoncSsg|]}|�qSrr�r
�entryrrrr%sz0TestDirEntry.test_unpickable.<locals>.<listcomp>r)r(rr>r@�scandirr�r-r,r=rrrjrpr)r0r&r0rrrr�test_unpickable#szTestDirEntry.test_unpickableN)rPrQrRrXr-r2rrrrr*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+rrUrY�
bytes_pathr�rErArWrrrrX/szTestScandir.setUpr�cCs2t|t�r|jn|j}tj�||�}t|d�|S)Nr.)r$rMr4r>rr@r()r0rr>r&rrrr(5s
zTestScandir.create_filecCs2tdd�t�|j�D��}|�t|���|�|S)Ncs��|]}|j|fVqdSr+rr/rrrr�<s��z*TestScandir.get_entries.<locals>.<genexpr>)r�rr1r>r=r��keys)r0�names�entriesrrr�get_entries;s

�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)r0Zstat1Zstat2Zskip_fieldsr
rrr�assert_stat_equalAs
��	zTestScandir.assert_stat_equalcCs(t�|j�}|�tt|��|��dSr+)rr1r>rjrpr|r\)r0�scandir_iterrrrr-NszTestScandir.test_uninstantiablecCs<|�d�}t�|j�}ddl}|�t|j||�|��dS)Nr�r)	r(rr1r>rrjrprr\)r0r&r>rrrrr2Ss

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)NFr�rg)r-rr,r=rr>r@�inoder�r;�is_dir�S_ISDIRr�is_file�S_ISREG�
is_symlinkr�r=)r0r0rr@rBrDZ
entry_statZentry_lstatrrr�check_entryZs>
�

�

�
�
�
�
��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.txtr0�symlink_dirT)r��symlink_file.txt)rFrGF)rrrrr>r@rAr(rrrhr�r&r�r9rE)	r0rr�rHr&r�r7r8r0rrr�test_attributesvsH


���


�zTestScandir.test_attributescCsNt|t�r|jn|j}tt�|��}|�t|�d�|d}|�|j	|�|Sr)
r$rMr4r>r!rr1r=r:r)r0rr>r8r0rrr�	get_entry�szTestScandir.get_entrycCs|j|d�}|�tj�|��S)Nr)r(rIrr>�basename)r0rr&rrr�create_file_entry�r%zTestScandir.create_file_entryc	Csn|��}t��}z(t�|j�tdd�t��D��}|�t|�	��tj�
|�g�Wt�|�dSt�|�w)Ncsr5r+rr/rrrr��r�z5TestScandir.test_current_directory.<locals>.<genexpr>)r(rr,rBr>r�r1r=r�r6rJ)r0r&Zold_dirr8rrr�test_current_directory�s�z"TestScandir.test_current_directorycCs|��}|�t|�d�dS)Nz<DirEntry 'file.txt'>)rKr=r��r0r0rrr�	test_repr�rEzTestScandir.test_reprcCs*|��}|�t�|�tj�|jd��dS)Nr�)rKr=r�fspathr>r@rMrrr�test_fspath_protocol�s"z TestScandir.test_fspath_protocolcCsNt�d�}|j|d�}t�|�}|�|t�|�|tj�t�|j�|��dS)Nz
bytesfile.txtr)	rrYrKrOr-rMr=r>r@)r0rZbytes_entryrOrrr�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�rgFr�r)rr>r@rArIr8rr]r@r�rBrDrjrCr?r�r�)r0r>r0rrr�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)NrgFr�r)rKrrVr>r�r@rr]rBrDrjrCr?r�r�rMrrr�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�)rrrhr(rr�r>r@r9rVr�r?r�r@rBr]rDrjrCr�)r0r&r8r0rrr�test_broken_symlink�s"

�
zTestScandir.test_broken_symlinkc	Csp|�d�t�|j�}tt�|��}|�t|�d|�|d}|�|jd�|�|jt�tj�	|jd���dS�Nr�rcrsfile.txt)
r(rrYr>r!r1r=r:rr@)r0�
path_bytesr8r0rrrr�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	dSrU)r(r�r�rrYr>�assertWarnsr�r!r1r=r:rr@r�r|rM)r0r}rVr8r0rrr�test_bytes_likes
���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/rrrr1rz'TestScandir.test_fd.<locals>.<listcomp>r�F)r�rgr�)r�rr1r�r(rrr�r>r@r&rlr!r=r�rrrOrDr�r�)r0Zexpected_namesr~r�r8r7r0rIrrr�test_fd$s2


���"�zTestScandir.test_fdcCs|�ttjd�dS)Nr|)rjrCrr1rWrrr�test_empty_path>r�zTestScandir.test_empty_pathcCsN|�d�t�|j�}t|�}|�t|�d|�t|�}|�t|�d|�dS)Nr�rcr)r(rr1r>r!r=r:)r0r�r8Zentries2rrr�test_consume_iterator_twiceAs
z'TestScandir.test_consume_iterator_twicecCs$digfD]
}|�ttj|�qdS)NgX9��v��?)rjrprr1)r0�objrrr�test_bad_path_typeLs�zTestScandir.test_bad_path_typecCsh|�d�|�d�t�|j�}t|�|��|��|���
~Wd�dS1s-wYdS�Nr��	file2.txt)r(rr1r>r�r\�check_no_resource_warning�r0r�rrr�
test_closePs


"�zTestScandir.test_closecCsx|�d�|�d�t�|j��}t|�Wd�n1swY|���
~Wd�dS1s5wYdSr^)r(rr1r>r�r`rarrr�test_context_manager[s


�
"�z TestScandir.test_context_managercCsV|�d�|�d�t�|j��}t|�|��Wd�dS1s$wYdSr^)r(rr1r>r�r\rarrr�test_context_manager_closecs


"�z&TestScandir.test_context_manager_closec	Cs�|�d�|�d�|�t��&t�|j��}t|�ddWd�n1s)wYWd�n1s8wY|���
~Wd�dS1sNwYdS)Nr�r_rcr)r(rj�ZeroDivisionErrorrr1r>r�r`rarrr�test_context_manager_exceptionjs


���
"�z*TestScandir.test_context_manager_exceptioncCs�|�d�|�d�t�|j�}t|�|�t��
~t��Wd�n1s)wYt�|j�}t	|�|�
��
~Wd�dS1sIwYdSr^)r(rr1r>r�rW�ResourceWarningr�
gc_collectr!r`rarrr�test_resource_warningts


�
"�z!TestScandir.test_resource_warningN)r�)&rPrQrRrr`rXr(r9r=r-r2rErHrIrKrLrNrPrQrRrSrTr�rXrrrrr�rYrZr[r]rbrcrdrfrirrrrr3,sB

)
	�

r3c@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=rO)r0�brrr�test_return_bytes���zTestPEP519.test_return_bytescCrk)N)ZhelloZgoodbyezsome/path/and/filerl)r0rrrr�test_return_string�rozTestPEP519.test_return_stringcCsLdD]!}t|�}|�||�|��|�dt�|��|�dt�|��qdS)N)�path/like/object�path/like/objectrrrq)rr=rOrrYrN)r0rZpathlikerrr�test_fsencode_fsdecode�s�z!TestPEP519.test_fsencode_fsdecodecCsB|�d|�td���|�tttj��|�ttd�tj��dS)Nz#feelthegilr�)r=rOrr]�
issubclassr�PathLiker$rWrrrr��szTestPEP519.test_pathlikecCs4tddi�}ttt|�fD]
}|�t|j|�q
dS)NZblahr)r|r�rrjrprO)r0Zvapor�orrr�test_garbage_in_exception_out�s�z(TestPEP519.test_garbage_in_exception_outcCs|�t|j�dSr+)rjrprOrWrrr�test_argument_required�r�z!TestPEP519.test_argument_requiredcCsR|�t|jtd��tddi�}d|_|�t|j|��|�t|jtt���dS)Nr�Zfoorrc)rjrprOrr|�
__fspath__re)r0�crrr�test_bad_pathlike�s
�zTestPEP519.test_bad_pathlikecCs8Gdd�dtj�}|�tt|��|�tttj��dS)Nc@r�)z0TestPEP519.test_pathlike_subclasshook.<locals>.ANr�rrrr�A�r�r|)rrur�rtrr])r0r|rrr�test_pathlike_subclasshook�sz%TestPEP519.test_pathlike_subclasshookcCs|�tjttj�dSr+)r-rrurM�types�GenericAliasrWrrr�test_pathlike_class_getitem�r�z&TestPEP519.test_pathlike_class_getitemN)rPrQrRr�rrOrnrprsr�rwrxr{r}r�rrrrrj�s
rjc@r�)�
TimesTestscCsrt��}|�|tj�dD]
}t||�}|�|t�q
tjdkr7|�|jd�|�|j	d�|�|j
d�dSdS)N)�user�system�
children_user�children_system�elapsedrgr)rrer-�times_resultrr"rr=r�r�r�)r0reZfieldr'rrr�
test_times�s

�zTimesTests.test_timesN)rPrQrRr�rrrrr��r�r��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)rPrQrRr�rrrrr��sr��_fspathc@seZdZ	eej�ZdS)�TestPEP519PurePythonN)rPrQrRr�rr�rOrrrrr��sr��__main__)r"r+)�r��
contextlibr�rEr�r�rHr�r�rrr�r]r~rcr�r�r�r8Z	sysconfigr;r�r_rrr~rr�r��testrZtest.supportrrrrrr9rr��simplefilterr�rNrar��ImportErrorrr��pwdZgetpwallr�rZ	_testcapirrr�Ztest.support.script_helperrrZtest.support.os_helperrr�rrr�versionr�r��getgidrDr r(r�r�ZTestCaser*rSr�rCr�ZBasicTestMappingProtocolr�rrrCrXr^rar{r�r�r�r�Zget_config_varZOS_URANDOM_DONT_USE_FDr��contextmanagerr�r�r�r�r+r9rUrer�r�r�r�r�r�r�r�r�r�rr�rCrIrbr`rMrr�Zrequires_linux_versionr�r�r�r�r�r�rrr&r'r*r3rjr�r�r�rP�mainrrrr�<module>s�

������
�EZe\)EG
^;)	-����M �h#w%CGs/<0![H4�VO�Q0
Q]
yB�Y:
�