Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_posix.cpython-38.opt-2.pyc
U

>��g/�@s\ddlmZddlmZe�d�ZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZe
j�e��ejd�Ze�ejdkd�Zdd	�Ze�e�d
�ZGdd�dej�ZGd
d�dej�ZGdd�d�Ze�e e
d�d�Gdd�deje��Z!e�e e
d�d�Gdd�deje��Z"dd�Z#e$dk�rXe#�dS)�)�support)�assert_python_ok�posixNz-dummy-symlink�z(test is only meaningful on 32-bit buildsc
CsZttd�sdSzt�d�Wn8tk
rT}z|jtjkrDWY�dSW5d}~XYnXdS)N�sched_getschedulerFrT)�hasattrrr�OSError�errnoZENOSYS)�e�r�./opt/cppython/lib/python3.8/test/test_posix.py�_supports_scheds
r
zrequires 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�ejkd1�e�eed2�d3�e�eed4�d5�d6d7����Ze�ee	d8�d9�e�eed2�d3�d:d;���Ze�eed2�d3�d<d=��Ze�ee	d>�d?�d@dA��Ze�ee	dB�dC�dDdE��Ze�ee	dF�dG�dHdI��Ze�ee	dF�dG�e�ee	dJ�dK�dLdM���Ze�ee	dF�dG�edNdO���Z e�ee	dP�dQ�dRdS��Z!e�ee	dT�dU�dVdW��Z"e�ee	dT�dU�e�ee	dX�dY�dZd[���Z#e�ee	dT�dU�ed\d]���Z$e�ee	d^�d_�d`da��Z%e�ee	d^�d_�dbdc��Z&e�ee	dd�de�dfdg��Z'e�ee	dd�de�dhdi��Z(e�ej)ejkdj�dkdl��Z*e�ej)ej+kdm�dndo��Z,e�ee	dp�dq�drds��Z-e�ee	dp�dq�edtdu���Z.e�ee	dv�dw�dxdy��Z/e�ee	dv�dw�edzd{���Z0e�ee	d|�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	jHejkdġ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�ZVe�eed�d�d�d��ZWe�ee	d�d��d�d���ZXe�ee	d��d��e�eeYd��d��e�eed��d��d�d�����ZZe�ee�d��d��d�d��Z[e�ej\ej]k�d��d�d��Z^e�ej_ej]k�d��d�d	��Z`e�ejaej]k�d
��d�d��Zbe�ej<ej]k�d
��d�d��Zce�ej)ej]k�d��d�d��Zde�ejeej]k�d��d�d��Zfe�ejgej]k�d��d�d��Zhe�ejiej]k�o�ee<d���d��d�d��Zje�ejkej]k�d��d�d��Zle�ejmej]k�d��d �d!��Zne�ejoej]k�d"��d#�d$��Zpe�ejqej]k�d%��d&�d'��Zre�ejsej]k�d(��d)�d*��Zte�ejuej]k�d+��d,�d-��Zve�ee	�d.��d/�Zwe�ee	�d0��d1�Zxew�d2�d3��Zyewe�ee	�d4��d5��d6�d7���Zze{�d8�d9��Z|e�ee	�d:��d;��d<�d=��Z}ex�d>�d?��Z~ex�d@�dA��Z�dB�dC�Z�e�ee�dD��dE��dF�dG��Z��dH�dI�Z��dJ�dK�Z��dL�dM�Z�d0S(N�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�fprrr�setUp*s


�zPosixTester.setUpcCs*|jD]}t�|�q|j�ddd�dS�N)rr�unlinkr�__exit__)rZ
teardown_filerrr�tearDown4s
zPosixTester.tearDowncCsXddddddddd	d
ddd
ddg}|D],}tt|d�}|dk	r&|�|�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_funcrrr�testNoArgFunctions9s$�zPosixTester.testNoArgFunctions�	getresuidztest needs posix.getresuid()cCs2t��}|�t|�d�|D]}|�|d�qdS�N�r)rr7�assertEqual�len�assertGreaterEqual)rZuser_ids�valrrr�test_getresuidHszPosixTester.test_getresuid�	getresgidztest needs posix.getresgid()cCs2t��}|�t|�d�|D]}|�|d�qdSr8)rr?r:r;r<)rZ	group_idsr=rrr�test_getresgidPszPosixTester.test_getresgid�	setresuidztest needs posix.setresuid()cCs0t��}|�tj|��|�t�ddd��dS�N���)rr7�assertIsNonerA)r�current_user_idsrrr�test_setresuidXszPosixTester.test_setresuidcCs:t��}d|kr6|ddddf}|jttjf|��dS�Nrr1rC)rr7r3rrA)rrEZnew_user_idsrrr�test_setresuid_exception`sz$PosixTester.test_setresuid_exception�	setresgidztest needs posix.setresgid()cCs0t��}|�tj|��|�t�ddd��dSrB)rr?rDrI)r�current_group_idsrrr�test_setresgidiszPosixTester.test_setresgidcCs:t��}d|kr6|ddddf}|jttjf|��dSrG)rr?r3rrI)rrJZ
new_group_idsrrr�test_setresgid_exceptionqsz$PosixTester.test_setresgid_exception�
initgroupsztest needs os.initgroups()c
Cs�|�ttj�|�ttjd�|�ttjdd�|�ttjddt��t��dkr�zt�t���j	}Wnt
k
r�t�d��YnXzt�|d�Wn2t
k
r�}z|�|jtj�W5d}~XYnX|�d�dS)Nr9�foorzneed a pwd entry�
z+Expected OSError to be raised by initgroups)r3r4rrM�object�osr/�pwd�getpwuid�pw_name�KeyError�unittest�SkipTestrr:r	�EPERM�fail)rr5r
rrr�test_initgroupszs"zPosixTester.test_initgroups�statvfsztest needs posix.statvfs()cCs|�t�tj��dSr)�
assertTruerr[rQ�curdir�rrrr�test_statvfs�szPosixTester.test_statvfs�fstatvfsztest needs posix.fstatvfs()cCsFttj�}z,|�t�|����|�t�|����W5|��XdSr)	rrrrr\rr`�filenor[rrrr�
test_fstatvfs�s

zPosixTester.test_fstatvfs�	ftruncateztest needs posix.ftruncate()cCsBttjd�}z&|�d�|��t�|��d�W5|��XdS)Nr�testr)	rrrr�write�flushrrcrarrrr�test_ftruncate�s
zPosixTester.test_ftruncate�truncateztest needs posix.truncate()c	Cs<ttjd��}|�d�|��W5QRXt�tjd�dS)N�wrdr)rrrrerfrrhrrrr�
test_truncate�s
zPosixTester.test_truncate�execveNz/test needs execve() to support the fd parameter�forkztest needs os.fork()�waitpidztest needs os.waitpid()c	Cs�t�tjtj�}z^t��}|dkrTt�tj�	tj�d�t
�|tjddgtj�n|�
t�|d�|df�W5t�|�XdS�Nr�-c�pass)rQr�sys�
executable�O_RDONLYrrl�chdir�path�splitrrk�environr:rm)rr�pidrrr�test_fexecve�szPosixTester.test_fexecve�waitidztest needs posix.waitid()cCsht��}|dkrDt�tj�tj�d�t�tjtjddgtj	�n t�
tj|tj�}|�
||j�dSrn)rQrlrtrurvrqrrrrkrwrz�P_PID�WEXITEDr:�si_pid)rrx�resrrr�test_waitid�szPosixTester.test_waitidc	Csv|jtdd��t�dd��W5QRX|jtdd��tjdd�W5QRX|jtdd��tjdd	�W5QRX|jtdd��tjd
d�W5QRX|jtdd��tjdd�W5QRX|jtdd��tjdd	�W5QRX|jtdd��tjdd�W5QRX|jtd
d��tjddd�d�W5QRX|jtd
d��tjdd�dd�W5QRXd}td|�dS)NzPositional args not allowed)�msgcSsdSrrrrrr�<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)Nr9rrrrrr��r�)r�r�cSsdSrrrrrrr��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)r3r4rQ�register_at_forkr)r�coderrr�test_register_at_fork�s(#z!PosixTester.test_register_at_fork�lockfztest needs posix.lockf()c	Csht�tjtjtjB�}z@t�|d�t�|dtj	�t
�|t
jd�t
�|t
j
d�W5t�|�XdS)N�testr�)rQrrr�O_WRONLY�O_CREATrre�lseek�SEEK_SETrr��F_LOCK�F_ULOCK�r�fdrrr�
test_lockf
szPosixTester.test_lockf�preadztest needs posix.pread()c	Csrt�tjtjtjB�}zJt�|d�t�|dtj	�|�
dt�|dd��|�
dt�
|d��W5t�|�XdS)Nr�rsesr�r1ste)rQrrr�O_RDWRr�rrer�r�r:rr��readr�rrr�
test_preadszPosixTester.test_pread�preadvztest needs posix.preadv()c	Csrt�tjtjtjB�}zJt�|d�dd�dD�}|�t	�
||d�d�|�ddd	gt|��W5t�|�XdS)
N�test1tt2t3t5t6t6t8cSsg|]}t|��qSr��	bytearray��.0�irrr�
<listcomp>*sz+PosixTester.test_preadv.<locals>.<listcomp>��r9r�r9�
�t1tt2�t3t�5t)rQrrrr�r�rrer:rr��list)rr��bufrrr�test_preadv%szPosixTester.test_preadv�	RWF_HIPRIztest needs posix.RWF_HIPRIc
Cs�t�tjtjtjB�}z�zNt�|d�dd�dD�}|�t	�
||dtj�d�|�ddd	gt|��Wn^t
k
r�|�d
�YnBtk
r�}z$|jtjtjhkr�t�d��n�W5d}~XYnXW5t�|�XdS)Nr�cSsg|]}t|��qSrr�r�rrrr�6sz1PosixTester.test_preadv_flags.<locals>.<listcomp>r�r9r�r�r�r�zpreadv2 not availablez0RWF_HIPRI is not supported by the current system)rQrrrr�r�rrer:rr�r�r��NotImplementedError�skipTestrr	�EINVAL�ENOTSUPrVrW)rr�r��instrrr�test_preadv_flags0szPosixTester.test_preadv_flagsc	Cs�t�tjtjtjB�}z`td�gd}|�t	��}t�
||d�W5QRX|�|jj
t
j�|�t|d�dd�W5t�|�XdS�N���r�)rQrrrr�r�rr�r3rr�r:�	exceptionr	r��bytes�rr�r��cmrrr�test_preadv_overflow_32bitsFsz'PosixTester.test_preadv_overflow_32bits�pwriteztest needs posix.pwrite()c	Csjt�tjtjtjB�}zBt�|d�t�|dtj	�t
�|dd�|�dt
�
|d��W5t�|�XdS)Nr�r�xxr1stxxtr�)rQrrrr�r�rrer�r�rr�r:r�r�rrr�test_pwriteSszPosixTester.test_pwrite�pwritevztest needs posix.pwritev()c	Cs�t�tjtjtjB�}zdt�|d�t�|dtj	�t�
|dddgd�}|�|d�t�|dtj	�|�dt�
|d	��W5t�|�XdS)
Nr�r�test1�tt2�t3r�r�sxxtest1tt2t3�d)rQrrrr�r�rrer�r�r�r:rr��rr��nrrr�test_pwritev^szPosixTester.test_pwritevzos.RWF_SYNCztest needs os.RWF_SYNCc	Cs�t�tjtjtjB�}zht�|d�t�|dtj	�t�
|dddgdtj�}|�|d�t�|dtj	�|�dt
�|d	��W5t�|�XdS)
Nr�rr�r�r�r�r�s
xxtest1tt2r�)rQrrrr�r�rrer�r�r��RWF_SYNCr:rr�r�rrr�test_pwritev_flagslszPosixTester.test_pwritev_flagsc	Cslt�tjtjtjB�}zD|�t��}t�	|ddgdd�W5QRX|�
|jjtj
�W5t�|�XdS)N�xr�r�r)rQrrrr�r�rr3rr�r:r�r	r��rr�r�rrr�test_pwritev_overflow_32bits{s"z(PosixTester.test_pwritev_overflow_32bits�posix_fallocatez"test needs posix.posix_fallocate()c
Cs�t�tjtjtjB�}z`zt�|dd�WnHt	k
rr}z*|j
t
jkr`tj
�d�r`t�d��n�W5d}~XYnXW5t�|�XdS)Nrr�)Zsunos�freebsd�netbsdZopenbsdZgnukfreebsdz test may fail on ZFS filesystems)rQrrrr�r�rrr�rr	r�rq�platform�
startswithrVrW)rr�r�rrr�test_posix_fallocate�s�z PosixTester.test_posix_fallocatec
CsHzt�ddd�Wn0tk
rB}z|jtjkr2�W5d}~XYnXdS)N����rr�)rr�rr	�EBADF�rr�rrr�test_posix_fallocate_errno�s
z&PosixTester.test_posix_fallocate_errno�
posix_fadvisez test needs posix.posix_fadvise()c	Cs8t�tjtj�}zt�|ddtj�W5t�|�XdS�Nr)	rQrrrrsrrr��POSIX_FADV_WILLNEEDr�rrr�test_posix_fadvise�szPosixTester.test_posix_fadvisec
CsLzt�dddtj�Wn0tk
rF}z|jtjkr6�W5d}~XYnXdS)Nr�r)rr�r�rr	r�r�rrr�test_posix_fadvise_errno�s
z$PosixTester.test_posix_fadvise_errnoz!test needs fd support in os.utimec	CsHt��}t�tjtj�}�zt�|�t�|d�|�	t
tj|d�|�	t
tj||df�|�	t
tj|d|f�t�|t|�t|�f�t�|||f�|j	ttj|||f||fd�|j	ttj||dfdd�|j	ttj|d|dfd�t�|t|�t|t|�d�f�tj|t|�t|t|�d�fd�W5t�|�XdS)N�NN)�nsr�e��A)
�timerQrrrrsrr�utimer3r4�int�
ValueError)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�rrr3r4r��rr�rrr�test_utime_nofollow_symlinks�sz(PosixTester.test_utime_nofollow_symlinks�writevztest needs posix.writev()c	Cs�t�tjtjtjB�}zrt�|d�}|�|d�t�	|dtj
�|�dt�|d��zt�|g�}Wnt
k
rxYnX|�|d�W5t�|�XdS)N)r�r�r�r�r�
test1tt2t3)rQrrrr�r�rr�r:r�r�rr�r)rr�r��sizerrr�test_writev�szPosixTester.test_writevc	Csjt�tjtjtjB�}zB|�t��}t�	|ddgd�W5QRX|�
|jjtj
�W5t�|�XdS)Nr�r�r�)rQrrrr�r�rr3rr�r:r�r	r�r�rrr�test_writev_overflow_32bits�s z'PosixTester.test_writev_overflow_32bits�readvztest needs posix.readv()c	Cs�t�tjtjtjB�}z�t�|d�t�|dtj	�dd�dD�}|�
t�||�d�|�
ddd	gd
d�|D��zt�|g�}Wnt
k
r�YnX|�
|d�W5t�|�XdS)Nr�rcSsg|]}t|��qSrr�r�rrrr��sz*PosixTester.test_readv.<locals>.<listcomp>r�r�r�r�r�cSsg|]}t|��qSr)r�r�rrrr��s)rQrrrr�r�rrer�r�r:rr�r)rr�r�r�rrr�
test_readv�szPosixTester.test_readvc	Cs�t�tjtjtjB�}z^td�gd}|�t	��}t�
||�W5QRX|�|jj
t
j�|�t|d�dd�W5t�|�XdSr�)rQrrrr�r�rr�r3rr�r:r�r	r�r�r�rrr�test_readv_overflow_32bitssz&PosixTester.test_readv_overflow_32bits�dupztest needs posix.dup()cCsBttj�}z(t�|���}|�|t�t	�|�W5|��XdSr)
rrrrrr�ra�assertIsInstancer�rQ)rrr�rrr�test_dups
zPosixTester.test_dup�confstrztest needs posix.confstr()cCs.|�ttjd�|�tt�d��dkd�dS)NZ
CS_garbage�CS_PATHrT)r3r�rr�r:r;r^rrr�test_confstr$szPosixTester.test_confstr�dup2ztest needs posix.dup2()cCsDttj�}ttj�}zt�|��|���W5|��|��XdSr)rrrrrr�ra)r�fp1�fp2rrr�	test_dup2*s

zPosixTester.test_dup2�	O_CLOEXECzneeds os.O_CLOEXECr���cCs8t�tjtjtjB�}|�tj|�|�t�	|��dSr)
rQrrrrsr��
addCleanupr�assertFalse�get_inheritabler�rrr�test_oscloexec5szPosixTester.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)rQrrrr�rr�r3r�
O_NONBLOCKrrrrr�rrr�
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)rQrrrr�rr�rrrr3rrsrr)r�fd1�fd2r�rrr�
test_osshlockLs ��


��zPosixTester.test_osshlock�fstatztest needs posix.fstat()cCs`ttj�}zF|�t�|����|�t�|����|�	t
dtjt|����W5|��XdS�Nz4should be string, bytes, os.PathLike or integer, not)rrrrr\rr	ra�stat�assertRaisesRegexr4�floatrrrr�
test_fstat]s

�zPosixTester.test_fstatc	Cs�|�t�tj��|�t�t�tj���|�tdtjt	t�tj���|�
tdtjd�|�
tdtjttj��|�
tdtjtt�tj���dSr
)
r\rrrrrQ�fsencodeZassertWarnsRegex�DeprecationWarningr�rr4r�r^rrr�	test_statks,����zPosixTester.test_stat�mkfifozdon't have mkfifo()c
Csvt�tj�zt�tjtjtjB�Wn0tk
rV}z|�	d|�W5d}~XYnX|�
t�t�tj�j��dS)N�posix.mkfifo(): %s)
rrrrrr�S_IRUSR�S_IWUSR�PermissionErrorr�r\�S_ISFIFO�st_mode)rr
rrr�test_mkfifo|s zPosixTester.test_mkfifo�mknod�S_IFIFOzdon't have mknod()/S_IFIFOc
Cs�t�tj�tjtjBtjB}zt�tj|d�Wn<t	k
rn}z|�
|jtjtj
tjf�W5d}~XYnX|�t�t�tj�j��t�tj�ztjtj|ddd�Wn<t	k
r�}z|�
|jtjtj
tjf�W5d}~XYnXdS)Nr)ru�modeZdevice�dir_fd)rrrrrrrrrr�assertInr	rXr��EACCESr\rr)rrr
rrr�
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)NrrC)rrrr�st_devr�r�r<�majorr:r3r4r
r��
OverflowError�minorr!)r�st�devr#r%rrr�test_makedev�s.

zPosixTester.test_makedevc		s����fdd�}t��}t��}|�||�|||�|�d|�|||�|�|d�|||�|dkr�d}|�||�|||�|�dd�|||�|�||�|||�nzt��dkr�t�d��nb��t|�dd�|||���t|�dd�|||�dt�	�k�r,��t|�dd�|||�t
tfD]F}��t|�||�|�|||���t|�|||��|||��q4dS)Ncs0�dk	r,���}��|j|���|j|�dSr)r:�st_uid�st_gid)�uid�gidr��first_paramr�	stat_funcrr�
check_stat�sz6PosixTester._test_all_chown_common.<locals>.check_statrCrl)zHP-UXZSunOSz1Skipping because of non-standard chown() behavior)
rQr/r*r��systemrVrWr3rr+�strr
r4)	rZ
chown_funcr.r/r0r+r,Z	big_value�trr-r�_test_all_chown_common�s>








z"PosixTester._test_all_chown_common�chownztest needs os.chown()cCsFt�tj�|�ttjtjdd�t�tj�|�	tjtjtj
�dSrB)rQrrrr3rrr5�create_empty_filer4rr^rrr�
test_chown�szPosixTester.test_chown�fchownztest needs os.fchown()cCsLt�tj�ttjd�}z$|��}|�tj	|t
tdd��W5|��XdS)Nrir	)rQrrrrrrar4rr8r2)rZ	test_filer�rrr�test_fchown�s

�zPosixTester.test_fchown�lchownztest needs os.lchown()cCs8t�tj�t�ttj�|�tjtjt	tdd��dS)N�lstat)
rQrrr�symlink�_DUMMY_SYMLINKr4rr:r2r^rrr�test_lchowns

�zPosixTester.test_lchownrtztest needs posix.chdir()cCs"t�tj�|�ttjtj�dSr)rrtrQr]r3rrrr^rrr�
test_chdirszPosixTester.test_chdircCs|�tjt�tj��dSr)rrrr�listdirrQr]r^rrr�test_listdirszPosixTester.test_listdircCs|�tjt���dSr)rrrrr@r^rrr�test_listdir_defaultsz PosixTester.test_listdir_defaultcCs|�t�tj�t�d��dS�N�.)rrQrrrrr@r^rrr�test_listdir_bytes!szPosixTester.test_listdir_bytesc
CsdttfD]V}|�t��t�|d��}W5QRX|�t�t	j
�|�|D]}|�t|�t
�qHqdSrC)r��
memoryviewZassertWarnsrrr@rrQrrrZassertIs�typer�)r�cls�namesr5rrr�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#rsr�rr:�sortedr@�r�frrr�test_listdir_fd.s��zPosixTester.test_listdir_fd�accessztest needs posix.access()cCs|�t�tjtj��dSr)r\rrPrrrQ�R_OKr^rrr�test_access=szPosixTester.test_access�umaskztest needs posix.umask()cCs$t�d�}|�|t�t�|�dSr�)rrSr�r�)rZold_maskrrr�
test_umaskAs
zPosixTester.test_umask�strerrorztest needs posix.strerror()cCs|�t�d��dSr�)r\rrUr^rrr�
test_strerrorGszPosixTester.test_strerror�pipeztest needs posix.pipe()cCs$t��\}}t�|�t�|�dSr)rrWrQr)r�reader�writerrrr�	test_pipeLs
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�Wntk
r�YnXdS)NZDEADBEEFrr1r�)r3r4rQr[rr�rr�r�r�get_blockingrr�rerZ
PIPE_MAX_SIZE)r�rrirrr�
test_pipe2Rs"

zPosixTester.test_pipe2cCs8ddl}|�ttj|jd�|�ttj|jd�dS�Nrr1)�	_testcapir3r$rQr[ZINT_MAXZUINT_MAX)rrarrr�test_pipe2_c_limitsnszPosixTester.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_utimewszPosixTester.test_utimec
Ks�t�|�}|�t|d��|jtjB}z|||f|�Wn>tk
rv}z |jtjkrX�d}|�	|�W5d}~XYnXzft�|�}|�|jtjB|j�zt
|d�}	Wn2tk
r�}
z|�|
jtj�W5d}
~
XYnXW5t
�||j�XdS)N�st_flags�2chflag UF_IMMUTABLE not supported by underlying fsr)rQrr\rrd�UF_IMMUTABLErr	�
EOPNOTSUPPr�r�chflagsr:rrX)rZchflags_funcZtarget_file�kwargsr&�flags�errr�Znew_str�r
rrr�_test_chflags_regular_file�s$

&z&PosixTester._test_chflags_regular_filerhztest needs os.chflags()cCs|�tjtj�dSr)rlrrhrrr^rrr�test_chflags�szPosixTester.test_chflags�lchflagsztest needs os.lchflags()cCs(|�tjtj�|jtjtjdd�dS�NFr�)rlrrnrrrhr^rrr�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>tk
r�}z |jtjkr��d}|�|�W5d}~XYnXz@t�tj�}t�
t�}	|�|j
|j
�|�|j
tjB|	j
�W5|t|j
�XqRdS)NrdcSstj||dd�Sro)rrh)rurjrrr�chflags_nofollow�sz;PosixTester.test_lchflags_symlink.<locals>.chflags_nofollowre)rQrrrr\rr<r=r�appendr;rrnrdrfrr	rgr�r:)
rZ	testfn_stZdummy_symlink_strq�fnrjrkr�Z
new_testfn_stZnew_dummy_symlink_strrr�test_lchflags_symlink�s.

�z!PosixTester.test_lchflags_symlinkcCsLtjdkrt}nt}tj��D](\}}|�t|�|�|�t|�|�qdS)N�nt)	rQr5r2r�rrw�itemsr:rG)rZ	item_type�k�vrrr�test_environ�s
zPosixTester.test_environ�putenvzrequires os.putenv()c	Cs�|�t��t�dd�W5QRX|�t��t�dd�W5QRX|�t��t�dd�W5QRX|�t��t�dd�W5QRX|�t��t�d	d
�W5QRX|�t��t�dd�W5QRXdS)
NzFRUITVEGETABLEZcabbagesFRUITVEGETABLEscabbageZFRUITzorangeVEGETABLE=cabbagesFRUITsorangeVEGETABLE=cabbagezFRUIT=ORANGEZlemonsFRUIT=ORANGEslemon)r3r�rQrzr^rrr�test_putenv�szPosixTester.test_putenvr#ztest needs posix.getcwd()c	sjd}t��}tj�tj�d}z0zt�|�t�|�WnYW�
dSXW5t�|�t�|�XdS)Nz8getcwd-test-directory-0123456789abcdef-01234567890abcdefz.getcwdrc	svzt�|�Wnt�d��YnXt�|�z*t��|dkrX�||t|�d�W5t�d�t�|�XdS)Nz?mkdir cannot create directory sufficiently deep for getcwd testz..ir1)rQ�mkdirrVrWrt�rmdirr#r;)�dirnameZcurrent_path_length��_create_and_do_getcwdrrr��s

zEPosixTester.test_getcwd_long_pathnames.<locals>._create_and_do_getcwd)	rQr#ru�abspathrrrt�rmtreer|)rr~r]�	base_pathrrr�test_getcwd_long_pathnames�s


z&PosixTester.test_getcwd_long_pathnames�getgrouplistztest needs posix.getgrouplist()rSztest needs pwd.getpwuid()r/ztest needs os.getuid()cCs<t�t���d}t�t���d}|�|t�||��dS)Nrr9)rRrSrQr/rrr�)r�user�grouprrr�test_getgrouplist�szPosixTester.test_getgrouplistr(ztest needs os.getegid()c	Cs�t�d��}|����}|��}W5QRXztdd�|��D��}Wntk
r^t�}YnX|dk	sl|svt�	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��grrr�	<genexpr>sz-PosixTester.test_getgroups.<locals>.<genexpr>zneed working 'id -G'�darwinrZMACOSX_DEPLOYMENT_TARGETz10.0css|]}t|�VqdSrr�)r�r�rrrr�srKr�)r�r�z$getgroups(2) is broken prior to 10.6)rQ�popenr��stripr�setrvr�rVrWrqr��	sysconfigZget_config_var�tuple�symmetric_differencerr+r\r()rZidg�groups�retZ
idg_groupsr�ZdtZsymdiffrrr�test_getgroupss 

$
zPosixTester.test_getgroupsz)test needs dir_fd support for os.access()c	CsBt�t��tj�}z|�tjtjt	j
|d��W5t�|�XdS�N�r)rrr#rsrr\rPrrrQrQrMrrr�test_access_dir_fd%szPosixTester.test_access_dir_fdz'test needs dir_fd support in os.chmod()c	Cs|t�tjtj�t�t��tj	�}zHtjtjtjtjB|d�t�tj�}|�|dtj
@tjtjB�W5t�
|�XdS)Nr�r)rQ�chmodrrrrrrr#rsrrr:�S_IRWXU)rrN�srrr�test_chmod_dir_fd-s"zPosixTester.test_chmod_dir_fdz'test needs dir_fd support in os.chown()c	Cs\t�tj�t�tj�t�t��tj�}z tj	tjt
��t
��|d�W5t�|�XdSr�)
rrrr6rrr#rsrr5rQr/r*rMrrr�test_chown_dir_fd:s zPosixTester.test_chown_dir_fdz&test needs dir_fd support in os.stat()c	Cs�t�tj�ttjd��}|�d�W5QRXt�t��tj�}z�t�	tj�}tj	tj|d�}|�
||�tj	tjdd�}|�
||�|jtdtj	tjt��d�|jtdtj	tjt
|�d�|jttj	tjdd�W5t�|�XdS)Nri�	testline
r�zshould be integer or None, notl F�x:^V)rrrrrerr#rsrrr:rr4r
r3r$)r�outfilerN�s1�s2rrr�test_stat_dir_fdEs4���
zPosixTester.test_stat_dir_fdz'test needs dir_fd support in os.utime()c	Cs�t�t��tj�}�zvt��}tjtjd|d�tjtj|d�|j	t
tjtj||d�|j	t
tjtjd|d�|j	t
tjtj|df|d�|j	t
tjtjd|f|d�|j	t
tjtj|df|d�tjtjt|�t|�f|d�tjtj||f|d�tjtjt|�t|t|�d�f|d�tjtj|t|�t|t|�d�fd�tjtj
k�r�ztjtjd|d�Wntk
�r�YnXW5t�|�XdS)Nr�r��xr�)rr&F)r�r)rrr#rsrr�r�rrr3r4r�rQ�supports_follow_symlinksr�)rrNr�rrr�test_utime_dir_fd[s2�
�
zPosixTester.test_utime_dir_fdz&test needs dir_fd support in os.link()c
Cs�t�t��tj�}z|ztjtjtjd||d�Wn0t	k
rb}z|�
d|�W5d}~XYn*X|�t�tj�dt�tjd�d�W5t�|�t�tjd�XdS)N�link�Z
src_dir_fdZ
dst_dir_fdzposix.link(): %sr1)
rrr#rsrrrrr�rr�r:r�rrNr
rrr�test_link_dir_fdys �
zPosixTester.test_link_dir_fdz'test needs dir_fd support in os.mkdir()c
Cs\t�t��tj�}z(tjtjd|d�t�	tjd�W5t�|�t�tjd�XdS)N�dirr�)
rrr#rsrrr�rr|rrMrrr�test_mkdir_dir_fd�s
zPosixTester.test_mkdir_dir_fdzAtest requires both stat.S_IFIFO and dir_fd support for os.mknod()c
Cs�t�tj�tjtjBtjB}t�t�	�tj
�}ztztjtj|d|d�Wn<t
k
r�}z|�|jtjtjtjf�W5d}~XYnX|�t�t�tj�j��W5t�|�XdS)Nrr�)rrrrrrrrrr#rsrrrrr	rXr�rr\rr)rrrNr
rrr�test_mknod_dir_fd�s,zPosixTester.test_mknod_dir_fdz&test needs dir_fd support in os.open()c	Cs�t�tj�ttjd��}|�d�W5QRXt�t��tj�}tjtjtj|d�}z$t�	|d�j
dd�}|�d|�W5t�|�t�|�XdS)Nrir�r��	zutf-8)�encoding)rrrrrerr#rsrr��decoder:)rr��a�br~rrr�test_open_dir_fd�s
zPosixTester.test_open_dir_fdz*test needs dir_fd support in os.readlink()c
Cstt�tjtjd�t�t��tj�}z,|�
t�tjd�tjtjd|d��W5t�tjd�t�	|�XdS�Nr�r�)rQr<rrrrr#rsrrr:�readlinkrMrrr�test_readlink_dir_fd�s�z PosixTester.test_readlink_dir_fdz(test needs dir_fd support in os.rename()c	Cs�t�tj�t�tjd�t�t��tj�}zRztj	tjdtj||d�Wn"t�	tjdtj��YnXt�
tj�W5t�|�XdS)NZrenr�)rrrr6rrr#rsr�renamerrMrrr�test_rename_dir_fd�szPosixTester.test_rename_dir_fdz)test needs dir_fd support in os.symlink()c
Csjt�t��tj�}z6tjtjtjd|d�|�	t�
tjd�tj�W5t�|�t�tjd�XdSr�)rrr#rsrrrrr<r:r�rMrrr�test_symlink_dir_fd�s
zPosixTester.test_symlink_dir_fdz(test needs dir_fd support in os.unlink()c	Cs�t�t��tj�}t�tjd�t�tjd�zRztj	tjd|d�Wnt�	tjd��YnX|�
ttjtjd�W5t�|�XdS)N�delr�r�)rrr#rsrr6rrrrr3rrMrrr�test_unlink_dir_fd�szPosixTester.test_unlink_dir_fdz(test needs dir_fd support in os.mkfifo()c
Cs�t�tj�t�t��tj�}znztjtjt	j
t	jB|d�Wn0tk
rn}z|�
d|�W5d}~XYnX|�t	�t�	tj�j��W5t�|�XdS)Nr�r)rrrrrr#rsrrrrrrr�r\rrr�rrr�test_mkfifo_dir_fd�s
�
 zPosixTester.test_mkfifo_dir_fd�sched_yieldzdon't have scheduling support�sched_setaffinityz!don't have sched affinity supportcCst��dSr)rr�r^rrr�test_sched_yield�szPosixTester.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<rqr�r3r)rZpol�lo�hirrr�test_sched_priority�s


zPosixTester.test_sched_priorityc
Cs�dd�tj��D�}t�d�}|�||�zt�t���}Wn0tk
rl}z|jtj	kr\�W5d}~XYnX|�||�|�
ttjd�|�
ttjd�t�d�}|�|j
t�tj�d��s&zt�d||�t�d|�Wn4tk
�r}z|jtj	k�r�W5d}~XYnX|�
ttjd|�|�
ttjd||�|�
ttjd|d�|�
ttjdd�t�d�}|�
ttjd|�d}t�|�}|�
ttjd|�tj|d�}|�
ttjd|�dS)	NcSsg|]\}}|�d�r|�qS)ZSCHED_)r�)r�r5Zschedrrrr�s
�zDPosixTester.test_get_and_set_scheduler_and_param.<locals>.<listcomp>rrC�r�r��+l���)�sched_priority)r�__dict__rvrrrQr.rr	rXr3�sched_getparamr�r�r�rqr�r��sched_setscheduler�sched_setparamr4�sched_paramr$)rZpossible_schedulersZmine�parentr
ZparamZlargerrr�$test_get_and_set_scheduler_and_params>



z0PosixTester.test_get_and_set_scheduler_and_param�sched_rr_get_intervalzno functionc
Csrzt�d�}Wn:tk
rH}z|jtjkr.�|�d�W5d}~XYnX|�|t�|�|d�|�	|d�dS)Nrz only works on SCHED_RR processesgg�?)
rr�rr	r�r�r�r
r<�
assertLess)r�intervalr
rrr�test_sched_rr_get_interval7sz&PosixTester.test_sched_rr_get_intervalcCsht�d�}|�|t�|�t|�d�|�ttjd�|D](}|�|t�|�|d�|�	|d�q:dS)Nrr1rCr)
r�sched_getaffinityr�r�r<r;r3rr�r�)r�maskZcpurrr�test_sched_getaffinityFs
z"PosixTester.test_sched_getaffinitycCs�t�d�}t|�dkr|��t�d|�|�t�d�|�|�ttjdg�|�ttjddg�|�ttjdt	t
d��|�ttjddd>g�|�ttjd|�dS)Nrr1i����Z0X�rC)rr�r;�popr�r:r3rr��mapr�r$)rr�rrr�test_sched_setaffinityQs
z"PosixTester.test_sched_setaffinitycCstjtjtjtjdSr)r�	RTLD_LAZY�RTLD_NOW�RTLD_GLOBAL�
RTLD_LOCALr^rrr�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
�Wntk
r�t�d��YnXW5QRXdS)Nzr+bshellozOSError raised!)rrrrerf�tellra�ranger:rQr��	SEEK_DATAZassertLessEqualr�r3rrVrW)rrr�Zfnor�rrr�
test_fs_holesfs	
zPosixTester.test_fs_holescCs�dD]�}tt|d�}|dkrqdtjfD]V}z|d|�Wq(tk
r|}z$|�d�|�t|��WY�qW5d}~XYq(Xq(|�d|�qdS)N)r��replacer�Znoodly2Zdoesnotexistfilenamez'doesnotexistfilename' -> '{}'z#No valid path_error2() test for os.)	r2rQrrrr�formatr2rY)rr5�function�dstr
rrr�test_path_error2�szPosixTester.test_path_error2c	Cs�tj}|d}|�tj|�t�|�d}z.|�t��t�|tj	tj
B�}W5QRXW5|dk	rlt�|�X|�tj�
|��|�ttj|�|�tj�
|��t|d���|�ttj|�dS)N��wb)rrr�rrQrr3r�rr�r�r�ru�existsr|r�rrsZfn_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
tjB�}W5QRXW5|dk	rrt�|�X|�tj
�|��|�ttj|�|�tj
�|��t	|d���|�ttj|�dS)Nr�r�)rQrrrr�rrr3r�rr�r�r�rur�r|rr�rrr�test_path_with_null_byte�s
"z$PosixTester.test_path_with_null_byte)��__name__�
__module__�__qualname__rr!r6rV�
skipUnlessrrr>r@rFrHrKrLrZr_rbrgrjr2rQ�supports_fdryrr�r�r�r�r��requires_32br�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rZrequires_linux_versionrrrrrrrr r(r4r7r9r>r?rArBrErJr@rOrRrTrVrZr_Zcpython_onlyrbrcrlrmrprtryr{r�rRr�r�rP�supports_dir_fdr�r�r�r5r�r�r�r�r�r|r�rr�rr�r�r�r�r�r<r�rr�rr�Zrequires_sched_hZrequires_sched_affinityr�r��requires_schedr�r�r�r�r�r�r�r�r�rrrrr(s�
�
�
�
�
�
�
�
�
�
�



	
<








	�
�
�
�




	
�
	�
�
	�
�
�

�

;
	


�



�


	


 	

#
	�

	
���
(

�rc@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)	rr/rVrWrrqr�r+�saved_groupsr^rrrr�s




zPosixGroupsTester.setUpcCsHttd�rt�|j�n,ttd�rDt�t���j}t�||jd�dS)N�	setgroupsrMr)	rrr�r�rRrSr/rTrM)rr5rrrr!�s


zPosixGroupsTester.tearDownrMztest needs posix.initgroups()cCsDt|jpdg�d}t�t���j}t�||�|�|t�	��dSr`)
�maxr�rRrSrr/rTrMrr+)rr�r5rrrrZ�sz!PosixGroupsTester.test_initgroupsr�ztest needs posix.setgroups()cCs6dgttd��fD]}t�|�|�|t���qdS)Nr�)r�r�rr�ZassertListEqualr+)rr�rrr�test_setgroups�s
z PosixGroupsTester.test_setgroupsN)r�r�r�rr!rVr�rrrZr�rrrrr��s	�
�r�c@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�-SrorpNcGstjddf|�S)Nr�r�)rqrr�r�argsrrr�python_args�sz_PosixSpawnMixin.python_argsc	Cs�tj}|�tj|�d|�d�}|�d|�}|�|d|tj�}|�t�	|d�|df�t
|��}|�|��t|��W5QRXdS)N�2if 1:
            import os
            with open(zO, "w") as pidfile:
                pidfile.write(str(os.getpid()))
            ror)
rrr�rr�
spawn_funcrQrwr:rmrr�r2)rZpidfile�scriptrrxrNrrr�test_returns_pid�s
z!_PosixSpawnMixin.test_returns_pidc
Cs|d}z|�||gtj�}Wn4ttfk
rN}z|�|j|�W5d}~XYn*Xt�|d�\}}|�||�|�|d�dS)N�no_such_executabler)	rrQrw�FileNotFoundErrorrr:�filenamerm�assertNotEqual)rrrx�exc�pid2�statusrrr�test_no_such_executable�s� z(_PosixSpawnMixin.test_no_such_executablec	Cs�tj}|�tj|�d|�d�}|�d|�}|�|d|tjddi��}|�t�	|d�|df�t
|��}|�|��d�W5QRXdS)NrzL, "w") as envfile:
                envfile.write(os.environ['foo'])
        rorrNZbar)rrr�rrrrQrwr:rmrr�)rZenvfilerrrxrNrrr�test_specify_environments�
z)_PosixSpawnMixin.test_specify_environmentcCs8|j|jd|jtjdd�}|�t�|d�|df�dS�Nr��file_actions�r�NOOP_PROGRAMrQrwr:rm�rrxrrr�test_none_file_actionss�z'_PosixSpawnMixin.test_none_file_actionscCs8|j|jd|jtjgd�}|�t�|d�|df�dSrrrrrr�test_empty_file_actionss�z(_PosixSpawnMixin.test_empty_file_actionscCs:|jtjtjddgtjdd�}|�t�|d�|df�dS)NrorpF�Zresetidsr�rrqrrrQrwr:rmrrrr�test_resetids_explicit_default&s
�z/_PosixSpawnMixin.test_resetids_explicit_defaultcCs:|jtjtjddgtjdd�}|�t�|d�|df�dS)NrorpTrrrrrrr�
test_resetids/s
�z_PosixSpawnMixin.test_resetidsc	Cs8|�t��$|jtjtjddgtjdd�W5QRXdS)Nrorpr�r3r4rrqrrrQrwr^rrr�test_resetids_wrong_type8s
�z)_PosixSpawnMixin.test_resetids_wrong_typecCs>|jtjtjddgtjt��d�}|�t�|d�|df�dS)Nrorp�Z	setpgroupr)rrqrrrQrwr-r:rmrrrr�test_setpgroup>s
�z_PosixSpawnMixin.test_setpgroupc	Cs8|�t��$|jtjtjddgtjdd�W5QRXdS)NrorpZ023rrr^rrr�test_setpgroup_wrong_typeGs
�z*_PosixSpawnMixin.test_setpgroup_wrong_type�pthread_sigmaskzneed signal.pthread_sigmask()cCsHt�d�}|jtjtjd|gtjtjgd�}|�	t�
|d�|df�dS)N�I            import signal
            signal.raise_signal(signal.SIGUSR1)ro�Z
setsigmaskr)�textwrap�dedentrrqrrrQrw�signal�SIGUSR1r:rm)rr�rxrrr�test_setsigmaskMs

�z _PosixSpawnMixin.test_setsigmaskc	Cs�|�t��$|jtjtjddgtjdd�W5QRX|�t��&|jtjtjddgtjdgd�W5QRX|�t��0|jtjtjddgtjtj	tj	dgd�W5QRXdS)Nrorp�"r#�jr1�
r3r4rrqrrrQrwr�r&�NSIGr^rrr�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�}Wnbtk
r�}z|�d|���W5d}~XYn2t
k
r�}z|�d|���W5d}~XYnXW5t�|�X|�t�|d�|df�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: rr�)rQrWr�r�set_inheritabler$r%rrqrrrwr�r�rr:rmr�r��getsidr,r
)	rZrfdZwfdr�rxr�outputZ	child_sidZ
parent_sidrrr�test_setsidks.�

�
 &z_PosixSpawnMixin.test_setsidc
Cs�t�tjtj�}t�d�}z&|jtjtjd|gtj	tjgd�}W5t�tj|�Xt�
|d�\}}|�||�|�t�
|�|�|�t�|�tj�dS)Nr"ro��	setsigdefr)r&r'�SIG_IGNr$r%rrqrrrQrwrmr:r\�WIFSIGNALED�WTERMSIG)rZoriginal_handlerr�rxrr
rrr�test_setsigdef�s

�
z_PosixSpawnMixin.test_setsigdefc	Cs�|�t��$|jtjtjddgtjdd�W5QRX|�t��&|jtjtjddgtjdgd�W5QRX|�t��0|jtjtjddgtjtj	tj	dgd�W5QRXdS)Nrorpr)r3r*r1r+r^rrr�test_setsigdef_wrong_type�s$
�
�
�z*_PosixSpawnMixin.test_setsigdef_wrong_typer�zbpo-34685: test can fail on BSDcCspt�d�}t�|�}t�d|�d|�d��}|jtjtjd|gtjdt�	|�fd�}|�
t�|d�|df�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	scheduler�rQrr�r$r%rrqrrrwr�r:rm�rZpolicy�priorityr�rxrrr�test_setscheduler_only_param�s

��

�z-_PosixSpawnMixin.test_setscheduler_only_paramcCspt�d�}t�|�}t�d|�d|�d��}|jtjtjd|gtj|t�	|�fd�}|�
t�|d�|df�dSr:r;r<rrr�test_setscheduler_with_policy�s

��

�z._PosixSpawnMixin.test_setscheduler_with_policycCsftjdtj�t�tjdftjdftjddfg}|j|j	d|j	tj
|d�}|�t�|d�|df�dS)Nr9rr1r�r)
rQ�POSIX_SPAWN_OPENru�realpath�__file__rs�POSIX_SPAWN_CLOSE�POSIX_SPAWN_DUP2rrrwr:rm)rrrxrrr�test_multiple_file_actions�s
��z+_PosixSpawnMixin.test_multiple_file_actionsc
Cs�|j}|�t�� |j|d|tjdgd�W5QRX|�t�� |j|d|tjdgd�W5QRX|�t�� |j|d|tjdgd�W5QRX|�t�� |j|d|tjdgd�W5QRX|�t��$|j|d|tjtjfgd�W5QRX|�t��(|j|d|tjtjddfgd�W5QRX|�t��&|j|d|tjtjdfgd�W5QRX|�t��2|j|d|tjtjdt	d	tj
dfgd�W5QRXdS)
Nrrrr)i90r1r�r9r�)rr3r4rrQrwrCr�r@rBrsrrrr�test_bad_file_actions�sL������
���z&_PosixSpawnMixin.test_bad_file_actionsc	Cs�tj}|�tj|�d}tjd|tjtjBtjBt	j
t	jBfg}|�d|�}|j
|d|tj|d�}|�t�|d�|df�t|��}|�|��d�W5QRXdS)N�Oif 1:
            import sys
            sys.stdout.write("hello")
            r1rorr�hello)rrr�rrQr@r�r��O_TRUNCrrrrrrwr:rmrr�)rr�rrrrxrNrrr�test_open_file�s
���
z_PosixSpawnMixin.test_open_filec	Cs�tj}|�tj|�d|�d�}|�d|�}|j|d|tjtjdfgd�}|�	t�
|d�|df�t|��}|�	|��dt
j�W5QRXdS)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)
            rorrzis closed %d)rrr�rrrrQrwrCr:rmrr�r	r�)rZ	closefilerrrxrNrrr�test_close_files
�
z _PosixSpawnMixin.test_close_filec	Cs�tj}|�tj|�d}t|d��T}tj|��dfg}|�d|�}|j	|d|tj
|d�}|�t�|d�|df�W5QRXt|��}|�|�
�d�W5QRXdS)NrGr�r1rorrrH)rrr�rrrQrDrarrrwr:rmr�)rZdupfilerZ	childfilerrrxrNrrrr�#s��"
z_PosixSpawnMixin.test_dup2)&r�r�r�rqrrrrrrrrrrrrrrr rVr�rr&r(r-r2r8r9r�ZskipIfr�r�r>r?rErFrJrKr�rrrrr��sN					�

�
��r��posix_spawnztest needs os.posix_spawnc@seZdZeedd�ZdS)�TestPosixSpawnrLN)r�r�r�r2rrrrrrrM6srM�posix_spawnpztest needs os.posix_spawnpc@s&eZdZeedd�Zejdd��ZdS)�TestPosixSpawnPrNNcCs�t��}|�tj|�d}tj�||�}t�t	j
|�ztj�|tjdf�}Wnt
k
rh|}YnX|ddddf}t�d|f�}d|f}t|d|i�dS)Nzposix_spawnp_test_program.exe�PATHr�r�rorpaI
            import os
            args = %a
            pid = os.posix_spawnp(args[0], args, os.environ)
            pid2, status = os.waitpid(pid, 0)
            if pid2 != pid:
                raise Exception(f"pid {pid2} != {pid}")
            if status != 0:
                raise Exception(f"status {status} != 0")
        )�tempfile�mkdtempr�rr�rQru�joinr<rqrr�pathseprwrUr$r%r)rZtemp_dirZprogramZprogram_fullpathruZ
spawn_argsr�rrrr�test_posix_spawnp?s
	�z!TestPosixSpawnP.test_posix_spawnp)	r�r�r�r2rrrZskip_unless_symlinkrUrrrrrO;srOcCs$zt�tttt�W5t��XdSr)r�
reap_childrenZrun_unittestrr�rMrOrrrr�	test_mainas�rW�__main__)%rdrZtest.support.script_helperr�
import_modulerr	rqr&r�rQr�rRrrQrVrr$rurS�
gettempdirrr=r��maxsizer�r
r�ZTestCaserr�r�rrMrOrWr�rrrr�<module>sZ
��
$]%


F1le Man4ger