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

�iI]�@s�dZddlmZddlmZddlmZddlmZddlmZe�	d�Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZdd	lmZej�e��ejd
�Ze�ejdkd�Z d
d�Z!e�e!�d�Z"Gdd�dej#�Z$Gdd�dej#�Z%Gdd�dej#�Z&Gdd�d�Z'e�e(ed�d�Gdd�dej#e'��Z)e�e(ed�d�Gdd�dej#e'��Z*e�ejd kd!�Gd"d#�d#ej#��Z+d$d%�Z,e-d&kr�e�.�dSdS)'zTest posix functions�)�support)�
import_helper)�	os_helper)�warnings_helper)�assert_python_ok�posixN)�contextmanagerz-dummy-symlink�z(test is only meaningful on 32-bit buildsc
Cs`ttd�sdSzt�d�WdSty/}z|jtjkr$WYd}~dSWYd}~dSd}~ww)N�sched_getschedulerFrT)�hasattrrr
�OSError�errno�ENOSYS)�e�r�,/usr/local/lib/python3.10/test/test_posix.py�_supports_sched s
�
���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���onee<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��e�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(,�PosixTestercCs\ttjd��Wd�n1swYtjg|_t��|_|j��t�	ddt
�dS)N�wb�ignorez.* potential security risk .*)�openr�TESTFN�teardown_filesrZcheck_warnings�_warnings_manager�	__enter__�warnings�filterwarnings�RuntimeWarning��selfrrr�setUp/s�


�zPosixTester.setUpcCs*|jD]}t�|�q|j�ddd�dS�N)rr�unlinkr�__exit__)rZ
teardown_filerrr�tearDown9s
zPosixTester.tearDowncCs>gd�}|D]}tt|d�}|dur|�|�t|d�qdS)N)�ctermid�getcwd�getcwdb�uname�times�
getloadavg�getegid�geteuid�getgid�	getgroups�getpid�getpgrp�getppid�getuid�sync�)�getattrr�assertRaises�	TypeError)rZNO_ARG_FUNCTIONS�nameZ
posix_funcrrr�testNoArgFunctions>s��zPosixTester.testNoArgFunctions�	getresuidztest needs posix.getresuid()cC�2t��}|�t|�d�|D]}|�|d�qdS�N�r)rr:�assertEqual�len�assertGreaterEqual)rZuser_ids�valrrr�test_getresuidM�
�zPosixTester.test_getresuid�	getresgidztest needs posix.getresgid()cCr;r<)rrDr>r?r@)rZ	group_idsrArrr�test_getresgidUrCzPosixTester.test_getresgid�	setresuidztest needs posix.setresuid()cC�0t��}|�tj|��|�t�ddd��dS�N���)rr:�assertIsNonerF)r�current_user_idsrrr�test_setresuid]�zPosixTester.test_setresuidcC�@t��}d|vr|ddddf}|jttjg|�R�dSdS�Nrr4rI)rr:r6rrF)rrKZnew_user_idsrrr�test_setresuid_exceptione�
�z$PosixTester.test_setresuid_exception�	setresgidztest needs posix.setresgid()cCrGrH)rrDrJrR)r�current_group_idsrrr�test_setresgidnrMzPosixTester.test_setresgidcCrNrO)rrDr6rrR)rrSZ
new_group_idsrrr�test_setresgid_exceptionvrQz$PosixTester.test_setresgid_exception�
initgroupsztest needs os.initgroups()c
Cs�|�ttj�|�ttjd�|�ttjdd�|�ttjddt��t��dkrkz
t�t���j	}Wnt
y?t�d��wzt�|d�Wnt
yc}z|�|jtj�WYd}~dSd}~ww|�d�dSdS)Nr=�foorzneed a pwd entry�
z+Expected OSError to be raised by initgroups)r6r7rrV�object�osr2�pwd�getpwuid�pw_name�KeyError�unittest�SkipTestrr>r
�EPERM�fail)rr8rrrr�test_initgroupss$
����zPosixTester.test_initgroups�statvfsztest needs posix.statvfs()cCs|�t�tj��dSr!)�
assertTruerrdrZ�curdirrrrr�test_statvfs��zPosixTester.test_statvfs�fstatvfsztest needs posix.fstatvfs()cCsLttj�}z|�t�|����|�t�|����W|��dS|��wr!)	rrrrerri�filenord�close�r�fprrr�
test_fstatvfs�s

zPosixTester.test_fstatvfs�	ftruncateztest needs posix.ftruncate()cCsHttjd�}z|�d�|��t�|��d�W|��dS|��w)N�w+�testr)	rrr�write�flushrrorjrkrlrrr�test_ftruncate�s
zPosixTester.test_ftruncate�truncateztest needs posix.truncate()cCsPttjd��}|�d�|��Wd�n1swYt�tjd�dS)N�wrqr)rrrrrrsrrurlrrr�
test_truncate�s


�zPosixTester.test_truncate�execveNz/test needs execve() to support the fd parameter�forkztest needs os.fork()c	Cs�t�tjtj�}z8t��}|dkr*t�tj�tj�d�t	�
|tjddgtj�ntj
|dd�Wt�|�dSWt�|�dSt�|�w)Nr�-c�pass��exitcode)rZr�sys�
executable�O_RDONLYry�chdir�path�splitrrx�environr�wait_processrk)rrm�pidrrr�test_fexecve�s�zPosixTester.test_fexecve�waitidztest needs posix.waitid()cCsjt��}|dkr#t�tj�tj�d�t�tjtjddgtj	�dSt�
tj|tj�}|�
||j�dS)Nrrzr{)rZryr�r�r�r~rrrxr�r��P_PID�WEXITEDr>�si_pid)rr��resrrr�test_waitid�szPosixTester.test_waitidcCs,|jtdd��t�dd��Wd�n1swY|jtdd��tjdd�Wd�n1s6wY|jtdd��tjdd	�Wd�n1sSwY|jtdd��tjd
d�Wd�n1spwY|jtdd��tjdd�Wd�n1s�wY|jtdd��tjdd	�Wd�n1s�wY|jtdd��tjdd�Wd�n1s�wY|jtd
d��tjddd�d�Wd�n1s�wY|jtd
d��tjdd�dd�Wd�n	1�swYd}td|�dS)NzPositional args not allowed)�msgcS�dSr!rrrrr�<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=rrrrrr��r�)r�r�cSr�r!rrrrrr��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'!')
            rz)r6r7rZ�register_at_forkr)r�coderrr�test_register_at_fork�s:���������#z!PosixTester.test_register_at_fork�lockfztest needs posix.lockf()c	Cspt�tjtjtjB�}z&t�|d�t�|dtj�t	�
|t	jd�t	�
|t	jd�Wt�
|�dSt�
|�w)N�testr�)rZrrr�O_WRONLY�O_CREATrr�lseek�SEEK_SETrr��F_LOCK�F_ULOCKrk�r�fdrrr�
test_lockfszPosixTester.test_lockf�preadztest needs posix.pread()c	Cszt�tjtjtjB�}z+t�|d�t�|dtj�|�	dt
�|dd��|�	dt
�|d��Wt�
|�dSt�
|�w)Nr�rsesr�r4ste)rZrrr�O_RDWRr�rrr�r�r>rr��readrkr�rrr�
test_preadszPosixTester.test_pread�preadvztest needs posix.preadv()c	Csxt�tjtjtjB�}z*t�|d�dd�dD�}|�t�	||d�d�|�gd�t
|��Wt�|�dSt�|�w)N�test1tt2t3t5t6t6t8cS�g|]}t|��qSr��	bytearray��.0�irrr�
<listcomp>.�z+PosixTester.test_preadv.<locals>.<listcomp>��r=r�r=�
�st1tt2st3ts5t)rZrrrr�r�rrr>rr��listrk)rr��bufrrr�test_preadv)szPosixTester.test_preadv�	RWF_HIPRIztest needs posix.RWF_HIPRIc
Cs�t�tjtjtjB�}z_z&t�|d�dd�dD�}|�t�	||dtj
�d�|�gd�t|��Wn(ty@|�
d�Yn#tyZ}z|jtjtjhvrUt�d	���d}~wwWt�|�dSWt�|�dSt�|�w)
Nr�cSr�rr�r�rrrr�:r�z1PosixTester.test_preadv_flags.<locals>.<listcomp>r�r=r�r�zpreadv2 not availablez0RWF_HIPRI is not supported by the current system)rZrrrr�r�rrr>rr�r�r��NotImplementedError�skipTestrr
�EINVAL�ENOTSUPr_r`rk)rr�r��instrrr�test_preadv_flags4s$
����
zPosixTester.test_preadv_flagsc	Cs�t�tjtjtjB�}z@td�gd}|�t��}t�	||d�Wd�n1s*wY|�
|jjtj
�|�
t|d�dd�Wt�|�dSt�|�w�N���r�)rZrrrr�r�r�r6rr�r>�	exceptionr
r��bytesrk�rr�r��cmrrr�test_preadv_overflow_32bitsJs�z'PosixTester.test_preadv_overflow_32bits�pwriteztest needs posix.pwrite()c	Csrt�tjtjtjB�}z't�|d�t�|dtj�t	�
|dd�|�dt	�|d��Wt�
|�dSt�
|�w)Nr�r�xxr4stxxtr�)rZrrrr�r�rrr�r�rr�r>r�rkr�rrr�test_pwriteWszPosixTester.test_pwrite�pwritevztest needs posix.pwritev()c	Cs�t�tjtjtjB�}z7t�|d�t�|dtj�t�	|gd�d�}|�
|d�t�|dtj�|�
dt�|d��Wt�
|�dSt�
|�w)Nr�r�stest1stt2st3r�r�sxxtest1tt2t3�d)rZrrrr�r�rrr�r�r�r>rr�rk�rr��nrrr�test_pwritevbszPosixTester.test_pwritevzos.RWF_SYNCztest needs os.RWF_SYNCc	Cs�t�tjtjtjB�}z9t�|d�t�|dtj�t�	|gd�dtj
�}|�|d�t�|dtj�|�dt�
|d��Wt�|�dSt�|�w)Nr�rr�r�r�s
xxtest1tt2r�)rZrrrr�r�rrr�r�r��RWF_SYNCr>rr�rkr�rrr�test_pwritev_flagspszPosixTester.test_pwritev_flagsc	Cs�t�tjtjtjB�}z2|�t��}t�|ddgdd�Wd�n1s(wY|�	|j
jtj�Wt�
|�dSt�
|�w)N�xr�r�r)rZrrrr�r�r6rr�r>r�r
r�rk�rr�r�rrr�test_pwritev_overflow_32bitss�z(PosixTester.test_pwritev_overflow_32bits�posix_fallocatez"test needs posix.posix_fallocate()c
Cs�t�tjtjtjB�}z0z	t�|dd�Wnty3}z|j	t	j
kr.tj�
d�r.t�d���d}~wwWt�|�dSt�|�w)Nrr�)Zsunos�freebsd�netbsdZopenbsdZgnukfreebsdz test may fail on ZFS filesystems)rZrrrr�r�rr�rr
r�r~�platform�
startswithr_r`rk)rr�r�rrr�test_posix_fallocate�s�
���z PosixTester.test_posix_fallocatec
CsJz
t�ddd�WdSty$}z|jtjkr�WYd}~dSd}~ww)N����rr�)rr�rr
�EBADF�rr�rrr�test_posix_fallocate_errno�s���z&PosixTester.test_posix_fallocate_errno�
posix_fadvisez test needs posix.posix_fadvise()c	Cs@t�tjtj�}zt�|ddtj�Wt�|�dSt�|�w�Nr)	rZrrrr�rr��POSIX_FADV_WILLNEEDrkr�rrr�test_posix_fadvise�szPosixTester.test_posix_fadvisec
CsNzt�dddtj�WdSty&}z|jtjkr�WYd}~dSd}~ww)Nr�r)rr�r�rr
r�r�rrr�test_posix_fadvise_errno�s���z$PosixTester.test_posix_fadvise_errnoz!test needs fd support in os.utimec	CsNt��}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�|�dSt�|�w)N�NN)�nsr�e��A)
�timerZrrrr�r�utimer6r7�int�
ValueErrorrk)r�nowr�rrr�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�rrr6r7r��rr�rrr�test_utime_nofollow_symlinks�s ����z(PosixTester.test_utime_nofollow_symlinks�writevztest needs posix.writev()c	Cs�t�tjtjtjB�}zFt�|d�}|�|d�t�|dtj	�|�dt
�|d��zt
�|g�}Wn	ty;Ynw|�|d�Wt�
|�dSWt�
|�dSt�
|�w)Nr�r�r�
test1tt2t3)rZrrrr�r�r�r>r�r�rr�rrk)rr�r��sizerrr�test_writev�s��zPosixTester.test_writevc	Cs�t�tjtjtjB�}z1|�t��}t�|ddgd�Wd�n1s'wY|�	|j
jtj�Wt�
|�dSt�
|�w)Nr�r�r�)rZrrrr�r�r6rr�r>r�r
r�rkr�rrr�test_writev_overflow_32bits�s�z'PosixTester.test_writev_overflow_32bits�readvztest needs posix.readv()c	Cs�t�tjtjtjB�}zTt�|d�t�|dtj�dd�dD�}|�	t
�||�d�|�	gd�dd�|D��zt
�|g�}Wn	tyIYnw|�	|d�Wt�
|�dSWt�
|�dSt�
|�w)	Nr�rcSr�rr�r�rrrr�r�z*PosixTester.test_readv.<locals>.<listcomp>r�r�r�cSr�r)r�r�rrrr�r�)rZrrrr�r�rrr�r�r>rr�rrk)rr�r�r�rrr�
test_readv�s ��zPosixTester.test_readvc	Cs�t�tjtjtjB�}z?td�gd}|�t��}t�	||�Wd�n1s)wY|�
|jjtj
�|�
t|d�dd�Wt�|�dSt�|�wr�)rZrrrr�r�r�r6rr�r>r�r
r�r�rkr�rrr�test_readv_overflow_32bitss�z&PosixTester.test_readv_overflow_32bits�dupztest needs posix.dup()cCsHttj�}zt�|���}|�|t�t�	|�W|�	�dS|�	�wr!)
rrrrr�rj�assertIsInstancer�rZrk)rrmr�rrr�test_dup!s
zPosixTester.test_dup�confstrztest needs posix.confstr()cCs.|�ttjd�|�tt�d��dkd�dS)NZ
CS_garbage�CS_PATHrT)r6r�rrr>r?rrrr�test_confstr,szPosixTester.test_confstr�dup2ztest needs posix.dup2()cCsRttj�}ttj�}zt�|��|���W|��|��dS|��|��wr!)rrrrrrjrk)r�fp1�fp2rrr�	test_dup22s

�
zPosixTester.test_dup2�	O_CLOEXECzneeds os.O_CLOEXECr���cCs8t�tjtjtjB�}|�tj|�|�t�	|��dSr!)
rZrrrr�r�
addCleanuprk�assertFalse�get_inheritabler�rrr�test_oscloexec=szPosixTester.test_oscloexec�O_EXLOCKztest needs posix.O_EXLOCKcCs�t�tjtjtjBtjB�}|�ttjtjtjtjBtj	B�t�
|�ttd�rOt�tjtjtj
BtjB�}|�ttjtjtjtjBtj	B�t�
|�dSdS)N�O_SHLOCK)rZrrrr�rr�r6r�
O_NONBLOCKrkrrrr�rrr�
test_osexlockDs ��

���zPosixTester.test_osexlockrztest needs posix.O_SHLOCKcCs�t�tjtjtjBtjB�}t�tjtjtjBtjB�}t�|�t�|�tt	d�rQt�tjtjtjBtjB�}|�
ttjtjtjtj
BtjB�t�|�dSdS)Nr)rZrrrr�rr�rkrrr6rr�rr)r�fd1�fd2r�rrr�
test_osshlockTs"��


���zPosixTester.test_osshlock�fstatztest needs posix.fstat()cCsfttj�}z(|�t�|����|�t�|����|�t	dtjt
|����W|��dS|��w�Nz4should be string, bytes, os.PathLike or integer, not)rrrrerrrj�stat�assertRaisesRegexr7�floatrkrlrrr�
test_fstates
�zPosixTester.test_fstatc	Cs�|�t�tj��|�t�t�tj���|�tdtjt	t�tj���|�
tdtjd�|�
tdtjttj��|�
tdtjtt�tj���dSr)
rerrrrrZ�fsencodeZassertWarnsRegex�DeprecationWarningr�rr7r�rrrr�	test_statss$����zPosixTester.test_stat�mkfifozdon't have mkfifo()c
Cs�tjdkrtj�dtj�}ntj}t�|�|�tj|�zt	�
|tjtj
B�WntyB}z
|�d|�WYd}~nd}~ww|�t�t	�|�j��dS)N�vxworksz/fifos/�posix.mkfifo(): %s)r~r�rZr��joinrrr"rrrr�S_IRUSR�S_IWUSR�PermissionErrorr�re�S_ISFIFO�st_mode)rZ	fifo_pathrrrr�test_mkfifo�s

��zPosixTester.test_mkfifo�mknod�S_IFIFOzdon't have mknod()/S_IFIFOc
Cs�t�tj�tjtjBtjB}z
t�tj|d�Wnt	y8}z|�
|jtjtj
tjf�WYd}~nd}~ww|�t�t�tj�j��t�tj�z
tjtj|ddd�WdSt	yy}z|�
|jtjtj
tjf�WYd}~dSd}~ww)Nr)r��modeZdevice�dir_fd)rr"rrr*r#r$rr)r�assertInr
rar��EACCESrer&r')rr+rrrr�
test_mknod�s$&���(��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)NrrI)rrrr�st_devr�r�r@�majorr>r6r7rr��
OverflowError�minorr0)r�st�devr2r4rrr�test_makedev�s.

zPosixTester.test_makedevc
	s����fdd�}t��}t��}|�||�|||�|�d|�|||�|�|d�|||�tjdkr;|dv}n|dk}|rltjdkrHdnd}|�||�|||�|�dd�|||�|�||�|||�n;t��d	vrwt�d
����t	|�dd�|||���t	|�dd�|||�dt�
�vr���t	|�dd�|||�ttfD]"}	��t
|�|	|�|�|||���t
|�||	|��|||�q�dS)z/Common code for chown, fchown and lchown tests.cs4�dur���}��|j|���|j|�dSdSr!)r>�st_uid�st_gid)�uid�gidr��first_paramr�	stat_funcrr�
check_stat�s
�z6PosixTester._test_all_chown_common.<locals>.check_statrIr )rr4rlr�)zHP-UXZSunOSz1Skipping because of non-standard chown() behaviorN)rZr2r-r~r��systemr_r`r6rr.�strrr7)
rZ
chown_funcr=r>r?r:r;Zis_rootZ	big_value�trr<r�_test_all_chown_common�sF











�z"PosixTester._test_all_chown_common�chownztest needs os.chown()cCsFt�tj�|�ttjtjdd�t�tj�|�	tjtjtj
�dSrH)rZr"rrr6rrrD�create_empty_filerCrrrrr�
test_chownszPosixTester.test_chown�fchownztest needs os.fchown()cCsRt�tj�ttjd�}z|��}|�tj|t	tdd��W|�
�dS|�
�w)Nrvr)rZr"rrrrjrCrrGr5rk)rZ	test_filer�rrr�test_fchowns

�zPosixTester.test_fchown�lchownztest needs os.lchown()cCs8t�tj�t�ttj�|�tjtjt	tdd��dS)N�lstat)
rZr"rr�symlink�_DUMMY_SYMLINKrCrrIr5rrrr�test_lchown"s

�zPosixTester.test_lchownr�ztest needs posix.chdir()cCs"t�tj�|�ttjtj�dSr!)rr�rZrfr6rrrrrrr�
test_chdir*szPosixTester.test_chdircCs|�tjt�tj��dSr!)r-rrr�listdirrZrfrrrr�test_listdir/szPosixTester.test_listdircCs|�tjt���dSr!)r-rrrrOrrrr�test_listdir_default2rhz PosixTester.test_listdir_defaultcCs|�t�tj�t�d��dS�N�.)r-rZrrrrrOrrrr�test_listdir_bytes7szPosixTester.test_listdir_bytesc	CsxttfD]5}|�t��t�|d��}Wd�n1swY|�t�t	j
�|�|D]
}|�t|�t
�q.qdSrR)r��
memoryviewZassertWarnsrrrOr-rZrrrZassertIs�typer�)r�cls�namesr8rrr�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&r�rrkr>�sortedrO)r�frrr�test_listdir_fdDs��zPosixTester.test_listdir_fd�accessztest needs posix.access()cCs|�t�tjtj��dSr!)rerr^rrrZ�R_OKrrrr�test_accessSszPosixTester.test_access�umaskztest needs posix.umask()cCs$t�d�}|�|t�t�|�dSr�)rrar�r�)rZold_maskrrr�
test_umaskWs
zPosixTester.test_umask�strerrorztest needs posix.strerror()cCs|�t�d��dSr�)rerrcrrrr�
test_strerror]szPosixTester.test_strerror�pipeztest needs posix.pipe()cCs$t��\}}t�|�t�|�dSr!)rrerZrk)r�reader�writerrrr�	test_pipebs
zPosixTester.test_pipe�pipe2ztest needs os.pipe2()�cCs�|�ttjd�|�ttjdd�t�d�\}}t�|�t�|�t�tjtjB�\}}|�tj|�|�tj|�|�t�	|��|�t�	|��|�t�
|��|�t�
|��|�ttj|d�zt�
|dtj�WdStyzYdSw)NZDEADBEEFrr4r�)r6r7rZrirkrrrrr
�get_blockingrr�rrrZ
PIPE_MAX_SIZE)r�rrvrrr�
test_pipe2hs$

�zPosixTester.test_pipe2cCs8ddl}|�ttj|jd�|�ttj|jd�dS�Nrr4)�	_testcapir6r3rZriZINT_MAXZUINT_MAX)rrorrr�test_pipe2_c_limits�szPosixTester.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�rrr�
test_utime�s
�

�

�zPosixTester.test_utimec
Kst�|�}|�t|d��|jtjB}z|||fi|��Wn ty>}z|jtjkr-�d}|�	|�WYd}~nd}~wwzFt�|�}|�
|jtjB|j�zt|d�}	Wntyq}
z|�
|
jtj�WYd}
~
nd}
~
wwWt
�||j�dSWt
�||j�dSt
�||j�w)N�st_flags�2chflag UF_IMMUTABLE not supported by underlying fsrp)rZrrerrr�UF_IMMUTABLErr
�
EOPNOTSUPPr�r>rrar�chflags)rZchflags_funcZtarget_file�kwargsr5�flags�errr�Znew_str�rrrr�_test_chflags_regular_file�s2
��
����"z&PosixTester._test_chflags_regular_filervztest needs os.chflags()cCs|�tjtj�dSr!)rzrrvrrrrrr�test_chflags�szPosixTester.test_chflags�lchflagsztest needs os.lchflags()cCs(|�tjtj�|jtjtjdd�dS�NFr�)rzrr|rrrvrrrr�test_lchflags_regular_file�s
�z&PosixTester.test_lchflags_regular_filec
Cst�tj�}|�t|d��t�tjt�|j�	t�t�
t�}dd�}tj|fD]]}|j
tjB}z|t|�Wn tyX}z|jtjkrG�d}|�|�WYd}~nd}~wwz&t�tj�}t�
t�}	|�|j
|j
�|�|j
tjB|	j
�W|t|j
�q)|t|j
�wdS)NrrcSstj||dd�Sr})rrv)r�rxrrr�chflags_nofollow�sz;PosixTester.test_lchflags_symlink.<locals>.chflags_nofollowrs)rZrrrrerrKrLr�appendrJrr|rrrtrr
rur�r>)
rZ	testfn_stZdummy_symlink_str�fnrxryr�Z
new_testfn_stZnew_dummy_symlink_strrr�test_lchflags_symlink�s4
��
��z!PosixTester.test_lchflags_symlinkcCsLtjdkrt}nt}tj��D]\}}|�t|�|�|�t|�|�qdS)N�nt)	rZr8rAr�rr��itemsr>rV)rZ	item_type�k�vrrr�test_environ�s
�zPosixTester.test_environcCsJ|�t��t�dd�Wd�n1swY|�t��t�dd�Wd�n1s1wY|�t��t�dd�Wd�n1sLwY|�t��t�dd�Wd�n1sgwY|�t��t�d	d
�Wd�n1s�wY|�t��t�dd�Wd�dS1s�wYdS)
NzFRUITVEGETABLEZcabbagesFRUITVEGETABLEscabbageZFRUITzorangeVEGETABLE=cabbagesFRUITsorangeVEGETABLE=cabbagezFRUIT=ORANGEZlemonsFRUIT=ORANGEslemon)r6r�rZ�putenvrrrr�test_putenv�s$�����"�zPosixTester.test_putenvr&ztest needs posix.getcwd()c	s�d}t��}tj�tj�d}z+zt�|�t�|�WnYWt�|�t�|�dSWt�|�t�|�dSt�|�t�|�w)Nz8getcwd-test-directory-0123456789abcdef-01234567890abcdefz.getcwd)	rZr&r��abspathrr�mkdirr��rmtree)r�dirnamerf�	base_pathr)Z_create_and_do_getcwdr�test_getcwd_long_pathnames�s

�

�z&PosixTester.test_getcwd_long_pathnames�getgrouplistztest needs posix.getgrouplist()r\ztest needs pwd.getpwuid()r2ztest needs os.getuid()cCs<t�t���d}t�t���d}|�|t�||��dS)Nrr=)r[r\rZr2r-rr�)r�user�grouprrr�test_getgrouplistszPosixTester.test_getgrouplistr+ztest needs os.getegid()�popenztest needs os.popen()cCst�d��}|����}|��}Wd�n1swYz
tdd�|��D��}Wnty8t�}Ynw|dus?|sDt�	d��t
jdkrkddl}|�
d�pSd}td	d�|�d
�dd�D��dkrkt�	d
��|�t���}|�|p}|t��hk�dS)Nzid -G 2>/dev/nullcs��|]}t|�VqdSr!�r�)r��grrr�	<genexpr>)��z-PosixTester.test_getgroups.<locals>.<genexpr>zneed working 'id -G'�darwinrZMACOSX_DEPLOYMENT_TARGETz10.3csr�r!r�)r�r�rrrr�3r�rZr�)r�r	z$getgroups(2) is broken prior to 10.6)rZr�r��striprk�setr�r�r_r`r~r��	sysconfigZget_config_var�tuple�symmetric_differencerr.rer+)rZidg�groups�retZ
idg_groupsr�ZdtZsymdiffrrr�test_getgroups!s$
�
�

$
zPosixTester.test_getgroups�SIGCHLDz2CLD_XXXX be placed in si_code for a SIGCHLD signal�
waitid_resultztest needs os.waitid_resultcCs(tjtjtjtjtjtjdSr!)rZ�
CLD_EXITED�
CLD_KILLED�
CLD_DUMPED�CLD_TRAPPED�CLD_STOPPED�
CLD_CONTINUEDrrrr�test_cld_xxxx_constants=s
z#PosixTester.test_cld_xxxx_constants�sched_yieldzdon't have scheduling support�sched_setaffinityz!don't have sched affinity supportcC�t��dSr!)rr�rrrr�test_sched_yieldLszPosixTester.test_sched_yield�sched_get_priority_maxz!requires sched_get_priority_max()cCsptj}t�|�}t�|�}|�|t�|�|t�|�||�tjdkr6|�	t
tjd�|�	t
tjd�dSdS)Nr�i��)r�SCHED_RR�sched_get_priority_minr�r�r�r@r~r�r6r)rZpol�lo�hirrr�test_sched_priorityQs


�zPosixTester.test_sched_priorityc
Cs�dd�tj��D�}t�d�}|�||�z	t�t���}Wnty7}z
|jtj	kr-�WYd}~nd}~ww|�||�|�
ttjd�|�
ttjd�t�d�}|�|j
t�tj�d�s�zt�d||�t�d|�Wnty�}z
|jtj	kr~�WYd}~nd}~ww|�
ttjd|�|�
ttjd||�|�
ttjd|d�|�
ttjdd�t�d�}|�
ttjd|�d}t�|�}|�
ttjd|�tj|d�}|�
ttjd|�dS)	NcSsg|]\}}|�d�r|�qS)ZSCHED_�r�)r�r8Zschedrrrr�cs
�zDPosixTester.test_get_and_set_scheduler_and_param.<locals>.<listcomp>rrI�r�r��+l���)�sched_priority)r�__dict__r�r
r-rZr1rr
rar6�sched_getparamr�r�r�r~r�r��sched_setscheduler�sched_setparamr7�sched_paramr3)rZpossible_schedulersZmine�parentrZparamZlargerrr�$test_get_and_set_scheduler_and_paramasJ
���
���

z0PosixTester.test_get_and_set_scheduler_and_param�sched_rr_get_intervalzno functionc
Cstzt�d�}Wnty%}z|jtjkr�|�d�WYd}~nd}~ww|�|t�|�|d�|�	|d�dS)Nrz only works on SCHED_RR processesgg�?)
rr�rr
r�r�r�rr@�
assertLess)r�intervalrrrr�test_sched_rr_get_interval�s��z&PosixTester.test_sched_rr_get_intervalcCstt�d�}|�|t�|�t|�d�tj�d�s!|�	t
tjd�|D]}|�|t�|�|d�|�|d�q#dS)Nrr4r�rIr	)
r�sched_getaffinityr�r�r@r?r~r�r�r6rr�r�)r�maskZcpurrr�test_sched_getaffinity�s
�z"PosixTester.test_sched_getaffinitycCs�t�d�}t|�dkr|��t�d|�|�t�d�|�|�ttjdg�|�ttjddg�|�ttjdt	t
d��|�ttjddd>g�tj
�d�sZ|�ttjd|�dSdS)Nrr4i����Z0X�r�rI)rr�r?�popr�r>r6rr��mapr�r3r~r�r�)rr�rrr�test_sched_setaffinity�s
�z"PosixTester.test_sched_setaffinitycCstjtjtjtjdSr!)r�	RTLD_LAZY�RTLD_NOW�RTLD_GLOBAL�
RTLD_LOCALrrrr�test_rtld_constants�s
zPosixTester.test_rtld_constants�	SEEK_HOLEz(test needs an OS that reports file holesc
Cs�ttjd��^}|�d�|��|��}|��}z7t|�D]}|�|t	�
||t	j��|�|t	�
||t	j
��q|�tt	j
||t	j�|�tt	j
||t	j
�Wnty[t�d��wWd�dS1sgwYdS)Nzr+bshellozOSError raised!)rrrrrrs�tellrj�ranger>rZr��	SEEK_DATAZassertLessEqualr�r6rr_r`)rrmr�Zfnor�rrr�
test_fs_holes�s 	

��"�zPosixTester.test_fs_holescCs�dD]A}tt|d�}|durqdtjfD]'}z|d|�Wqty;}z|�d�|�t|��WYd}~nd}~ww|�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.)	r5rZrrrr-�formatrArb)rr8�function�dstrrrr�test_path_error2�s����zPosixTester.test_path_error2c	Cs�tj}|d}|�tj|�t�|�d}z*|�t��t�|tjtj	B�}Wd�n1s0wYW|dur?t�
|�n|durJt�
|�ww|�tj�
|��|�ttj|�|�tj�
|��t|d��
�|�ttj|�dS)N�r)rrrr"r6r�rZrr�r�rkrr��existsr�r�rr�Zfn_with_NULr�rrr�test_path_with_null_character�s*
��
���z)PosixTester.test_path_with_null_characterc	Cs�t�tj�}|d}|�tj|�t�|�d}z*|�t��t�|tj	tj
B�}Wd�n1s3wYW|durBt�|�n|durMt�|�ww|�tj
�|��|�ttj|�|�tj
�|��t|d���|�ttj|�dS)Nr�r)rZrrrrr"r6r�rr�r�rkrr�r�r�rr�rrr�test_path_with_null_byte�s*
��
���z$PosixTester.test_path_with_null_byte�
pidfd_openzpidfd_open unavailablecCs�|�t��
}t�d�Wd�n1swY|jjtjkr&|�d�t|jt	�r5|�d|j���|�
|jjtj�t�t�t�
�d��dS)NrIz"system does not support pidfd_openzpidfd_open syscall blocked: r)r6rrZr�r�r
rr��
isinstancer%r>r�rkr/)rr�rrr�test_pidfd_opens�
zPosixTester.test_pidfd_open)m�__name__�
__module__�__qualname__r r$r9r_�
skipUnlessrrrBrErLrPrTrUrcrgrnrtrwr5rZ�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�rrrrZrequires_linux_versionrrrrrr(rr/r7rCrFrHrMrNrPrQrTrYrOr]r`rbrdrhrmZcpython_onlyrprqrzr{r~r�r�r�r�r[r�r��signalr�Zrequires_sched_hZrequires_sched_affinityr�r��requires_schedr�r�r�r�r�r�r�r�r�r�rrrrr-s�
�
�
�
�
�
�
�
�
�
�



	
<








	�
�
�
�



	
�
	�
�
	�
�
�


�

D
	


�


�





 	
#���
(�rc@s�eZdZdZedd��Zedd��Ze�e	j
e	jvd�dd��Ze�e	j
e	jvd	�d
d��Ze�ee	d�o:e	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�o�e	je	jvo�eed�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	�
||�}tj	�|�r6J�t�|��}|||fVWd�dS1sMwYdS)Nr4�_�base)
r��countrrrr�r�rmdirrZr�r"r�Zopen_dir_fd)rr8�base_dir�fullnamer,rrr�prepares�
"�zTestPosixDirFd.prepareccsZ�|���\}}}t�|�|�tj|�|||fVWd�dS1s&wYdSr!)r�rrErrr"�rr,r8r�rrr�prepare_file*s�
"�zTestPosixDirFd.prepare_filez)test needs dir_fd support for os.access()cCsL|���\}}}|�tj|tj|d��Wd�dS1swYdS�N�r,)r�rerr^rZr_r�rrr�test_access_dir_fd1s"�z!TestPosixDirFd.test_access_dir_fdz'test needs dir_fd support in os.chmod()cCs�|���2\}}}t�|tj�tj|tjtjB|d�t�|�}|�|jtj@tjtjB�Wd�dS1s9wYdSr�)	r�r�chmodrr#r$r>r'�S_IRWXU)rr,r8r��srrr�test_chmod_dir_fd6s

�"�z TestPosixDirFd.test_chmod_dir_fdrDz'test needs dir_fd support in os.chown()cCsN|���\}}}tj|t��t��|d�Wd�dS1s wYdSr�)r�rrDrZr2r-r�rrr�test_chown_dir_fd?s"�z TestPosixDirFd.test_chown_dir_fdz&test needs dir_fd support in os.stat()c	Cs�|���p\}}}t|d��
}|�d�Wd�n1swY|�tj|�t�|�}tj||d�}|�||�tj|dd�}|�||�|jt	dtj|t�
�d�|jt	dtj|t|�d�|jt
tj|dd�Wd�dS1swwYdS)Nrvz	testline
r�zshould be integer or None, notl F�x:^V)r�rrrrrr"rr>rr7r&rr6r3)rr,r8r��outfile�s1�s2rrr�test_stat_dir_fdEs(�
���"�zTestPosixDirFd.test_stat_dir_fdz'test needs dir_fd support in os.utime()c	Cs�|����\}}}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�tjtjvr�z
tj|d|d�Wnt	y�YnwWd�dSWd�dSWd�dS1s�wYdS)Nr�r��xr�)r,r)F)r�r,)
r�r�rr�r6r7r�rZr�r�)rr,r8r�r�rrr�test_utime_dir_fdYsN�����������"�z TestPosixDirFd.test_utime_dir_fdz&test needs dir_fd support in os.link()cCs�|���g\}}}|���G\}}}ztj||||d�Wnty4}z
|�d|�WYd}~nd}~ww|�tj|�|�t�	|�dt�	|�d�Wd�n1sVwYWd�dSWd�dS1snwYdS)N��
src_dir_fd�
dst_dir_fdzposix.link(): %sr4)
r�r�rr�r%r�rr"r>r)rr,r8r��dir_fd2ZlinknameZfulllinknamerrrr�test_link_dir_fdxs����P�zTestPosixDirFd.test_link_dir_fdz'test needs dir_fd support in os.mkdir()cCsZ|���\}}}tj||d�|�tj|�t�|�Wd�dS1s&wYdSr�)r�rr�rr�rr�rrr�test_mkdir_dir_fd�s
"�z TestPosixDirFd.test_mkdir_dir_fdr)r*zAtest requires both stat.S_IFIFO and dir_fd support for os.mknod()cCs�|���[\}}}tjtjBtjB}ztj||d|d�Wnty;}z|�|j	t	j
t	jt	jf�WYd}~n d}~ww|�
tj|�|�t�t�|�j��Wd�dSWd�dS1sbwYdS)Nrr�)r�rr*r#r$rr)rr-r
rar�r.rr"rer&r')rr,r8r�r+rrrr�test_mknod_dir_fd�s&���"�z TestPosixDirFd.test_mknod_dir_fdz&test needs dir_fd support in os.open()c
Cs�|���P\}}}t|d��
}|�d�Wd�n1swY|�tj|�tj|tj|d�}zt�|d�}|�d|�Wt�	|�nt�	|�wWd�dS1sWwYdS)Nrs	testline
r��	)
r�rrrrrr"r�r�r>rk)rr,r8r�rr�r�rrr�test_open_dir_fd�s�"�zTestPosixDirFd.test_open_dir_fd�readlinkz*test needs dir_fd support in os.readlink()cCsd|���$\}}}t�d|�|�tj|�|�tj||d�d�Wd�dS1s+wYdS�NrKr�)r�rZrKrrr"r>rr�rrr�test_readlink_dir_fd�s
"�z#TestPosixDirFd.test_readlink_dir_fdz(test needs dir_fd support in os.rename()c	Cs�|���?\}}}|���\}}}tj||||d�t�|�t�||�Wd�n1s.wYWd�dSWd�dS1sFwYdS)Nr)r�r�rr�r)rr,r8r�r	Zname2Z	fullname2rrr�test_rename_dir_fd�s��
P�z!TestPosixDirFd.test_rename_dir_fdz)test needs dir_fd support in os.symlink()cCsd|���$\}}}tjd||d�|�tj|�|�t�|�d�Wd�dS1s+wYdSr)r�rrKrr"r>rr�rrr�test_symlink_dir_fd�s
"�z"TestPosixDirFd.test_symlink_dir_fdz(test needs dir_fd support in os.unlink()cCs�|���3\}}}t�|�t�|�ztj||d�|�ttj|�Wn|�tj|��Wd�dS1s:wYdSr�)	r�rrErrr"r6rrr�rrr�test_unlink_dir_fd�s

�"�z!TestPosixDirFd.test_unlink_dir_fdz(test needs dir_fd support in os.mkfifo()cCs�|���G\}}}ztj|tjtjB|d�Wnty/}z
|�d|�WYd}~nd}~ww|�tj	|�|�
t�t�|�j��Wd�dS1sNwYdS)Nr�r!)
r�rrrr#r$r%r�rr"rer&r')rr,r8r�rrrr�test_mkfifo_dir_fd�s��"�z!TestPosixDirFd.test_mkfifo_dir_fdN)(r�r�r�r�rr�r�r_r�rZr^�supports_dir_fdr�r�r�rrDr�rrr�rr�r
r�rr)rrrrrr�rrKrr"rrrrrrrr�sV



�





��

�



r�c@sPeZdZdd�Zdd�Ze�eed�d�dd��Z	e�eed	�d
�dd��Z
d
S)�PosixGroupsTestercCsLt��dkrt�d��ttd�st�d��tjdkrt�d��t��|_dS)Nrznot enough privilegesr.zneed posix.getgroupsr�zgetgroups(2) is broken on OSX)	rr2r_r`rr~r�r.�saved_groupsrrrrr �s




zPosixGroupsTester.setUpcCsNttd�r
t�|j�dSttd�r%t�t���j}t�||jd�dSdS)N�	setgroupsrVr)	rrrrr[r\r2r]rV�rr8rrrr$�s

�zPosixGroupsTester.tearDownrVztest needs posix.initgroups()cCsDt|jpdg�d}t�t���j}t�||�|�|t�	��dSrn)
�maxrr[r\rr2r]rVr-r.)rr�r8rrrrc�sz!PosixGroupsTester.test_initgroupsrztest needs posix.setgroups()cCs6dgttd��fD]}t�|�|�|t���q	dS)Nr�)r�r�rrZassertListEqualr.)rr�rrr�test_setgroups�s
�z PosixGroupsTester.test_setgroupsN)r�r�r�r r$r_r�rrrcrrrrrr�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�-Srzr{NcGstjddg|�RS)Nrr )r~r�r�argsrrr�python_argssz_PosixSpawnMixin.python_argscCs�tj}|�tj|�d|�d�}|�d|�}|�|d|tj�}tj	|dd�t
|dd��}|�|��t
|��Wd�dS1sCwYdS)N�2if 1:
            import os
            with open(zO, "w") as pidfile:
                pidfile.write(str(os.getpid()))
            rzrr|�utf-8��encoding)rrrr"r#�
spawn_funcrZr�rr�rr>r�rA)rZpidfile�scriptr"r�r\rrr�test_returns_pids�"�z!_PosixSpawnMixin.test_returns_pidc
Cs�d}z|�||gtj�}Wnttfy)}z|�|j|�WYd}~dSd}~wwt�|d�\}}|�||�|�|d�dS)N�no_such_executabler)	r(rZr��FileNotFoundErrorr%r>�filename�waitpid�assertNotEqual)rr+r��excZpid2�statusrrr�test_no_such_executables���z(_PosixSpawnMixin.test_no_such_executablecCs�tj}|�tj|�d|�d�}|�d|�}|�|d|itj�ddi��}tj	|dd�t
|dd	��}|�|��d�Wd�dS1sGwYdS)
Nr$z^, "w", encoding="utf-8") as envfile:
                envfile.write(os.environ['foo'])
        rzrrWZbarr|r%r&)
rrrr"r#r(rZr�rr�rr>r�)rZenvfiler)r"r�r\rrr�test_specify_environment)s��"�z)_PosixSpawnMixin.test_specify_environmentcCs.|j|jd|jtjdd�}tj|dd�dS�Nr��file_actionsr|�r(�NOOP_PROGRAMrZr�rr��rr�rrr�test_none_file_actions8��z'_PosixSpawnMixin.test_none_file_actionscCs.|j|jd|jtjgd�}tj|dd�dSr4r7r9rrr�test_empty_file_actionsAr;z(_PosixSpawnMixin.test_empty_file_actionscC�0|jtjtjddgtjdd�}tj|dd�dS)Nrzr{F�Zresetidsrr|�r(r~rrZr�rr�r9rrr�test_resetids_explicit_defaultJ�
�z/_PosixSpawnMixin.test_resetids_explicit_defaultcCr=)Nrzr{Tr>rr|r?r9rrr�
test_resetidsSrAz_PosixSpawnMixin.test_resetidscCsN|�t��|jtjtjddgtjdd�Wd�dS1s wYdS)Nrzr{r>�r6r7r(r~rrZr�rrrr�test_resetids_wrong_type\�
�"�z)_PosixSpawnMixin.test_resetids_wrong_typecCs4|jtjtjddgtjt��d�}tj|dd�dS)Nrzr{�Z	setpgrouprr|)r(r~rrZr�r0rr�r9rrr�test_setpgroupbs
�z_PosixSpawnMixin.test_setpgroupcCsN|�t��|jtjtjddgtjdd�Wd�dS1s wYdS)Nrzr{Z023rFrCrrrr�test_setpgroup_wrong_typekrEz*_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)rz�Z
setsigmaskrr|)�textwrap�dedentr(r~rrZr�r��SIGUSR1rr�)rr�r�rrr�test_setsigmaskqs

�z _PosixSpawnMixin.test_setsigmaskcC��|�t��|jtjtjddgtjdd�Wd�n1swY|�t��|jtjtjddgtjdgd�Wd�n1sDwY|�t��|jtjtjddgtjtj	tj	dgd�Wd�dS1sowYdS)Nrzr{�"rK�jr4�
r6r7r(r~rrZr�r�r��NSIGrrrr�test_setsigmask_wrong_type�s(
��
��
��"�z+_PosixSpawnMixin.test_setsigmask_wrong_typec	
Cst��\}}|�tj|�z[t�|d�t�d|�d��}z|jtj	tj	d|gtj
dd�}Wn3tyH}z|�d|���WYd}~nd}~wt
ya}z|�d|���WYd}~nd}~wwWt�|�nt�|�wtj|dd	�t�|d
�}t|�}t�t���}|�||�dS)NTz0
                import os
                fd = z`
                sid = os.getsid(0)
                os.write(fd, str(sid).encode())
            rz)�setsidzsetsid is not supported: zsetsid failed with: rr|r�)rZrerrk�set_inheritablerLrMr(r~rr�r�r�r%rr�r�r��getsidr/r/)	rZrfdZwfdr�r�r0�outputZ	child_sidZ
parent_sidrrr�test_setsid�s4
�

�����z_PosixSpawnMixin.test_setsidc
Csvt�tjtj�}t�d�}z|jtjtjd|gtj	tjgd�}Wt�tj|�nt�tj|�wt
j|tjd�dS)NrJrz��	setsigdefr|)r�rN�SIG_IGNrLrMr(r~rrZr�rr�)rZoriginal_handlerr�r�rrr�test_setsigdef�s

� z_PosixSpawnMixin.test_setsigdefcCrP)Nrzr{rQr[rRr4rSrrrr�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)rz)Z	schedulerr|�rZr
r�rLrMr(r~rr�r�rr��rZpolicy�priorityr�r�rrr�test_setscheduler_only_param��

�
�
�z-_PosixSpawnMixin.test_setscheduler_only_paramcCsft�d�}t�|�}t�d|�d|�d��}|jtjtjd|gtj|t�	|�fd�}t
j|dd�dSr`rarbrrr�test_setscheduler_with_policy�rez._PosixSpawnMixin.test_setscheduler_with_policycCs\tjdtj�t�tjdftjdftjddfg}|j|j	d|j	tj
|d�}tj|dd�dS)Nr=rr4r�r5r|)
rZ�POSIX_SPAWN_OPENr��realpath�__file__r��POSIX_SPAWN_CLOSE�POSIX_SPAWN_DUP2r(r8r�rr�)rr6r�rrr�test_multiple_file_actions�s
��z+_PosixSpawnMixin.test_multiple_file_actionsc
CsR|j}|�t��|j|d|tjdgd�Wd�n1s wY|�t��|j|d|tjdgd�Wd�n1sBwY|�t��|j|d|tjdgd�Wd�n1sdwY|�t��|j|d|tjdgd�Wd�n1s�wY|�t��|j|d|tjtjfgd�Wd�n1s�wY|�t��|j|d|tjtjddfgd�Wd�n1s�wY|�t��|j|d|tjtjdfgd�Wd�n1s�wY|�t��|j|d|tjtjdt	d	tj
dfgd�Wd�dS1�s"wYdS)
Nrr5rr!)i90r4r�r=r�)r8r6r7r(rZr�rjr�rgrir�r!rrr�test_bad_file_actionssX������������
����$�z&_PosixSpawnMixin.test_bad_file_actionscCs�tj}|�tj|�d}tjd|tjtjBtjBt	j
t	jBfg}|�d|�}|j
|d|tj|d�}tj|dd�t|dd��}|�|��d	�Wd�dS1sSwYdS)
N�Oif 1:
            import sys
            sys.stdout.write("hello")
            r4rzrr5r|r%r&�hello)rrrr"rZrgr�r��O_TRUNCrr#r$r#r(r�rr�rr>r�)rrr)r6r"r�r\rrr�test_open_file s 
���"�z_PosixSpawnMixin.test_open_filecCs�tj}|�tj|�d|�d�}|�d|�}|j|d|tjtjdfgd�}t	j
|dd�t|dd��}|�|�
�d	tj�Wd�dS1sJwYdS)
Nz�if 1:
            import os
            try:
                os.fstat(0)
            except OSError as e:
                with open(zq, 'w', encoding='utf-8') as closefile:
                    closefile.write('is closed %d' % e.errno)
            rzrr5r|r%r&zis closed %d)rrrr"r#r(rZr�rjrr�rr>r�r
r�)rZ	closefiler)r"r�r\rrr�test_close_file4s�
�"�z _PosixSpawnMixin.test_close_filecCs�tj}|�tj|�d}t|d��*}tj|��dfg}|�d|�}|j	|d|tj
|d�}tj|dd�Wd�n1s>wYt|dd	��}|�
|��d
�Wd�dS1s]wYdS)Nrnrr4rzrr5r|r%r&ro)rrrr"rrZrkrjr#r(r�rr�r>r�)rZdupfiler)Z	childfiler6r"r�r\rrrrGs���"�z_PosixSpawnMixin.test_dup2)&r�r�r�r~rr8r(r#r*r2r3r:r<r@rBrDrGrHr_r�rr�rOrUrZr^r_r�ZskipIfr�r�rdrfrlrmrqrrrrrrrr�sP					�

�
��r�posix_spawnztest needs os.posix_spawnc@seZdZeedd�ZdS)�TestPosixSpawnrsN)r�r�r�r5rr(rrrrrtZsrt�posix_spawnpztest needs os.posix_spawnpc@s&eZdZeedd�Zejdd��ZdS)�TestPosixSpawnPruNcCs�t��}|�tj|�d}tj�||�}t�t	j
|�z
tj�|tjdf�}Wnt
y3|}Ynw|ddddf}t�d|f�}d|f}t|d|i�dS)Nzposix_spawnp_test_program.exe�PATHrr rzr{z�
            import os
            from test import support

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

            support.wait_process(pid, exitcode=0)
        )�tempfile�mkdtemprrr�rZr�r"rKr~r�pathsepr�r^rLrMr)r�temp_dirZprogramZprogram_fullpathr�Z
spawn_argsr�r"rrr�test_posix_spawnpcs ��
z!TestPosixSpawnP.test_posix_spawnp)	r�r�r�r5rr(rZskip_unless_symlinkr|rrrrrv_srvr�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_varsrr�	<setcomp>�s"z-TestPosixWeaklinking.setUp.<locals>.<setcomp>csr�r!r�)r��partrrrr��r�z-TestPosixWeaklinking.setUp.<locals>.<genexpr>rZ)r�r�Zget_config_vars�	availabler��mac_verr�)rr�r�rr~rr �s
&zTestPosixWeaklinking.setUpcCs||jvr
t�|�d���dS)Nz not weak-linked)r�r_r`rrrr�_verify_available�s
�z&TestPosixWeaklinking._verify_availablecCsd|�d�|jdkr|�ttd�d�|�ttd�d�dS|�ttd�d�|�ttd�d�dS)	NZHAVE_PWRITEV)r�rr�zos.pwritev is not availabler�zos.readv is not availablezos.pwritev is availablezos.readv is available)r�r�rerrZrrrrrr��s

z!TestPosixWeaklinking.test_pwritevcC�t|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	ddd�Wd�dS1s3wYdS)NZHAVE_FSTATAT�r�r��dir_fd unavailable�filerr�)
r�r�r-r�_have_functions�assertNotInrr�rZrrrrrr��

"�zTestPosixWeaklinking.test_statcCs�|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	dtj
dd�Wd�n1s4wY|�td��tj	dtj
dd	�Wd�n1sSwY|�td
��tj	dtj
dd�Wd�dS1sswYdS)
NZHAVE_FACCESSATr�r�r�rr�zfollow_symlinks unavailableFr�zeffective_ids unavailableT)Z
effective_ids)r�r�r-rr�r�rr�rZr^r_rrrrr`�s

��"�z TestPosixWeaklinking.test_accesscCs�|�d�|jdkr|�dtj�dS|�dtj�|�dtj�|�td��tj	dddd�Wd�dS1s;wYdS)	NZ
HAVE_FCHMODATr�ZHAVE_LCHMODr�r�i�rr�)
r�r�r-rr�r�rr�rZr�rrrr�
test_chmod�s

"�zTestPosixWeaklinking.test_chmodcCs�|�d�|jdkr|�dtj�dS|�dtj�|�dtj�|�td��tj	ddddd�Wd�dS1s<wYdS)NZ
HAVE_FCHOWNATr�ZHAVE_LCHOWNr�r�rr�)
r�r�r-rr�r�rr�rZrDrrrrrF�s

"�zTestPosixWeaklinking.test_chownc	Cs|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	dddd�Wd�n1s3wY|�td��tj	dddd	�Wd�n1sQwY|�td��tj	ddddd
�Wd�n1spwYt
����}tj�
|d�}tj�
|d�}tj�
|d�}t|d��
}|�d
�Wd�n1s�wYt�d|�|�t��tj	||dd�Wd�n1s�wY|�t��tj	||dd�Wd�n1s�wYWd�dSWd�dS1s�wYdS)NZHAVE_LINKATr�zsrc_dir_fd unavailable�source�targetr�rzdst_dir_fd unavailable�rrr�rv�dataTr�F)r�r�r-rr�r�rr�rZr�rr{r�r"rrrrKr6�FileExistsError)rr�Z	link_pathZtarget_path�source_pathrmrrr�	test_link�s<

���
����"�zTestPosixWeaklinking.test_linkcCs�|�d�|jdkr|�dtj�dS|�dtj�|�td��
t�	d�Wd�n1s0wY|�td��t�
d�Wd�dS1sLwYdS)NZHAVE_FDOPENDIRr�zClistdir: path should be string, bytes, os.PathLike or None, not intrzCscandir: path should be string, bytes, os.PathLike or None, not int)r�r�r-rr�r�rr7rZrO�scandirrrrr�test_listdir_scandir�s

�"�z)TestPosixWeaklinking.test_listdir_scandircCr�)NZHAVE_MKDIRATr�r��dirrr�)
r�r�r-rr�r�rr�rZr�rrrr�
test_mkdir
r�zTestPosixWeaklinking.test_mkdircCr�)NZ
HAVE_MKFIFOAT�rXrr�r�rr�)
r�r�r-rr�r�rr�rZrrrrrr(r�z TestPosixWeaklinking.test_mkfifocCr�)NZHAVE_MKNODATr�r�r�rr�)
r�r�r-rr�r�rr�rZr)rrrrr/ r�zTestPosixWeaklinking.test_mknodcCs*|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	dddd�Wd�n1s3wY|�td��tj	dddd�Wd�n1sQwY|�td��tj
dddd�Wd�n1sowY|�td��tj
dddd�Wd�dS1s�wYdS)	NZ
HAVE_RENAMEATr�z%src_dir_fd and dst_dir_fd unavailable�a�brr�r�)r�r�r-rr�r�rr�rZr�r�rrrr�test_rename_replace+s 

���"�z(TestPosixWeaklinking.test_rename_replacecCs�|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	ddd�Wd�n1s2wY|�td��tj
ddd�Wd�dS1sPwYdS)NZ
HAVE_UNLINKATr�r�r�rr�)r�r�r-rr�r�rr�rZr"r�rrrr�test_unlink_rmdir?s

�"�z&TestPosixWeaklinking.test_unlink_rmdircCsx|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	dtj
dd�Wd�dS1s5wYdS)NZHAVE_OPENATr�r�r�rr�)r�r�r-rr�r�rr�rZrr�rrrr�	test_openMs

"�zTestPosixWeaklinking.test_opencCr�)NZHAVE_READLINKATr�r�r�rr�)
r�r�r-rr�r�rr�rZrrrrr�
test_readlinkXr�z"TestPosixWeaklinking.test_readlinkcCsv|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	dddd�Wd�dS1s4wYdS)NZHAVE_SYMLINKATr�r�r�r�rr�)
r�r�r-rr�r�rr�rZrKrrrr�test_symlinkcs

"�z!TestPosixWeaklinking.test_symlinkcCs�|�d�|�d�|jdkr|�dtj�|�dtj�dS|�dtj�|�dtj�|�td��tj	ddd�Wd�dS1sFwYdS)NZ
HAVE_FUTIMENSZHAVE_UTIMENSAT)r�rXr�r�rr�)
r�r�r-rr�r�rr�rZr�rrrrrqns


"�zTestPosixWeaklinking.test_utimeN)r�r�r�r r�r�rr`r�rFr�r�r�r(r/r�r�r�r�r�rqrrrrr}�s&
'r}cCr�r!)r�
reap_childrenrrrr�tearDownModule}sr��__main__)/�__doc__rqrZtest.supportrrrZtest.support.script_helperr�
import_modulerr
r~r�r�rZr�r[rrxr_rrL�
contextlibrr�r"�
gettempdirrrLr��maxsizer�rr�ZTestCaserr�rrrrtrvr}r�r��mainrrrr�<module>sn
��
wA$]$y�