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.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�szst_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)r0r
r�value�memberr
rrr�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#r3r�)r0r
rrr�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�r5r=r3�FILE_ATTRIBUTE_DIRECTORYrrUrAr��rmdir)r0r
rHrrr�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_PROCESSr
rrr�test_access_denied�s

�
z%StatAttributeTests.test_access_deniedcCs6dtj�t���d}t�|�}|�|jtj�dS)Nz//./r)rr>�
splitdriver,r�r=r�S_IFBLK)r0r�r
rrr�test_stat_block_device�s
z)StatAttributeTests.test_stat_block_deviceN)rPrQrRrXrrrrrrrrr(r*r8r9r-r2r5r8r>rArrrrr�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�rIrr�rrErFr=�st_atime_ns�st_mtime_ns)r0�set_timer&rI�atime_ns�mtime_nsrHrrr�_test_utime�s"

zUtimeTests._test_utimecC�dd�}|�|�dS)NcS�tj||d�dS�N��ns�r�utime�r&rVrrrrN�z'UtimeTests.test_utime.<locals>.set_time�rQ�r0rNrrr�
test_utimeszUtimeTests.test_utimecCs|ddS)NrKg��&�.>rrUrrr�	ns_to_sec szUtimeTests.ns_to_secc��fdd�}��|�dS)Ncs0|\}}��|�}��|�}t�|||f�dSr+�r^rrX�r&rVrOrPZatime�mtimerWrrrN)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)�timesr`rarWrrrN3s

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.cCrR)NcSstj||dd�dS)NF)rV�follow_symlinksrWrYrrrrN?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.cCrR)NcSsDt|dd��}tj|��|d�Wd�dS1swYdS)N�wbrrU)r$rrXry)r&rVr'rrrrNHs"�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.cCrR)NcSsPtj�|�\}}t�|��}tj|||d�Wd�dS1s!wYdS)N)r�rV)rr>rr�open_dir_fdrX)r&rVrHr�dirfdrrrrNRs"�z.UtimeTests.test_utime_dir_fd.<locals>.set_timer[r\rrr�test_utime_dir_fdOrjzUtimeTests.test_utime_dir_fdcCsdd�}|j||jd�dS)NcSrSrTrWrYrrrrNZrZz1UtimeTests.test_utime_directory.<locals>.set_time�r&)rQrHr\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�rIrr�rFr)r0rN�currentr�rHrprrr�_test_utime_current_s
�

�zUtimeTests._test_utime_currentcr_)Ncst��j�dSr+�rrXr�rnrWrrrNv�z/UtimeTests.test_utime_current.<locals>.set_time�rsr\rrWr�test_utime_currentu�zUtimeTests.test_utime_currentcr_)Ncst��jd�dSr+rtrnrWrrrN|rZz3UtimeTests.test_utime_current_old.<locals>.set_timervr\rrWr�test_utime_current_old{rxz!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 NTFSrJ)	r�rHrhrrXr�r=r�rF)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�rUr�)r�)r�r�r�F�rfrhr�r�)rjr�rrXr�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�*rcrUr)rcrer�)rjrprrXr�)r0r�rrr�test_issue31577�s��"�zUtimeTests.test_issue31577r+)rPrQrRrXrIrQr]�staticmethodr^rcrerrrrXr�rgr�rir�rmrorsrwryr�r�r�rr�r�rrrrrB�s<

	�
�
�


rB)�
mapping_testsc@sBeZdZdZdZdd�Zdd�Zdd�Zd	d
�Ze	�
eo!ej
�e�d�e	�
eed�d
�dd���Ze	�
eo:ej
�e�d�e	�
eed�d
�dd���Zdd�Zdd�Zdd�Zdd�Ze	�
ejd�dd��Zdd�Ze�dd �d!d"��Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Z d-d.�Z!d/d0�Z"d1d2�Z#d3d4�Z$d5d6�Z%d7d8�Z&dS)9�EnvironTestsz8check that os.environ object conform to mapping protocolNcCsBttj�|_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
Cs4tj}|�t|�d�d�dd�|��D����dS)z>Check that the repr() of os.environ looks like environ({...}).zenviron({{{}}})z, css �|]\}}d�||�VqdS)z
{!r}: {!r}N��format)r
r�r&rrr�	<genexpr>s
�
�
�z-EnvironTests.test___repr__.<locals>.<genexpr>N)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_bytesrpZ	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)'rPrQrR�__doc__Z	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�r�rrrrrr��sN��)�


	
r�c@sZeZdZdZdd�Zdd�Zdd�Zdd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�	WalkTestszTests for os.walk().cKs(d|vr|�d�|d<tj|fi|��S�Nrf�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�rrDrU�	walk_path�	sub1_path�
sub11_path�	link_path�makedirsr$r%�can_symlinkr�r|�	sub2_tree�chmod�listdir�PermissionErrorr��S_IRWXUrVr7)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��dirsrrrr�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(rrrr�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+)
rPrQrRrrrXr%r)r*r-r/r7rArrrrr�sE
r�fwalkzTest needs os.fwalk()c@sLeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dZdS)�
FwalkTestszTests for os.fwalk().cks2�|j|fi|��D]\}}}}|||fVq
dSr+)rB)r0rrr�r(rZroot_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�qCqdS)z.
        compare with walk() results.
        �TFre��repeat)r,r)r,rfNr)
r��	itertools�productr�rr�setrBr�r=)
r0�walk_kwargs�fwalk_kwargsr,rfrIr�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)NrErerFrf)rHrIrrUrBr�fstatr�r=rJr)r0r,rfr�r�r(rrMrrr�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)rPrQrRrrrBrNrOrRrTrVrArrrrrC�s
rCc@�eZdZdZdd�ZdS)�BytesWalkTests�Tests for os.walk() with bytes.c	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(rrrrr�s�"
�zBytesWalkTests.walkN)rPrQrRrrrrrrrX�srXc@seZdZdZddd�ZdS)�BytesFwalkTestsrYrQcos��tjt�|�g|�Ri|��D]:\}}}}t�|�}tttj|��}	tttj|��}
||	|
|fVtttj|	��|dd�<tttj|
��|dd�<qdSr+)rrBrZrNr!r[)r0rr�rr\r]r^�topfdr�r(rrrrrB
s�*
�zBytesFwalkTests.fwalkN)rQ)rPrQrRrrBrrrrr_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�rn�/)
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�rlzCannot set S_ISGID for dir.z No support for S_ISGID dir mode.Trm)rr>r@rrUr��S_ISGIDrp�S_IMODE�lstatrrrr�SkipTestr)r0r>rsr�rqZexisting_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)	Nr4r0r�r�r�FrmT)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�|�dSre)rr>r@rrUr�rH�
removedirs�r0r>rrrr�fs��zMakedirTests.tearDownN)
rPrQrRrXrgrkrrrwrxr�rrrrrbs
rb�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)�ChownFileTestscCrcr+rd��clsrrr�
setUpClassuruzChownFileTests.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�	fractionsZFractionrjrpr{�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�r{r�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�r{r�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�rjrr{)r0r�r�r�rrr�test_chown_without_permission�s"�z,ChownFileTests.test_chown_without_permissioncCrcr+)rr7rrUr}rrr�
tearDownClass�ruzChownFileTests.tearDownClassN)rPrQrR�classmethodrr�rrrrr��
root_in_posixr:r�r�r�r�rrrrr|rs 


�

�
r|c@�4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�RemoveDirsTestscCrcr+)rrrrUrWrrrrX�rzRemoveDirsTests.setUpcCst�tj�dSr+)rrDrUrWrrrr��rzRemoveDirsTests.tearDowncCsxtj�tjd�}t�|�tj�|d�}t�|�t�|�|�tj�|��|�tj�|��|�tj�tj��dS)N�dira�dirb)	rr>r@rrUrAry�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(ryr�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(rjrDryr]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)Nrhr�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�rrv)r~rJrrrrs
��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�rr�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)z�
    Stubs out execv and execve functions when used as context manager.
    Records exec calls. The mock execv and execve functions always raise an
    exception as they would normally never return.
    cs��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_execveN)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�rhZspamr�rcrr�)r�r�r�r�r�)rr?rMr>r@rZrr�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)Nrh)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@ra)�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+)rjrDrrXrrUrWrrrr]*�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=rEr/r)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�rrSrDrrvr=ri)r0r~r�rrrrmNs�� zTestInvalidFD.test_closerange�dup2ztest needs os.dup2()cC�|�tjd�dS)N�)r�rrrWrrr�	test_dup2^rZzTestInvalidFD.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.rEr/)r0Zvalid_fd�fdsr~rr1rrr�test_dup2_negative_fdbs �����z#TestInvalidFD.test_dup2_negative_fd�fchmodztest needs os.fchmod()cCrrn)r�rr
rWrrr�test_fchmodrrZzTestInvalidFD.test_fchmod�fchownztest needs os.fchown()cC�|�tjdd�dS)Nr )r�rrrWrrr�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��rZzTestInvalidFD.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�rZzTestInvalidFD.test_tcsetpgrptr%ztest needs os.write()cCr)N� )r�rr%rWrrrr��rZzTestInvalidFD.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�rrrrrrmrr	rrrrrr�rrr�r r%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�rC�f2rrr�
_test_link�s��P�zLinkTests._test_linkcCs|�|j|j�dSr+)r4r-r.rWrrr�	test_link�r�zLinkTests.test_linkcCs(|�t|jt���t|jt����dSr+)r4rMr-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�)rrZ�UnicodeErrorrrvr-r.r4rWrrr�test_unicode_name�s
�zLinkTests.test_unicode_nameN)	rPrQrRrXr�r4r5r6r9rrrrr,�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_GROUPrjrDrCrpr?�GID_OVERFLOWrWrrr�test_setgid��zPosixUidGidTests.test_setgid�seteuidztest needs os.seteuid()cCsBt��dkr|�ttjd�|�ttjd�|�ttj|j�dSr=)	rr>rjrDrIrp�setegidr?r@rWrrr�test_seteuid�rBzPosixUidGidTests.test_seteuidrJztest needs os.setegid()cCrDr=)	rr>rErjrDrJrpr?rFrWrrr�test_setegid�rHzPosixUidGidTests.test_setegid�setreuidztest needs os.setreuid()cCsnt��dkr|�ttjdd�|�ttjdd�|�ttjdd�|�ttj|jd�|�ttjd|j�dSr=)rr>rjrDrMrpr?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>rErjrDrSrpr?rFrWrrr�
test_setregid	szPosixUidGidTests.test_setregidcCrO)Nr�z,import os,sys;os.setregid(-1,-1);sys.exit(0)rPrWrrr�test_setregid_neg1		rRz#PosixUidGidTests.test_setregid_neg1N)rPrQrRr@rFrrrrrArGrKrLrNrQrTrUrrrrr:�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+)rrZrr&)�fn��bytesfnrr�add_filename	s�z'Pep383Tests.setUp.<locals>.add_filenamez&couldn't create any non-ascii filenamezduplicate filename)r�TESTFN_UNENCODABLEr�ZTESTFN_NONASCIIrUrrZZbdirZTESTFN_UNICODErhrJ�	unicodefnrAZcreate_empty_filer>r@rNr��add�shutilrD)r0rZrWrrXrrX	s8







�zPep383Tests.setUpcCst�|j�dSr+)r^rDr�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\)r0rWrarrr�	test_openG	s

�zPep383Tests.test_openrr)cCs*|jD]}tj�|j|�}t�|�qdSr+)r\rr>r@r�r)r0rW�fullnamerrr�test_statvfsL	s
�zPep383Tests.test_statvfscCs&|jD]
}t�tj�|j|��qdSr+)r\rr�r>r@r�)r0rWrrr�	test_statU	s
�zPep383Tests.test_statN)
rPrQrRrXr�r`rbrrrrrdrerrrrrV	s%�
rVc@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}rh�msvcrtr~r�
PeekNamedPipe�BOOL�restype�HANDLE�POINTERZc_char�DWORD�argtypesr��Popenr8r�r�r�r�r�r\rjrk�pollZcreate_string_bufferr:Z
get_osfhandleryZsizeofr=r&r=r�rq�sleeprr�kill�pid�wait)r0�sigr}rhrnrorpr�r��maxr�Zrsltrrr�_kill[	sP




�
���
�
zWin32KillTests._killcCr�r+)r~�signal�SIGTERMrWrrr�test_kill_sigterm�	ruz 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:rlrmz'Subprocess didn't finish initializationg�?zsubprocess did not stop on {})�uuidZuuid1�mmapr�rvr8r�rr>r@rHr�ZCREATE_NEW_PROCESS_GROUPrwrqrxryrzr�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)Nrrg�CTRL_C_EVENT)
r}rhrsZc_intr~r�SetConsoleCtrlHandlerrprurqr�rr�)r0rhr}ZNULLr�rrr�test_CTRL_C_EVENT�	s

�
z Win32KillTests.test_CTRL_C_EVENTcCr)N�CTRL_BREAK_EVENT)r�rr�rWrrr�test_CTRL_BREAK_EVENT�	�z$Win32KillTests.test_CTRL_BREAK_EVENTN)rPrQrRr~r�r�r�r�skipr�r�rrrrrfY	s6
rfc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Win32ListdirTestszTest listdir on Windows.c	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%dr0r�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.setUpcCrcr+)r^rDrrUrWrrrr��	rzWin32ListdirTests.tearDowncCsH|�tt�tj��|j�|�tt�t�tj���dd�|jD��dS)z-Test when the path is not an "extended" path.cS�g|]}t�|��qSr�rrZ�r
r>rrrr�	r2zCWin32ListdirTests.test_listdir_no_extended_path.<locals>.<listcomp>N)r=�sortedrrrrUr�rZrWrrr�test_listdir_no_extended_path�	s��z/Win32ListdirTests.test_listdir_no_extended_pathcCshdtj�tj�}|�tt�|��|j�dt�	tj�tj��}|�tt�|��dd�|jD��dS)z&Test when the path starts with '\\?\'.�\\?\�\\?\cSr�rr�r�rrrr�	r2z@Win32ListdirTests.test_listdir_extended_path.<locals>.<listcomp>N)
rr>r|rrUr=r�rr�rZrzrrr�test_listdir_extended_path�	s��z,Win32ListdirTests.test_listdir_extended_pathN)rPrQrRrrXr�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-rMrzrrr�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-rMrzrrr�
test_bytes1
s
zReadlinkTests.test_bytesN)rPrQrRr�rr>r|r�r�rZr�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 linkcCs^tj�|j�s	J�tj�|j�sJ�tj�|j�rJ�tj�|j�r$J�tj�|j�r-J�dSr+)rr>r��dirlink_targetr��dirlinkr��missing_linkrWrrrrXC
s
zWin32SymlinkTests.setUpcCsVtj�|j�r
t�|j�tj�|j�rt�|j�tj�|j�r)t�|j�dSdSr+)	rr>r�r�r'r�r7rTr�rWrrrr�J
s�zWin32SymlinkTests.tearDowncC�`t�|j|j�|�tj�|j��|�tj�|j��|�tj�|j��|�	|j|j�dSr+)
rr�r�r�r]r>r�ri�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_linkcCsF|j}tj�|�rt�|�d}tj�|�rJ�d}t�|||�dS)z2Create a "directory" link to a non-existent targetz"c:\\target does not exist.29r3c740TN)r�rr>rTr'r�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>rir�rWrrr�.test_isdir_on_directory_link_to_missing_targetq
r/z@Win32SymlinkTests.test_isdir_on_directory_link_to_missing_targetcCr�r+)r�rr7r�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=rurZ)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�rDrAr(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)NZXXXXXXXXXXXXXXXXXXXXXXXXXXXrdrz�)rr>r@r�rCr'rDrZ)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>�
expandvarsrirh�fnmatch�filterrrrFrGrur=r�r��S_ISLNKr�st_reparse_tagZIO_REPARSE_TAG_APPEXECLINK)r0�aliases�aliasrHrr�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junctiontestcCs(tj�|j�s	J�tj�|j�rJ�dSr+)rr>r��junction_targetrT�junctionrWrrrrX�
�zWin32JunctionTests.setUpcCs"tj�|j�rt�|j�dSdSr+)rr>rTr�rVrWrrrr��
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�CreateJunctionr�r�r]rr>rTr�rir=r�rur=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)Nrhr}rzKernel32.dllT)Zuse_last_errorrcz\\?\C:z\\?\NULz	\\?\CONINrd)r�
import_moduleZctypes.wintypesZWinDLLrhrrZGetCurrentProcessrqrpZGetProcessHandleCountZLPDWORDrurtZbyrefr=r&r�r�Z_getfinalpathname�	Exceptionrr�)r0rhr}ZkernelZhprocZhandle_countr�Zbefore_count�	filenames�_rZhandle_deltarrr�test_getfinalpathname_handlessH

�
����
z*Win32NtTests.test_getfinalpathname_handlescCstj}|�tj|�t��d}t�d�}t�t	j
d||t|�g��T}t��|krPzt�
|�WntyI}z
|jdks?J�WYd}~nd}~wwt��|ks)z|�d�Wntjye|��Yn	wWd�dSWd�dS1sywYdS)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�rerc)rrUr�rVrq�textwrap�dedentr�rvr8r�r.rr�rCr�r{�TimeoutExpired�	terminate)r0r&�deadlineZcommandr�r�rrr�test_stat_unlink_race?s,
������	"�z"Win32NtTests.test_stat_unlink_raceN)rPrQrRr�r�rrrrr�
s0r�c@r))�NonLocalSymlinkTestscCst�d�dS)zM
        Create this structure:

        base
         \___ some_dir
        z
base/some_dirN)rrrWrrrrXlszNonLocalSymlinkTests.setUpcCst�d�dS)Nr>)r^rDrWrrrr�uszNonLocalSymlinkTests.tearDowncCs.tj�dd�}t�d|�tj�|�sJ�dS)a�
        The symlink target should resolve relative to the link, not relative
        to the current directory.

        Then, link base/some_link -> base/some_dir and ensure that some_link
        is resolved as a directory.

        In issue13772, it was discovered that directory detection failed if
        the symlink target was not specified relative to the current
        directory, which was a defect in the implementation.
        r>Z	some_linkZsome_dirN)rr>r@r�ri)r0r�rrr�test_directory_link_nonlocalxsz1NonLocalSymlinkTests.test_directory_link_nonlocalN)rPrQrRrXr�r�rrrrr�is	r�c@r�)�FSEncodingTestscCs(|�t�d�d�|�t�d�d�dS)Nsabc�uabcŁ)r=rrZrNrWrrr�test_nop�r�zFSEncodingTests.test_nopc	CsBdD]}zt�|�}Wn	tyYqw|�t�|�|�qdS)N)u	unicodeŁulatiné�ascii)rrZrr=rN)r0rWrYrrr�
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�rvr8r�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�rzZpid2�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(rr	r)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)Nr4rrcr�r�r )r=rrrjr�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+)rry)rz��signumrr�kill_process�rz?PidTests.test_waitstatus_to_exitcode_kill.<locals>.kill_process)rr)rZLONG_TIMEOUTrrr)r0r�rrrr� test_waitstatus_to_exitcode_kill�sz)PidTests.test_waitstatus_to_exitcode_killr+)rPrQrRrrrrr�rrr
r8r9rr
rrrrrrr��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)r0r�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)rrr1rr=rrrrr�test_spawnvp5szSpawnTests.test_spawnvp�spawnvpecCr-r$)rrr3rr�r=rrrrr�
test_spawnvpe;r0zSpawnTests.test_spawnvpecCs0|��}t�tj|d|�}tj||jd�dS)Nrr	)rrr�r�rZwait_processr)r0r�rzrrr�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�dSr7)rrjr�rr"r�r8rrr�test_spawnle_noargsTs zSpawnTests.test_spawnle_noargscCsv|��}|�ttjtj|dd�|�ttjtj|dg�|�ttjtj|dd�|�ttjtj|ddg�dS�Nrrr�r{)rrjr�rr�r�r8rrr�test_spawnv_noargsZs
 zSpawnTests.test_spawnv_noargscCs~|��}|�ttjtj|ddi�|�ttjtj|dgi�|�ttjtj|ddi�|�ttjtj|ddgi�dSr;)rrjr�rr,r�r8rrr�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�r0r�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�ruz#SpawnTests.test_spawnve_invalid_envcCr�r+)r@rr3rWrrr�test_spawnvpe_invalid_env�ruz$SpawnTests.test_spawnvpe_invalid_envN)rPrQrRrr r r%r(r*r+r/r2r4r5r6r9r:r<r=r@rArBrrrrr�sF




	








.
rz>Skip due to platform/environment differences on *NIX buildbots�getloginztest needs os.getloginc@r�)�
LoginTestscCst��}|�t|�d�dSrn)rrCr=r:)r0Z	user_namerrr�
test_getlogin��zLoginTests.test_getloginN)rPrQrRrErrrrrD��rD�getpriority�setpriorityz'needs os.getpriority and os.setpriorityc@rW)�ProgramPriorityTestsz0Tests for os.getpriority() and os.setpriority().cCs
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)rrH�PRIO_PROCESSr�rIrrvr=rDrEZEACCES)r0r>Znew_prior�rrr�test_set_get_priority�s2��������z*ProgramPriorityTests.test_set_get_priorityN)rPrQrRrrMrrrrrJ�srJc@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�connrrrrQ�s
z#SendfileTestServer.Handler.__init__cCs$|�d�}|jr|j�|�dSdS)N�)�recvrSrRr&r�rrr�handle_read�s
�z&SendfileTestServer.Handler.handle_readcCsd�|j�S)Nr�)r@rRrWrrr�get_data�r�z#SendfileTestServer.Handler.get_datacCs|��d|_dSr")r\rTrWrrr�handle_close�s
z'SendfileTestServer.Handler.handle_closecC��r+rrWrrr�handle_error��z'SendfileTestServer.Handler.handle_errorN)rPrQrRrQrYrZr[r]rrrr�Handler�sr_cCsptj�|�tj�|�|�tjtj�|�	|�|�
d�|j��dd�\|_|_
d|_d|_t��|_dS)Nr�reF)�	threading�ThreadrQ�asyncore�
dispatcherZ
create_socket�socket�AF_INET�SOCK_STREAM�bind�listen�getsockname�host�port�handler_instance�_active�Lock�_active_lock)r0�addressrrrrQ�s

zSendfileTestServer.__init__cCs|jSr+)rmrWrrrri�szSendfileTestServer.runningcCs.|jrJ�t��|_tj�|�|j��dSr+)rir`�Event�_SendfileTestServer__flagra�startr{rWrrrrs�s

zSendfileTestServer.startcCs|jsJ�d|_|��dSr)rirmr@rWrrr�stop�s
zSendfileTestServer.stopcCs2t|jdd�st�d�t|jdd�r|��dS)NrTF���MbP?)rrlrqrxrtrWrrrr{�s
�zSendfileTestServer.waitcCsVd|_|j��|jr%tjr%|j��tjddd�|j��|jr%tjst�	�dS)NTrurc)�timeoutr�)
rmrrrJrbZ
socket_mapro�acquireZloop�releaseZ	close_allrWrrrr�
s


�zSendfileTestServer.runcCs|��\}}|�|�|_dSr+)�acceptr_rl)r0rV�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)rPrQrRrOrPr_rQ�propertyrirsrtr{r�r{r|rYr}r]rrrrrN�s
	rN�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�)rNrZHOST�serverrsrd�client�connectrjrk�
settimeoutrXry�socknor$rrUr0rWrrrrX/
s

zTestSendfile.setUpcCs0|j��|j��|jjr|j��d|_dSr+)r0r\r�r�rirtrWrrrr�;
s




zTestSendfile.tearDownc
Os\	z	tj|i|��WSty-}z|jtjkr�|jtjtjfvr(WYd}~q�d}~ww)zfA higher level wrapper representing how an application is
        supposed to use sendfile().
        TN)rrrDrEZ
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)NrrW)r:r�r�r�ryr]r=r��shutdownrd�	SHUT_RDWRr\r�r{rlrZ)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)NrrerW)r:r�r�r�ryr]r�r�rdr�r\r�r{rlrZr=)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)NrWrr�)r:r�rrr�ryrDrE�EINVALr=r�r�rdr�r\r�r{rlrZ)r0r�r�r�r�rrr�test_offset_overflow�
s���

z!TestSendfile.test_offset_overflowcCsT|�t��}t�|j|jdd�Wd�n1swY|�|jjtj	�dS)Nr rW)
rjrDrrr�ryr=r.rEr��r0r�rrr�test_invalid_offset�
s�z TestSendfile.test_invalid_offsetc	Cs@tj|j|jddd�|jrtj|j|jdddddd�dSdS)NrrW)r�r�r�r�r)r�r�r�r��headers�trailersr�)rrr�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 rWsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy�r�i)r�rrr�ryZassertLessEqualr:�minr�r=r�r\r�r{rlrZ�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$rrr�ryr�r\r�r{rlrZr=)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�rlrSrjrDrrr�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)NrrW)r�)	rrr�ryr�rDrEr�r�)r0r�rrr�
test_flags�
s����zTestSendfile.test_flagsN)rPrQrRr�r8r9r�r�rrZrequires_headers_trailers�maxsizeZrequires_32br�rr�rXr�r�r�r�r�r�r�r�r�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$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�	listxattrrrWr�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.rrVrUrrZrDrrr�
_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�S1swYdSra)r$rr�ry�r>r�r'rrrr�>�$�z1ExtendedAttributeTests.test_fds.<locals>.getxattrcW�Ht|dd��}tj|��g|�R�Wd�dS1swYdS�Nrhr)r$rr�ryr�rrrr�A�"�z1ExtendedAttributeTests.test_fds.<locals>.setxattrcWr�r�)r$rr�ryr�rrrr�Dr�z4ExtendedAttributeTests.test_fds.<locals>.removexattrcWr�ra)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
Csnzt��}Wn ty&}ztjdks|jtjtjfvr!|�d��d}~ww|�	|j
d�|�	|jd�dS)z�Check if get_terminal_size() returns a meaningful value.

        There's no easy portable way to actually check the size of the
        terminal, so let's check if it returns something sensible instead.
        r��failed to query terminal sizeNr)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 tyX}ztjdksN|jtjtjfvrS|�d	��d
}~ww|�||�d
S)z�Check if stty returns the same results

        stty actually tests stdin, so get_terminal_size is invoked on
        stdin explicitly. If stty succeeded, then get_terminal_size()
        should work too.
        Zsttyr�T)rjr�zstty invocation failedrcrr�r�N)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 rhF)�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�~rGr��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)z$Pack as native uint64_t
            z@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_filenamesrr[rUr&ZTESTFN_UNDECODABLErrZr�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�r{r�lchownr�chflags�lchflags�chrootrr�r�suser�lchmodr�z	should bezNo exception thrown by {}),r�rrBrrur$r�r7r�rVr8r9r�r�rqr�r�rrr&r{r�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)rPrQrRrrrrrr�?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.rEr/r$)r0r~r1rrr�test_get_set_inheritable_badfvs���z0FDInheritanceTests.test_get_set_inheritable_badfcCs2t�ttj�}|�tj|�|�t�|�d�dSr)rr$r�r�r�r\r=r#r�rrrrb�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�rcCsHt�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�rrr	rrrrrrbrrrr8r9rrrrrrrrIs(






rc@sHeZdZddddejfdfddddd	eed
d�fgZdd�Zd
d�ZdS)�PathTConverterTests)r�TrN)ruFrNr^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)Nrhr)rr>zto return str or byteszos.PathLike)rrUrrrZrr$r�rZr�rVr\�	functionsrrr�assertRaisesRegexrp)r0Zstr_filenameZbytes_fspath�bytes_filenamer~Z
int_fspathZ
str_fspathrZallow_fd�
extra_argsZ
cleanup_fnrWr>r
rrr�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$)r0rprrr�&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�)�
BlockingTestscCrr
)	rr$r�r�r�r\r=r'r)r�rrrr*szBlockingTests.test_blockingN)rPrQrRr*rrrrr'rGr'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�rDrArWrrrrXszTestDirEntry.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&r1rrrr�test_unpickable#szTestDirEntry.test_unpickableN)rPrQrRrXr.r3rrrrr+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,rrUrZ�
bytes_pathr�rDrArWrrrrX/szTestScandir.setUpr�cCs2t|t�r|jn|j}tj�||�}t|d�|S)Nr/)r#rMr5r>rr@r()r0rr>r&rrrr(5s
zTestScandir.create_filecCs2tdd�t�|j�D��}|�t|���|�|S)Ncs��|]}|j|fVqdSr+rr0rrrr�<s��z*TestScandir.get_entries.<locals>.<genexpr>)r�rr2r>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+)rr2r>rjrpr|r\)r0�scandir_iterrrrr.NszTestScandir.test_uninstantiablecCs<|�d�}t�|j�}ddl}|�t|j||�|��dS)Nr�r)	r(rr2r>rrjrprr\)r0r&r?rrrrr3Ss

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�rh)r-rr-r=rr>r@�inoder�r<�is_dir�S_ISDIRr�is_file�S_ISREG�
is_symlinkr�r>)r0r1rrArCrEZ
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.txtr1�symlink_dirT)r��symlink_file.txt)rGrHF)rrrrr>r@rAr(rrrhr�r&r�r:rF)	r0rr�rHr&r�r8r9r1rrr�test_attributesvsH


���


�zTestScandir.test_attributescCsNt|t�r|jn|j}tt�|��}|�t|�d�|d}|�|j	|�|Sr)
r#rMr5r>r!rr2r=r:r)r0rr>r9r1rrr�	get_entry�szTestScandir.get_entrycCs|j|d�}|�tj�|��S)Nr)r(rJrr>�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)Ncsr6r+rr0rrrr��r�z5TestScandir.test_current_directory.<locals>.<genexpr>)r(rr,rBr>r�r2r=r�r7rK)r0r&Zold_dirr9rrr�test_current_directory�s�z"TestScandir.test_current_directorycCs|��}|�t|�d�dS)Nz<DirEntry 'file.txt'>)rLr=r��r0r1rrr�	test_repr�rFzTestScandir.test_reprcCs*|��}|�t�|�tj�|jd��dS)Nr�)rLr=r�fspathr>r@rNrrr�test_fspath_protocol�s"z TestScandir.test_fspath_protocolcCsNt�d�}|j|d�}t�|�}|�|t�|�|tj�t�|j�|��dS)Nz
bytesfile.txtr)	rrZrLrPr-rMr=r>r@)r0r Zbytes_entryrPrrr�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�rhFr�r)rr>r@rArJr7rr]rAr�rCrErjrCr@r�r�)r0r>r1rrr�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)NrhFr�r)rLrrVr>r�rArr]rCrErjrCr@r�r�rNrrr�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@r:rVr�r@r�rArCr]rErjrCr�)r0r&r9r1rrr�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(rrZr>r!r2r=r:rr@)r0�
path_bytesr9r1rrrr�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	dSrV)r(r�r�rrZr>�assertWarnsr�r!r2r=r:rr@r�r|rM)r0r~rWr9r1rrr�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
rrr0rrrr1rz'TestScandir.test_fd.<locals>.<listcomp>r�F)r�rfr�)r�rr2r�r(rrr�r>r@r&rkr!r=r�rrrPrEr�r�)r0Zexpected_namesr~r�r9r8r1rHrrr�test_fd$s2

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


"�zTestScandir.test_closecCsx|�d�|�d�t�|j��}t|�Wd�n1swY|���
~Wd�dS1s5wYdSr_)r(rr2r>r�rarbrrr�test_context_manager[s


�
"�z TestScandir.test_context_managercCsV|�d�|�d�t�|j��}t|�|��Wd�dS1s$wYdSr_)r(rr2r>r�r\rbrrr�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�ZeroDivisionErrorrr2r>r�rarbrrr�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(rr2r>r�rX�ResourceWarningr�
gc_collectr!rarbrrr�test_resource_warningts


�
"�z!TestScandir.test_resource_warningN)r�)&rPrQrRrrarXr(r:r>r.r3rFrIrJrLrMrOrQrRrSrTrUr�rYrrrrr�rZr[r\r^rcrdrergrjrrrrr4,sB

)
	�

r4c@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=rP)r0�brrr�test_return_bytes���zTestPEP519.test_return_bytescCrl)N)ZhelloZgoodbyezsome/path/and/filerm)r0rrrr�test_return_string�rpzTestPEP519.test_return_stringcCsLdD]!}t|�}|�||�|��|�dt�|��|�dt�|��qdS)N)�path/like/object�path/like/objectrsrr)rr=rPrrZrN)r0rZpathlikerrr�test_fsencode_fsdecode�s�z!TestPEP519.test_fsencode_fsdecodecCsB|�d|�td���|�tttj��|�ttd�tj��dS)Nz#feelthegilr�)r=rPrr]�
issubclassr�PathLiker#rWrrrr��szTestPEP519.test_pathlikecCs4tddi�}ttt|�fD]
}|�t|j|�q
dS)NZblahr)r|r�rrjrprP)r0Zvapor�orrr�test_garbage_in_exception_out�s�z(TestPEP519.test_garbage_in_exception_outcCs|�t|j�dSr+)rjrprPrWrrr�test_argument_required�r�z!TestPEP519.test_argument_requiredcCsR|�t|jtd��tddi�}d|_|�t|j|��|�t|jtt���dS)Nr�Zfoorrc)rjrprPrr|�
__fspath__rf)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})rrvr�rurr])r0r}rrr�test_pathlike_subclasshook�sz%TestPEP519.test_pathlike_subclasshookcCs|�tjttj�dSr+)r-rrvrM�types�GenericAliasrWrrr�test_pathlike_class_getitem�r�z&TestPEP519.test_pathlike_class_getitemN)rPrQrRr�rrProrqrtr�rxryr|r~r�rrrrrk�s
rkc@r�)�
TimesTestscCsrt��}|�|tj�dD]
}t||�}|�|t�q
tjdkr7|�|jd�|�|j	d�|�|j
d�dSdS)N)�user�system�
children_user�children_system�elapsedrhr)rrdr-�times_resultrr#rr=r�r�r�)r0rdZfieldr&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@seZdZdZeej�ZdS)�TestPEP519PurePythonz>Explicitly test the pure Python implementation of os.fspath().N)rPrQrRrr�rr�rPrrrrr��sr��__main__)r"r+)�r��
contextlibr�rEr�r�rHr�r�rrr�r^rrdr�r�r�r8Z	sysconfigr;r�r`rqrrr�r��testrZtest.supportrrrrrr9rr��simplefilterr�rOrbr��ImportErrorrr��pwdZgetpwallr�rZ	_testcapirrr�Ztest.support.script_helperrrZtest.support.os_helperrr�rrr�versionr�r��getgidrEr r(r�r�ZTestCaser*rSr�rBr�ZBasicTestMappingProtocolr�rrrCrXr_rbr|r�r�r�r�Zget_config_varZOS_URANDOM_DONT_USE_FDr��contextmanagerr�r�r�r�r,r:rVrfr�r�r�r�r�r�r�r�r�r�rr�rDrJrcrarNr�r�Zrequires_linux_versionr�r�r�r�r�r�rrr'r(r+r4rkr�r�r�rP�mainrrrr�<module>s�

������
�EZe\)EG
^;)	-����M �h#w%CGs/<0![H4�VO�Q0
Q]
yB�Y:
�