Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_posix.cpython-39.opt-1.pyc

a

��g�W�@s�dZddlmZddlmZe�d�ZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlmZej�e��ejd�Ze�ejdkd	�Zd
d�Ze�e�d�ZGd
d�dej�Z Gdd�dej�Z!Gdd�dej�Z"Gdd�d�Z#e�e$ed�d�Gdd�deje#��Z%e�e$ed�d�Gdd�deje#��Z&e�ejdkd�Gdd �d ej��Z'd!d"�Z(e)d#k�r�e�*�dS)$zTest posix functions�)�support)�assert_python_ok�posixN)�contextmanagerz-dummy-symlink�z(test is only meaningful on 32-bit buildsc
Cs`ttd�sdSzt�d�Wn>tyZ}z&|jtjkrFWYd}~dSWYd}~n
d}~00dS)N�sched_getschedulerFrT)�hasattrrr�OSError�errno�ENOSYS)�e�r
�+/usr/local/lib/python3.9/test/test_posix.py�_supports_scheds
$rzrequires POSIX scheduler APIc@s�eZdZdd�Zdd�Zdd�Ze�ee	d�d�d	d
��Z
e�ee	d�d�d
d��Ze�ee	d�d�dd��Ze�ee	d�d�dd��Z
e�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�eed/d0�ejvd1�e�eed2�d3�d4d5���Ze�ee	d6�d7�e�eed2�d3�d8d9���Ze�eed2�d3�d:d;��Ze�ee	d<�d=�d>d?��Ze�ee	d@�dA�dBdC��Ze�ee	dD�dE�dFdG��Ze�ee	dD�dE�e�ee	dH�dI�dJdK���Ze�ee	dD�dE�edLdM���Z e�ee	dN�dO�dPdQ��Z!e�ee	dR�dS�dTdU��Z"e�ee	dR�dS�e�ee	dV�dW�dXdY���Z#e�ee	dR�dS�edZd[���Z$e�ee	d\�d]�d^d_��Z%e�ee	d\�d]�d`da��Z&e�ee	db�dc�ddde��Z'e�ee	db�dc�dfdg��Z(e�ej)ejvdh�didj��Z*e�ej)ej+vdk�dldm��Z,e�ee	dn�do�dpdq��Z-e�ee	dn�do�edrds���Z.e�ee	dt�du�dvdw��Z/e�ee	dt�du�edxdy���Z0e�ee	dz�d{�d|d}��Z1e�ee	d~�d�d�d���Z2e�ee	d��d��d�d���Z3e�eed��d��e4�5d�d�d��d�d����Z6e�ee	d��d��d�d���Z7e�ee	d��d��d�d���Z8e�ee	d��d��d�d���Z9d�d��Z:e�ee	d��d��d�d���Z;e�ee	d���o�ee<d��d��d�d���Z=e�ee	d��d��d�d���Z>d�d��Z?e�ee	d��d��d�d���Z@e�ee	d��d��d�d���ZAe�ee	d��d��d�d���ZBe�ee	d��d��d�d���ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGe�e	jHejvd¡d�dĄ�ZIe�ee	dŃdơd�dȄ�ZJe�ee	dɃdʡd�d̄�ZKe�ee	d̓dΡd�dЄ�ZLe�ee	dуdҡd�dԄ�ZMe�eedՃd֡e4�5d�d�dסd�dل��ZNe4jOe�eedՃd֡e4�5d�d�dסd�dۄ���ZPe�ee	d܃dݡd�d߄�ZQd�d�ZRe�ee	d�d�d�d��ZSe�ee	d�d�d�d��ZTe�ee	d�d�d�d��ZUd�d�ZVd�d�ZWe�ee	d�d�d�d��ZXe�ee	d�d��e�eeYd��d��e�eed��d��d�d�����ZZe�eed��d��d�d���Z[e�ee\�d��d�e�ee�d��d��d�d���Z]e�ee	�d��d�Z^e�ee	�d��d	�Z_e^�d
�d��Z`e^e�ee	�d��d
��d�d���Zaeb�d�d��Zce�ee	�d��d��d�d��Zde_�d�d��Zee_�d�d��Zf�d�d�Zge�ee�d��d��d�d��Zh�d �d!�Zi�d"�d#�Zj�d$�d%�Zke�ee�d&��d'��d(�d)��Zld0S(*�PosixTestercCsDttjd�}|��tjg|_t��|_|j��t�	ddt
�dS)N�w+�ignorez.* potential security risk .*)�openr�TESTFN�close�teardown_filesZcheck_warnings�_warnings_manager�	__enter__�warnings�filterwarnings�RuntimeWarning��self�fpr
r
r�setUp,s


�zPosixTester.setUpcCs*|jD]}t�|�q|j�ddd�dS�N)rr�unlinkr�__exit__)rZ
teardown_filer
r
r�tearDown6s
zPosixTester.tearDowncCs>gd�}|D],}tt|d�}|dur|�|�t|d�qdS)N)�ctermid�getcwd�getcwdb�uname�times�
getloadavg�getegid�geteuid�getgid�	getgroups�getpid�getpgrp�getppid�getuid�sync�)�getattrr�assertRaises�	TypeError)rZNO_ARG_FUNCTIONS�nameZ
posix_funcr
r
r�testNoArgFunctions;szPosixTester.testNoArgFunctions�	getresuidztest needs posix.getresuid()cCs2t��}|�t|�d�|D]}|�|d�qdS�N�r)rr9�assertEqual�len�assertGreaterEqual)rZuser_ids�valr
r
r�test_getresuidJszPosixTester.test_getresuid�	getresgidztest needs posix.getresgid()cCs2t��}|�t|�d�|D]}|�|d�qdSr:)rrAr<r=r>)rZ	group_idsr?r
r
r�test_getresgidRszPosixTester.test_getresgid�	setresuidztest needs posix.setresuid()cCs0t��}|�tj|��|�t�ddd��dS�N���)rr9�assertIsNonerC)r�current_user_idsr
r
r�test_setresuidZszPosixTester.test_setresuidcCs<t��}d|vr8|ddddf}|jttjg|�R�dS�Nrr3rE)rr9r5r	rC)rrGZnew_user_idsr
r
r�test_setresuid_exceptionbsz$PosixTester.test_setresuid_exception�	setresgidztest needs posix.setresgid()cCs0t��}|�tj|��|�t�ddd��dSrD)rrArFrK)r�current_group_idsr
r
r�test_setresgidkszPosixTester.test_setresgidcCs<t��}d|vr8|ddddf}|jttjg|�R�dSrI)rrAr5r	rK)rrLZ
new_group_idsr
r
r�test_setresgid_exceptionssz$PosixTester.test_setresgid_exception�
initgroupsztest needs os.initgroups()c
Cs�|�ttj�|�ttjd�|�ttjdd�|�ttjddt��t��dkr�zt�t���j	}Wnt
y�t�d��Yn0zt�|d�Wn4t
y�}z|�|jtj�WYd}~nd}~00|�d�dS)Nr;�foorzneed a pwd entry�
z+Expected OSError to be raised by initgroups)r5r6rrO�object�osr1�pwd�getpwuid�pw_name�KeyError�unittest�SkipTestr	r<r
�EPERM�fail)rr7rr
r
r�test_initgroups|s&zPosixTester.test_initgroups�statvfsztest needs posix.statvfs()cCs|�t�tj��dSr )�
assertTruerr]rS�curdir�rr
r
r�test_statvfs�szPosixTester.test_statvfs�fstatvfsztest needs posix.fstatvfs()cCsNttj�}z4|�t�|����|�t�|����W|��n
|��0dSr )	rrrr^rrb�filenor]rrr
r
r�
test_fstatvfs�s

zPosixTester.test_fstatvfs�	ftruncateztest needs posix.ftruncate()cCsJttjd�}z.|�d�|��t�|��d�W|��n
|��0dS)Nr�testr)	rrr�write�flushrrercrrr
r
r�test_ftruncate�s
zPosixTester.test_ftruncate�truncateztest needs posix.truncate()cCsPttjd��"}|�d�|��Wd�n1s40Yt�tjd�dS)N�wrfr)rrrrgrhrrjrr
r
r�
test_truncate�s
&zPosixTester.test_truncate�execveNz/test needs execve() to support the fd parameter�forkztest needs os.fork()c	Cs�t�tjtj�}z^t��}|dkrTt�tj�tj�d�t	�
|tjddgtj�ntj
|dd�Wt�|�nt�|�0dS)Nr�-c�pass��exitcode)rSr�sys�
executable�O_RDONLYrn�chdir�path�splitrrm�environr�wait_processr)rr�pidr
r
r�test_fexecve�szPosixTester.test_fexecve�waitidztest needs posix.waitid()cCsht��}|dkrDt�tj�tj�d�t�tjtjddgtj	�n t�
tj|tj�}|�
||j�dS)Nrrorp)rSrnrvrwrxrsrtrrmryr}�P_PID�WEXITEDr<�si_pid)rr{�resr
r
r�test_waitid�szPosixTester.test_waitidcCs4|jtdd��t�dd��Wd�n1s20Y|jtdd��tjdd�Wd�n1sl0Y|jtdd��tjdd	�Wd�n1s�0Y|jtdd��tjd
d�Wd�n1s�0Y|jtdd��tjdd�Wd�n1�s0Y|jtdd��tjdd	�Wd�n1�sX0Y|jtdd��tjdd�Wd�n1�s�0Y|jtd
d��"tjddd�d�Wd�n1�s�0Y|jtd
d��"tjdd�dd�Wd�n1�s0Yd}td|�dS)NzPositional args not allowed)�msgcSsdSr r
r
r
r
r�<lambda>��z3PosixTester.test_register_at_fork.<locals>.<lambda>zArgs must be callable�)�beforeZthree)�after_in_childsFive)�after_in_parentzArgs must not be NonezInvalid arg was allowedcSsdS)Nr;r
r
r
r
rr��r�)r�r�cSsdSr r
r
r
r
rr��r��)r�r�a�if 1:
            import os

            r, w = os.pipe()
            fin_r, fin_w = os.pipe()

            os.register_at_fork(before=lambda: os.write(w, b'A'))
            os.register_at_fork(after_in_parent=lambda: os.write(w, b'C'))
            os.register_at_fork(after_in_child=lambda: os.write(w, b'E'))
            os.register_at_fork(before=lambda: os.write(w, b'B'),
                                after_in_parent=lambda: os.write(w, b'D'),
                                after_in_child=lambda: os.write(w, b'F'))

            pid = os.fork()
            if pid == 0:
                # At this point, after-forkers have already been executed
                os.close(w)
                # Wait for parent to tell us to exit
                os.read(fin_r, 1)
                os._exit(0)
            else:
                try:
                    os.close(w)
                    with open(r, "rb") as f:
                        data = f.read()
                        assert len(data) == 6, data
                        # Check before-fork callbacks
                        assert data[:2] == b'BA', data
                        # Check after-fork callbacks
                        assert sorted(data[2:]) == list(b'CDEF'), data
                        assert data.index(b'C') < data.index(b'D'), data
                        assert data.index(b'E') < data.index(b'F'), data
                finally:
                    os.write(fin_w, b'!')
            ro)r5r6rS�register_at_forkr)r�coder
r
r�test_register_at_fork�s(,***,,,22#z!PosixTester.test_register_at_fork�lockfztest needs posix.lockf()c	Csrt�tjtjtjB�}zJt�|d�t�|dtj�t	�
|t	jd�t	�
|t	jd�Wt�
|�nt�
|�0dS)N�testr�)rSrrr�O_WRONLY�O_CREATrg�lseek�SEEK_SETrr��F_LOCK�F_ULOCKr�r�fdr
r
r�
test_lockfszPosixTester.test_lockf�preadztest needs posix.pread()c	Cs|t�tjtjtjB�}zTt�|d�t�|dtj�|�	dt
�|dd��|�	dt
�|d��Wt�
|�nt�
|�0dS)Nr�rsesr�r3ste)rSrrr�O_RDWRr�rgr�r�r<rr��readrr�r
r
r�
test_preadszPosixTester.test_pread�preadvztest needs posix.preadv()c	Cszt�tjtjtjB�}zRt�|d�dd�dD�}|�t�	||d�d�|�gd�t
|��Wt�|�nt�|�0dS)N�test1tt2t3t5t6t6t8cSsg|]}t|��qSr
��	bytearray��.0�ir
r
r�
<listcomp>+r�z+PosixTester.test_preadv.<locals>.<listcomp>��r;r�r;�
�st1tt2st3ts5t)rSrrrr�r�rgr<rr��listr)rr��bufr
r
r�test_preadv&szPosixTester.test_preadv�	RWF_HIPRIztest needs posix.RWF_HIPRIc
Cs�t�tjtjtjB�}z�zLt�|d�dd�dD�}|�t�	||dtj
�d�|�gd�t|��Wn^ty�|�
d�YnDty�}z,|jtjtjhvr�t�d	��n�WYd}~n
d}~00Wt�|�nt�|�0dS)
Nr�cSsg|]}t|��qSr
r�r�r
r
rr�7r�z1PosixTester.test_preadv_flags.<locals>.<listcomp>r�r;r�r�zpreadv2 not availablez0RWF_HIPRI is not supported by the current system)rSrrrr�r�rgr<rr�r�r��NotImplementedError�skipTestr	r
�EINVAL�ENOTSUPrXrYr)rr�r��instr
r
r�test_preadv_flags1szPosixTester.test_preadv_flagsc	Cs�t�tjtjtjB�}z~td�gd}|�t��}t�	||d�Wd�n1sT0Y|�
|jjtj
�|�
t|d�dd�Wt�|�nt�|�0dS�N���r�)rSrrrr�r�r�r5r	r�r<�	exceptionr
r��bytesr�rr�r��cmr
r
r�test_preadv_overflow_32bitsGs,z'PosixTester.test_preadv_overflow_32bits�pwriteztest needs posix.pwrite()c	Cstt�tjtjtjB�}zLt�|d�t�|dtj�t	�
|dd�|�dt	�|d��Wt�
|�nt�
|�0dS)Nr�r�xxr3stxxtr�)rSrrrr�r�rgr�r�rr�r<r�rr�r
r
r�test_pwriteTszPosixTester.test_pwrite�pwritevztest needs posix.pwritev()c	Cs�t�tjtjtjB�}zlt�|d�t�|dtj�t�	|gd�d�}|�
|d�t�|dtj�|�
dt�|d��Wt�
|�nt�
|�0dS)Nr�r�stest1stt2st3r�r�sxxtest1tt2t3�d)rSrrrr�r�rgr�r�r�r<rr�r�rr��nr
r
r�test_pwritev_szPosixTester.test_pwritevzos.RWF_SYNCztest needs os.RWF_SYNCc	Cs�t�tjtjtjB�}zpt�|d�t�|dtj�t�	|gd�dtj
�}|�|d�t�|dtj�|�dt�
|d��Wt�|�nt�|�0dS)Nr�rr�r�r�s
xxtest1tt2r�)rSrrrr�r�rgr�r�r�ZRWF_SYNCr<rr�rr�r
r
r�test_pwritev_flagsmszPosixTester.test_pwritev_flagsc	Cs�t�tjtjtjB�}zb|�t��(}t�|ddgdd�Wd�n1sP0Y|�	|j
jtj�Wt�
|�nt�
|�0dS)N�xr�r�r)rSrrrr�r�r5r	r�r<r�r
r�r�rr�r�r
r
r�test_pwritev_overflow_32bits|s6z(PosixTester.test_pwritev_overflow_32bits�posix_fallocatez"test needs posix.posix_fallocate()c
Cs�t�tjtjtjB�}zlzt�|dd�WnJtyt}z2|j	t	j
kr^tj�
d�r^t�d��n�WYd}~n
d}~00Wt�|�nt�|�0dS)Nrr�)Zsunos�freebsd�netbsdZopenbsdZgnukfreebsdz test may fail on ZFS filesystems)rSrrrr�r�rr�r	r
r�rs�platform�
startswithrXrYr)rr�r�r
r
r�test_posix_fallocate�s�z PosixTester.test_posix_fallocatec
CsJzt�ddd�Wn2tyD}z|jtjkr0�WYd}~n
d}~00dS)N����rr�)rr�r	r
�EBADF�rr�r
r
r�test_posix_fallocate_errno�s
z&PosixTester.test_posix_fallocate_errno�
posix_fadvisez test needs posix.posix_fadvise()c	CsBt�tjtj�}z t�|ddtj�Wt�|�nt�|�0dS�Nr)	rSrrrrurr��POSIX_FADV_WILLNEEDrr�r
r
r�test_posix_fadvise�szPosixTester.test_posix_fadvisec
CsNzt�dddtj�Wn2tyH}z|jtjkr4�WYd}~n
d}~00dS)Nr�r)rr�r�r	r
r�r�r
r
r�test_posix_fadvise_errno�s
z$PosixTester.test_posix_fadvise_errnoz!test needs fd support in os.utimec	CsRt��}t�tjtj�}�z&t�|�t�|d�|�t	tj|d�|�t	tj||df�|�t	tj|d|f�t�|t
|�t
|�f�t�|||f�|jttj|||f||fd�|jttj||dfdd�|jttj|d|dfd�t�|t
|�t
|t
|�d�f�tj|t
|�t
|t
|�d�fd�Wt�|�nt�|�0dS)N�NN)�nsr�e��A)
�timerSrrrrur�utimer5r6�int�
ValueErrorr)r�nowr�r
r
r�test_utime_with_fd�s 
$(zPosixTester.test_utime_with_fdz.test needs follow_symlinks support in os.utimecCs�t��}tjtjddd�|jttjtjddd�|jttjtj|dfdd�|jttjtjd|fdd�tjtjt|�t|�fdd�tjtj||fdd�tjtjdd�dS)NF��follow_symlinksr��r�rr�rrr5r6r��rr�r
r
r�test_utime_nofollow_symlinks�sz(PosixTester.test_utime_nofollow_symlinks�writevztest needs posix.writev()c	Cs�t�tjtjtjB�}zzt�|d�}|�|d�t�|dtj	�|�dt
�|d��zt
�|g�}WntyvYn0|�|d�Wt�
|�nt�
|�0dS)Nr�r�r�
test1tt2t3)rSrrrr�r�r�r<r�r�rr�r	r)rr�r��sizer
r
r�test_writev�szPosixTester.test_writevc	Cs�t�tjtjtjB�}z`|�t��&}t�|ddgd�Wd�n1sN0Y|�	|j
jtj�Wt�
|�nt�
|�0dS)Nr�r�r�)rSrrrr�r�r5r	r�r<r�r
r�rr�r
r
r�test_writev_overflow_32bits�s4z'PosixTester.test_writev_overflow_32bits�readvztest needs posix.readv()c	Cs�t�tjtjtjB�}z�t�|d�t�|dtj�dd�dD�}|�	t
�||�d�|�	gd�dd�|D��zt
�|g�}Wnty�Yn0|�	|d�Wt�
|�nt�
|�0dS)	Nr�rcSsg|]}t|��qSr
r�r�r
r
rr��r�z*PosixTester.test_readv.<locals>.<listcomp>r�r�r�cSsg|]}t|��qSr
)r�r�r
r
rr��r�)rSrrrr�r�rgr�r�r<rr�r	r)rr�r�r�r
r
r�
test_readv�szPosixTester.test_readvc	Cs�t�tjtjtjB�}z|td�gd}|�t��}t�	||�Wd�n1sR0Y|�
|jjtj
�|�
t|d�dd�Wt�|�nt�|�0dSr�)rSrrrr�r�r�r5r	r�r<r�r
r�r�rr�r
r
r�test_readv_overflow_32bits
s*z&PosixTester.test_readv_overflow_32bits�dupztest needs posix.dup()cCsJttj�}z0t�|���}|�|t�t�	|�W|�	�n
|�	�0dSr )
rrrrr�rc�assertIsInstancer�rSr)rrr�r
r
r�test_dups
zPosixTester.test_dup�confstrztest needs posix.confstr()cCs.|�ttjd�|�tt�d��dkd�dS)NZ
CS_garbage�CS_PATHrT)r5r�rr�r<r=r`r
r
r�test_confstr%szPosixTester.test_confstr�dup2ztest needs posix.dup2()cCsTttj�}ttj�}z(t�|��|���W|��|��n|��|��0dSr )rrrrr�rcr)r�fp1�fp2r
r
r�	test_dup2+s


�zPosixTester.test_dup2�	O_CLOEXECzneeds os.O_CLOEXECr���cCs8t�tjtjtjB�}|�tj|�|�t�	|��dSr )
rSrrrrur��
addCleanupr�assertFalse�get_inheritabler�r
r
r�test_oscloexec6szPosixTester.test_oscloexec�O_EXLOCKztest needs posix.O_EXLOCKcCs�t�tjtjtjBtjB�}|�ttjtjtjtjBtj	B�t�
|�ttd�r�t�tjtjtj
BtjB�}|�ttjtjtjtjBtj	B�t�
|�dS)N�O_SHLOCK)rSrrrr�rr�r5r	�
O_NONBLOCKrrrrr�r
r
r�
test_osexlock=s��

��zPosixTester.test_osexlockrztest needs posix.O_SHLOCKcCs�t�tjtjtjBtjB�}t�tjtjtjBtjB�}t�|�t�|�tt	d�r�t�tjtjtjBtjB�}|�
ttjtjtjtj
BtjB�t�|�dS)Nr)rSrrrr�rr�rrrr5r	rurr)r�fd1�fd2r�r
r
r�
test_osshlockMs ��


��zPosixTester.test_osshlock�fstatztest needs posix.fstat()cCshttj�}zN|�t�|����|�t�|����|�t	dtjt
|����W|��n
|��0dS�Nz4should be string, bytes, os.PathLike or integer, not)rrrr^rrrc�stat�assertRaisesRegexr6�floatrrr
r
r�
test_fstat^s
�zPosixTester.test_fstatc	Cs�|�t�tj��|�t�t�tj���|�tdtjt	t�tj���|�
tdtjd�|�
tdtjttj��|�
tdtjtt�tj���dSr)
r^rr	rrrS�fsencodeZassertWarnsRegex�DeprecationWarningr�r
r6r�r`r
r
r�	test_statls$����zPosixTester.test_stat�mkfifozdon't have mkfifo()c
Csxt�tj�zt�tjtjtjB�Wn2tyX}z|�	d|�WYd}~n
d}~00|�
t�t�tj�j��dS)N�posix.mkfifo(): %s)
rr!rrrr	�S_IRUSR�S_IWUSR�PermissionErrorr�r^�S_ISFIFO�st_mode)rrr
r
r�test_mkfifo}s$zPosixTester.test_mkfifo�mknod�S_IFIFOzdon't have mknod()/S_IFIFOc
Cs�t�tj�tjtjBtjB}zt�tj|d�Wn>t	yp}z&|�
|jtjtj
tjf�WYd}~n$d}~00|�t�t�tj�j��t�tj�ztjtj|ddd�Wn>t	y�}z&|�
|jtjtj
tjf�WYd}~n
d}~00dS)Nr)rw�modeZdevice�dir_fd)rr!rr	rrrrrr	�assertInr
rZr��EACCESr^rr)rrrr
r
r�
test_mknod�s0�
zPosixTester.test_mknod�makedevztest needs posix.makedev()cCs`t�tj�}|j}|�|t�|�|d�t�|�}|�|t�|�|d�|�	t�|�|�|�
ttjt|��|�
ttj�|�
t
tftjd�t�|�}|�|t�|�|d�|�	t�|�|�|�
ttjt|��|�
ttj�|�
t
tftjd�|�	t�||�|�|�
ttjt|�|�|�
ttj|t|��|�
ttj|�|�
ttj�dS)NrrE)rr	rr�st_devr�r�r>�majorr<r5r6rr��
OverflowError�minorr)r�st�devr!r#r
r
r�test_makedev�s.

zPosixTester.test_makedevc		s����fdd�}t��}t��}|�||�|||�|�d|�|||�|�|d�|||�|dkr�d}|�||�|||�|�dd�|||�|�||�|||�nzt��dvr�t�d��nb��t|�dd�|||���t|�dd�|||�dt�	�v�r,��t|�dd�|||�t
tfD]F}��t|�||�|�|||���t|�|||��|||��q4dS)	z/Common code for chown, fchown and lchown tests.cs0�dur,���}��|j|���|j|�dSr )r<�st_uid�st_gid)�uid�gidr	��first_paramr�	stat_funcr
r�
check_stat�sz6PosixTester._test_all_chown_common.<locals>.check_statrErl)zHP-UXZSunOSz1Skipping because of non-standard chown() behaviorN)
rSr1r,r��systemrXrYr5r	r-�strrr6)	rZ
chown_funcr,r-r.r)r*Z	big_value�tr
r+r�_test_all_chown_common�s>








z"PosixTester._test_all_chown_common�chownztest needs os.chown()cCsFt�tj�|�ttjtjdd�t�tj�|�	tjtjtj
�dSrD)rSr!rrr5r	rr3�create_empty_filer2r	r`r
r
r�
test_chown�szPosixTester.test_chown�fchownztest needs os.fchown()cCsTt�tj�ttjd�}z,|��}|�tj|t	tdd��W|�
�n
|�
�0dS)Nrkr)rSr!rrrrcr2rr6r4r)rZ	test_filer�r
r
r�test_fchowns

�zPosixTester.test_fchown�lchownztest needs os.lchown()cCs8t�tj�t�ttj�|�tjtjt	tdd��dS)N�lstat)
rSr!rr�symlink�_DUMMY_SYMLINKr2rr8r4r`r
r
r�test_lchown
s

�zPosixTester.test_lchownrvztest needs posix.chdir()cCs"t�tj�|�ttjtj�dSr )rrvrSr_r5r	rrr`r
r
r�
test_chdirszPosixTester.test_chdircCs|�tjt�tj��dSr )rrrr�listdirrSr_r`r
r
r�test_listdirszPosixTester.test_listdircCs|�tjt���dSr )rrrrr>r`r
r
r�test_listdir_defaultsz PosixTester.test_listdir_defaultcCs|�t�tj�t�d��dS�N�.)rrSr
rrrr>r`r
r
r�test_listdir_bytes"szPosixTester.test_listdir_bytesc	CsxttfD]j}|�t��t�|d��}Wd�n1s:0Y|�t�t	j
�|�|D]}|�t|�t
�q\qdSrA)r��
memoryviewZassertWarnsrrr>rrSr
rrZassertIs�typer�)r�cls�namesr7r
r
r�test_listdir_bytes_like's,z#PosixTester.test_listdir_bytes_likez)test needs fd support for posix.listdir()cCsdt�t��tj�}|�tj|�|�tt�d��tt�|���|�tt�d��tt�|���dS)N�.)	rrr%rur�rr<�sortedr>)r�fr
r
r�test_listdir_fd/s��zPosixTester.test_listdir_fd�accessztest needs posix.access()cCs|�t�tjtj��dSr )r^rrMrrrS�R_OKr`r
r
r�test_access>szPosixTester.test_access�umaskztest needs posix.umask()cCs$t�d�}|�|t�t�|�dSr�)rrPr�r�)rZold_maskr
r
r�
test_umaskBs
zPosixTester.test_umask�strerrorztest needs posix.strerror()cCs|�t�d��dSr�)r^rrRr`r
r
r�
test_strerrorHszPosixTester.test_strerror�pipeztest needs posix.pipe()cCs$t��\}}t�|�t�|�dSr )rrTrSr)r�reader�writerr
r
r�	test_pipeMs
zPosixTester.test_pipe�pipe2ztest needs os.pipe2()�cCs�|�ttjd�|�ttjdd�t�d�\}}t�|�t�|�t�tjtjB�\}}|�tj|�|�tj|�|�t�	|��|�t�	|��|�t�
|��|�t�
|��|�ttj|d�zt�
|dtj�Wnty�Yn0dS)NZDEADBEEFrr3r�)r5r6rSrXrr�rr�r�r��get_blockingr	r�rgrZ
PIPE_MAX_SIZE)r�rrkr
r
r�
test_pipe2Ss"

zPosixTester.test_pipe2cCs8ddl}|�ttj|jd�|�ttj|jd�dS�Nrr3)�	_testcapir5r"rSrXZINT_MAXZUINT_MAX)rr^r
r
r�test_pipe2_c_limitsoszPosixTester.test_pipe2_c_limitsr�ztest needs posix.utime()cCs�t��}t�tjd�|�ttjtjd�|�ttjtj|df�|�ttjtjd|f�t�tjt|�t|�f�t�tj||f�dS)Nr�r�r�r
r
r�
test_utimexszPosixTester.test_utimec
Ks
t�|�}|�t|d��|jtjB}z|||fi|��Wn@ty|}z(|jtjkrZ�d}|�	|�WYd}~n
d}~00zvt�|�}|�
|jtjB|j�zt|d�}	Wn4ty�}
z|�
|
jtj�WYd}
~
n
d}
~
00Wt
�||j�nt
�||j�0dS)N�st_flags�2chflag UF_IMMUTABLE not supported by underlying fsr)rSr	r^rra�UF_IMMUTABLEr	r
�
EOPNOTSUPPr�r<rrZr�chflags)rZchflags_funcZtarget_file�kwargsr$�flags�errr�Znew_str�rr
r
r�_test_chflags_regular_file�s$
 
(z&PosixTester._test_chflags_regular_filereztest needs os.chflags()cCs|�tjtj�dSr )rirrerrr`r
r
r�test_chflags�szPosixTester.test_chflags�lchflagsztest needs os.lchflags()cCs(|�tjtj�|jtjtjdd�dS�NFr�)rirrkrrrer`r
r
r�test_lchflags_regular_file�sz&PosixTester.test_lchflags_regular_filec
Cst�tj�}|�t|d��t�tjt�|j�	t�t�
t�}dd�}tj|fD]�}|j
tjB}z|t|�Wn@ty�}z(|jtjkr��d}|�|�WYd}~n
d}~00zLt�tj�}t�
t�}	|�|j
|j
�|�|j
tjB|	j
�W|t|j
�qR|t|j
�0qRdS)NracSstj||dd�Srl)rre)rwrgr
r
r�chflags_nofollow�sz;PosixTester.test_lchflags_symlink.<locals>.chflags_nofollowrb)rSr	rrr^rr:r;r�appendr9rrkrarcr	r
rdr�r<)
rZ	testfn_stZdummy_symlink_strn�fnrgrhr�Z
new_testfn_stZnew_dummy_symlink_str
r
r�test_lchflags_symlink�s.
 
�z!PosixTester.test_lchflags_symlinkcCsLtjdkrt}nt}tj��D](\}}|�t|�|�|�t|�|�qdS)N�nt)	rSr7r0r�rry�itemsr<rE)rZ	item_type�k�vr
r
r�test_environ�s
zPosixTester.test_environcCsL|�t��t�dd�Wd�n1s,0Y|�t��t�dd�Wd�n1sb0Y|�t��t�dd�Wd�n1s�0Y|�t��t�dd�Wd�n1s�0Y|�t��t�d	d
�Wd�n1�s0Y|�t��t�dd�Wd�n1�s>0YdS)
NzFRUITVEGETABLEZcabbagesFRUITVEGETABLEscabbageZFRUITzorangeVEGETABLE=cabbagesFRUITsorangeVEGETABLE=cabbagezFRUIT=ORANGEZlemonsFRUIT=ORANGEslemon)r5r�rS�putenvr`r
r
r�test_putenv�s****,zPosixTester.test_putenvr%ztest needs posix.getcwd()c	s�d}t��}tj�tj�d}zVzt�|�t�|�Wn$YWt�|�t�|�dS0Wt�|�t�|�nt�|�t�|�0dS)Nz8getcwd-test-directory-0123456789abcdef-01234567890abcdefz.getcwdrc	s�zt�|�Wnt�d��Yn0t�|�z>t��|dkrX�||t|�d�Wt�d�t�|�nt�d�t�|�0dS)Nz?mkdir cannot create directory sufficiently deep for getcwd testir3z..)rS�mkdirrXrYrvr%r=�rmdir)�dirnameZcurrent_path_length��_create_and_do_getcwdr
rr}�s

�
zEPosixTester.test_getcwd_long_pathnames.<locals>._create_and_do_getcwd)	rSr%rw�abspathrrryrv�rmtree)rr{r_�	base_pathr
r|r�test_getcwd_long_pathnames�s"


�
�
z&PosixTester.test_getcwd_long_pathnames�getgrouplistztest needs posix.getgrouplist()rUztest needs pwd.getpwuid()r1ztest needs os.getuid()cCs<t�t���d}t�t���d}|�|t�||��dS)Nrr;)rTrUrSr1rrr�)r�user�groupr
r
r�test_getgrouplist�szPosixTester.test_getgrouplistr*ztest needs os.getegid()cCst�d��$}|����}|��}Wd�n1s40Yztdd�|��D��}Wntypt�}Yn0|dus~|s�t�	d��t
jdkr�ddl}|�
d�p�d}td	d�|�d
�dd�D��dkr�t�	d
��|�t���}|�|p�|t��hk�dS)Nzid -G 2>/dev/nullcss|]}t|�VqdSr �r�)r��gr
r
r�	<genexpr>r�z-PosixTester.test_getgroups.<locals>.<genexpr>zneed working 'id -G'�darwinrZMACOSX_DEPLOYMENT_TARGETz10.0css|]}t|�VqdSr r�)r�r�r
r
rr�r�rIr�)r�r�z$getgroups(2) is broken prior to 10.6)rS�popenr��stripr�setrxr�rXrYrsr��	sysconfigZget_config_var�tuple�symmetric_differencerr-r^r*)rZidg�groups�retZ
idg_groupsr�ZdtZsymdiffr
r
r�test_getgroupss &

$
zPosixTester.test_getgroups�SIGCHLDz2CLD_XXXX be placed in si_code for a SIGCHLD signal�
waitid_resultztest needs os.waitid_resultcCs(tjtjtjtjtjtjdSr )rS�
CLD_EXITED�
CLD_KILLED�
CLD_DUMPED�CLD_TRAPPED�CLD_STOPPED�
CLD_CONTINUEDr`r
r
r�test_cld_xxxx_constants#sz#PosixTester.test_cld_xxxx_constants�sched_yieldzdon't have scheduling support�sched_setaffinityz!don't have sched affinity supportcCst��dSr )rr�r`r
r
r�test_sched_yield2szPosixTester.test_sched_yield�sched_get_priority_maxz!requires sched_get_priority_max()cCsltj}t�|�}t�|�}|�|t�|�|t�|�||�tjdkrh|�	t
tjd�|�	t
tjd�dS)Nr�i��)r�SCHED_RR�sched_get_priority_minr�r�r�r>rsr�r5r	)rZpol�lo�hir
r
r�test_sched_priority7s


zPosixTester.test_sched_priorityc
Cs�dd�tj��D�}t�d�}|�||�zt�t���}Wn2tyn}z|jtj	krZ�WYd}~nd}~00|�||�|�
ttjd�|�
ttjd�t�d�}|�|j
t�tj�d��s*zt�d||�t�d|�Wn6t�y}z|jtj	k�r�WYd}~n
d}~00|�
ttjd|�|�
ttjd||�|�
ttjd|d�|�
ttjdd�t�d�}|�
ttjd|�d}t�|�}|�
ttjd|�tj|d�}|�
ttjd|�dS)	NcSsg|]\}}|�d�r|�qS)ZSCHED_�r�)r�r7Zschedr
r
rr�Is
�zDPosixTester.test_get_and_set_scheduler_and_param.<locals>.<listcomp>rrE�r�r��+l���)�sched_priority)r�__dict__rsrrrSr0r	r
rZr5�sched_getparamr�r�r�rsr�r��sched_setscheduler�sched_setparamr6�sched_paramr")rZpossible_schedulersZmine�parentrZparamZlarger
r
r�$test_get_and_set_scheduler_and_paramGs>



z0PosixTester.test_get_and_set_scheduler_and_param�sched_rr_get_intervalzno functionc
Cstzt�d�}Wn<tyJ}z$|jtjkr,�|�d�WYd}~n
d}~00|�|t�|�|d�|�	|d�dS)Nrz only works on SCHED_RR processesgg�?)
rr�r	r
r�r�r�rr>�
assertLess)r�intervalrr
r
r�test_sched_rr_get_intervalps z&PosixTester.test_sched_rr_get_intervalcCstt�d�}|�|t�|�t|�d�tj�d�sB|�	t
tjd�|D](}|�|t�|�|d�|�|d�qFdS)Nrr3r�rEr)
r�sched_getaffinityr�r�r>r=rsr�r�r5r	r�r�)r�maskZcpur
r
r�test_sched_getaffinitys
z"PosixTester.test_sched_getaffinitycCs�t�d�}t|�dkr|��t�d|�|�t�d�|�|�ttjdg�|�ttjddg�|�ttjdt	t
d��|�ttjddd>g�tj
�d�s�|�ttjd|�dS)Nrr3i����Z0X�r�rE)rr�r=�popr�r<r5r	r��mapr�r"rsr�r�)rr�r
r
r�test_sched_setaffinity�s
z"PosixTester.test_sched_setaffinitycCstjtjtjtjdSr )r�	RTLD_LAZY�RTLD_NOW�RTLD_GLOBAL�
RTLD_LOCALr`r
r
r�test_rtld_constants�szPosixTester.test_rtld_constants�	SEEK_HOLEz(test needs an OS that reports file holesc
Cs�ttjd���}|�d�|��|��}|��}znt|�D]4}|�|t	�
||t	j��|�|t	�
||t	j
��q:|�tt	j
||t	j�|�tt	j
||t	j
�Wnty�t�d��Yn0Wd�n1s�0YdS)Nzr+bshellozOSError raised!)rrrrgrh�tellrc�ranger<rSr��	SEEK_DATAZassertLessEqualr�r5r	rXrY)rrr�Zfnor�r
r
r�
test_fs_holes�s	
zPosixTester.test_fs_holescCs�dD]�}tt|d�}|durqdtjfD]\}z|d|�Wq(ty�}z0|�d�|�t|��WYd}~qWYd}~q(d}~00q(|�d|�qdS)zf
        Test functions that call path_error2(), providing two filenames in their exceptions.
        )�rename�replace�linkNZnoodly2Zdoesnotexistfilenamez'doesnotexistfilename' -> '{}'z#No valid path_error2() test for os.)	r4rSrrr	r�formatr0r[)rr7�function�dstrr
r
r�test_path_error2�s&zPosixTester.test_path_error2c	Cs�tj}|d}|�tj|�t�|�d}zT|�t��$t�|tjtj	B�}Wd�n1s`0YW|dur�t�
|�n|dur�t�
|�0|�tj�
|��|�ttj|�|�tj�
|��t|d��
�|�ttj|�dS)N��wb)rrr�r!r5r�rSrr�r�rr�rw�existsryr	�rrpZfn_with_NULr�r
r
r�test_path_with_null_character�s"
4�z)PosixTester.test_path_with_null_characterc	Cs�t�tj�}|d}|�tj|�t�|�d}zT|�t��$t�|tj	tj
B�}Wd�n1sf0YW|dur�t�|�n|dur�t�|�0|�tj
�|��|�ttj|�|�tj
�|��t|d���|�ttj|�dS)Nr�r�)rSr
rrr�r!r5r�rr�r�rr�rwr�ryr	r�r
r
r�test_path_with_null_byte�s"
4�z$PosixTester.test_path_with_null_byte�
pidfd_openzpidfd_open unavailablecCs�|�t��}t�d�Wd�n1s*0Y|jjtjkrL|�d�t|jt	�rj|�d|j���|�
|jjtj�t�t�t�
�d��dS)NrEz"system does not support pidfd_openzpidfd_open syscall blocked: r)r5r	rSr�r�r
rr��
isinstancerr<r�rr.)rr�r
r
r�test_pidfd_open�s(
zPosixTester.test_pidfd_open)m�__name__�
__module__�__qualname__rr#r8rX�
skipUnlessrrr@rBrHrJrMrNr\rardrirlr4rS�supports_fdr|r�r�r�r�r�r��requires_32br�r�r�r�r�r�r�r�r�r�r��supports_follow_symlinksr�r�r�r�r�r�r�r�rZrequires_linux_versionr�rrrrrr	rr&r2r5r7r<r=r?r@rCrHr>rLrOrQrSrWr\Zcpython_onlyr_r`rirjrmrqrvrxr�rTr�r��signalr�Zrequires_sched_hZrequires_sched_affinityr�r��requires_schedr�r�r�r�r�r�r�r�r�r�r
r
r
rr*s�
�
�
�
�
�
�
�
�
�
�



	
<








	�
�
�
�




	
�
	�
�
	�
�
�

�

;
	


�



�


	


 	
#
���
(�rc@s�eZdZdZedd��Zedd��Ze�e	j
e	jvd�dd��Ze�e	j
e	jvd	�d
d��Ze�ee	d�ote	je	jvd
�dd��Ze�e	je	jvd�dd��Ze�e	je	jvd�dd��Ze�e	je	jvd�dd��Ze�e	je	jvd�dd��Ze�ee	d��oe	je	jv�oeed�d�dd ��Ze�e	je	jvd!�d"d#��Ze�ee	d$��o\e	je	jvd%�d&d'��Ze�e	j e	jvd(�d)d*��Z!e�e	j"e	jvd+�d,d-��Z#e�e	j$e	jvd.�d/d0��Z%e�e	j&e	jvd1�d2d3��Z'd4S)5�TestPosixDirFdrccs�tjd7_tj�d|j��}tj�d|j�d�}t�|�|�tj|�tj	�
||�}t�|��}|||fVWd�n1s�0YdS)Nr3�_�base)r��countrrrryr�rzrSrw�joinZopen_dir_fd)rr7�base_dir�fullnamerr
r
r�prepares
zTestPosixDirFd.prepareccsV|���:\}}}t�|�|�tj|�|||fVWd�n1sH0YdSr )r�rr4r�rr!�rrr7r�r
r
r�prepare_files
zTestPosixDirFd.prepare_filez)test needs dir_fd support for os.access()cCsJ|���.\}}}|�tj|tj|d��Wd�n1s<0YdS�N�r)r�r^rrMrSrNr�r
r
r�test_access_dir_fdsz!TestPosixDirFd.test_access_dir_fdz'test needs dir_fd support in os.chmod()cCs~|���b\}}}t�|tj�tj|tjtjB|d�t�|�}|�|jtj@tjtjB�Wd�n1sp0YdSr�)	r�r�chmodr	rrr<r�S_IRWXU)rrr7r��sr
r
r�test_chmod_dir_fds

�z TestPosixDirFd.test_chmod_dir_fdr3z'test needs dir_fd support in os.chown()cCsL|���0\}}}tj|t��t��|d�Wd�n1s>0YdSr�)r�rr3rSr1r,r�r
r
r�test_chown_dir_fd%sz TestPosixDirFd.test_chown_dir_fdz&test needs dir_fd support in os.stat()c	Cs�|����\}}}t|d��}|�d�Wd�n1s:0Y|�tj|�t�|�}tj||d�}|�||�tj|dd�}|�||�|jt	dtj|t�
�d�|jt	dtj|t|�d�|jt
tj|dd�Wd�n1s�0YdS)Nrkz	testline
r�zshould be integer or None, notl F�x:^V)r�rrgr�rr!r	r<r
r6r%rr5r")rrr7r��outfile�s1�s2r
r
r�test_stat_dir_fd+s$(
���zTestPosixDirFd.test_stat_dir_fdz'test needs dir_fd support in os.utime()c	Cs�|����n\}}}t��}tj|d|d�tj||d�|jttj|||d�|jttj|d|d�|jttj||df|d�|jttj|d|f|d�|jttj||df|d�tj|t|�t|�f|d�tj|||f|d�tj|t|�t|t|�d�f|d�tj||t|�t|t|�d�fd�tjtjv�rjztj|d|d�Wnt	�yhYn0Wd�n1�s�0YdS)Nr�r��xr�)rr(F)r�r)
r�r�rr�r5r6r�rSr�r�)rrr7r�r�r
r
r�test_utime_dir_fd?s@�������z TestPosixDirFd.test_utime_dir_fdz&test needs dir_fd support in os.link()cCs�|����\}}}|����\}}}ztj||||d�Wn2tyh}z|�d|�WYd}~n
d}~00|�tj|�|�t�	|�dt�	|�d�Wd�n1s�0YWd�n1s�0YdS)N��
src_dir_fd�
dst_dir_fdzposix.link(): %sr3)
r�r�rr�rr�r�r!r<r	)rrr7r��dir_fd2ZlinknameZfulllinknamerr
r
r�test_link_dir_fd^s�$�zTestPosixDirFd.test_link_dir_fdz'test needs dir_fd support in os.mkdir()cCsX|���<\}}}tj||d�|�tj|�t�|�Wd�n1sJ0YdSr�)r�rryr�rzr	r�r
r
r�test_mkdir_dir_fdksz TestPosixDirFd.test_mkdir_dir_fdrrzAtest requires both stat.S_IFIFO and dir_fd support for os.mknod()cCs�|����\}}}tjtjBtjB}ztj||d|d�Wn>tyv}z&|�|j	t	j
t	jt	jf�WYd}~n0d}~00|�
tj|�|�t�t�|�j��Wd�n1s�0YdS)Nrr�)r�r	rrrrrr	rr
rZr�rr�r!r^rr)rrr7r�rrr
r
r�test_mknod_dir_fdrs0z TestPosixDirFd.test_mknod_dir_fdz&test needs dir_fd support in os.open()c
Cs�|����\}}}t|d��}|�d�Wd�n1s:0Y|�tj|�tj|tj|d�}z&t�|d�}|�d|�Wt�	|�nt�	|�0Wd�n1s�0YdS)Nr�s	testline
r��	)
r�rrgr�rr!rur�r<r)rrr7r�r�r�r�r
r
r�test_open_dir_fd�s(zTestPosixDirFd.test_open_dir_fd�readlinkz*test needs dir_fd support in os.readlink()cCsb|���F\}}}t�d|�|�tj|�|�tj||d�d�Wd�n1sT0YdS�Nr:r�)r�rSr:r�rr!r<r�r�r
r
r�test_readlink_dir_fd�sz#TestPosixDirFd.test_readlink_dir_fdz(test needs dir_fd support in os.rename()c	Cs�|���l\}}}|���>\}}}tj||||d�t�|�t�||�Wd�n1s\0YWd�n1sz0YdS)Nr�)r�r�rr�r	)rrr7r�r�Zname2Z	fullname2r
r
r�test_rename_dir_fd�s��
z!TestPosixDirFd.test_rename_dir_fdz)test needs dir_fd support in os.symlink()cCsb|���F\}}}tjd||d�|�tj|�|�t�|�d�Wd�n1sT0YdSr)r�rr:r�r!r<r�r�r
r
r�test_symlink_dir_fd�sz"TestPosixDirFd.test_symlink_dir_fdz(test needs dir_fd support in os.unlink()cCs�|���j\}}}t�|�t�|�z"tj||d�|�ttj|�Wn|�tj|��Yn0Wd�n1sx0YdSr�)	r�rr4rr	r!r5r	r�r�r
r
r�test_unlink_dir_fd�s

z!TestPosixDirFd.test_unlink_dir_fdz(test needs dir_fd support in os.mkfifo()cCs�|����\}}}ztj|tjtjB|d�Wn2ty^}z|�d|�WYd}~n
d}~00|�tj	|�|�
t�t�|�j��Wd�n1s�0YdS)Nr�r)
r�rrr	rrrr�r�r!r^rr)rrr7r�rr
r
r�test_mkfifo_dir_fd�s$z!TestPosixDirFd.test_mkfifo_dir_fdN)(r�r�r�r�rr�r�rXr�rSrM�supports_dir_fdr�r�r�rr3r�r	r�r�r�r�r�ryr�rr�rr�r�rr�rr:rr!rrrr
r
r
rr�sT



�





��

�



r�c@sPeZdZdd�Zdd�Ze�eed�d�dd��Z	e�eed	�d
�dd��Z
d
S)�PosixGroupsTestercCsLt��dkrt�d��ttd�s*t�d��tjdkr>t�d��t��|_dS)Nrznot enough privilegesr-zneed posix.getgroupsr�zgetgroups(2) is broken on OSX)	rr1rXrYrrsr�r-�saved_groupsr`r
r
rr�s




zPosixGroupsTester.setUpcCsHttd�rt�|j�n,ttd�rDt�t���j}t�||jd�dS)N�	setgroupsrOr)	rrr	rrTrUr1rVrO�rr7r
r
rr#�s


zPosixGroupsTester.tearDownrOztest needs posix.initgroups()cCsDt|jpdg�d}t�t���j}t�||�|�|t�	��dSr])
�maxrrTrUrr1rVrOrr-)rr�r7r
r
rr\�sz!PosixGroupsTester.test_initgroupsr	ztest needs posix.setgroups()cCs6dgttd��fD]}t�|�|�|t���qdS)Nr�)r�r�rr	ZassertListEqualr-)rr�r
r
r�test_setgroups�s
z PosixGroupsTester.test_setgroupsN)r�r�r�rr#rXr�rrr\r
r
r
r
rr�s	�
�rc@s,eZdZejddddfZdZdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Ze�eed�d�dd��Zd d!�Zd"d#�Ze�eed�d�d$d%��Zd&d'�Zee�ej�d(�d)�d*d+���Zee�ej�d(�d)�d,d-���Z d.d/�Z!d0d1�Z"d2d3�Z#d4d5�Z$d6d7�Z%dS)8�_PosixSpawnMixin�-I�-SrorpNcGstjddg|�RS)Nrr)rsrt�r�argsr
r
r�python_args�sz_PosixSpawnMixin.python_argscCs�tj}|�tj|�d|�d�}|�d|�}|�|d|tj�}tj|dd�t	|��$}|�
|��t|��Wd�n1s�0YdS)N�2if 1:
            import os
            with open(zO, "w") as pidfile:
                pidfile.write(str(os.getpid()))
            rorrq)
rrr�r!r�
spawn_funcrSryrzrr<r�r0)rZpidfile�scriptrr{rKr
r
r�test_returns_pid�s�
z!_PosixSpawnMixin.test_returns_pidc
Cs~d}z|�||gtj�}Wn6ttfyP}z|�|j|�WYd}~n2d}~00t�|d�\}}|�||�|�|d�dS)N�no_such_executabler)	rrSry�FileNotFoundErrorrr<�filename�waitpid�assertNotEqual)rrr{�excZpid2�statusr
r
r�test_no_such_executables�$z(_PosixSpawnMixin.test_no_such_executablecCs�tj}|�tj|�d|�d�}|�d|�}|�|d|itj�ddi��}tj|dd�t	|�� }|�
|��d�Wd�n1s�0YdS)NrzL, "w") as envfile:
                envfile.write(os.environ['foo'])
        rorrPZbarrq)rrr�r!rrrSryrzrr<r�)rZenvfilerrr{rKr
r
r�test_specify_environments��
z)_PosixSpawnMixin.test_specify_environmentcCs.|j|jd|jtjdd�}tj|dd�dS�Nr��file_actionsrq�r�NOOP_PROGRAMrSryrrz�rr{r
r
r�test_none_file_actionss�z'_PosixSpawnMixin.test_none_file_actionscCs.|j|jd|jtjgd�}tj|dd�dSr!r$r&r
r
r�test_empty_file_actions's�z(_PosixSpawnMixin.test_empty_file_actionscCs0|jtjtjddgtjdd�}tj|dd�dS)NrorpF�Zresetidsrrq�rrsrtrSryrrzr&r
r
r�test_resetids_explicit_default0s
�z/_PosixSpawnMixin.test_resetids_explicit_defaultcCs0|jtjtjddgtjdd�}tj|dd�dS)NrorpTr)rrqr*r&r
r
r�
test_resetids9s
�z_PosixSpawnMixin.test_resetidscCsL|�t��.|jtjtjddgtjdd�Wd�n1s>0YdS)Nrorpr)�r5r6rrsrtrSryr`r
r
r�test_resetids_wrong_typeBs

�z)_PosixSpawnMixin.test_resetids_wrong_typecCs4|jtjtjddgtjt��d�}tj|dd�dS)Nrorp�Z	setpgrouprrq)rrsrtrSryr/rrzr&r
r
r�test_setpgroupHs
�z_PosixSpawnMixin.test_setpgroupcCsL|�t��.|jtjtjddgtjdd�Wd�n1s>0YdS)NrorpZ023r/r-r`r
r
r�test_setpgroup_wrong_typeQs

�z*_PosixSpawnMixin.test_setpgroup_wrong_type�pthread_sigmaskzneed signal.pthread_sigmask()cCs>t�d�}|jtjtjd|gtjtjgd�}t	j
|dd�dS)N�I            import signal
            signal.raise_signal(signal.SIGUSR1)ro�Z
setsigmaskrrq)�textwrap�dedentrrsrtrSryr��SIGUSR1rrz)rr�r{r
r
r�test_setsigmaskWs

�z _PosixSpawnMixin.test_setsigmaskcCs�|�t��.|jtjtjddgtjdd�Wd�n1s>0Y|�t��0|jtjtjddgtjdgd�Wd�n1s�0Y|�t��:|jtjtjddgtjtj	tj	dgd�Wd�n1s�0YdS)Nrorp�"r4�jr3�
r5r6rrsrtrSryr�r��NSIGr`r
r
r�test_setsigmask_wrong_typefs"
�$
�$
��z+_PosixSpawnMixin.test_setsigmask_wrong_typec	
Cst��\}}|�tj|�z�t�|d�t�d|�d��}z"|jtj	tj	d|gtj
dd�}Wnfty�}z|�d|���WYd}~n<d}~0t
y�}z|�d|���WYd}~n
d}~00Wt�|�nt�|�0tj|dd	�t�|d
�}t|�}t�t���}|�||�dS)NTz0
                import os
                fd = z`
                sid = os.getsid(0)
                os.write(fd, str(sid).encode())
            ro)�setsidzsetsid is not supported: zsetsid failed with: rrqr�)rSrTr�r�set_inheritabler5r6rrsrtryr�r�rrrzr�r��getsidr.r)	rZrfdZwfdr�r{r�outputZ	child_sidZ
parent_sidr
r
r�test_setsidus,�

�
$(z_PosixSpawnMixin.test_setsidc
Csvt�tjtj�}t�d�}z4|jtjtjd|gtj	tjgd�}Wt�tj|�nt�tj|�0t
j|tjd�dS)Nr3ro��	setsigdefrq)r�r7�SIG_IGNr5r6rrsrtrSryrrz)rZoriginal_handlerr�r{r
r
r�test_setsigdef�s

� z_PosixSpawnMixin.test_setsigdefcCs�|�t��.|jtjtjddgtjdd�Wd�n1s>0Y|�t��0|jtjtjddgtjdgd�Wd�n1s�0Y|�t��:|jtjtjddgtjtj	tj	dgd�Wd�n1s�0YdS)Nrorpr9rCr:r3r;r`r
r
r�test_setsigdef_wrong_type�s
�$
�$
�z*_PosixSpawnMixin.test_setsigdef_wrong_typer�zbpo-34685: test can fail on BSDcCsft�d�}t�|�}t�d|�d|�d��}|jtjtjd|gtjdt�	|�fd�}t
j|dd�dS�NrzF            import os, sys
            if os.sched_getscheduler(0) != zV:
                sys.exit(101)
            if os.sched_getparam(0).sched_priority != z:
                sys.exit(102)ro)Z	schedulerrq�rSrr�r5r6rrsrtryr�rrz�rZpolicy�priorityr�r{r
r
r�test_setscheduler_only_param�s

��

�z-_PosixSpawnMixin.test_setscheduler_only_paramcCsft�d�}t�|�}t�d|�d|�d��}|jtjtjd|gtj|t�	|�fd�}t
j|dd�dSrHrIrJr
r
r�test_setscheduler_with_policy�s

��

�z._PosixSpawnMixin.test_setscheduler_with_policycCs\tjdtj�t�tjdftjdftjddfg}|j|j	d|j	tj
|d�}tj|dd�dS)Nr;rr3r�r"rq)
rS�POSIX_SPAWN_OPENrw�realpath�__file__ru�POSIX_SPAWN_CLOSE�POSIX_SPAWN_DUP2rr%ryrrz)rr#r{r
r
r�test_multiple_file_actions�s
��z+_PosixSpawnMixin.test_multiple_file_actionsc
CsX|j}|�t��*|j|d|tjdgd�Wd�n1s@0Y|�t��*|j|d|tjdgd�Wd�n1s�0Y|�t��*|j|d|tjdgd�Wd�n1s�0Y|�t��*|j|d|tjdgd�Wd�n1�s0Y|�t��.|j|d|tjtjfgd�Wd�n1�sX0Y|�t��2|j|d|tjtjddfgd�Wd�n1�s�0Y|�t��0|j|d|tjtjdfgd�Wd�n1�s�0Y|�t��<|j|d|tjtjdt	d	tj
dfgd�Wd�n1�sJ0YdS)
Nrr"r
r )i90r3r�r;r�)r%r5r6rrSryrQr�rNrPrurr
r
r�test_bad_file_actions�sH�$�$�$�&�&�&
�&��z&_PosixSpawnMixin.test_bad_file_actionscCs�tj}|�tj|�d}tjd|tjtjBtjBt	j
t	jBfg}|�d|�}|j
|d|tj|d�}tj|dd�t|�� }|�|��d�Wd�n1s�0YdS)N�Oif 1:
            import sys
            sys.stdout.write("hello")
            r3rorr"rq�hello)rrr�r!rSrNr�r��O_TRUNCr	rrrrryrzrr<r�)rr�rr#rr{rKr
r
r�test_open_files
���
z_PosixSpawnMixin.test_open_filecCs�tj}|�tj|�d|�d�}|�d|�}|j|d|tjtjdfgd�}tj	|dd�t
|��&}|�|��dt
j�Wd�n1s�0YdS)Nz�if 1:
            import os
            try:
                os.fstat(0)
            except OSError as e:
                with open(z_, 'w') as closefile:
                    closefile.write('is closed %d' % e.errno)
            rorr"rqzis closed %d)rrr�r!rrrSryrQrzrr<r�r
r�)rZ	closefilerrr{rKr
r
r�test_close_files�
�
z _PosixSpawnMixin.test_close_filecCs�tj}|�tj|�d}t|d��T}tj|��dfg}|�d|�}|j	|d|tj
|d�}tj|dd�Wd�n1s|0Yt|�� }|�|�
�d�Wd�n1s�0YdS)	NrUr�r3rorr"rqrV)rrr�r!rrSrRrcrrryrzr<r�)rZdupfilerZ	childfiler#rr{rKr
r
rr�-s��,
z_PosixSpawnMixin.test_dup2)&r�r�r�rsrtr%rrrrr r'r(r+r,r.r0r1rXr�rr�r8r=rBrFrGr�ZskipIfr�r�rLrMrSrTrXrYr�r
r
r
rr�sN					�

�
��r�posix_spawnztest needs os.posix_spawnc@seZdZeedd�ZdS)�TestPosixSpawnrZN)r�r�r�r4rrr
r
r
rr[@sr[�posix_spawnpztest needs os.posix_spawnpc@s&eZdZeedd�Zejdd��ZdS)�TestPosixSpawnPr\NcCs�t��}|�tj|�d}tj�||�}t�t	j
|�ztj�|tjdf�}Wnt
yf|}Yn0|ddddf}t�d|f�}d|f}t|d|i�dS)Nzposix_spawnp_test_program.exe�PATHrrrorpz�
            import os
            from test import support

            args = %a
            pid = os.posix_spawnp(args[0], args, os.environ)

            support.wait_process(pid, exitcode=0)
        )�tempfile�mkdtempr�rrrSrwr�r:rsrt�pathsepryrWr5r6r)r�temp_dirZprogramZprogram_fullpathrwZ
spawn_argsr�rr
r
r�test_posix_spawnpIs
�
z!TestPosixSpawnP.test_posix_spawnp)	r�r�r�r4rrrZskip_unless_symlinkrcr
r
r
rr]Esr]r�ztest weak linking on macOSc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%S)&�TestPosixWeaklinkingcsRddl}ddl}|����fdd��D�|_tdd�|��d�d�D��|_dS)Nrcs"h|]}|�d�r�|r|�qS)ZHAVE_r�)r�Znm�Zconfig_varsr
r�	<setcomp>vr�z-TestPosixWeaklinking.setUp.<locals>.<setcomp>css|]}t|�VqdSr r�)r��partr
r
rr�wr�z-TestPosixWeaklinking.setUp.<locals>.<genexpr>rI)r�r�Zget_config_vars�	availabler��mac_verrx)rr�r�r
rerrqs
zTestPosixWeaklinking.setUpcCs||jvrt�|�d���dS)Nz not weak-linked)rhrXrYr
r
r
r�_verify_availableys
z&TestPosixWeaklinking._verify_availablecCsb|�d�|jdkr:|�ttd�d�|�ttd�d�n$|�ttd�d�|�ttd�d�dS)	NZHAVE_PWRITEV)r�rr�zos.pwritev is not availabler�zos.readv is not availablezos.pwritev is availablezos.readv is available)rjrir^rrSr�r`r
r
rr�}s

z!TestPosixWeaklinking.test_pwritevcCsp|�d�|jdkr$|�dtj�nH|�dtj�|�td��tj	ddd�Wd�n1sb0YdS)NZHAVE_FSTATAT�r�r��dir_fd unavailable�filerr�)
rjrirr�_have_functions�assertNotInr
r�rSr	r`r
r
rr�s

zTestPosixWeaklinking.test_statcCs�|�d�|jdkr$|�dtj�n�|�dtj�|�td��"tj	dtj
dd�Wd�n1sf0Y|�td��"tj	dtj
dd	�Wd�n1s�0Y|�td
��"tj	dtj
dd�Wd�n1s�0YdS)
NZHAVE_FACCESSATrkrlrmrr�zfollow_symlinks unavailableFr�zeffective_ids unavailableT)Z
effective_ids)rjrirrrnror
r�rSrMrNr`r
r
rrO�s

00z TestPosixWeaklinking.test_accesscCs�|�d�|jdkr$|�dtj�nX|�dtj�|�dtj�|�td�� tj	dddd�Wd�n1sr0YdS)	NZ
HAVE_FCHMODATrkZHAVE_LCHMODrlrmi�rr�)
rjrirrrnror
r�rSr�r`r
r
r�
test_chmod�s

zTestPosixWeaklinking.test_chmodcCs�|�d�|jdkr$|�dtj�nZ|�dtj�|�dtj�|�td��"tj	ddddd�Wd�n1st0YdS)NZ
HAVE_FCHOWNATrkZHAVE_LCHOWNrlrmrr�)
rjrirrrnror
r�rSr3r`r
r
rr5�s

zTestPosixWeaklinking.test_chownc	Cs�|�d�|jdkr&|�dtj��n�|�dtj�|�td�� tj	dddd�Wd�n1sf0Y|�td�� tj	dddd	�Wd�n1s�0Y|�td��"tj	ddddd
�Wd�n1s�0Yt
����}tj�
|d�}tj�
|d�}tj�
|d�}t|d��}|�d
�Wd�n1�sJ0Yt�d|�|�t�� tj	||dd�Wd�n1�s�0Y|�t�� tj	||dd�Wd�n1�s�0YWd�n1�s�0YdS)NZHAVE_LINKATrkzsrc_dir_fd unavailable�source�targetr�r�zdst_dir_fd unavailable�r�r�r�rk�dataTr�F)rjrirrrnror
r�rSr�rrbrwr�rrgr:r5�FileExistsError)rr�Z	link_pathZtarget_path�source_pathrr
r
r�	test_link�s*

..0
*0zTestPosixWeaklinking.test_linkcCs�|�d�|jdkr$|�dtj�nz|�dtj�|�td��t�	d�Wd�n1s^0Y|�td��t�
d�Wd�n1s�0YdS)NZHAVE_FDOPENDIRrkzClistdir: path should be string, bytes, os.PathLike or None, not intrzCscandir: path should be string, bytes, os.PathLike or None, not int)rjrirrrnror
r6rSr>�scandirr`r
r
r�test_listdir_scandir�s

(z)TestPosixWeaklinking.test_listdir_scandircCsp|�d�|jdkr$|�dtj�nH|�dtj�|�td��tj	ddd�Wd�n1sb0YdS)NZHAVE_MKDIRATrkrl�dirrr�)
rjrirrrnror
r�rSryr`r
r
r�
test_mkdir�s

zTestPosixWeaklinking.test_mkdircCsp|�d�|jdkr$|�dtj�nH|�dtj�|�td��tj	ddd�Wd�n1sb0YdS)NZ
HAVE_MKFIFOAT�rQrrlrwrr�)
rjrirrrnror
r�rSrr`r
r
rr�s

z TestPosixWeaklinking.test_mkfifocCsp|�d�|jdkr$|�dtj�nH|�dtj�|�td��tj	ddd�Wd�n1sb0YdS)NZHAVE_MKNODATr}rlrwrr�)
rjrirrrnror
r�rSrr`r
r
rrs

zTestPosixWeaklinking.test_mknodcCs*|�d�|jdkr&|�dtj��n|�dtj�|�td�� tj	dddd�Wd�n1sf0Y|�td�� tj	dddd�Wd�n1s�0Y|�td�� tj
dddd�Wd�n1s�0Y|�td�� tj
dddd�Wd�n1�s0YdS)	NZ
HAVE_RENAMEATrkz%src_dir_fd and dst_dir_fd unavailable�a�brrsrt)rjrirrrnror
r�rSr�r�r`r
r
r�test_rename_replaces

...z(TestPosixWeaklinking.test_rename_replacecCs�|�d�|jdkr$|�dtj�n�|�dtj�|�td��tj	ddd�Wd�n1sb0Y|�td��tj
ddd�Wd�n1s�0YdS)NZ
HAVE_UNLINKATrkrlrwrr�)rjrirrrnror
r�rSr!rzr`r
r
r�test_unlink_rmdir%s

,z&TestPosixWeaklinking.test_unlink_rmdircCst|�d�|jdkr$|�dtj�nL|�dtj�|�td��"tj	dtj
dd�Wd�n1sf0YdS)NZHAVE_OPENATrkrlrwrr�)rjrirrrnror
r�rSrrur`r
r
r�	test_open3s

zTestPosixWeaklinking.test_opencCsp|�d�|jdkr$|�dtj�nH|�dtj�|�td��tj	ddd�Wd�n1sb0YdS)NZHAVE_READLINKATrkrlrwrr�)
rjrirrrnror
r�rSr�r`r
r
r�
test_readlink>s

z"TestPosixWeaklinking.test_readlinkcCsr|�d�|jdkr$|�dtj�nJ|�dtj�|�td�� tj	dddd�Wd�n1sd0YdS)NZHAVE_SYMLINKATrkrlr~rrr�)
rjrirrrnror
r�rSr:r`r
r
r�test_symlinkIs

z!TestPosixWeaklinking.test_symlinkcCs�|�d�|�d�|jdkr<|�dtj�|�dtj�nV|�dtj�|�dtj�|�td��tj	ddd�Wd�n1s�0YdS)NZ
HAVE_FUTIMENSZHAVE_UTIMENSAT)r�rQrlrwrr�)
rjrirrrnror
r�rSr�r`r
r
rr`Ts


zTestPosixWeaklinking.test_utimeN)r�r�r�rrjr�rrOrpr5rxrzr|rrr�r�r�r�r�r`r
r
r
rrdjs$
'rdcCst��dSr )r�
reap_childrenr
r
r
r�tearDownModulecsr��__main__)+�__doc__rfrZtest.support.script_helperr�
import_modulerr
rsr�r�rSr�rTr	r_rXrr5�
contextlibrrwr��
gettempdirrr;r��maxsizer�rr�ZTestCaserr�rrrr[r]rdr�r��mainr
r
r
r�<module>sd
��
`A$]$y


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists