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

nadelinn - rinduu

Command :

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

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

�_g�t�	@sBddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZddlm Z zddl!Z!Wne"�y dZ!Yn0zddl#Z#Wne"�yFdZ#Yn0zddl$Z$Wne"�yldZ$Yn0zddl%Z%dd�e%�&�D�Z'Wne"e(f�y�gZ'Yn0zddl)m*Z*m+Z+Wne"�y�ej,Z*Z+Yn0ddl-m.Z.dd	lm/Z/m0Z0d
Z1e2ed��re�3�dkZ1e2ed��r<ej4j5�r<ej4j5�6d
�Z7nd
Z7ej�6d��oXe�8�dkZ9dd�Z:d�dd�Z;Gdd�dej<�Z=Gdd�dej<�Z>Gdd�dej<�Z?Gdd�dej<�Z@ddlmAZAGdd�deAjB�ZCGdd �d ej<�ZDe�Ee2ed!�d"�Gd#d$�d$eD��ZFGd%d&�d&eD�ZGe�Ee2ed!�d"�Gd'd(�d(eF��ZHGd)d*�d*ej<�ZIe�Ee2ed+�d,�Gd-d.�d.ej<��ZJGd/d0�d0ej<�ZKGd1d2�d2ej<�ZLGd3d4�d4ej<�ZMe�Ee2ed5�d6�Gd7d8�d8ej<��ZNe�Od9�d:k�p�e�Od;�d:k�p�e�Od<�d:kZPe�QePd=�e�Qejd>kd?�Gd@dA�dAej<���ZRejSd�dBdC��ZTe�Ee2edD�dE�GdFdG�dGej<��ZUe�EejdHkdI�GdJdK�dKej<��ZVGdLdM�dMej<�ZWGdNdO�dOej<�ZXe�QejdHkdP�GdQdR�dRej<��ZYe�QejdHkdP�GdSdT�dTej<��ZZe�EejdHkdI�GdUdV�dVej<��Z[e�EejdHkdI�GdWdX�dXej<��Z\e�Ee2edY�dZ�Gd[d\�d\ej<��Z]e�EejdHkdI�ej^Gd]d^�d^ej<���Z_e�EejdHkdI�Gd_d`�d`ej<��Z`e�EejdHkdI�Gdadb�dbej<��Zaej^Gdcdd�ddej<��ZbGdedf�dfej<�ZcGdgdh�dhej<�ZdGdidj�djej<�ZeGdkdl�dlej<�Zfe�gdm�e�Ee2edn�do�Gdpdq�dqej<���Zhe�Ee2edr��one2eds�dt�Gdudv�dvej<��ZiGdwdx�dxejjejk�Zle�Ee2edy�dz�Gd{d|�d|ej<��Zmd}d~�Zne�Een�d�e�od�d�d��Gd�d��d�ej<���Zpe�Ee2ed��d��Gd�d��d�ej<��Zqe�Ee2ed��d��e�od�d��Gd�d��d�ej<���ZrGd�d��d�ej<�ZsGd�d��d�ej<�ZtGd�d��d�ej<�ZuGd�d��d�ej<�Zve�Ee2ed��d��Gd�d��d�ej<��ZwGd�d��d�ej<�ZxGd�d��d�ej<�ZyGd�d��d�ej<�ZzGd�d��d�ej<�Z{Gd�d��d�ej<�Z|e2ed���r,Gd�d��d�e{�Z}e~d�k�r>e��dS)��N)�support)�
socket_helper)�win32_is_iotcCsg|]
}|j�qS�)�pw_uid)�.0�urr�+/vddos/python/lib/python3.9/test/test_os.py�
<listcomp>2�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_funcOsr�contentcCs:t|dd��}|�|�Wd�n1s,0YdS)N�xbr)�open�write)�filenameZcontent�fprrr	�create_fileSsr!c@s$eZdZdd�Zdd�Zdd�ZdS)�	MiscTestscCst��}|�|t�dS�N)r�getcwd�assertIsInstance�str��self�cwdrrr	�test_getcwdYszMiscTests.test_getcwdc
Cs~d}d}d}|d|t|�}t����>}t�|���}|}t��}|�||�|t|�ttjj	�}|dkrv�q t|�|kr�|dkr�|d|�}tj�
||�}zt�|�t�|�Wn\t
y�Y�q YnFt�y}	z,|	jtjk�rWYd}	~	�q n�WYd}	~	n
d}	~	00|}q>tj�r:tdt|����Wd�n1�sP0YWd�n1�sp0YdS)Ni���Zpython_test_dir_�arz!Tested current directory length: )�len�tempfile�TemporaryDirectoryrZ
change_cwdrr$�assertEqual�path�sep�join�mkdir�chdir�FileNotFoundError�OSError�errnoZENAMETOOLONG�verbose�print)
r(Zmin_lenZdirlen�dirnameZtmpdirr1�expectedr)Zneed�excrrr	�test_getcwd_long_path]s6

zMiscTests.test_getcwd_long_pathcCs.t��}|�|t�|�t�|�t���dSr#)r�getcwdbr%�bytesr0�fsdecoder$r'rrr	�test_getcwdb�szMiscTests.test_getcwdbN)�__name__�
__module__�__qualname__r*r>rBrrrr	r"Xs5r"c@seZdZdd�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+��Zd,S)-�	FileTestscCstj�tj�rt�tj�dSr#)rr1�lexistsr�TESTFN�unlink�r(rrr	�setUp�szFileTests.setUpcCs:t�tjtjtjB�}t�|�|�t�tjtj	��dSr#)
rrrrH�O_CREAT�O_RDWR�close�
assertTrue�access�W_OK�r(�frrr	�test_access�s
zFileTests.test_accessc	Cs�t�tjtjtjB�}t�|�}zTd}||dkrht�|�|d7}|dkrV|�d�|t�|�}}q&Wt�|�nt�|�0t�	||d�|�
ttj|d�dS)Nr��
z%couldn't allocate two consecutive fds��a)
rrrrHrLrM�duprN�skipTest�
closerange�assertRaisesr7r)r(�first�secondZretriesrrr	�test_closerange�s


zFileTests.test_closerangecCs<tj}t�|�}|�ttj|d�t�|�}|�||�dS�Nr)	rrH�sys�getrefcountr\�	TypeErrorr�renamer0)r(r1�old�newrrr	�test_rename�s


zFileTests.test_renamecCs�ttjd��`}|�d�|��|��}t�|dd�t�|d�}|�	t
|�t�|�	|d�Wd�n1sr0YdS)N�w+b�spamr�)rrrHr�flush�filenor�lseek�readr0�typer@)r(�fobj�fd�srrr	�	test_read�s
zFileTests.test_readzneeds INT_MAX < PY_SSIZE_T_MAXrVrUF)�sizeZmemuse�dry_runcCsh|�tjtj�ttjd�ttjd�� }t�|��|�}Wd�n1sN0Y|�	|d�dS)Nstest�rb)
�
addCleanuprrIrHr!rrrnrlr0)r(rtr �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�n1s�0YdS)N�beanssbacon
seggs
sspam
rv)sbaconseggsri)rrrrHrL�O_WRONLYr\rcr�	bytearray�
memoryviewrNr0rn�
splitlines)r(rqrprrr	�
test_write�s
�zFileTests.test_writecGs"tj|tjdd�}|�|d�dS)NT)�
creationflags�shellr)�
subprocess�callZCREATE_NEW_CONSOLEr0)r(�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�ra�
executable�r(�coderrr	�test_write_windows_console�sz$FileTests.test_write_windows_consolecGs.t�tjtj�}tj|g|�R�}|��dSr#)rrrrH�O_RDONLY�fdopenrN)r(r�rqrSrrr	�
fdopen_helper�szFileTests.fdopen_helpercCsBt�tjtjtjB�}t�|�|��|�d�|�dd�dS)N�r�d)rrrrHrLrMrNr��r(rqrrr	�test_fdopens


zFileTests.test_fdopencCs�tjd}|�tjtj�|�tj|�ttjd�t|d�t�tj|�|�ttj	tj�t
|d�� }|�|��d�Wd�n1s�0YdS)Nz.2�1�2r��1)
rrHrwrIr!r�replacer\r6�statrr0rn)r(�TESTFN2rSrrr	�test_replace
s

zFileTests.test_replacecCs"tjttjddd�}t�|�dS)N�)r1�flags�mode�dir_fd)rr�__file__r�rNrRrrr	�test_open_keywordss�zFileTests.test_open_keywordsc	Cs>t�td�}z|dtjddd�Wnttfy8Yn0dS)N�symlink�targetF)�src�dst�target_is_directoryr�)rZ
get_attributerrH�NotImplementedErrorr7)r(r�rrr	�test_symlink_keywordss�
zFileTests.test_symlink_keywords�copy_file_rangeztest needs os.copy_file_range()cCs<|�t��t�ddd�Wd�n1s.0YdS)NrrUi����)r\�
ValueErrorrr�rJrrr	�#test_copy_file_range_invalid_values$sz-FileTests.test_copy_file_range_invalid_valuesc	
Cs tjd}d}ttj|�|�tjtj�ttjd�}|�|j�|��}t|d�}|�tj|�|�|j�|��}zt�	||d�}Wn<t
y�}z$|jtjkr��|�
|�WYd}~n`d}~00|�|tdd��t|d��(}|�|��|d|��Wd�n1�s0YdS)Nz.3�
0123456789rvrh�r�)rrHr!rwrIrrNrlrr�r7r8�ENOSYSrZ�assertIn�ranger0rn)	r(r�rx�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�|��}	ztj	||	|||d�}
Wn<t
y�}z$|jtjkr��|�
|�WYd}~n�d}~00|�|
td	|d
��t|d��}|��}Wd�n1�s0Y|�|d|�d|�|�||d�||||
��dS)Nz.4r�r��r�rvrh)Z
offset_srcZ
offset_dstrrU�)rrHr!rwrIrrNrlrr�r7r8r�rZr�r�rnr0)
r(ZTESTFN4rxZ
bytes_to_copyZin_skipZout_seekr�r�r�r�r�r�rnrrr	�test_copy_file_range_offsetKs<


�
 (�z%FileTests.test_copy_file_range_offsetN) rCrDrErK�tearDownrTr_r�cpython_onlyrgrsrrrr
Z
bigmemtestryrr�ra�platformr�r�r�r�r�r�rrr�r�r�rrrr	rF�s<


�
�
	


!rFc@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)rrH�fnamerwrIr!rJrrr	rKzszStatAttributeTests.setUpc
	Cs�t�|�}|�|tjd�|�|jd�t|�}tt�D]d}|dd�dkr:|��}|�d�rjdd�}ndd�}|�|t||��|tt|��|�	||�q:d�
�D]8}tt||�d�}t||d	�d
}|j||dd�q�z|d
|�
d�Wnt�yYn0zd|_|�
d�Wnt�y6Yn0zd|_|�
d�Wnttf�ydYn0zd|_|�
d�Wnt�y�Yn0zt�d�}	|�
d�Wnt�y�Yn0zt�d�}	Wnt�y�Yn0dS)Nr�ZST_ZTIMEcSst|�Sr#)�int��xrrr	�trunc�rz7StatAttributeTests.check_stat_attributes.<locals>.trunccSs|Sr#rr�rrr	r��rzst_atime st_mtime st_ctimei��Z_nsi'rW��deltar+�No exception raisedrU�rV�rrUrWr�rjr�r����	rV���
�)rr�r0�ST_SIZE�st_size�dir�lower�endswith�getattrr��splitr��assertAlmostEqual�fail�
IndexError�st_mode�AttributeError�st_rdevrc�parrot�stat_result)
r(r��result�membersr�attrr�ZfloatyZnanosecondy�result2rrr	�check_stat_attributess^


�
z(StatAttributeTests.check_stat_attributescCs|�|j�dSr#)r�r�rJrrr	�test_stat_attributes�sz'StatAttributeTests.test_stat_attributescCsFz|j�t���}Wn"ty6|�d|j�Yn0|�|�dS)Nz#cannot encode %a for the filesystem)r��encodera�getfilesystemencoding�UnicodeEncodeErrorrZr�)r(r�rrr	�test_stat_attributes_bytes�s
z-StatAttributeTests.test_stat_attributes_bytescCsft�|j�}ttjd�D]F}t�||�}|�d|�|dkrJ|�d|�t�|�}|�	||�qdS)NrUsstat_resultrjscos
stat_result
)
rr�r�r��pickle�HIGHEST_PROTOCOL�dumpsr��loadsr0�r(r��proto�pZ	unpickledrrr	�test_stat_result_pickle�s
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�zd|_|�d�Wnt
y�Yn0zd|_|�d�Wnt
y�Yn0zt�d�}|�d�Wnty�Yn0zt�d�}Wnt�yYn0dS)	Nr�)
ZbsizeZfrsizeZblocksZbfreeZbavail�filesZffreeZfavail�flagZnamemaxZf_rVrUr�r�r�)rr�r�r0�f_bfree�	enumerater�rO�
isinstance�f_fsidr�r-r�r�r��statvfs_resultrc)r(r�r��value�memberr�rrr	�test_statvfs_attributes�s4
z*StatAttributeTests.test_statvfs_attributes�need os.statvfs()cCsft�|j�}ttjd�D]F}t�||�}|�d|�|dkrJ|�d|�t�|�}|�	||�qdS)NrUsstatvfs_resultrjscos
statvfs_result
)
rr�r�r�r�r�r�r�r�r0r�rrr	�test_statvfs_result_pickles
z-StatAttributeTests.test_statvfs_result_pickler��Win32 specific testsc
Cs\zt�d�WnHty*|�d�Yn.tyV}z|�d�WYd}~n
d}~00dS)Nzc:\pagefile.syszc:\pagefile.sys does not existzCould not stat pagefile.sys)rr�r6rZr7r��r(r�rrr	�test_1686475
szStatAttributeTests.test_1686475�pipezrequires os.pipe()c	Cs�t��\}}z"t�|�Wt�|�t�|�nt�|�t�|�0|�t��}t�|�Wd�n1sp0Y|�|jjtj	�dSr#)
rrr�rNr\r7r0�	exceptionr8�EBADF)r(r��w�ctxrrr	�
test_15261s
�
(zStatAttributeTests.test_15261cCsF|�t|d��|�t|jt��|�d|jko:dkn�dS)N�st_file_attributesr���)rOrr�rr�)r(r�rrr	�check_file_attributes%sz(StatAttributeTests.check_file_attributesz$st_file_attributes is Win32 specificcCszt�|j�}|�|�|�|jtj@d�tjd}t�	|�|�
tj|�t�|�}|�|�|�|jtj@tj�dS)Nrr�)rr�r�r
r0r�FILE_ATTRIBUTE_DIRECTORYrrHr4rw�rmdir)r(r�r;rrr	�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)rr1r3�environr�rwrrIr!r��
check_callr��assertNotEqualr�)r(r�ZDETACHED_PROCESSr�rrr	�test_access_denied?s

�
z%StatAttributeTests.test_access_deniedcCs6dtj�t���d}t�|�}|�|jtj�dS)Nz//./r)rr1�
splitdriver$r�r0r��S_IFBLK)r(r�r�rrr	�test_stat_block_deviceTs
z)StatAttributeTests.test_stat_block_deviceN)rCrDrErKr�r�r�r�rrrrr�r�rar�rrr
r
rrrrrr	r�ys2A

+�

	�

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)rrHr;rr1r3r�rw�rmtreer4r!rJrrr	rK^s
zUtimeTests.setUpcCs4t�|�}|j|dkp2|j|dkp2|j|dkS)Nr�r�r�)rr��st_atime�st_mtime�st_ctime)r(r�strrr	�support_subsecondfs
��zUtimeTests.support_subsecondNcCs�|s
|j}|�|�}|r"d}d}nd}d}||||f�t�|�}|rt|j|j|ddd�|j|j|ddd�n$|�|j|d�|�|j|d�|�|j|�|�|j	|�dS)Ni8Z�;l�
o]�rTlP�9��&�.>g���ư>r�)
r�rrr�r�rrr0�st_atime_ns�st_mtime_ns)r(�set_timerr�atime_ns�mtime_nsrrrr	�_test_utimens"

zUtimeTests._test_utimecCsdd�}|�|�dS)NcSstj||d�dS�N��ns�r�utime�rr)rrr	r#�sz'UtimeTests.test_utime.<locals>.set_time�r&�r(r#rrr	�
test_utime�szUtimeTests.test_utimecCs|ddS)Nr g��&�.>rr(rrr	�	ns_to_sec�szUtimeTests.ns_to_seccs�fdd�}��|�dS)Ncs0|\}}��|�}��|�}t�|||f�dSr#�r0rr+�rr)r$r%Zatime�mtimerJrr	r#�s

z2UtimeTests.test_utime_by_indexed.<locals>.set_timer-r.rrJr	�test_utime_by_indexed�sz UtimeTests.test_utime_by_indexedcs�fdd�}��|�dS)Ncs2|\}}��|�}��|�}tj|||fd�dS)N)�timesr1r2rJrr	r#�s

z0UtimeTests.test_utime_by_times.<locals>.set_timer-r.rrJr	�test_utime_by_times�szUtimeTests.test_utime_by_timesz9follow_symlinks support for utime required for this test.cCsdd�}|�|�dS)NcSstj||dd�dS)NF)r)�follow_symlinksr*r,rrr	r#�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.cCsdd�}|�|�dS)NcSsBt|dd��"}tj|��|d�Wd�n1s40YdS)N�wbrr()rrr+rl)rr)r rrr	r#�sz*UtimeTests.test_utime_fd.<locals>.set_timer-r.rrr	�
test_utime_fd�szUtimeTests.test_utime_fdz0dir_fd support for utime required for this test.cCsdd�}|�|�dS)Nc	SsNtj�|�\}}t�|tj�}ztj|||d�Wt�|�nt�|�0dS)N)r�r))rr1r�rr�r+rN)rr)r;r�dirfdrrr	r#�s
z.UtimeTests.test_utime_dir_fd.<locals>.set_timer-r.rrr	�test_utime_dir_fd�szUtimeTests.test_utime_dir_fdcCsdd�}|j||jd�dS)NcSstj||d�dSr'r*r,rrr	r#�sz1UtimeTests.test_utime_directory.<locals>.set_time�r)r&r;r.rrr	�test_utime_directory�szUtimeTests.test_utime_directorycCsbt��}||j�|�|j�s$d}nd}t�|j�}d|j||j|f}|j|j|||d�dS)Ng�?g�������?zst_time=%r, current=%r, dt=%r)r��msg)�timer�rrr�rr�)r(r#�currentr�rr?rrr	�_test_utime_current�s
�
�zUtimeTests._test_utime_currentcs�fdd�}��|�dS)Ncst��j�dSr#�rr+r�r=rJrr	r#�sz/UtimeTests.test_utime_current.<locals>.set_time�rBr.rrJr	�test_utime_current�szUtimeTests.test_utime_currentcs�fdd�}��|�dS)Ncst��jd�dSr#rCr=rJrr	r#�sz3UtimeTests.test_utime_current_old.<locals>.set_timerDr.rrJr	�test_utime_current_old�sz!UtimeTests.test_utime_current_oldcCsltjdkrhtj�tj�|��dd}ddl}|jj}|�	dd�}|�
|ddddd|t|��}|rh|jSdS)Nr�r�\�r�)
rar�rr1r�abspath�ctypes�windll�kernel32Zcreate_unicode_bufferZGetVolumeInformationWr-r�)r(r1�rootrJrL�buf�okrrr	�get_file_system�s

�zUtimeTests.get_file_systemcCsJ|�|j�dkr|�d�d}t�|j||f�|�t�|j�j|�dS)NZNTFSz
requires NTFSr)	rPr;rZrr+r�r0r�r)r(Zlargerrr	�test_large_times

zUtimeTests.test_large_timec	Cs�|�t��"tj|jddd�Wd�n1s20Y|�t��"t�|jddg�Wd�n1sn0Y|�t��t�|jd�Wd�n1s�0Y|�t��t�|jd�Wd�n1s�0Y|�t��$tj|jddgd�Wd�n1�s0Y|�t�� tj|jdd�Wd�n1�sZ0Y|�t�� tj|jdd�Wd�n1�s�0Ytjtjv�r�|�t��"tj|jddd�Wd�n1�s�0Ytjtjv�rft	|jdd	��L}|�t�� t�|�
�d�Wd�n1�s<0YWd�n1�s\0Ytjtjv�r�|�t��"tj|jdd	d
�Wd�n1�s�0YdS)N)r�r�r(r�)r�)r�r�r�F�r7r9r�r�)r\r�rr+r�rc�supports_follow_symlinksr��supports_fdrrl�supports_dir_fd)r(r rrr	�test_utime_invalid_argumentss000,,4002Pz'UtimeTests.test_utime_invalid_argumentscCs�dd�}|�t��(tj|j|d�dfd�Wd�n1s@0Y|�t��(tj|j|d�dfd�Wd�n1s�0Y|�t��(tj|j|d�dfd�Wd�n1s�0YdS)NcsG�fdd�d�}|�S)NcseZdZ�fdd�ZdS)z?UtimeTests.test_issue31577.<locals>.get_bad_int.<locals>.BadIntcs�Sr#r)r���divmod_ret_valrr	�
__divmod__0szJUtimeTests.test_issue31577.<locals>.get_bad_int.<locals>.BadInt.__divmod__N)rCrDrErZrrXrr	�BadInt/sr[r)rYr[rrXr	�get_bad_int.sz/UtimeTests.test_issue31577.<locals>.get_bad_int�*rUr(r)rUrWr�)r\rcrr+r�)r(r\rrr	�test_issue31577*s66zUtimeTests.test_issue31577)N)rCrDrErKrr&r/�staticmethodr0r4r6rrrr+rTr8rUr:rVr<r>rBrErFrPrQrWrr�r^rrrr	r]s:

	�
�
�


r)�
mapping_testsc@seZdZdZdZdd�Zdd�Zdd�Zd	d
�Ze	�
eoBej
�e�d�dd
��Ze	�
eobej
�e�d�dd��Zdd�Zdd�Zdd�Zdd�Ze	�
ejd�dd��Zdd�Ze�dd�dd ��Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Z d-d.�Z!d/d0�Z"d1d2�Z#d3d4�Z$d5d6�Z%dS)7�EnvironTestsz8check that os.environ object conform to mapping protocolNcCsBttj�|_tjrttj�|_|����D]\}}|tj|<q*dSr#)	�dictrr�_EnvironTests__save�supports_bytes_environ�environb�_EnvironTests__saveb�
_reference�items�r(�keyr�rrr	rKAs
zEnvironTests.setUpcCs:tj��tj�|j�tjr6tj��tj�|j�dSr#)rr�clear�updatercrdrerfrJrrr	r�Hs


zEnvironTests.tearDowncCsdddd�S)NZVALUE1ZVALUE2ZVALUE3)ZKEY1ZKEY2ZKEY3rrJrrr	rgOszEnvironTests._referencecCstj��tjSr#)rrrkrJrrr	�_empty_mappingRs
zEnvironTests._empty_mappingzrequires a shellcCsbtj��tjjdd�t�dt��(}|����}|�|d�Wd�n1sT0YdS)NZWorld)ZHELLOz%s -c 'echo $HELLO')	rrrkrl�popenrrn�stripr0)r(rnr�rrr	�test_update2Ws

zEnvironTests.test_update2cCsxt�dt��V}t|�}|�t|�d�|�t|�d�|�t|�d�|�tt|�Wd�n1sj0YdS)Nz %s -c 'echo "line1
line2
line3"'zline1
zline2
zline3
)rrnr�iterr0�nextr\�
StopIteration)r(rn�itrrr	�test_os_popen_iter`s�zEnvironTests.test_os_popen_itercCs8tj��D](\}}|�t|�t�|�t|�t�q
dSr#)rrrhr0ror&)r(rj�valrrr	�test_keyvalue_typesmsz EnvironTests.test_keyvalue_typescCs.|����D]\}}|�tj�|�|�qdSr#)rgrhr0rr�getrirrr	�
test_itemsrszEnvironTests.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)rrjr�rrr	�	<genexpr>zs�z-EnvironTests.test___repr__.<locals>.<genexpr>N)rrr0�reprr{r3rh)r(�envrrr	�
test___repr__ws�zEnvironTests.test___repr__cCsZtj�tj�}gd�}dtj�|�i}tj}z8t|�t_|�|t���|�|tjdd��W|t_n|t_0|�|t�i��|�dt�ddi��|�|t�|��tj	�rVz:t
jdd��dd	d
�}Wd�n1s�0YWnty�Yn0|�
ttj|�|�t�ddi�d
g�|�t�dd
i�d
g�|�t�ddi�d
g�dS)N)z/montyz/pythonrHz/flying/circus�PATH�r~�rHrHT)�recordr�r�)r��PATHr��abc�abc)r�defpathr��pathsepr3rrb�assertSequenceEqual�
get_exec_pathrd�warnings�catch_warnings�BytesWarningr\r�)r(Zdefpath_listZ	test_pathZtest_envZ
saved_environZ	mixed_envrrr	�test_get_exec_path~s8
,���zEnvironTests.test_get_exec_pathz#os.environb required for this test.cCs�d}z|�t��d�}Wn*tyBdt��f}|�|�Yn0|tjd<|�tjd|�|�tjd|�d}|tjd<|�tjd|�|�	t��d�}|�tjd|�dS)	Nueuro€�surrogateescapez'U+20AC character is not encodable to %s�unicodesunicode��sbytesr@)
r�rar�r�rZrrr0re�decode)r(r�Zvalue_bytesr?Z	value_strrrr	�
test_environb�s$
��

zEnvironTests.test_environbcCs�d}d}d|�d�}t����}|�|d�t�||�tjtjd|gdtj	dd�}|�
|j��t
|��t�|�tjtjd|gdtj	dd�}|�
|j��t
d��Wd�n1s�0YdS)NZ
PYTHONTESTVARZ	testvaluez%import os; print(repr(os.environ.get(z)))r�T)�check�stdout�text)rZEnvironmentVarGuard�popr�putenvr��runrar��PIPEr0r��rstripr}�unsetenv)r(rr�r�r~�procrrr	�test_putenv_unsetenv�s
�
�z!EnvironTests.test_putenv_unsetenvrVr�cCs~dD].}|�ttftj|d�|�ttftj|�qtjdkrzdd}|�ttj|d�|�ttjd|�|�ttj|�dS)N)rHz=namezna=mezname=znameznamer�r�r���r��X)r\r7r�rr�r�rar�)r(rZlongstrrrr	�test_putenv_unsetenv_error�s
z'EnvironTests.test_putenv_unsetenv_errorcCs�d}|�|tj�|�t��}tj|Wd�n1s<0Y|�|jjd|�|�|jj	�|�t��}tj|=Wd�n1s�0Y|�|jjd|�|�|jj	�dS)NZ
missingkeyr)
�assertNotInrrr\�KeyError�assertIsrr�rO�__suppress_context__)r(�missing�cmrrr	�
test_key_type�s(&zEnvironTests.test_key_typecCsTt|�}d}t|�dtj|<z&t|�|�tj|d�Wtj|=n
tj|=0dS)NZ__new_key__Ztest_environ_iteration)rqrrrrr0)r(Z
collection�iteratorZnew_keyrrr	�_test_environ_iteration�s
z$EnvironTests._test_environ_iterationcCs|�tj�dSr#)r�rrrJrrr	�(test_iter_error_when_changing_os_environ�sz5EnvironTests.test_iter_error_when_changing_os_environcCs|�tj���dSr#)r�rrrhrJrrr	�.test_iter_error_when_changing_os_environ_itemssz;EnvironTests.test_iter_error_when_changing_os_environ_itemscCs|�tj���dSr#)r�rr�valuesrJrrr	�/test_iter_error_when_changing_os_environ_valuessz<EnvironTests.test_iter_error_when_changing_os_environ_valuescCsftrtj�t�sdSt�t�d|�d���}|����}Wd�n1sL0Y|�||�dS)Nz -c 'echo $�')rrr1�existsrnrnror0)r(�varr<rnr�rrr	�_test_underlying_process_envs
*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�3rH)rrrbrl�assertDictEqualr0rhr��NotImplemented�__or__r��r(�overridden_keyr��
new_vars_dictr<�actual�new_vars_itemsrrr	�test_or_operators



zEnvironTests.test_or_operatorcCs|d}dtj|<dddd|di}ttj�}|�|�tj|O_|�|tj�|�dtj|�|�dd�|�|d�dS)Nr�r�r�r�r�r�r��rrrbrlr0r�)r(r�r�r<rrr	�test_ior_operator#s


zEnvironTests.test_ior_operatorcCs�tj��}|�t��&ddi}tj|O_Wd�n1s@0Y|�t��&ddi}tj|O_Wd�n1s�0Y|�|tj�dS)NrUr�)rr�copyr\rcr0)r(Zos_environ_copyZdict_with_bad_keyZdict_with_bad_valrrr	�test_ior_operator_invalid_dicts2s
,,z,EnvironTests.test_ior_operator_invalid_dictscCszd}dtj|<dd|dff}ttj�}|�|�tj|O_|�|tj�|�dtj|�|�dd�|�|d�dS)Nr�r�)r�r�)r�r�r�r�r�r�)r(r�r�r<rrr	�$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�)rrrbrlr�r0rhr�r��__ror__r�r�rrr	�test_ror_operatorNs

zEnvironTests.test_ror_operator)&rCrDrE�__doc__Z	type2testrKr�rgrmrrrrr1r�rprurwryrr�rdr�r�rZrequires_mac_verr�r�r�r�r�r�r�r�r�r�r�r�rrrr	ra=sH�
�
)�


	
rac@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�Nr7�followlinks)r�r�walk)r(�top�kwargsrrr	r�gszWalkTests.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]H}
t|
ddd��"}|�
d|
d�Wd�n1�s<0Y�qt���r�t�tj�|�|j
�t�d|
d�t�|dd�|d�t�|dd�|d�|dd	ggd�f|_n|dgdgf|_t�|d�zt�|�Wn&t�y|�tj|tj�Yn40t�|tj�t�|�t�|�|jddd�=dS)NZTEST1�SUB1�SUB11�SUB2ZSUB21�tmp1�tmp2�tmp3�linkZTEST2�tmp4�broken_link�broken_link2�broken_link3r��utf-8��encodingzI'm z" and proud of it.  Blame test_os.
�brokenTZtmp5)r�r�r�r�rrU)rr1r3rwrrrH�	walk_path�	sub1_path�
sub11_path�	link_path�makedirsrr�can_symlinkr�rI�	sub2_tree�chmod�listdir�PermissionErrorr��S_IRWXUrIr)r(r3Z	sub2_pathZ
sub21_pathZ	tmp1_pathZ	tmp2_pathZ	tmp3_pathZ	tmp5_pathZt2_pathZ	tmp4_pathZbroken_link_pathZbroken_link2_pathZbroken_link3_pathr1rSrrr	rKlsT








6
�

zWalkTests.setUpcCs�t|�|j��}|�t|�d�|ddddk}|dd��|dd|d��|dd|d��|�|d|jddgd	gf�|�|d||jd
gdgf�|�|d||jggf�|�|dd||j�dS)NrjrrUr�r�rW���r�r�r�r�)	�listr�r�r0r-�sortr�r�r��r(�allZflippedrrr	�test_walk_topdown�s zWalkTests.test_walk_topdownNcCs�|dur|j}g}|�|�D],\}}}|�|||f�d|vr|�d�q|�t|�d�|�|d|jdgdgf�|dd��|dd��|�|d|j�dS)Nr�rWrr�r�rUr�)r�r��append�remover0r-r�r�)r(r�r�rM�dirsr�rrr	�test_walk_prune�szWalkTests.test_walk_prunecCs|�t|j��dSr#)r�rr�rJrrr	�test_file_like_path�szWalkTests.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��topdownrjr�rUrr�rWr�r�r�r�r�)	r�r�r�r0r-r�r�r�r�r�rrr	�test_walk_bottom_up�s$
�

���zWalkTests.test_walk_bottom_upcCsht��s|�d�|j|jdd�}|D]2\}}}||jkr&|�|g�|�|dg�qdq&|�d�dS)Nzneed symlink supportTrRr�z+Didn't follow symlink with followlinks=True)rr�rZr�r�r�r0r�)r(�walk_itrMr�r�rrr	�test_walk_symlink�s

zWalkTests.test_walk_symlinkc
Cs�g}|j|j|jd�}t|�\}}}|�|g�d}tj�||�}tj�||d�}t�||�zhdd�|D�}	|�	|�|�
||	�|�
||	�|D]"}
|
|kr�|�tj�||
�|	�q�Wt�||�nt�||�0dS)N)�onerrorr�z.newcSsg|]\}}}|�qSrr)rr��drSrrr	r
rz/WalkTests.test_walk_bad_dir.<locals>.<listcomp>)r�r�r�rrr0rr1r3rdrOr�r�)r(�errorsr�rMr�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]>}||rldgnggf}|D]}��t|�|�qxtj�	|�}q\��fdd�td�D�}�}t|d�D]D}|||kr�dgnggf}|D]}��t|�|�q�tj�|d�}q�dS)	N�Zdeepr�csg|]}�j�dd��qS)Fr��r��r�j��baser(rr	r
rz7WalkTests.test_walk_many_open_files.<locals>.<listcomp>r�rUcsg|]}�j�dd��qS)Tr�rrrrr	r
r)
rr1r3rrHr�r�r0rrr;)r(�depthr�Zitersr�r<rtrrr	�test_walk_many_open_filess"
z#WalkTests.test_walk_many_open_files)N)
rCrDrEr�r�rKr�r�r�r�r�rr	rrrr	r�bsE
r��fwalkzTest needs os.fwalk()c@sLeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dZdS)�
FwalkTestszTests for os.fwalk().cks0|j|fi|��D]\}}}}|||fVqdSr#)r
)r(r�r�rMr�r�Zroot_fdrrr	r�*szFwalkTests.walkcOstj|i|��Sr#)rr
�r(r�r�rrr	r
.szFwalkTests.fwalkc
Cs�|��}|��}tjddd�D]�\}}|j||d�|j||d�i}tjfi|��D]\}}}t|�t|�f||<qV|jfi|��D]4\}}}}	|�||�|�	||t|�t|�f�q�qdS)z.
        compare with walk() results.
        �TFrW��repeat)r�r�)r�r7N)
r��	itertools�productrlrr��setr
r�r0)
r(�walk_kwargs�fwalk_kwargsr�r7r<rMr�r��rootfdrrr	�_compare_to_walk1szFwalkTests._compare_to_walkcCsdtji}|�||�dS)Nr�)rrHr)r(r�rrr	�test_compare_to_walkCs
zFwalkTests.test_compare_to_walkc	CsTzBt�dtj�}dtji}|��}||d<|�||�Wt�|�nt�|�0dS)N�.r�r�)rrr�rrHr�rrN)r(rqrrrrr	�test_dir_fdGs
zFwalkTests.test_dir_fdcCs|tjddd�D]h\}}tj|df}|j|d|i�D]B\}}}}t�|�t�|�|�t	t�
|��t	|�t	|�B�q2qdS)Nr
rWrr7)rrrrHr
r�fstatr�r0rr�)r(r�r7r�rMr�r�rrrr	�test_yields_correct_dir_fdQs

z%FwalkTests.test_yields_correct_dir_fdcCs\t�d�}t�|�td�D]}|�tj�D]}q,qt�d�}|�tj|�|�||�dS)NrU�)	rrYrNr�r
rrHrwr0)r(Zminfdr�r�Znewfdrrr	�test_fd_leak]s


zFwalkTests.test_fd_leakN)rCrDrEr�r�r
rrrrrr	rrrr	r&s
rc@seZdZdZdd�ZdS)�BytesWalkTests�Tests for os.walk() with bytes.c	ks�d|vr|�d�|d<tjt�|�fi|��D]p\}}}t�|�}tttj|��}tttj|��}|||fVtttj|��|dd�<tttj|��|dd�<q.dSr�)r�rr��fsencoderAr��map)	r(r�r��broot�bdirs�bfilesrMr�r�rrr	r�ps"
zBytesWalkTests.walkN)rCrDrEr�r�rrrr	rnsrc@seZdZdZddd�ZdS)�BytesFwalkTestsrrcos�tjt�|�g|�Ri|��D]t\}}}}t�|�}tttj|��}	tttj|��}
||	|
|fVtttj|	��|dd�<tttj|
��|dd�<qdSr#)rr
r rAr�r!)r(r�r�r�r"r#r$�topfdrMr�r�rrr	r
~s*
zBytesFwalkTests.fwalkN)r)rCrDrEr�r
rrrr	r%{sr%c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�MakedirTestscCst�tj�dSr#�rr4rrHrJrrr	rK�szMakedirTests.setUpc
Cs�tj}tj�|ddd�}t�|�tj�|dddd�}t�|�|�ttjtj�tj�|dddddtj�}t�|�tj�|dtjddddd�}t�|�dS�Nr�rZdir3Zdir4Zdir5Zdir6)	rrHrr1r3r�r\r7�curdir)r(rr1rrr	�test_makedir�s


�zMakedirTests.test_makedircCs�t�d���tj}tj�|d�}tj�|d�}t�|d�|�tj�|��|�tj�	|��tj
dkr�|�t�|�j
d@d�|�t�|�j
d@d�Wd�n1s�0YdS)NrWr�rim�ntr�i�)rZ
temp_umaskrHrr1r3r�rOr��isdirrr0r�r�)r(r�parentr1rrr	�	test_mode�s
zMakedirTests.test_modecCs�tj�tjd�}d}t�d�}t�||�|�ttj||�|jttj||dd�tj|ddd�tj||dd�t�|�tjtj�	d	�dd�dS)
Nr�r��F��exist_oki�T)r�r2�/)
rr1r3rrH�umaskr�r\r7rI)r(r1r��old_maskrrr	� test_exist_ok_existing_directory�s

z-MakedirTests.test_exist_ok_existing_directoryc	Cstj�tjd�}tj}d}t�d�}z�t�t�	tj�j
�}zt�tj||B�Wntylt
�d��Yn0t�	tj�j
|@|kr�t
�d��t�|||B�tj||dd�t�|t�t�	|�j
�|@�tj|||Bdd�Wt�|�nt�|�0dS)Nr�r�r0zCannot set S_ISGID for dir.z No support for S_ISGID dir mode.Tr1)rr1r3rrHr��S_ISGIDr4�S_IMODE�lstatr�r�r�r�SkipTestr�)r(r1r7r�r5Zexisting_testfn_moderrr	�test_exist_ok_s_isgid_directory�s&
�
 z,MakedirTests.test_exist_ok_s_isgid_directorycCs�tj}tj�tjd�}t|d��}|�d�Wd�n1s@0Y|�ttj	|�|jttj	|dd�|jttj	|dd�t�
|�dS)Nr�rr�Fr1T)rrHrr1r3rrr\r7r�r�)r(rr1rSrrr	�#test_exist_ok_existing_regular_file�s(z0MakedirTests.test_exist_ok_existing_regular_filec	CsLtj�tjdddddd�}tj�|�s>|tjkr>tj�|�}qt�|�dSr))rr1r3rrHr�r;�
removedirs�r(r1rrr	r��s�zMakedirTests.tearDownN)
rCrDrErKr+r/r6r;r<r�rrrr	r'�s
r'�chownzTest needs chownc@s�eZdZedd��Zdd�Ze�ee	d�d�dd��Z
e�eoHee
�d	kd
�dd��Ze�eojee
�d	kd
�dd��Zedd��ZdS)�ChownFileTestscCst�tj�dSr#r(��clsrrr	�
setUpClass�szChownFileTests.setUpClasscCs�t�tj�}|j}|j}ddt�d�t�	dd�fD]0}|�
ttjtj||�|�
ttjtj||�q2|�
t�tj||��|�
t�tjdd��dS)Ng�y��r����rW)rr�rrH�st_uid�st_gid�decimalZDecimal�	fractionsZFractionr\rcr?�assertIsNone)r(r��uid�gidr�rrr	�*test_chown_uid_gid_arguments_must_be_index�sz9ChownFileTests.test_chown_uid_gid_arguments_must_be_index�	getgroupszneed os.getgroupscCs�t��}t|�dkr|�d�|dd�\}}t�tj�j}t�tj||�t�tj�j	}|�
||�t�tj||�t�tj�j	}|�
||�dS)NrWztest needs at least 2 groups)rrMr-rZr�rrHrEr?rFr0)r(�groupsZgid_1Zgid_2rJrKrrr	�test_chown_gid�s
zChownFileTests.test_chown_gidrUz0test needs root privilege and more than one usercCsvtdd�\}}t�tj�j}t�tj||�t�tj�j}|�||�t�tj||�t�tj�j}|�||�dS�NrW)	�	all_usersrr�rrHrFr?rEr0)r(�uid_1�uid_2rKrJrrr	�test_chown_with_rootsz#ChownFileTests.test_chown_with_rootz2test needs non-root account and more than one usercCsltdd�\}}t�tj�j}|�t��0t�tj||�t�tj||�Wd�n1s^0YdSrP)	rQrr�rrHrFr\r�r?)r(rRrSrKrrr	�test_chown_without_permissions
z,ChownFileTests.test_chown_without_permissioncCst�tj�dSr#)rrrrHrArrr	�
tearDownClassszChownFileTests.tearDownClassN)rCrDrE�classmethodrCrLrrrrrO�
root_in_posixr-rQrTrUrVrrrr	r@�s


�

�
r@c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�RemoveDirsTestscCst�tj�dSr#)rr�rrHrJrrr	rK#szRemoveDirsTests.setUpcCst�tj�dSr#)rrrHrJrrr	r�&szRemoveDirsTests.tearDowncCsxtj�tjd�}t�|�tj�|d�}t�|�t�|�|�tj�|��|�tj�|��|�tj�tj��dS)N�dira�dirb)	rr1r3rrHr4r=�assertFalser��r(rZr[rrr	�test_remove_all)s


zRemoveDirsTests.test_remove_allcCs�tj�tjd�}t�|�tj�|d�}t�|�ttj�|d��t�|�|�tj�	|��|�
tj�	|��|�
tj�	tj��dS�NrZr[�file.txt)rr1r3rrHr4r!r=r\r�rOr]rrr	�test_remove_partial3s


z#RemoveDirsTests.test_remove_partialcCs�tj�tjd�}t�|�tj�|d�}t�|�ttj�|d��|�t��t�	|�Wd�n1sn0Y|�
tj�|��|�
tj�|��|�
tj�tj��dSr_)rr1r3rrHr4r!r\r7r=rOr�r]rrr	�test_remove_nothing>s

(z#RemoveDirsTests.test_remove_nothingN)rCrDrErKr�r^rarbrrrr	rY"s

rYc@seZdZdd�ZdS)�DevNullTestscCs�ttjdd��"}|�d�|��Wd�n1s60Yttjd�� }|�|��d�Wd�n1sr0YdS)Nr9r�hellorvr)rr�devnullrrNr0rnrRrrr	�test_devnullLs

&zDevNullTests.test_devnullN)rCrDrErfrrrr	rcKsrcc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�URandomTestscCsr|�tt�d��d�|�tt�d��d�|�tt�d��d�|�tt�d��d�|�tt�d��d�dS)NrrUrVr�i�)r0r-r�urandomrJrrr	�test_urandom_lengthUs
z URandomTests.test_urandom_lengthcCs0t�d�}|�|t�t�d�}|�||�dS�N�)rrhr%r@r�r(Zdata1Zdata2rrr	�test_urandom_value\s

zURandomTests.test_urandom_valuecCs<d�dd|ddf�}td|�}|d}|�t|�|�|S)N�
zimport os, syszdata = os.urandom(%s)zsys.stdout.buffer.write(data)zsys.stdout.buffer.flush()r�rU)r3rr0r-)r(�countr��outr�rrr	�get_urandom_subprocessbs�
z#URandomTests.get_urandom_subprocesscCs$|�d�}|�d�}|�||�dSrj)rqrrlrrr	�test_urandom_subprocessms

z$URandomTests.test_urandom_subprocessN)rCrDrErirmrqrrrrrr	rgTsrg�	getrandomzneed os.getrandom()c@s@eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�GetRandomTestsc
CsRzt�d�Wn>tyL}z&|jtjkr6t�d��n�WYd}~n
d}~00dS)NrUz%getrandom() syscall fails with ENOSYS)rrsr7r8r�rr:)rBr=rrr	rCuszGetRandomTests.setUpClasscCs*t�d�}|�|t�|�t|�d�dSrj)rrsr%r@r0r-�r(rxrrr	�test_getrandom_type�s
z"GetRandomTests.test_getrandom_typecCst�d�}|�|d�dS)Nrr)rrsr0)r(�emptyrrr	�test_getrandom0�s
zGetRandomTests.test_getrandom0cCs|�ttd��dS)N�GRND_RANDOM)rOrrrJrrr	�test_getrandom_random�sz$GetRandomTests.test_getrandom_randomcCs*zt�dtj�Wnty$Yn0dS�NrU)rrs�
GRND_NONBLOCK�BlockingIOErrorrJrrr	�test_getrandom_nonblock�sz&GetRandomTests.test_getrandom_nonblockcCs$t�d�}t�d�}|�||�dSrj)rrsrrlrrr	�test_getrandom_value�s

z#GetRandomTests.test_getrandom_valueN)
rCrDrErWrCrvrxrzr~rrrrr	rtss
rtZHAVE_GETENTROPYrUZHAVE_GETRANDOMZHAVE_GETRANDOM_SYSCALLz*os.random() does not use a file descriptorZvxworksz$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_failure�sz#URandomFDTests.test_urandom_failurecCsd}td|�\}}}dS)Naif 1:
            import os
            import sys
            import test.support
            os.urandom(4)
            with test.support.SuppressCrashReport():
                os.closerange(3, 256)
            sys.stdout.buffer.write(os.urandom(4))
            �-Scr)r(r��rcrp�errrrr	�test_urandom_fd_closed�s	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))
            )rHr�r�rrj)
rwrrIrHr!r{rr0r-r)r(r�r�rpr�Zout2Zerr2rrr	�test_urandom_fd_reopened�s�z'URandomFDTests.test_urandom_fd_reopenedN)	rCrDrErr�resourcer�r�r�rrrr	r��s

r�c#s~g��fdd�}�fdd�}zHtj}tj}tj}|t_|t_|durJ|t_�VW|t_|t_|t_n|t_|t_|t_0dS)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��dS)N�execvzexecv called)r��RuntimeError�rr���callsrr	�
mock_execvsz#_execvpe_mockup.<locals>.mock_execvcs ��d||f�ttjd��dS)N�execvez
execve called)r�r7r8�ENOTDIRr�r�rr	�mock_execvesz$_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-)r\r7r�execvperJrrr	�test_execvpe_with_bad_programs�z'ExecTests.test_execvpe_with_bad_programcCsN|�ttjdd�|�ttjdg�|�ttjdd�|�ttjddg�dS)N�notepadrr�rH)r\r�rr�rJrrr	�test_execv_with_bad_arglist sz%ExecTests.test_execv_with_bad_arglistcCsB|�ttjdgd�|�ttjdgi�|�ttjddgi�dS)Nr�rH)r\r�rr�rJrrr	�test_execvpe_with_bad_arglist&sz'ExecTests.test_execvpe_with_bad_arglist�_execvpez)No internal os._execvpe function to test.c
Cs�tjd}|tur8d}tj�t�|�|�}|}gd�}n4d}gd�}tj�||�}tjdkrht�|�}n|}ddi}t��J}|�t	tj
||�|�t|�d	�|�|d
d||ff�Wd�n1s�0Yt|d��P}|jt
tj
|||d
�|�t|�d	�|�|d
d|||ff�Wd�n1�s60Yt��t}|��}	|tu�rd||	d<n||	d<|jt
tj
|||	d
�|�t|�d	�|�|d
d|||	ff�Wd�n1�s�0YdS)NZabsolutepaths
executable)sprogname�arg1�arg2r�)Zprognamer�r�r,ZspamrzrUrr�)r�r�r�r�r�)rr2r@r1r3r rr�r\r�r�r0r-r7r�r�)
r(Z	test_typeZprogram_pathZprogram�fullpathZnative_fullpathZ	argumentsr~r�Zenv_pathrrr	�_test_internal_execvpe+sN


�6
�
�$


�
�z ExecTests._test_internal_execvpecCs"|�t�tjdkr|�t�dS)Nr,)r�r&rrr@rJrrr	�test_internal_execvpe_str\s

z#ExecTests.test_internal_execvpe_strcCs�tjddg}tj��}d|d<|�t��"t�|d||�Wd�n1sP0Ytj��}d|d<|�t��"t�|d||�Wd�n1s�0Ytj��}d|d	<|�t��"t�|d||�Wd�n1s�0YdS)
Nr��pass�cabbage�FRUITVEGETABLEr�orangeVEGETABLE=cabbage�FRUIT�lemon�FRUIT=ORANGE)rar�rrr�r\r�r�)r(r��newenvrrr	�test_execve_invalid_envas
0
0
z!ExecTests.test_execve_invalid_envr�zWin32-specific testc
Csbzt�ddgi�Wn>tyR}z&|�|jdup:|jdk�WYd}~nd}~00|�d�dS)NrH�argrzNo OSError raised)rr�r7rO�winerrorr�rrrr	�test_execve_with_empty_pathvs
0z%ExecTests.test_execve_with_empty_pathN)rCrDrEr�skipIf�USING_LINUXTHREADSr�r�r�rrrr�r�r�rar�r�rrrr	r�s�
�
/r�r�r�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�Win32ErrorTestsc
Csvzt�tj�WnPty&d}YnLty`}z$d}|�dtj|f�WYd}~nd}~00|�dtj�dS)NFTz.file %s must not exist; os.stat failed with %szfile %s must not exist)rr�rrHr6r7r�)r(r�r=rrr	rK�s�zWin32ErrorTests.setUpcCs|�ttjtjtjd�dS)Nz.bak)r\r7rrdrrHrJrrr	rg�szWin32ErrorTests.test_renamecCs|�ttjtj�dSr#)r\r7rr�rrHrJrrr	�test_remove�szWin32ErrorTests.test_removecCs|�ttjtj�dSr#)r\r7rr5rrHrJrrr	�
test_chdir�szWin32ErrorTests.test_chdircCsR|�tjtj�ttjd��"}|�ttjtj�Wd�n1sD0YdS)Nr�)	rwrrIrHrr\r7rr4rRrrr	�
test_mkdir�szWin32ErrorTests.test_mkdircCs|�ttjtjd�dSr#)r\r7rr+rrHrJrrr	r/�szWin32ErrorTests.test_utimecCs|�ttjtjd�dSr`)r\r7rr�rrHrJrrr	�
test_chmod�szWin32ErrorTests.test_chmodN)
rCrDrErKrgr�r�r�r/r�rrrr	r��sr�c@s�eZdZgd�Zdd�ZeD]Zee�e�de<qdd�Ze�	e
ed�d�d	d
��Ze�	e
ed�d�d
d��Z
e�	e
ed�d�dd��Ze�	e
ed�d�dd��Ze�	e
ed�d�dd��Ze�	e
ed�d�dd��Ze�	e
ed�d �d!d"��Ze�	e
ed#�d$�d%d&��Ze�	e
ed'�d(�d)d*��Ze�	e
ed+�d,�d-d.��Ze�	e
ed/�d0�d1d2��Ze�	e
ed3�d4�d5d6��Ze�	e
ed7�d8�d9d:��Zd;d<�Ze�	e
ed=�d>�d?d@��ZdAS)B�
TestInvalidFD)	�fchdirrYr��	fdatasyncr�fstatvfs�fsync�	tcgetpgrp�ttynamecs�fdd�}|S)Ncstt��r|�tt���dSr#)rrr�r�rJ�rSrr	�helper�s
z(TestInvalidFD.get_single.<locals>.helperr)rSr�rr�r	�
get_single�szTestInvalidFD.get_singleZtest_c
Gs`z|t��g|�R�Wn4tyL}z|�|jtj�WYd}~nd}~00|�d|�dS)Nz5%r didn't raise an OSError with a bad file descriptor)r�make_bad_fdr7r0r8rr�)r(rSr�r�rrr	r��s&�zTestInvalidFD.check�isattyztest needs os.isatty()cCs|�t�t���d�dS�NF)r0rr�rr�rJrrr	�test_isatty�szTestInvalidFD.test_isattyr[ztest needs os.closerange()c	Csrt��}td�D].}zt�||�Wnty8Yq0q@q|dkrRt�d��|�t�	|||d�d�dS)NrVrWz5Unable to acquire a range of invalid file descriptorsrU)
rr�r�rrr7rr:r0r[)r(rqr�rrr	r_�s�zTestInvalidFD.test_closerange�dup2ztest needs os.dup2()cCs|�tjd�dS)N�)r�rr�rJrrr	�	test_dup2�szTestInvalidFD.test_dup2�fchmodztest needs os.fchmod()cCs|�tjd�dSr`)r�rr�rJrrr	�test_fchmod�szTestInvalidFD.test_fchmod�fchownztest needs os.fchown()cCs|�tjdd�dS)Nr�)r�rr�rJrrr	�test_fchown�szTestInvalidFD.test_fchown�	fpathconfztest needs os.fpathconf()cCs |�tjd�|�tjd�dS)N�PC_NAME_MAX)r�r�pathconfr�rJrrr	�test_fpathconf�szTestInvalidFD.test_fpathconf�	ftruncateztest needs os.ftruncate()cCs |�tjd�|�tjd�dSr`)r�r�truncater�rJrrr	�test_ftruncate�szTestInvalidFD.test_ftruncatermztest needs os.lseek()cCs|�tjdd�dSr`)r�rrmrJrrr	�
test_lseek�szTestInvalidFD.test_lseekrnztest needs os.read()cCs|�tjd�dSr{)r�rrnrJrrr	rs�szTestInvalidFD.test_read�readvztest needs os.readv()cCstd�}|�tj|g�dS)NrV)r|r�rr�)r(rNrrr	�
test_readv�szTestInvalidFD.test_readv�	tcsetpgrpztest needs os.tcsetpgrp()cCs|�tjd�dSr`)r�rr�rJrrr	�test_tcsetpgrpt�szTestInvalidFD.test_tcsetpgrptrztest needs os.write()cCs|�tjd�dS)N� )r�rrrJrrr	r�szTestInvalidFD.test_write�writevztest needs os.writev()cCs|�tjdg�dS)Nr�)r�rr�rJrrr	�test_writev�szTestInvalidFD.test_writevcCs|�tj�|�tjd�dS�NT)r�r�get_inheritable�set_inheritablerJrrr	�test_inheritable�szTestInvalidFD.test_inheritable�get_blocking�-needs os.get_blocking() and os.set_blocking()cCs|�tj�|�tjd�dSr�)r�rr��set_blockingrJrrr	�
test_blockingszTestInvalidFD.test_blockingN)rCrDrEZsinglesr�rS�localsr�rrrrr�r_r�r�r�r�r�r�rsr�r�rr�r�r�rrrr	r��sH	












�r�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�	LinkTestscCs tj|_tj�tjd�|_dS)Nr�)rrH�file1rr1r3�file2rJrrr	rK
szLinkTests.setUpcCs,|j|jfD]}tj�|�rt�|�qdSr#)r�r�rr1r�rI)r(�filerrr	r�szLinkTests.tearDownc
Cs�t|�zt�||�Wn2tyJ}z|�d|�WYd}~n
d}~00t|d��V}t|d��,}|�tj�|�	�|�	���Wd�n1s�0YWd�n1s�0YdS)N�
os.link(): %sr�)
r!rr�r�rZrrOr1�sameopenfilerl)r(r�r�r�r�f2rrr	�
_test_links$zLinkTests._test_linkcCs|�|j|j�dSr#)r�r�r�rJrrr	�	test_linkszLinkTests.test_linkcCs(|�t|jt���t|jt����dSr#)r�r@r�rar�r�rJrrr	�test_link_bytes s�zLinkTests.test_link_bytescCsZzt�d�Wnty*t�d��Yn0|jd7_|jd|_|�|j|j�dS)N�ñz#Unable to encode for this platform.r�)rr �UnicodeErrorrr:r�r�r�rJrrr	�test_unicode_name$szLinkTests.test_unicode_nameN)	rCrDrErKr�r�r�r�r�rrrr	r�	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�getuidr\r7r�rc�
OverflowError�UID_OVERFLOWrJrrr	�test_setuid4szPosixUidGidTests.test_setuid�setgidztest needs os.setgid()cCsFt��dkr ts |�ttjd�|�ttjd�|�ttj|j�dSr�)	rr��HAVE_WHEEL_GROUPr\r7r�rcr��GID_OVERFLOWrJrrr	�test_setgid;szPosixUidGidTests.test_setgid�seteuidztest needs os.seteuid()cCsBt��dkr|�ttjd�|�ttjd�|�ttj|j�dSr�)	rr�r\r7r�rc�setegidr�r�rJrrr	�test_seteuidBszPosixUidGidTests.test_seteuidr�ztest needs os.setegid()cCsFt��dkr ts |�ttjd�|�ttjd�|�ttj|j�dSr�)	rr�r�r\r7r�rcr�r�rJrrr	�test_setegidIszPosixUidGidTests.test_setegid�setreuidztest needs os.setreuid()cCsnt��dkr|�ttjdd�|�ttjdd�|�ttjdd�|�ttj|jd�|�ttjd|j�dSr�)rr�r\r7r�rcr�r�rJrrr	�
test_setreuidPszPosixUidGidTests.test_setreuidcCst�tjddg�dS)Nr�z,import os,sys;os.setreuid(-1,-1);sys.exit(0)�r�rrar�rJrrr	�test_setreuid_neg1Ys�z#PosixUidGidTests.test_setreuid_neg1�setregidztest needs os.setregid()cCsrt��dkr"ts"|�ttjdd�|�ttjdd�|�ttjdd�|�ttj|jd�|�ttjd|j�dSr�)	rr�r�r\r7r�rcr�r�rJrrr	�
test_setregidaszPosixUidGidTests.test_setregidcCst�tjddg�dS)Nr�z,import os,sys;os.setregid(-1,-1);sys.exit(0)r�rJrrr	�test_setregid_neg1js�z#PosixUidGidTests.test_setregid_neg1N)rCrDrEr�r�rrrrr�r�r�r�r�r�rrrrrr	r�.s$






r�c@sNeZdZdd�Zdd�Zdd�Zdd�Ze�e	e
d	�d
�dd��Zd
d�ZdS)�Pep383Testscs�tjrtj|_ntjr tj|_ntj|_t�|j�|_g��fdd�}|tj�tjr`|tj�tjrp|tj��s~|�	d�t
�|_t�|j�zL�D]B}t�
tj�|j|��t�|�}||jvr�td��|j�|�q�Wnt�|j��Yn0dS)Ncs2zt�|�}Wnty"YdS0��|�dSr#)rr r�r�)�fn��bytesfnrr	�add_filename~s
z'Pep383Tests.setUp.<locals>.add_filenamez&couldn't create any non-ascii filenamezduplicate filename)r�TESTFN_UNENCODABLEr�ZTESTFN_NONASCIIrHrr ZbdirZTESTFN_UNICODErZr�	unicodefnr4Zcreate_empty_filer1r3rAr��add�shutilr)r(rrrrr	rKts6







zPep383Tests.setUpcCst�|j�dSr#)r
rr�rJrrr	r��szPep383Tests.tearDownc	Csv|j}tt�|j��}|�||�t��}z:t�tj�|�tt���tt�tj���Wt�|�nt�|�0dSr#)	rrrr�r�r0r$r5r2)r(r<�foundZcurrent_directoryrrr	�test_listdir�s"zPep383Tests.test_listdircCs.|jD]"}ttj�|j|�d�}|��qdS�Nrv)rrrr1r3r�rN)r(rrSrrr	�	test_open�s
zPep383Tests.test_openr�r�cCs*|jD]}tj�|j|�}t�|�qdSr#)rrr1r3r�r�)r(r�fullnamerrr	�test_statvfs�s
zPep383Tests.test_statvfscCs&|jD]}t�tj�|j|��qdSr#)rrr�r1r3r�)r(rrrr	�	test_stat�s
zPep383Tests.test_statN)
rCrDrErKr�rrrrrrrrrrrr	rrs%�
rc@sFeZdZdd�Zdd�Zdd�Zdd�Ze�d	�d
d��Z	dd
�Z
dS)�Win32KillTestscCsvddl}ddlm}ddl}|jjj}|j|_|j|�	|j
�|j|�	|j�|�	|j�|�	|j�f|_d}t
jtjdd�|�gt
jt
jt
jd�}|�|jj�|�|jj�|�|jj�d\}}	||	k�rJ|��du�rJ|�t|��}
||�|j���|
|�|
�ddd�}|�|dd�|
j�r6|� ||
j�!���qTt"�#d	�|d
7}q�|�$d�t%�&|j'|�|� |�(�|�dS)Nr��wintypes�runningr�z<import sys;sys.stdout.write('{}');sys.stdout.flush();input())r��stderr�stdin�rr�zPeekNamedPipe failed皙�����?rUz1Did not receive communication from the subprocess))rJr�msvcrtrKrL�
PeekNamedPipe�BOOL�restype�HANDLE�POINTERZc_char�DWORD�argtypesr��Popenrar�r{r�rwr�rNrr�pollZcreate_string_bufferr-Z
get_osfhandlerlZsizeofrr�r0r�r@�sleepr�r�kill�pid�wait)r(�sigrJrrrr?r�ro�maxrNZrsltrrr	�_kill�sP




�
����


zWin32KillTests._killcCs|�tj�dSr#)r*�signal�SIGTERMrJrrr	�test_kill_sigterm�sz Win32KillTests.test_kill_sigtermcCs|�d�dS)Nr�)r*rJrrr	�
test_kill_int�szWin32KillTests.test_kill_intcCs�dt��}t�dd|�}d|d<tjtjtj�	tj�
t�d�|gtjd�}d\}}||kr�|�
�dur�|ddkrvq�t�d�|d7}qTt�|jtj�|�d	�t�|j|�t�d
�|�
�s�t�|jtj�|�d�|��dS)Nz
test_os_%sr�rUrzwin_console_handler.pyrrrz'Subprocess didn't finish initializationg�?zsubprocess did not stop on {})�uuidZuuid1�mmapr�r"rar�rr1r3r;r�ZCREATE_NEW_PROCESS_GROUPr#r@r$r%r&r+�SIGINTr�r{)r(�eventrZtagname�mr�ror)rrr	�_kill_with_event�s0���



zWin32KillTests._kill_with_eventz.subprocesses aren't inheriting Ctrl+C propertycCsdddlm}ddl}|�|j��}|jjj}|�|j�|jf|_|j|_	||d�|�
tjd�dS)Nrr�CTRL_C_EVENT)
rJrrZc_intrKrL�SetConsoleCtrlHandlerrr!rr4r+r5)r(rrJZNULLr6rrr	�test_CTRL_C_EVENT	s

�
z Win32KillTests.test_CTRL_C_EVENTcCs|�tjd�dS)N�CTRL_BREAK_EVENT)r4r+r8rJrrr	�test_CTRL_BREAK_EVENT*	sz$Win32KillTests.test_CTRL_BREAK_EVENTN)rCrDrEr*r-r.r4r�skipr7r9rrrr	r�s6
rc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Win32ListdirTestszTest listdir on Windows.c	Cs�g|_td�D]�}d|}tj�tj|�}d|}tj�tj|�}t�|�t|ddd��}|�	d|�Wd�n1s~0Y|j�
||g�q|j��dS)NrWzSUB%dzFILE%drr�r�z'I'm %s and proud of it. Blame test_os.
)�
created_pathsr�rr1r3rrHr�rr�extendr�)r(r�Zdir_nameZdir_path�	file_nameZ	file_pathrSrrr	rK2	s
,zWin32ListdirTests.setUpcCst�tj�dSr#)r
rrrHrJrrr	r�?	szWin32ListdirTests.tearDowncCsH|�tt�tj��|j�|�tt�t�tj���dd�|jD��dS)z-Test when the path is not an "extended" path.cSsg|]}t�|��qSr�rr �rr1rrr	r
L	rzCWin32ListdirTests.test_listdir_no_extended_path.<locals>.<listcomp>N)r0�sortedrr�rrHr<r rJrrr	�test_listdir_no_extended_pathB	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 '\\?\'.�\\?\�\\?\cSsg|]}t�|��qSrr?r@rrr	r
[	rz@Win32ListdirTests.test_listdir_extended_path.<locals>.<listcomp>N)
rr1rIrrHr0rAr�r<r r>rrr	�test_listdir_extended_pathN	s��z,Win32ListdirTests.test_listdir_extended_pathN)rCrDrEr�rKr�rBrErrrr	r;.	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�|�}tjdkrRdd�}||�r>|dd�}||�rR|dd�}|�||�dS)Nr�cSs|�t|t�rdnd�S)NrDrC)�
startswithr�r@)r�rrr	�<lambda>k	s�z/ReadlinkTests.assertPathEqual.<locals>.<lambda>rj)rr1�normcaserar�r0)r(�left�rightZ
has_prefixrrr	�assertPathEquale	s
zReadlinkTests.assertPathEqualcCsT|�tj�|j��|�tj�|j��|�tj�|j��|�tj�|j��dSr#)	rOrr1r��filelink_target�filelinkb_targetr\�filelink�	filelinkbrJrrr	rKs	szReadlinkTests.setUpcCs0t|j�}|�ttj|j�|�ttj|�dSr#)rrNr\r7rrF)r(rNrrr	�test_not_symlinky	s
zReadlinkTests.test_not_symlinkcCs(|�ttjd�|�ttjtd��dS)Nzmissing-link)r\r6rrFrrJrrr	�test_missing_link~	s
�zReadlinkTests.test_missing_linkcCsBt�|j|j�|�tj|j�t|j�}|�t�	|�|j�dSr#)
rr�rNrPrwrrIrrMrF)r(rPrrr	�
test_pathlike�	s
zReadlinkTests.test_pathlikecCsNt�|j|j�|�tj|j�t�t|j��}|�	||j�|�
|t�dSr#)rr�rOrQrwrrIrFrrMr%r@r>rrr	�test_pathlike_bytes�	s
z!ReadlinkTests.test_pathlike_bytescCsJt�|j|j�|�tj|j�t�|j�}|�||j�|�	|t
�dSr#)rr�rOrQrwrrIrFrMr%r@r>rrr	�
test_bytes�	s
zReadlinkTests.test_bytesN)rCrDrErPrr1rIr�rNr rQrOrMrKrRrSr�skip_unless_symlinkrTrUrVrrrr	rG^	s



rGc@s�eZdZdZej�e�ZdZ	ej�
e�ZdZdd�Z
dd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Ze�ej�d�o�ej�d�d�dd��Zdd�Zdd �Zd!S)"�Win32SymlinkTestsZfilelinktestZdirlinktestzmissing linkcCsdSr#rrJrrr	rK�	szWin32SymlinkTests.setUpcCsRtj�|j�rt�|j�tj�|j�r4t�|j�tj�|j�rNt�|j�dSr#)	rr1r�rPr��dirlinkrrG�missing_linkrJrrr	r��	szWin32SymlinkTests.tearDowncCs`t�|j|j�|�tj�|j��|�tj�|j��|�tj�|j��|�	|j|j�dSr#)
rr��dirlink_targetrYrOr1r�r-�islink�
check_statrJrrr	�test_directory_link�	s
z%Win32SymlinkTests.test_directory_linkcCs`t�|j|j�|�tj�|j��|�tj�|j��|�tj�|j��|�	|j|j�dSr#)
rr�rNrPrOr1r��isfiler\r]rJrrr	�test_file_link�	s
z Win32SymlinkTests.test_file_linkcCs6|j}tj�|�rt�|�d}d}t�|||�dS)z2Create a "directory" link to a non-existent targetz"c:\\target does not exist.29r3c740TN)rZrr1rGr�r�)r(Zlinknamer�Z
target_is_dirrrr	�_create_missing_dir_link�	s
z*Win32SymlinkTests._create_missing_dir_linkcCs|��t�|j�dSr#)rarr�rZrJrrr	�,test_remove_directory_link_to_missing_target�	sz>Win32SymlinkTests.test_remove_directory_link_to_missing_targetcCs |��|�tj�|j��dSr#)rar\rr1r-rZrJrrr	�.test_isdir_on_directory_link_to_missing_target�	sz@Win32SymlinkTests.test_isdir_on_directory_link_to_missing_targetcCs|��t�|j�dSr#)rarrrZrJrrr	�.test_rmdir_on_directory_link_to_missing_target�	sz@Win32SymlinkTests.test_rmdir_on_directory_link_to_missing_targetcCsn|�t�|�t�|��|�t�|�t�|��t�|�}|�t�|�t�|��|�t�|�t�|��dSr#)r0rr�rr9r )r(r�r�Z
bytes_linkrrr	r]�	s

zWin32SymlinkTests.check_statc	CsJtj�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�|�nt�|�0dS)N�level2�level3r�r�)rr1rIrrHr3rwrr4r!r$r5r��relpathr�r�r0r�)r(Zlevel1rerfr�Zorig_dirr�rrr	�
test_12084�	s2




�
�zWin32SymlinkTests.test_12084�C:\Users\All Users�C:\ProgramDatazTest directories not foundcCs"t�d�}|�tj�|d��dS)Nrirj)rrFrOr1�samefile)r(r�rrr	�
test_29248
s
zWin32SymlinkTests.test_29248c	Cs�d}tjj|gd�}d||f||f|dd�|dd�fg}|D]�\}}zt�||�WntynYn$0zt�|�Wnty�Yn0zt�t�|�t�|��Wnty�YqD0zt�|�WqDty�YqD0qDdS)NZXXXXXXXXXXXXXXXXXXXXXXXXXXXrVrG�)rr1r3r�r6r�r7r )r(Zsegmentr1Z
test_casesr��destrrr	�test_buffer_overflow
s.
�z&Win32SymlinkTests.test_buffer_overflowcs�tj�d��tj���s"|�d��fdd�t�t���d�D�}|D]\}tj	r`t
�t
d|�t�|�}|�|t�
|��|�t
�|j��|�|jt
j�q�qF|�d�dS)Nz$%LOCALAPPDATA%\Microsoft\WindowsAppsz%test requires a WindowsApps directorycsg|]}tj��|��qSr)rr1r3�rr,�rMrr	r
<
s�z6Win32SymlinkTests.test_appexeclink.<locals>.<listcomp>z*.exezTesting withz$test requires an app execution alias)rr1�
expandvarsr-rZ�fnmatch�filterr�rr9r:r9r0r�r\�S_ISLNKr��st_reparse_tagZIO_REPARSE_TAG_APPEXECLINK)r(�aliases�aliasrrrqr	�test_appexeclink7
s 

�

z"Win32SymlinkTests.test_appexeclinkN)rCrDrErPrr1rIr�rNrYr;r[rZrKr�r^r`rarbrcrdr]rhrrrGr�rlroryrrrr	rX�	s,
#
�
#rXc@sDeZdZdZej�ej�e��Z	dd�Z
dd�Zdd�Zdd	�Z
d
S)�Win32JunctionTestsZjunctiontestcCsdSr#rrJrrr	rKQ
szWin32JunctionTests.setUpcCstj�|j�rt�|j�dSr#)rr1rG�junctionrIrJrrr	r�U
szWin32JunctionTests.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)NrC)�_winapi�CreateJunction�junction_targetr{rOrr1rGr�r-rr�r9r0r\r\rJrFrJrrr	�test_create_junctionY
s�z'Win32JunctionTests.test_create_junctioncCs\t�|j|j�|�tj�|j��|�tj�|j��t�	|j�|�
tj�|j��dSr#)r|r}r~r{rOrr1r�rGrIr\rJrrr	�test_unlink_removes_junctionf
s
z/Win32JunctionTests.test_unlink_removes_junctionN)rCrDrEr{rr1r;rIr�r~rKr�rr�rrrr	rzL
s
rzc@seZdZdd�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]R}	|D]H}
z|�|
�Wnty�Yn0zt�|
�Wq�ty�Yq�0q�q�|�	||�
|��}|�d|�|j|}|�d|�dS)Nr,rJrzKernel32.dllT)Zuse_last_errorrUz\\?\C:z\\?\NULz	\\?\CONINrV)r�
import_moduleZctypes.wintypesZWinDLLrrZGetCurrentProcessrrZGetProcessHandleCountZLPDWORDr!r Zbyrefr0r�r�r��_getfinalpathname�	Exceptionrr�)r(r,rJZkernelZhprocZhandle_countrOZbefore_count�	filenames�_rZhandle_deltarrr	�test_getfinalpathname_handlesp
sB

�
�

z*Win32NtTests.test_getfinalpathname_handlesN)rCrDrEr�rrrr	r�n
sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�NonLocalSymlinkTestscCst�d�dS)zM
        Create this structure:

        base
         \___ some_dir
        z
base/some_dirN)rr�rJrrr	rK�
szNonLocalSymlinkTests.setUpcCst�d�dS)Nr)r
rrJrrr	r��
szNonLocalSymlinkTests.tearDowncCstj�dd�}t�d|�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.
        rZ	some_linkZsome_dirN)rr1r3r�)r(r�rrr	�test_directory_link_nonlocal�
sz1NonLocalSymlinkTests.test_directory_link_nonlocalN)rCrDrErKr�r�rrrr	r��
s	r�c@seZdZdd�Zdd�ZdS)�FSEncodingTestscCs(|�t�d�d�|�t�d�d�dS)Nsabc�uabcŁ)r0rr rArJrrr	�test_nop�
szFSEncodingTests.test_nopc	CsFdD]<}zt�|�}Wnty,YqYn0|�t�|�|�qdS)N)u	unicodeŁulatiné�ascii)rr r�r0rA)r(rrrrr	�
test_identity�
s
zFSEncodingTests.test_identityN)rCrDrEr�r�rrrr	r��
sr�c@sVeZdZdd�Ze�e�d�oDe�oDe	j
�d�pDee
d�oDee
d�d�dd	��Zd
S)�DeviceEncodingTestscCs|�t�d��dS)Ni@�)rIr�device_encodingrJrrr	�test_bad_fd�
szDeviceEncodingTests.test_bad_fdr�win�nl_langinfo�CODESETz>test requires a tty and either Windows or nl_langinfo(CODESET)cCs(t�d�}|�|�|�t�|��dSr`)rr�ZassertIsNotNonerO�codecs�lookup)r(r�rrr	�test_device_encoding�
s

z(DeviceEncodingTests.test_device_encodingN)rCrDrEr�rrrr�rrar�rHr�localer�rrrr	r��
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�r"rar�r��communicater0r�r�getpid)r(r�r�r�rrr	�test_getppid�
s
��zPidTests.test_getppidNcCs�tjdkr(dtj�d�dd|�d�g}ntjd|g}t�tjtj|�}|durV||�t�|d�\}}|�t�|�|�|�||�dS)Nr��"r�r)	rar�r�r�spawnv�P_NOWAIT�waitpidr0�waitstatus_to_exitcode)r(r��exitcode�callbackr�r&Zpid2�statusrrr	�
check_waitpid�
s
zPidTests.check_waitpidcCs|jddd�dS)Nr�r)r�r��r�rJrrr	�test_waitpid�
szPidTests.test_waitpidcCsVd}d|�d�}|j||d�|�t��t�d�Wd�n1sH0YdS)N�zimport sys; sys.exit(�)�r�g)r�r\rcrr�)r(r�r�rrr	�test_waitstatus_to_exitcode�
s
z$PidTests.test_waitstatus_to_exitcoder��win32-specific testcCs"d}d|�d�}|j||d�dS)Nl:z$import _winapi; _winapi.ExitProcess(r�r�r�)r(ZSTATUS_CONTROL_C_EXITr�rrr	�test_waitpid_windowsszPidTests.test_waitpid_windowscCs�d}ddd|fD]}|�t�|d>�|�q|�t��"t�|dd>�Wd�n1s^0Y|�t��t�d�Wd�n1s�0YdS)Nr	rrUr�r�r�)r0rr�r\r�r�)r(Zmax_exitcoder�rrr	�#test_waitstatus_to_exitcode_windowss�0z,PidTests.test_waitstatus_to_exitcode_windows�SIGKILLzneed signal.SIGKILLcs6dtj�d�}tj��fdd�}|j|�|d�dS)Nzimport time; time.sleep(r�cst�|��dSr#)rr%)r&��signumrr	�kill_process!sz?PidTests.test_waitstatus_to_exitcode_kill.<locals>.kill_process)r�r�)rZLONG_TIMEOUTr+r�r�)r(r�r�rr�r	� test_waitstatus_to_exitcode_killsz)PidTests.test_waitstatus_to_exitcode_kill)N)rCrDrErrrrr�r�r�r�rar�r�r�r+r�rrrr	r��
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|�|s*d|j}n8ttj�|_t	t
���|_|j|j|j<d|j|jf}t
|d��}|�|�Wd�n1s�0Ytj|g}|r�dd�|D�}dd�|j��D�|_|S)	N�zimport sys; sys.exit(%s)z4import sys, os; magic = os.environ[%r]; sys.exit(%s)rcSsg|]}t�|��qSrr?rprrr	r
>rz*SpawnTests.create_args.<locals>.<listcomp>cSs"i|]\}}t�|�t�|��qSrr?)r�k�vrrr	�
<dictcomp>?s�z*SpawnTests.create_args.<locals>.<dictcomp>)r�rrHrwrIrbrrr~r&r/Zuuid4rjrrrar�rh)r(r�r�rr�r r�rrr	�create_args(s(
�(
�zSpawnTests.create_args�spawnlcCs4|��}tjtj|dg|�R�}|�||j�dSr`)r�rr��P_WAITr0r��r(r�r�rrr	�test_spawnlDszSpawnTests.test_spawnl�spawnlecCs>|jdd�}tjtj|dg|�|j�R�}|�||j�dS�NT)r�r)r�rr�r�r~r0r�r�rrr	�test_spawnleJs zSpawnTests.test_spawnle�spawnlpcCs4|��}tjtj|dg|�R�}|�||j�dSr`)r�rr�r�r0r�r�rrr	�test_spawnlpPszSpawnTests.test_spawnlp�spawnlpecCs>|jdd�}tjtj|dg|�|j�R�}|�||j�dSr�)r�rr�r�r~r0r�r�rrr	�
test_spawnlpeVs zSpawnTests.test_spawnlper�cCsT|��}t�tj|d|�}|�||j�t�tjt|d�|�}|�||j�dSr`)r�rr�r�r0r�rr�rrr	�test_spawnv\s
zSpawnTests.test_spawnv�spawnvecCs6|jdd�}t�tj|d||j�}|�||j�dSr��r�rr�r�r~r0r�r�rrr	�test_spawnvefszSpawnTests.test_spawnve�spawnvpcCs.|��}t�tj|d|�}|�||j�dSr`)r�rr�r�r0r�r�rrr	�test_spawnvplszSpawnTests.test_spawnvp�spawnvpecCs6|jdd�}t�tj|d||j�}|�||j�dSr�)r�rr�r�r~r0r�r�rrr	�
test_spawnvperszSpawnTests.test_spawnvpecCs0|��}t�tj|d|�}tj||jd�dS)Nrr�)r�rr�r�rZwait_processr�)r(r�r&rrr	�test_nowaitxszSpawnTests.test_nowaitcCs8|jddd�}t�tj|d||j�}|�||j�dS)NTr�rr�r�rrr	�test_spawnve_bytes~szSpawnTests.test_spawnve_bytescCs>|��}|�ttjtj|d�|�ttjtj|dd�dS�NrrH)r�r\r�rr�r��r(r�rrr	�test_spawnl_noargs�szSpawnTests.test_spawnl_noargscCsB|��}|�ttjtj|di�|�ttjtj|ddi�dSr�)r�r\r�rr�r�r�rrr	�test_spawnle_noargs�szSpawnTests.test_spawnle_noargscCsv|��}|�ttjtj|dd�|�ttjtj|dg�|�ttjtj|dd�|�ttjtj|ddg�dS�Nrrr�rH)r�r\r�rr�r�r�rrr	�test_spawnv_noargs�s
zSpawnTests.test_spawnv_noargscCs~|��}|�ttjtj|ddi�|�ttjtj|dgi�|�ttjtj|ddi�|�ttjtj|ddgi�dSr�)r�r\r�rr�r�r�rrr	�test_spawnve_noargs�s
zSpawnTests.test_spawnve_noargscCsttjddg}tj��}d|d<z|tj|d||�}WntyHYn0|�|d�tj��}d|d<z|tj|d||�}Wnty�Yn0|�|d�tj��}d	|d
<z|tj|d||�}Wnty�Yn0|�|d�tj	}|�
tj|�t|d��}|�
d�Wd�n1�s*0Ytj|g}tj��}d
|d<|tj|d||�}|�|d�dS)Nr�r�r�r�r�r�r�r�r�rzPimport sys, os
if os.getenv("FRUIT") != "orange=lemon":
    raise AssertionErrorzorange=lemon)rar�rrr�r�r�r0rrHrwrIrr)r(�spawnr�r�r�rr rrr	�_test_invalid_env�s>


*

zSpawnTests._test_invalid_envcCs|�tj�dSr#)r�rr�rJrrr	�test_spawnve_invalid_env�sz#SpawnTests.test_spawnve_invalid_envcCs|�tj�dSr#)r�rr�rJrrr	�test_spawnvpe_invalid_env�sz$SpawnTests.test_spawnvpe_invalid_envN)rCrDrEr�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrr	r�'sD




	








.
r�z>Skip due to platform/environment differences on *NIX buildbots�getloginztest needs os.getloginc@seZdZdd�ZdS)�
LoginTestscCst��}|�t|�d�dSr`)rr�rr-)r(Z	user_namerrr	�
test_getlogin�szLoginTests.test_getloginN)rCrDrEr�rrrr	r��sr��getpriority�setpriorityz'needs os.getpriority and os.setpriorityc@seZdZdZdd�ZdS)�ProgramPriorityTestsz0Tests for os.getpriority() and os.setpriority().cCst�tjt���}t�tjt��|d�z�t�tjt���}|dkr^|dkr^t�d|��n|�||d�Wzt�tjt��|�Wn2ty�}z|j	t	j
kr��WYd}~n
d}~00nPzt�tjt��|�Wn4t�y
}z|j	t	j
kr��WYd}~n
d}~000dS)NrU�z?unable to reliably test setpriority at current nice level of %s)rr��PRIO_PROCESSr�r�rr:r0r7r8ZEACCES)r(rZnew_prior�rrr	�test_set_get_priority�s&��z*ProgramPriorityTests.test_set_get_priorityN)rCrDrEr�r�rrrr	r��sr�c@sveZdZGdd�dej�Zdd�Zedd��Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�ZeZdd�Zdd�ZdS)�SendfileTestServerc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)zSendfileTestServer.HandlercCs.tj�||�g|_d|_d|_|�d�dS)NTFs220 ready
)�asynchat�
async_chat�__init__�	in_buffer�
accumulate�closed�push)r(�connrrr	r��s
z#SendfileTestServer.Handler.__init__cCs |�d�}|jr|j�|�dS)N�)�recvr�r�r�rurrr	�handle_reads
z&SendfileTestServer.Handler.handle_readcCsd�|j�S)Nr)r3r�rJrrr	�get_data
sz#SendfileTestServer.Handler.get_datacCs|��d|_dSr�)rNr�rJrrr	�handle_close
sz'SendfileTestServer.Handler.handle_closecCs�dSr#rrJrrr	�handle_errorsz'SendfileTestServer.Handler.handle_errorN)rCrDrEr�r�r�r�r�rrrr	�Handler�s
r�cCsptj�|�tj�|�|�tjtj�|�	|�|�
d�|j��dd�\|_|_
d|_d|_t��|_dS)Nr�rWF)�	threading�Threadr��asyncore�
dispatcherZ
create_socket�socket�AF_INET�SOCK_STREAM�bind�listen�getsockname�host�port�handler_instance�_active�Lock�_active_lock)r(�addressrrr	r�s

zSendfileTestServer.__init__cCs|jSr#)rrJrrr	r!szSendfileTestServer.runningcCs$t��|_tj�|�|j��dSr#)r��Event�_SendfileTestServer__flagr��startr'rJrrr	r
%s
zSendfileTestServer.startcCsd|_|��dSr�)rr3rJrrr	�stop+szSendfileTestServer.stopcCs&t|jdd�st�d�q|��dS)Nr�F���MbP?)r�rr@r$rrJrrr	r'0szSendfileTestServer.waitcCsLd|_|j��|jr@tjr@|j��tjddd�|j��qt�	�dS)NTrrU)�timeoutro)
rr	rr�Z
socket_mapr�acquireZloop�releaseZ	close_allrJrrr	r�8s

zSendfileTestServer.runcCs|��\}}|�|�|_dSr#)�acceptr�r)r(r��addrrrr	�
handle_acceptAsz SendfileTestServer.handle_acceptcCs|��dSr#)rNrJrrr	�handle_connectEsz!SendfileTestServer.handle_connectcCsdSr`rrJrrr	�writableIszSendfileTestServer.writablecCs�dSr#rrJrrr	r�LszSendfileTestServer.handle_errorN)rCrDrEr�r�r�r��propertyrr
rr'r�rrr�rr�rrrr	r��s

	r��sendfileztest needs os.sendfile()c@s
eZdZddZej�d�o8ej�d�o8ej�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_setuprjr!rH�DATArArrr	rC\s
zTestSendfile.setUpClasscCstj|j�t�tj�dSr#)rZthreading_cleanuprjrIrHrArrr	rVaszTestSendfile.tearDownClasscCs~ttjdf�|_|j��t��|_|j�|jj|jj	f�|j�
d�|j�d�|j��|_
ttjd�|_|j��|_dS)NrrUrrv)r�rZHOST�serverr
r��client�connectrr�
settimeoutr�rl�socknorrrHr�rJrrr	rKfs

zTestSendfile.setUpcCs0|j��|j��|jjr&|j��d|_dSr#)r�rNrrrrrJrrr	r�rs



zTestSendfile.tearDownc
Ospztj|i|��WStyh}z>|jtjkr2�n"|jtjtjfvrRWYd}~qn�WYd}~qd}~00qdS)zfA higher level wrapper representing how an application is
        supposed to use sendfile().
        N)rrr7r8Z
ECONNRESET�EAGAIN�EBUSY)r(r�r�r�rrr	�sendfile_wrapperyszTestSendfile.sendfile_wrappercCs�d}d}d}|t|j�krd|�|j|j||�}|dkr8qd||7}||7}|�||k�|�||�q|�|t|j��|j�t	j
�|j��|j�
�|jj��}|�t|�t|j��|�||j�dS)Nrr�)r-rr"rrlrOr0r�shutdownr��	SHUT_RDWRrNrr'rr�)r(�
total_sent�offset�nbytes�sentrxrrr	�test_send_whole_file�s$

z!TestSendfile.test_send_whole_filecCs�d}t|j�d}t|j�|}d}||krj|�|j|j||�}|dkrJqj||7}||7}|�||k�q$|j�tj	�|j�
�|j��|jj
��}|jt|j�dd�}|�|t|��|�t|�t|��|�||�dS)NrrWr�)r-rr"rrlrOrr#r�r$rNrr'rr�r0)r(r%r&Z	must_sendr'r(rxr<rrr	�test_send_at_certain_offset�s&

z(TestSendfile.test_send_at_certain_offsetc
Cs�t|j�d}zt�|j|j|d�}Wn2tyX}z|jtjkrD�WYd}~nd}~00|�	|d�|j
�tj
�|j
��|j��|jj��}|�	|d�dS)Nr�rr)r-rrrrrlr7r8�EINVALr0rr#r�r$rNrr'rr�)r(r&r(r�rxrrr	�test_offset_overflow�s

z!TestSendfile.test_offset_overflowcCsT|�t��$}t�|j|jdd�Wd�n1s40Y|�|jjtj	�dS)Nr�r�)
r\r7rrrrlr0rr8r+�r(r�rrr	�test_invalid_offset�s2z TestSendfile.test_invalid_offsetc	Cs<tj|j|jddd�|jr8tj|j|jdddddd�dS)Nrr�)r�r�r&ror)r�r�r&ro�headers�trailersr�)rrrrl�SUPPORT_HEADERS_TRAILERSrJrrr	�
test_keywords�s��zTestSendfile.test_keywordscCs�d}d|jdd�}tj|j|jddddgd�}|�|d�||7}d}|t|�kr�tt|�|d�}|�|j|j||�}|dkr�q�|�||�||7}||7}qJ|�	|t|��|j
��|j�
�|jj��}|�	t|�t|��dS)	Nrsxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyr�r�sxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy�r/i)rrrrrlZassertLessEqualr-�minr"r0rrNrr'rr��hash)r(r%Z
expected_datar(r&r'rxrrr	�test_headers�s.��


zTestSendfile.test_headerscCs�tjd}d}|�tj|�t||�t|d��Z}tj|j|�	�ddddgd�|j
��|j�
�|jj��}|�|d	�Wd�n1s�0YdS)
Nr�sabcdefrvrr�s123456s789�r0sabcde123456789)rrHrwrIr!rrrrrlrrNrr'rr�r0)r(r�Z	file_datarSrxrrr	�
test_trailers�s

�

zTestSendfile.test_trailerscCsld|jj_|�t��2}tj|j|jddddgdd�Wd�n1sL0Y|�	|j
jtj�dS)NFr�x�r�r3�
rrr�r\r7rrrrlr0rr8r+r-rrr	�test_headers_overflow_32bits
s
�$z)TestSendfile.test_headers_overflow_32bitscCsld|jj_|�t��2}tj|j|jddddgdd�Wd�n1sL0Y|�	|j
jtj�dS)NFrr9r:r�r7r;r-rrr	�test_trailers_overflow_32bits

s
�$z*TestSendfile.test_trailers_overflow_32bits�SF_NODISKIOztest needs os.SF_NODISKIOc
Cs\ztj|j|jddtjd�Wn8tyV}z |jtjtjfvrB�WYd}~n
d}~00dS)Nrr�)r�)	rrrrlr>r7r8r!r )r(r�rrr	�
test_flags
s�
zTestSendfile.test_flagsN)rCrDrErrar�rHr1rrZrequires_headers_trailers�maxsizeZrequires_32brWrCrVrKr�r"r)r*r,r.r2r6r8r<r=rrr?rrrr	rPsN����



�rc	Cs�ttd�sdSz�ttjdd��V}zt�|��dd�Wn.tydYWd�Wt�tj�dS0Wd�n1sz0YWt�tj�nt�tj�0dS)N�setxattrFrr�	user.testrT)	rrrrrHrArlr7rI)r rrr	�supports_extended_attributes
s
�&rCz(no non-broken extended attribute supportrWr��'c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ExtendedAttributeTestsc
KsJtj}|�tj|�t|�|�t��&}|||d�fi|��Wd�n1sR0Y|�|jj	t	j
�||�}	|�|	t�|||d�dfi|��t
|	�}
|
�d�|�t
||��|
�|�||dfi|��d�|||d�dtjfi|��|�||dfi|��d�|�t��,}|||d�dtjfi|��Wd�n1�sN0Y|�|jj	t	j�|�t��,}|||d�dtjfi|��Wd�n1�s�0Y|�|jj	t	j
�|||d�dtjfi|��|
�d�|�t
||��|
�|||d�fi|��|�t��&}|||d�fi|��Wd�n1�sL0Y|�|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.testrrBrdsbyez
user.test2sfoosaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacss|]}d�|�VqdS)zuser.test{}Nrz)rr�rrr	r|`
rz;ExtendedAttributeTests._check_xattrs_str.<locals>.<genexpr>r�r9)rrHrwrIr!r\r7r0rr8�ENODATAr%r�rr	r�
XATTR_REPLACE�XATTR_CREATE�EEXISTr�rAr�)
r(rr�getxattrrA�removexattr�	listxattrr�rr�Z
init_xattrZxattr�many�thingrrr	�_check_xattrs_str5
sL4
<<
6
z(ExtendedAttributeTests._check_xattrs_strcOsN|jtg|�Ri|��t�tj�|jtjg|�Ri|��t�tj�dSr#)rPr&rrIrHrr rrrr	�
_check_xattrse
sz$ExtendedAttributeTests._check_xattrscCs|�tjtjtjtj�dSr#�rQrrKrArLrMrJrrr	�test_simplel
s�z"ExtendedAttributeTests.test_simplecCs |jtjtjtjtjdd�dS)NFrRrRrJrrr	�
test_lpathp
s�z!ExtendedAttributeTests.test_lpathcCs4dd�}dd�}dd�}dd�}|�||||�dS)	NcWsDt|d��&}tj|��g|�R�Wd�S1s60YdSr
)rrrKrl�r1r�r rrr	rKu
sz1ExtendedAttributeTests.test_fds.<locals>.getxattrcWsFt|dd��&}tj|��g|�R�Wd�n1s80YdS�Nr9r)rrrArlrUrrr	rAx
sz1ExtendedAttributeTests.test_fds.<locals>.setxattrcWsFt|dd��&}tj|��g|�R�Wd�n1s80YdSrV)rrrLrlrUrrr	rL{
sz4ExtendedAttributeTests.test_fds.<locals>.removexattrcWsDt|d��&}tj|��g|�R�Wd�S1s60YdSr
)rrrMrlrUrrr	rM~
sz2ExtendedAttributeTests.test_fds.<locals>.listxattr)rQ)r(rKrArLrMrrr	�test_fdst
s
zExtendedAttributeTests.test_fdsN)rCrDrErPrQrSrTrWrrrr	rE/
s
0rE�get_terminal_sizezrequires os.get_terminal_sizec@seZdZdd�Zdd�ZdS)�
TermsizeTestsc
Cszzt��}WnLtyX}z4tjdks8|jtjtjfvrB|�d��WYd}~n
d}~00|�	|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)rrXr7rar�r8r+�ENOTTYrZZassertGreaterEqual�columns�lines)r(rtr�rrr	�test_does_not_crash�
s
z!TermsizeTests.test_does_not_crashc
Cs�ztjddgtjdd���}Wn$ttjtfyB|�d�Yn0t|d�t|d�f}zt	�
tj�
��}WnLty�}z4tjdks�|jtjtjfvr�|�d	��WYd
}~n
d
}~00|�||�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.
        ZsttyrtT)rr�zstty invocation failedrUrr�rZN)r��check_output�DEVNULLr�r6�CalledProcessErrorr�rZr�rrXra�	__stdin__rlr7r�r8r+r[r0)r(rtr<r�r�rrr	�test_stty_match�
s"���

zTermsizeTests.test_stty_matchN)rCrDrEr^rcrrrr	rY�
srY�memfd_createzrequires os.memfd_creater�r�c@seZdZdd�ZdS)�MemfdCreateTestscCs�t�dtj�}|�|d�|�tj|�|�t�|��t|ddd��*}|�	d�|�
|��d�Wd�n1sv0Yt�d�}|�tj|�|�t�|��dS)NZHir�r9F)�closefdsmemfd_creater�)rrdZMFD_CLOEXECrrwrNr\r�rrr0�tell)r(rqrS�fd2rrr	�test_memfd_create�
s
.
z"MemfdCreateTests.test_memfd_createN)rCrDrErirrrr	re�
srec@seZdZdd�Zdd�ZdS)�OSErrorTestscCs�Gdd�dt�}g|_g|_tjdur.tj}ntj}|j�|�|j�||��tjdurbtj}nt�	tj�}|j�|�|j�t
|��|j�t|��|j|j|_dS)Nc@seZdZdS)zOSErrorTests.setUp.<locals>.StrN�rCrDrErrrr	�Str�
srl)
r&�bytes_filenames�unicode_filenamesrrrHr�ZTESTFN_UNDECODABLErr r|r}r�)r(rlZdecoded�encodedrrr	rK�
s

zOSErrorTests.setUpcCsJ|jtjf|jtjdf|jtjf|jtjtjf|jtjf|jtjf|jtj	fg}t
jdkr�|�|j
tjdf|j
tjdf|jtjdf|jtjdf|jtjff�n,|�|jtjf|jtjdf|jtjdff�ttd�r�|�|jtjddf�ttd��r|�|jtjddf�ttd��r.|�|jtjdf�ttd	��rN|�|jtjdf�ttd
��rn|�|jtjdf�ttd��r�|�|jtjf�ttd��r�t
jdk�r�|�|j
tjdf�|�|jtjdf�n|�|jtjdf�ttd
��r(|�|jtjf|jtjdf|jtjddf|jtjdff�ttd��rH|�|jtjdf�ttd��rf|�|jtj f�|D]�^}}}|D]�}zdt!|t"t#f��r�||g|�R�n>|�$t%d�� ||g|�R�Wd�n1�s�0YWnLt&�y}z |�'|j(|t"|��WYd}~n,d}~0t)�y,Yn0|�*d�+|���qx�qjdS)Nr�r�sdstr�r?r�lchownr��chflags�lchflags�chrootr�rMrFsuser�lchmodrFz	should bezNo exception thrown by {}),r�rr5r�r9rr�rr�rIrar�r=rmrdr�rnr�rr�r?rpr�rqrrrsr�rMrKrArLrtrFr�r&r@ZassertWarnsRegex�DeprecationWarningr7r�r�UnicodeDecodeErrorr�r{)r(Zfuncsr��funcZ	func_argsrr�rrr	�test_oserror_filename�
sz




�	

�
�

�4(z"OSErrorTests.test_oserror_filenameN)rCrDrErKrxrrrr	rj�
srjc@seZdZdd�ZdS)�
CPUCountTestscCs8t��}|dur*|�|t�|�|d�n
|�d�dS)Nrz&Could not determine the number of CPUs)r�	cpu_countr%r��
assertGreaterrZ)r(Zcpusrrr	�test_cpu_count$s
zCPUCountTests.test_cpu_countN)rCrDrEr|rrrr	ry#sryc@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)	rrr�r�rwrNr0r�r�r�rrr	�test_get_set_inheritable.s
z+FDInheritanceTests.test_get_set_inheritableNz
need fcntlcCsnt�ttj�}|�tj|�|�t�|�d�t�|tj	�}|tj
M}t�|tj|�|�t�|�d�dSr~)rrr�r�rwrNr0r��fcntl�F_GETFD�
FD_CLOEXECZF_SETFD)r(rqr�rrr	�test_get_inheritable_cloexec6sz/FDInheritanceTests.test_get_inheritable_cloexeccCsft�ttj�}|�tj|�|�t�|tj�tj	@tj	�t�
|d�|�t�|tj�tj	@d�dS)NTr)rrr�r�rwrNr0r�r�r�r�r�rrr	�test_set_inheritable_cloexecCs��z/FDInheritanceTests.test_set_inheritable_cloexec�O_PATHzneed os.O_PATHcCsnt�ttj�}|�tj|�|�t�|�d�t�|d�|�t�|�d�t�|d�|�t�|�d�dSr~)	rrr�r�rwrNr0r�r�r�rrr	�test_get_set_inheritable_o_pathNsz2FDInheritanceTests.test_get_set_inheritable_o_pathcCs�t��}|�t��}t�|�Wd�n1s20Y|�|jjtj	�|�t��}t�
|d�Wd�n1sz0Y|�|jjtj	�|�t��}t�
|d�Wd�n1s�0Y|�|jjtj	�dS�NTF)rr�r\r7rr�r0rr8rr�)r(rqrrrr	�test_get_set_inheritable_badfZs(**z0FDInheritanceTests.test_get_set_inheritable_badfcCs2t�ttj�}|�tj|�|�t�|�d�dSr�)rrr�r�rwrNr0r�r�rrr	riszFDInheritanceTests.test_openrzneed os.pipe()cCsPt��\}}|�tj|�|�tj|�|�t�|�d�|�t�|�d�dSr�)rrrwrNr0r�)r(ZrfdZwfdrrr	�	test_pipens
zFDInheritanceTests.test_pipecCsJt�ttj�}|�tj|�t�|�}|�tj|�|�t�|�d�dSr�)	rrr�r�rwrNrYr0r��r(�fd1rhrrr	�test_dupvs

zFDInheritanceTests.test_dupcCs(t�d�}|�tj|�|�|d�dS�NrUr)rrYrwrNr{r�rrr	�test_dup_standard_stream~s
z+FDInheritanceTests.test_dup_standard_streamr�r�cCsHt�dtj�}|�tj|�t�|�}|�tj|�|�t�|��dS)N�NUL)rrr�rwrNrYr\r�r�rrr	�test_dup_nul�s

zFDInheritanceTests.test_dup_nulr�zneed os.dup2()cCs�t�ttj�}|�tj|�t�ttj�}|�tj|�|�t�||�|�|�t�	|��t�ttj�}|�tj|�|�tj||dd�|�|�
t�	|��dS)NF)�inheritable)rrr�r�rwrNr0r�rOr�r\)r(rqrhZfd3rrr	r��szFDInheritanceTests.test_dup2�openptyzneed os.openpty()cCsPt��\}}|�tj|�|�tj|�|�t�|�d�|�t�|�d�dSr�)rr�rwrNr0r�)r(Z	master_fdZslave_fdrrr	�test_openpty�s
zFDInheritanceTests.test_openpty)rCrDrErrr�r�r�r�rrrr�r�rr�r�r�rar�r�r�r�rrrr	r}-s&






r}c@sHeZdZddddejfdfddddd	eed
d�fgZdd�Zd
d�ZdS)�PathTConverterTests)r�TrN)r9FrNrPFN)rqF�rN)rrFr�Nrr�rNcCstj}tjdkrd}}nt�tj�}t|�}t�t|�tjtjB�}|�	tj
tj�|�	tj|�t|�}t|�}|jD�]�\}}}	}
|j
|d���Vztt|�}Wn"ty�YWd�qzYn0||||fD]`}|dur�q�|j
||d��2||g|	�R�}
|
du�r|
|
�Wd�q�1�s,0Yq�|�td�� ||g|	�R�Wd�n1�sl0Y|�r�||g|	�R�}
|
du�r�|
|
�n>|�td�� ||g|	�R�Wd�n1�s�0YWd�qz1�s�0YqzdS)Nr,r)rr1zto return str or byteszos.PathLike)rrHrrr rrr{rLrwrIrN�	functionsZsubTestr�r��assertRaisesRegexrc)r(Zstr_filenameZbytes_fspath�bytes_filenamerqZ
int_fspathZ
str_fspathrZallow_fd�
extra_argsZ
cleanup_fnrr1r�rrr	�test_path_t_converter�sL

�
*�0

�z)PathTConverterTests.test_path_t_convertercCs�d}|�t|d��t�td��Wd�n1s80Y|�t|d��t�td��Wd�n1sv0Y|�t|d�� t�tt���Wd�n1s�0YdS)Nz-__fspath__\(\) to return str or bytes, not %sr�rW�floatg���Q�@�object)r�rcrr�rr�)r(r?rrr	�&test_path_t_converter_and_custom_class�s,,z:PathTConverterTests.test_path_t_converter_and_custom_class)	rCrDrEr�F_OKr�r�r�r�rrrr	r��s�	,r�r�r�c@seZdZdd�ZdS)�
BlockingTestscCsnt�ttj�}|�tj|�|�t�|�d�t�|d�|�t�|�d�t�|d�|�t�|�d�dSr�)	rrr�r�rwrNr0r�r�r�rrr	r��szBlockingTests.test_blockingN)rCrDrEr�rrrr	r��sr�c@seZdZdd�ZdS)�ExportsTestscCs |�dtj�|�dtj�dS)Nrr�)r�r�__all__rJrrr	�test_os_all�szExportsTests.test_os_allN)rCrDrEr�rrrr	r��sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�TestDirEntrycCs0tj�tj�|_|�tj|j�t�|j�dSr#)rr1�realpathrrHrwrr4rJrrr	rK�szTestDirEntry.setUpcCs|�ttj�dSr#)r\rcr�DirEntryrJrrr	�test_uninstantiablesz TestDirEntry.test_uninstantiablecCsjttj�|jd�d�}dd�t�|j�D���}|�|tj�|�|j	d�ddl
}|�t|j
||�dS)Nr`�pythoncSsg|]}|�qSrr�r�entryrrr	r
	rz0TestDirEntry.test_unpickable.<locals>.<listcomp>r)r!rr1r3�scandirr�r%r�r0rr�r\rcr�)r(rr�r�rrr	�test_unpickableszTestDirEntry.test_unpickableN)rCrDrErKr�r�rrrr	r��sr�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#)
rr1r�rrHr �
bytes_pathrwrr4rJrrr	rKszTestScandir.setUpr`cCs2t|t�r|jn|j}tj�||�}t|d�|S)Nr�)r�r@r�r1rr3r!)r(rr1rrrr	r!s
zTestScandir.create_filecCs2tdd�t�|j�D��}|�t|���|�|S)Ncss|]}|j|fVqdSr#rr�rrr	r| s�z*TestScandir.get_entries.<locals>.<genexpr>)rbrr�r1r0rA�keys)r(�names�entriesrrr	�get_entriess

�zTestScandir.get_entriescCsZ|rJt|�D]:}|�d�sq|dvr&q|�t||�t||�|||f�qn|�||�dS)NZst_)�st_dev�st_ino�st_nlink)r�rHr0r�)r(Zstat1Zstat2Zskip_fieldsr�rrr	�assert_stat_equal%s
�zTestScandir.assert_stat_equalcCs(t�|j�}|�tt|��|��dSr#)rr�r1r\rcrorN)r(�scandir_iterrrr	r�2szTestScandir.test_uninstantiablecCs<|�d�}t�|j�}ddl}|�t|j||�|��dS)Nr`r)	r!rr�r1r�r\rcr�rN)r(rr�r�rrr	r�7s

zTestScandir.test_unpickablecCs2|�|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��|�|��|tjdk�o|�|�|jdd�|tjdk�dS)NFrRr,)r%rr�r0rr1r3�inoder�r��is_dir�S_ISDIRr��is_file�S_ISREG�
is_symlinkr\r�)r(r�rr�r�r�Z
entry_statZentry_lstatrrr	�check_entry>s>
�

�

�
�
�
�
��zTestScandir.check_entryc	
Cs�ttd�}t��}tj�|jd�}t�|�|�d�}|r�zt�|tj�|jd��Wn2t	y�}z|�
d|�WYd}~n
d}~00|r�tj|tj�|jd�dd�t�|tj�|jd	��ddg}|r�|�d�|r�|�
d
�|�|�}|d}|�|dddd�|d}|�|dddd�|�rD|d}|�|dddd�|�r~|d}|�|dddd�|d	}|�|d	ddd�dS)Nr�r�r`z
link_file.txtr��symlink_dirT)r��symlink_file.txt)r�r�F)rrrr�r1r3r4r!r�r�rZr�r�r=r�r�)	r(r�r�r;rr�r�r�r�rrr	�test_attributesZsB


$�


zTestScandir.test_attributescCsNt|t�r|jn|j}tt�|��}|�t|�d�|d}|�|j	|�|Sr�)
r�r@r�r1r�rr�r0r-r)r(rr1r�r�rrr	�	get_entry�szTestScandir.get_entrycCs|j|d�}|�tj�|��S)Nr)r!r�rr1�basename)r(rrrrr	�create_file_entry�szTestScandir.create_file_entryc	Csp|��}t��}zNt�|j�tdd�t��D��}|�t|�	��tj�
|�g�Wt�|�nt�|�0dS)Ncss|]}|j|fVqdSr#rr�rrr	r|�rz5TestScandir.test_current_directory.<locals>.<genexpr>)r!rr$r5r1rbr�r0rAr�r�)r(rZold_dirr�rrr	�test_current_directory�s�z"TestScandir.test_current_directorycCs|��}|�t|�d�dS)Nz<DirEntry 'file.txt'>)r�r0r}�r(r�rrr	�	test_repr�szTestScandir.test_reprcCs*|��}|�t�|�tj�|jd��dS)Nr`)r�r0r�fspathr1r3r�rrr	�test_fspath_protocol�sz TestScandir.test_fspath_protocolcCsNt�d�}|j|d�}t�|�}|�|t�|�|tj�t�|j�|��dS)Nz
bytesfile.txtr)	rr r�r�r%r@r0r1r3)r(r�Zbytes_entryr�rrr	�test_fspath_protocol_bytes�s

�z&TestScandir.test_fspath_protocol_bytescCs�tj�|jd�}t�|�|�d�}t�|�tjdkrF|�|���|�	|�
��|�	|���tjdkr�|�t
|j�|��|jdd�n0|�|��d�|�t
|j�|jt
|jdd�dS)Nr�r,FrRr)rr1r3r4r�rrrOr�r\r�r�r\r6r�r�r{)r(r1r�rrr	�test_removed_dir�s




zTestScandir.test_removed_dircCs�|��}t�|j�|�|���tjdkr:|�|���|�|�	��tjdkrv|�
t|j�|�
�|j
dd�n0|�|��d�|�
t|j
�|j
t|j
dd�dS)Nr,FrRr)r�rrIr1r\r�rrOr�r�r\r6r�r�r{r�rrr	�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.txtrFrR)rr�rZr!rr�r1r3r�rIr{r�r\r�r�rOr�r\r6r�)r(rr�r�rrr	�test_broken_symlink�s"

�
zTestScandir.test_broken_symlinkc	Csp|�d�t�|j�}tt�|��}|�t|�d|�|d}|�|jd�|�|jt�tj�	|jd���dS�Nr`rUrsfile.txt)
r!rr r1r�r�r0r-rr3)r(�
path_bytesr�r�rrr	rV�s
�zTestScandir.test_bytesc
Cs�|�d�ttfD]�}|t�|j��}|�t��tt�	|��}Wd�n1sT0Y|�
t|�d|�|d}|�
|jd�|�
|jt�tj�
|jd���|�t|j�t�|�t|j�t�qdSr�)r!r|r}rr r1�assertWarnsrur�r�r0r-rr3r�ror@)r(rBr�r�r�rrr	�test_bytes_like�s
,�zTestScandir.test_bytes_likez.fd support for listdir required for this test.c	Cst|�tjtj�|�d�dg}t��rJt�dtj�	|jd��|�
d�t�|jtj�}�zt�|��}t
|�}Wd�n1s�0Ydd�|D�}|�t|�|�|�|t�|��|D]�}|�|j|j�|�t�|�|j�|�|��|jdk�tjtjvr�tj|j|d�}|�|��|�tj|j|dd�}|�|jdd�|�q�Wt�|�nt�|�0dS)	Nr`r�cSsg|]
}|j�qSrrr�rrr	r
rz'TestScandir.test_fd.<locals>.<listcomp>rSF)r�r7rR)r�rr�rUr!rr�r�r1r3r�rr�r�r0rAr�rr�r�r�rVrN)r(Zexpected_namesrqrtr�r�r�rrrr	�test_fds.

&zTestScandir.test_fdcCs|�ttjd�dS)NrH)r\r6rr�rJrrr	�test_empty_path%szTestScandir.test_empty_pathcCsN|�d�t�|j�}t|�}|�t|�d|�t|�}|�t|�d|�dS)Nr`rUr)r!rr�r1r�r0r-)r(r�r�Zentries2rrr	�test_consume_iterator_twice(s
z'TestScandir.test_consume_iterator_twicecCs$digfD]}|�ttj|�q
dS)NgX9��v��?)r\rcrr�)r(�objrrr	�test_bad_path_type3szTestScandir.test_bad_path_typecCsf|�d�|�d�t�|j�}t|�|��|��|���~Wd�n1sX0YdS�Nr`�	file2.txt)r!rr�r1rrrN�check_no_resource_warning�r(r�rrr	�
test_close7s


zTestScandir.test_closecCsv|�d�|�d�t�|j��}t|�Wd�n1s>0Y|���~Wd�n1sh0YdSr�)r!rr�r1rrr�r�rrr	�test_context_managerBs

&
z TestScandir.test_context_managercCsT|�d�|�d�t�|j�� }t|�|��Wd�n1sF0YdSr�)r!rr�r1rrrNr�rrr	�test_context_manager_closeJs


z&TestScandir.test_context_manager_closec	Cs�|�d�|�d�|�t��Lt�|j�� }t|�ddWd�n1sR0YWd�n1sp0Y|���~Wd�n1s�0YdS)Nr`r�rUr)r!r\�ZeroDivisionErrorrr�r1rrr�r�rrr	�test_context_manager_exceptionQs

D
z*TestScandir.test_context_manager_exceptioncCs�|�d�|�d�t�|j�}t|�|�t��~t��Wd�n1sR0Yt�|j�}t	|�|�
��~Wd�n1s�0YdSr�)r!rr�r1rrr��ResourceWarningr�
gc_collectr�r�r�rrr	�test_resource_warning[s

&
z!TestScandir.test_resource_warningN)r`)r`)&rCrDrErr�rKr!r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rVr�rrrr�rUr�r�r�r�r�r�r�r�r�rrrr	r�s@

)	
�

r�c@s^eZdZeej�Zdd�Zdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�ZdS)�
TestPEP519cCs dD]}|�||�|��qdS)N)rdsgoodbyessome/path/and/file�r0r�)r(�brrr	�test_return_bytespszTestPEP519.test_return_bytescCs dD]}|�||�|��qdS)N)ZhelloZgoodbyezsome/path/and/filer�)r(rrrrr	�test_return_stringtszTestPEP519.test_return_stringcCsLdD]B}t|�}|�||�|��|�dt�|��|�dt�|��qdS)N)�path/like/object�path/like/objectr�r�)rr0r�rr rA)r(r�Zpathlikerrr	�test_fsencode_fsdecodexs
z!TestPEP519.test_fsencode_fsdecodecCsB|�d|�td���|�tttj��|�ttd�tj��dS)Nz#feelthegilr�)r0r�rrO�
issubclassr�PathLiker�rJrrr	rT�szTestPEP519.test_pathlikecCs4tddi�}ttt|�fD]}|�t|j|�qdS)NZblahr)ror�rr\rcr�)r(Zvapor�orrr	�test_garbage_in_exception_out�sz(TestPEP519.test_garbage_in_exception_outcCs|�t|j�dSr#)r\rcr�rJrrr	�test_argument_required�sz!TestPEP519.test_argument_requiredcCsR|�t|jtd��tddi�}d|_|�t|j|��|�t|jtt���dS)Nr]ZfoorrU)r\rcr�rro�
__fspath__r�)r(�crrr	�test_bad_pathlike�s
�zTestPEP519.test_bad_pathlikecCs8Gdd�dtj�}|�tt|��|�tttj��dS)Nc@seZdZdS)z0TestPEP519.test_pathlike_subclasshook.<locals>.ANrkrrrr	�A�sr�)rr�r\r�rrO)r(r�rrr	�test_pathlike_subclasshook�sz%TestPEP519.test_pathlike_subclasshookcCs|�tjttj�dSr#)r%rr�r@�types�GenericAliasrJrrr	�test_pathlike_class_getitem�sz&TestPEP519.test_pathlike_class_getitemN)rCrDrEr_rr�r�r�r�rTr�r�r�r�r�rrrr	r�js
r�c@seZdZdd�ZdS)�
TimesTestscCsnt��}|�|tj�dD]}t||�}|�|t�qtjdkrj|�|jd�|�|j	d�|�|j
d�dS)N)�user�system�
children_user�children_system�elapsedr,r)rr5r%�times_resultr�r�rr0r�r�r�)r(r5Zfieldr�rrr	�
test_times�s

zTimesTests.test_timesN)rCrDrEr�rrrr	r��sr��_fspathc@seZdZdZeej�ZdS)�TestPEP519PurePythonz>Explicitly test the pure Python implementation of os.fspath().N)rCrDrEr�r_rr�r�rrrr	r�sr�__main__)r)N)�r�r�r��
contextlibrGr8rsrHrr�r0rr�r
r+r�r�r�raZ	sysconfigr.r�r@r�rr/r��testrZtest.supportrr�rr��ImportErrorr�r|�pwd�getpwallrQr�Z	_testcapirr
r@Ztest.support.script_helperrrrrXrrr�versionrHr��getgidr�rr!ZTestCaser"rFr�rr`ZBasicTestMappingProtocolrar�rrrr%r'r@rYrcrgrtZget_config_varZOS_URANDOM_DONT_USE_FDr�r��contextmanagerr�r�r�r�r�r�rrr;rGrWrXrzr�r�r�r�r�r�r:r�r�r�r�r�rrCZrequires_linux_versionrErYrerjryr}r�r�r�r�r�r�r�rrC�mainrrrr	�<module>s^




Aae_'EG
^;)	-����M �h#d%CGs/<0!1H4�VO�Q0
]
yB�\:


Kontol Shell Bypass