Uname:Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64

403WebShell
403Webshell
Server IP : 3.111.61.48  /  Your IP : 216.73.216.67
Web Server : Apache
System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.2.31
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.10/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.10/test/__pycache__/test_posix.cpython-310.pyc
o

�9jI]�@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/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_filesr�check_warnings�_warnings_manager�	__enter__�warnings�filterwarnings�RuntimeWarning��selfrrr�setUp/s�


�zPosixTester.setUpcCs*|jD]}t�|�q|j�ddd�dS�N)rr�unlinkr�__exit__)r �
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)r �NO_ARG_FUNCTIONS�name�
posix_funcrrr�testNoArgFunctions>s��zPosixTester.testNoArgFunctions�	getresuidztest needs posix.getresuid()cC�2t��}|�t|�d�|D]}|�|d�qdS�N�r)rr>�assertEqual�len�assertGreaterEqual)r �user_ids�valrrr�test_getresuidM�
�zPosixTester.test_getresuid�	getresgidztest needs posix.getresgid()cCr?r@)rrIrBrCrD)r �	group_idsrFrrr�test_getresgidUrHzPosixTester.test_getresgid�	setresuidztest needs posix.setresuid()cC�0t��}|�tj|��|�t�ddd��dS�N���)rr>�assertIsNonerL)r �current_user_idsrrr�test_setresuid]�zPosixTester.test_setresuidcC�@t��}d|vr|ddddf}|jttjg|�R�dSdS�Nrr6rO)rr>r8rrL)r rQ�new_user_idsrrr�test_setresuid_exceptione�
�z$PosixTester.test_setresuid_exception�	setresgidztest needs posix.setresgid()cCrMrN)rrIrPrY)r �current_group_idsrrr�test_setresgidnrSzPosixTester.test_setresgidcCrTrU)rrIr8rrY)r rZ�
new_group_idsrrr�test_setresgid_exceptionvrXz$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)NrA�foorzneed a pwd entry�
z+Expected OSError to be raised by initgroups)r8r9rr^�object�osr4�pwd�getpwuid�pw_name�KeyError�unittest�SkipTestrrBr
�EPERM�fail)r r;rrrr�test_initgroupss$
����zPosixTester.test_initgroups�statvfsztest needs posix.statvfs()cCs|�t�tj��dSr")�
assertTruerrlrb�curdirrrrr�test_statvfs��zPosixTester.test_statvfs�fstatvfsztest needs posix.fstatvfs()cCsLttj�}z|�t�|����|�t�|����W|��dS|��wr")	rrrrmrrq�filenorl�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�flushrrwrrrsrtrrr�test_ftruncate�s
zPosixTester.test_ftruncate�truncateztest needs posix.truncate()cCsPttjd��}|�d�|��Wd�n1swYt�tjd�dS)N�wryr)rrrrzr{rr}rtrrr�
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)rbr�sys�
executable�O_RDONLYr��chdir�path�splitrr��environr�wait_processrs)r ru�pidrrr�test_fexecve�s�zPosixTester.test_fexecve�waitidztest needs posix.waitid()cCsjt��}|dkr#t�tj�tj�d�t�tjtjddgtj	�dSt�
tj|tj�}|�
||j�dS)Nrr�r�)rbr�r�r�r�r�r�rr�r�r��P_PID�WEXITEDrB�si_pid)r r��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�)�before�three)�after_in_childsFive)�after_in_parentzArgs must not be NonezInvalid arg was allowedcSsdS)NrArrrrrr��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'!')
            r�)r8r9rb�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�)rbrrr�O_WRONLY�O_CREATrz�lseek�SEEK_SETrr��F_LOCK�F_ULOCKrs�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�r6ste)rbrrr�O_RDWRr�rzr�r�rBrr��readrsr�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>��rAr�rA�
�st1tt2st3ts5t)rbrrrr�r�rzrBrr��listrs)r r��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�rAr�r�zpreadv2 not availablez0RWF_HIPRI is not supported by the current system)rbrrrr�r�rzrBrr�r�r��NotImplementedError�skipTestrr
�EINVAL�ENOTSUPrgrhrs)r r�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�)rbrrrr�r�r�r8rr�rB�	exceptionr
r��bytesrs�r r�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�xxr6stxxtr�)rbrrrr�r�rzr�r�rr�rBr�rsr�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)rbrrrr�r�rzr�r�r�rBrr�rs�r r��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�)rbrrrr�r�rzr�r�r��RWF_SYNCrBrr�rsr�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)rbrrrr�r�r8rr�rBr�r
r�rs�r r�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�)�sunos�freebsd�netbsd�openbsd�gnukfreebsdz test may fail on ZFS filesystems)rbrrrr�r�rr�rr
r�r��platform�
startswithrgrhrs)r r�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�r r�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)	rbrrrr�rr��POSIX_FADV_WILLNEEDrsr�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)
�timerbrrrr�r�utimer8r9�int�
ValueErrorrs)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�rrr8r9r��r r�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)rbrrrr�r�rrBr�r�rr�rrs)r r�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�)rbrrrr�r�r8rrrBr�r
r�rsr�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)	NrrcSr�rr�r�rrrr�r�z*PosixTester.test_readv.<locals>.<listcomp>r�r�r�cSr�r)r�r�rrrr�r�)rbrrrr�r�rzr�r�rBrrrrs)r r�r�rrrr�
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�)rbrrrr�r�r�r8rrrBr�r
r�r�rsr�rrr�test_readv_overflow_32bitss�z&PosixTester.test_readv_overflow_32bits�dupztest needs posix.dup()cCsHttj�}zt�|���}|�|t�t�	|�W|�	�dS|�	�wr")
rrrrr
rr�assertIsInstancer�rbrs)r rur�rrr�test_dup!s
zPosixTester.test_dup�confstrztest needs posix.confstr()cCs.|�ttjd�|�tt�d��dkd�dS)N�
CS_garbage�CS_PATHrT)r8r�rr
rBrCrrrr�test_confstr,szPosixTester.test_confstr�dup2ztest needs posix.dup2()cCsRttj�}ttj�}zt�|��|���W|��|��dS|��|��wr")rrrrrrrrs)r �fp1�fp2rrr�	test_dup22s

�
zPosixTester.test_dup2�	O_CLOEXECzneeds os.O_CLOEXECr���cCs8t�tjtjtjB�}|�tj|�|�t�	|��dSr")
rbrrrr�r�
addCleanuprs�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)rbrrrr�rr�r8r�
O_NONBLOCKrsrrrr�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)rbrrrr�rr�rsrrr8r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)rrrrmrr#rr�stat�assertRaisesRegexr9�floatrsrtrrr�
test_fstates
�zPosixTester.test_fstatc	Cs�|�t�tj��|�t�t�tj���|�tdtjt	t�tj���|�
tdtjd�|�
tdtjttj��|�
tdtjtt�tj���dSr$)
rmrr%rrrb�fsencode�assertWarnsRegex�DeprecationWarningr�r&r9r�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�rbr��joinrrr#rrr-r%�S_IRUSR�S_IWUSR�PermissionErrorr�rm�S_ISFIFO�st_mode)r �	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��mode�device�dir_fd)rr#rr%r9r1r2rr8r�assertInr
rir��EACCESrmr4r5)r r: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)NrrO)rr%rr�st_devrr�rD�majorrBr8r9r'r��
OverflowError�minorr@)r �st�devrBrDrrr�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")rB�st_uid�st_gid)�uid�gidr%��first_paramr �	stat_funcrr�
check_stat�s
�z6PosixTester._test_all_chown_common.<locals>.check_statrOr.)rr6rlr�)zHP-UX�SunOSz1Skipping because of non-standard chown() behaviorN)rbr4r/r�r��systemrgrhr8rr0�strr'r9)
r �
chown_funcrMrNrOrJrK�is_root�	big_value�trrLr�_test_all_chown_common�sF











�z"PosixTester._test_all_chown_common�chownztest needs os.chown()cCsFt�tj�|�ttjtjdd�t�tj�|�	tjtjtj
�dSrN)rbr#rrr8rrrX�create_empty_filerWr%rrrr�
test_chownszPosixTester.test_chown�fchownztest needs os.fchown()cCsRt�tj�ttjd�}z|��}|�tj|t	tdd��W|�
�dS|�
�w)Nr~r#)rbr#rrrrrrWrr[r7rs)r �	test_filer�rrr�test_fchowns

�zPosixTester.test_fchown�lchownztest needs os.lchown()cCs8t�tj�t�ttj�|�tjtjt	tdd��dS)N�lstat)
rbr#rr�symlink�_DUMMY_SYMLINKrWrr^r7rrrr�test_lchown"s

�zPosixTester.test_lchownr�ztest needs posix.chdir()cCs"t�tj�|�ttjtj�dSr")rr�rbrnr8rrrrrrr�
test_chdir*szPosixTester.test_chdircCs|�tjt�tj��dSr")r=rrr�listdirrbrnrrrr�test_listdir/szPosixTester.test_listdircCs|�tjt���dSr")r=rrrrdrrrr�test_listdir_default2rpz PosixTester.test_listdir_defaultcCs|�t�tj�t�d��dS�N�.)r=rbr)rrrrdrrrr�test_listdir_bytes7szPosixTester.test_listdir_bytesc	CsxttfD]5}|�t��t�|d��}Wd�n1swY|�t�t	j
�|�|D]
}|�t|�t
�q.qdSrg)r��
memoryview�assertWarnsr+rrdr=rbr)rr�assertIs�typer�)r �cls�namesr;rrr�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�rrsrB�sortedrd)r �frrr�test_listdir_fdDs��zPosixTester.test_listdir_fd�accessztest needs posix.access()cCs|�t�tjtj��dSr")rmrrurrrb�R_OKrrrr�test_accessSszPosixTester.test_access�umaskztest needs posix.umask()cCs$t�d�}|�|t�t�|�dSr�)rrxrr�)r �old_maskrrr�
test_umaskWs
zPosixTester.test_umask�strerrorztest needs posix.strerror()cCs|�t�d��dSr�)rmrr{rrrr�
test_strerror]szPosixTester.test_strerror�pipeztest needs posix.pipe()cCs$t��\}}t�|�t�|�dSr")rr}rbrs)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)N�DEADBEEFrr6r�)r8r9rbr�rsrrrrr�get_blockingrr�rzr�
PIPE_MAX_SIZE)r �rr~rrr�
test_pipe2hs$

�zPosixTester.test_pipe2cCs8ddl}|�ttj|jd�|�ttj|jd�dS�Nrr6)�	_testcapir8rCrbr��INT_MAX�UINT_MAX)r r�rrr�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�rrrr�
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 fsrx)rbr%rmrr��UF_IMMUTABLErr
�
EOPNOTSUPPr�rBrrir�chflags)r �chflags_func�target_file�kwargsrE�flags�errr��new_str�rrrr�_test_chflags_regular_file�s2
��
����"z&PosixTester._test_chflags_regular_filer�ztest needs os.chflags()cCs|�tjtj�dSr")r�rr�rrrrrr�test_chflags�szPosixTester.test_chflags�lchflagsztest needs os.lchflags()cCs(|�tjtj�|jtjtjdd�dS�NFr�)r�rr�rrr�rrrr�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)Nr�cSstj||dd�Sr�)rr�)r�r�rrr�chflags_nofollow�sz;PosixTester.test_lchflags_symlink.<locals>.chflags_nofollowr�)rbr%rrrmrr`rar�appendr_rr�r�r�rr
r�r�rB)
r �	testfn_st�dummy_symlink_str��fnr�r�r��
new_testfn_st�new_dummy_symlink_strrr�test_lchflags_symlink�s4
��
��z!PosixTester.test_lchflags_symlinkcCsLtjdkrt}nt}tj��D]\}}|�t|�|�|�t|�|�qdS)N�nt)	rbr;rRr�rr��itemsrBrm)r �	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)
NzFRUITVEGETABLE�cabbagesFRUITVEGETABLEscabbage�FRUITzorangeVEGETABLE=cabbagesFRUITsorangeVEGETABLE=cabbagezFRUIT=ORANGE�lemonsFRUIT=ORANGEslemon)r8r�rb�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)	rbr(r��abspathrr�mkdirr��rmtree)r �dirnamern�	base_pathr)�_create_and_do_getcwdr�test_getcwd_long_pathnames�s

�

�z&PosixTester.test_getcwd_long_pathnames�getgrouplistztest needs posix.getgrouplist()rdztest needs pwd.getpwuid()r4ztest needs os.getuid()cCs<t�t���d}t�t���d}|�|t�||��dS)NrrA)rcrdrbr4r=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'�darwinr�MACOSX_DEPLOYMENT_TARGETz10.3csr�r"r�)r�r�rrrr�3r�rqr�)r�rz$getgroups(2) is broken prior to 10.6)rbr�r��striprs�setr�r�rgrhr�r��	sysconfig�get_config_var�tuple�symmetric_differencerr0rmr-)r �idg�groups�ret�
idg_groupsr��dt�symdiffrrr�test_getgroups!s$
�
�

$
zPosixTester.test_getgroups�SIGCHLDz2CLD_XXXX be placed in si_code for a SIGCHLD signal�
waitid_resultztest needs os.waitid_resultcCs(tjtjtjtjtjtjdSr")rb�
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�rr�rDr�r�r8r)r �pol�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)�SCHED_�r�)r�r;�schedrrrr�cs
�zDPosixTester.test_get_and_set_scheduler_and_param.<locals>.<listcomp>rrO�r�r��+l���)�sched_priority)r�__dict__r�r
r=rbr3rr
rir8�sched_getparamrr�r�r�r�r��sched_setscheduler�sched_setparamr9�sched_paramrC)r �possible_schedulers�mine�parentr�param�largerrr�$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�rr'rD�
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)Nrr6r�rOr	)
r�sched_getaffinityrr�rDrCr�r�r�r8rr�r�)r �mask�cpurrr�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)Nrr6i�����0X�r�rO)rr�rC�popr�rBr8rr��mapr�rCr�r�r�)r r�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!)rrrrzr{�tellrr�rangerBrbr��	SEEK_DATA�assertLessEqualrr8rrgrh)r rur�fnor�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�linkN�noodly2�doesnotexistfilenamez'doesnotexistfilename' -> '{}'z#No valid path_error2() test for os.)	r7rbrrrr=�formatrRrj)r r;�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#r8r�rbrr�r�rsrr��existsr�r%�r r��fn_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)rbr)rrrr#r8r�rr�r�rsrr�rr�r%rrrr�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)NrOz"system does not support pidfd_openzpidfd_open syscall blocked: r)r8rrbrr�r
rr��
isinstancer3rBr�rsr1)r r�rrr�test_pidfd_opens�
zPosixTester.test_pidfd_open)m�__name__�
__module__�__qualname__r!r&r=rg�
skipUnlessrrrGrKrRrWr[r]rkrorvr|rr7rb�supports_fdr�r�r�r�r�r�r��requires_32br�r�r�r�r�r�r�r�r�r�r��supports_follow_symlinksrrrrr	rrrr�requires_linux_versionrrr"r(r,r7r%r?rGrWrZr]rbrcrerfrirprdrtrwrzr|r�r��cpython_onlyr�r�r�r�r�r�r�r�r�rcr�r��signalr��requires_sched_h�requires_sched_affinityr�r��requires_schedr�r�r�rrrrrrr 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)Nr6�_�base)
r.�countrrrr�r�rmdirrbr�r0r�open_dir_fd)r r;�base_dir�fullnamer<rrr�prepares�
"�zTestPosixDirFd.prepareccsZ�|���\}}}t�|�|�tj|�|||fVWd�dS1s&wYdSr")r6rrYrrr#�r r<r;r5rrr�prepare_file*s�
"�zTestPosixDirFd.prepare_filez)test needs dir_fd support for os.access()cCsL|���\}}}|�tj|tj|d��Wd�dS1swYdS�N�r<)r8rmrrurbrvr7rrr�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�dS1s9wYdSr9)	r8r�chmodr%r1r2rBr5�S_IRWXU)r r<r;r5�srrr�test_chmod_dir_fd6s

�"�z TestPosixDirFd.test_chmod_dir_fdrXz'test needs dir_fd support in os.chown()cCsN|���\}}}tj|t��t��|d�Wd�dS1s wYdSr9)r8rrXrbr4r/r7rrr�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)Nr~z	testline
r:zshould be integer or None, notl F�x:^V)r6rrzrrr#r%rBr&r9r(r'r8rC)r r<r;r5�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<)
r8r�rr�r8r9r�rbr'r�)r r<r;r5r�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(): %sr6)
r8r6rrr3r�rr#rBr%)r r<r;r5�dir_fd2�linkname�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&wYdSr9)r6rr�rr2r%r7rrr�test_mkdir_dir_fd�s
"�z TestPosixDirFd.test_mkdir_dir_fdr8r9zAtest 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:)r6r%r9r1r2rr8rr=r
rir�r>rr#rmr4r5)r r<r;r5r: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:�	)
r6rrzrrr#r�r�rBrs)r r<r;r5rAr�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�Nr`r:)r6rbr`rrr#rBrRr7rrr�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)NrG)r8r6rrr%)r r<r;r5rJ�name2�	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+wYdSrS)r6rr`rr#rBrRr7rrr�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:wYdSr9)	r6rrYrr%r#r8rrr7rrr�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/)
r6rr-r%r1r2r3r�rr#rmr4r5)r r<r;r5rrrr�test_mkfifo_dir_fd�s��"�z!TestPosixDirFd.test_mkfifo_dir_fdN)(r!r"r#r1rr6r8rgr$rbru�supports_dir_fdr;r<r?rrXr@r%rDr�rFrrMr�rNr8rOrrQrRrTrrWr`rXr#rYr-rZrrrrr.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 privilegesr0zneed posix.getgroupsr�zgetgroups(2) is broken on OSX)	rr4rgrhrr�r�r0�saved_groupsrrrrr!�s




zPosixGroupsTester.setUpcCsNttd�r
t�|j�dSttd�r%t�t���j}t�||jd�dSdS)N�	setgroupsr^r)	rrr^r]rcrdr4rer^�r r;rrrr&�s

�zPosixGroupsTester.tearDownr^ztest needs posix.initgroups()cCsDt|jpdg�d}t�t���j}t�||�|�|t�	��dSr�)
�maxr]rcrdrr4rer^r=r0)r r�r;rrrrk�sz!PosixGroupsTester.test_initgroupsr^ztest needs posix.setgroups()cCs6dgttd��fD]}t�|�|�|t���q	dS)Nr�)r�r
rr^�assertListEqualr0)r r�rrr�test_setgroups�s
�z PosixGroupsTester.test_setgroupsN)r!r"r#r!r&rgr$rrrkrcrrrrr\�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�-Sr�r�NcGstjddg|�RS)Nrerf)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()))
            r�rr��utf-8��encoding)rrrr#ri�
spawn_funcrbr�rr�rrBr�rR)r �pidfile�scriptrhr�rsrrr�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)	rnrbr��FileNotFoundErrorr3rB�filename�waitpid�assertNotEqual)r rrr��exc�pid2�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)
Nrjz^, "w", encoding="utf-8") as envfile:
                envfile.write(os.environ['foo'])
        r�rr_�barr�rkrl)
rrrr#rirnrbr�rr�rrBr�)r �envfilerprhr�rsrrr�test_specify_environment)s��"�z)_PosixSpawnMixin.test_specify_environmentcCs.|j|jd|jtjdd�}tj|dd�dS�Nr��file_actionsr��rn�NOOP_PROGRAMrbr�rr��r r�rrr�test_none_file_actions8��z'_PosixSpawnMixin.test_none_file_actionscCs.|j|jd|jtjgd�}tj|dd�dSr~r�r�rrr�test_empty_file_actionsAr�z(_PosixSpawnMixin.test_empty_file_actionscC�0|jtjtjddgtjdd�}tj|dd�dS)Nr�r�F��resetidsrr��rnr�r�rbr�rr�r�rrr�test_resetids_explicit_defaultJ�
�z/_PosixSpawnMixin.test_resetids_explicit_defaultcCr�)Nr�r�Tr�rr�r�r�rrr�
test_resetidsSr�z_PosixSpawnMixin.test_resetidscCsN|�t��|jtjtjddgtjdd�Wd�dS1s wYdS)Nr�r�r��r8r9rnr�r�rbr�rrrr�test_resetids_wrong_type\�
�"�z)_PosixSpawnMixin.test_resetids_wrong_typecCs4|jtjtjddgtjt��d�}tj|dd�dS)Nr�r���	setpgrouprr�)rnr�r�rbr�r2rr�r�rrr�test_setpgroupbs
�z_PosixSpawnMixin.test_setpgroupcCsN|�t��|jtjtjddgtjdd�Wd�dS1s wYdS)Nr�r��023r�r�rrrr�test_setpgroup_wrong_typekr�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)r���
setsigmaskrr�)�textwrap�dedentrnr�r�rbr�r*�SIGUSR1rr�)r r�r�rrr�test_setsigmaskqs

�z _PosixSpawnMixin.test_setsigmaskcC��|�t��|jtjtjddgtjdd�Wd�n1swY|�t��|jtjtjddgtjdgd�Wd�n1sDwY|�t��|jtjtjddgtjtj	tj	dgd�Wd�dS1sowYdS)Nr�r��"r��jr6�
r8r9rnr�r�rbr�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())
            r�)�setsidzsetsid is not supported: zsetsid failed with: rr�r�)rbr}rrs�set_inheritabler�r�rnr�r�r�r�r�r3rr�r�r��getsidr1rv)	r �rfd�wfdr�r�rw�output�	child_sid�
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)Nr�r���	setsigdefr�)r*r��SIG_IGNr�r�rnr�r�rbr�rr�)r �original_handlerr�r�rrr�test_setsigdef�s

� z_PosixSpawnMixin.test_setsigdefcCr�)Nr�r�r�r�r�r6r�rrrr�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)r�)�	schedulerr��rbr
r�r�r�rnr�r�r�r�rr��r �policy�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�r�r�rrr�test_setscheduler_with_policy�r�z._PosixSpawnMixin.test_setscheduler_with_policycCs\tjdtj�t�tjdftjdftjddfg}|j|j	d|j	tj
|d�}tj|dd�dS)NrArr6r�rr�)
rb�POSIX_SPAWN_OPENr��realpath�__file__r��POSIX_SPAWN_CLOSE�POSIX_SPAWN_DUP2rnr�r�rr�)r r�r�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)
Nrrrr")i90r6r�rAr)r�r8r9rnrbr�r�r�r�r�r�rgrrr�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")
            r6r�rrr�rkrl�hello)rrrr#rbr�r�r��O_TRUNCr%r1r2rirnr�rr�rrBr�)r rArpr�rhr�rsrrr�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)
            r�rrr�rkrlzis closed %d)rrrr#rirnrbr�r�rr�rrBr�r
r�)r �	closefilerprhr�rsrrr�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)Nr�rr6r�rrr�rkrlr�)rrrr#rrbr�rrrirnr�rr�rBr�)r �dupfilerp�	childfiler�rhr�rsrrrrGs���"�z_PosixSpawnMixin.test_dup2)&r!r"r#r�r�r�rnrirqrzr}r�r�r�r�r�r�r�rgr$rr*r�r�r�r�r�r-�skipIfr�r�r�r�r�r�r�r�rrrrrrd�sP					�

�
��rd�posix_spawnztest needs os.posix_spawnc@seZdZeedd�ZdS)�TestPosixSpawnr�N)r!r"r#r7rrnrrrrr�Zsr��posix_spawnpztest needs os.posix_spawnpc@s&eZdZeedd�Zejdd��ZdS)�TestPosixSpawnPr�NcCs�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�PATHrerfr�r�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�rbr�r0r`r�r��pathsepr�rfr�r�r)r �temp_dir�program�program_fullpathr��
spawn_argsr�rhrrr�test_posix_spawnpcs ��
z!TestPosixSpawnP.test_posix_spawnp)	r!r"r#r7rrnr�skip_unless_symlinkr�rrrrr�_s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)�HAVE_r�)r��nm��config_varsrr�	<setcomp>�s"z-TestPosixWeaklinking.setUp.<locals>.<setcomp>csr�r"r�)r��partrrrr��r�z-TestPosixWeaklinking.setUp.<locals>.<genexpr>rq)r�r��get_config_vars�	availabler��mac_verr�)r r�r�rr�rr!�s
&zTestPosixWeaklinking.setUpcCs||jvr
t�|�d���dS)Nz not weak-linked)r�rgrhr_rrr�_verify_available�s
�z&TestPosixWeaklinking._verify_availablecCsd|�d�|jdkr|�ttd�d�|�ttd�d�dS|�ttd�d�|�ttd�d�dS)	N�HAVE_PWRITEV)r�rar�zos.pwritev is not availabler�zos.readv is not availablezos.pwritev is availablezos.readv is available)r�r�rmrrbrrrrrr��s

z!TestPosixWeaklinking.test_pwritevcC�t|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	ddd�Wd�dS1s3wYdS)N�HAVE_FSTATAT�r�r��dir_fd unavailable�filerr:)
r�r�r=r�_have_functions�assertNotInr&r�rbr%rrrrr,��

"�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)
N�HAVE_FACCESSATr�r�r�rr:zfollow_symlinks unavailableFr�zeffective_ids unavailableT)�
effective_ids)r�r�r=rr�r�r&r�rbrurvrrrrrw�s

��"�z TestPosixWeaklinking.test_accesscCs�|�d�|jdkr|�dtj�dS|�dtj�|�dtj�|�td��tj	dddd�Wd�dS1s;wYdS)	N�
HAVE_FCHMODATr��HAVE_LCHMODr�r�i�rr:)
r�r�r=rr�r�r&r�rbr<rrrr�
test_chmod�s

"�zTestPosixWeaklinking.test_chmodcCs�|�d�|jdkr|�dtj�dS|�dtj�|�dtj�|�td��tj	ddddd�Wd�dS1s<wYdS)N�
HAVE_FCHOWNATr��HAVE_LCHOWNr�r�rr:)
r�r�r=rr�r�r&r�rbrXrrrrrZ�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)N�HAVE_LINKATr�zsrc_dir_fd unavailable�source�targetr�rHzdst_dir_fd unavailable�rIrGrr~�dataTr�F)r�r�r=rr�r�r&r�rbrrr�r�r0rrzr`r8�FileExistsError)r r��	link_path�target_path�source_pathrurrr�	test_link�s<

���
����"�zTestPosixWeaklinking.test_linkcCs�|�d�|jdkr|�dtj�dS|�dtj�|�td��
t�	d�Wd�n1s0wY|�td��t�
d�Wd�dS1sLwYdS)N�HAVE_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�r&r9rbrd�scandirrrrr�test_listdir_scandir�s

�"�z)TestPosixWeaklinking.test_listdir_scandircCr�)N�HAVE_MKDIRATr�r��dirrr:)
r�r�r=rr�r�r&r�rbr�rrrr�
test_mkdir
r�zTestPosixWeaklinking.test_mkdircCr�)N�
HAVE_MKFIFOAT�r`rr�r�rr:)
r�r�r=rr�r�r&r�rbr-rrrrr7r�z TestPosixWeaklinking.test_mkfifocCr�)N�HAVE_MKNODATrr�r�rr:)
r�r�r=rr�r�r&r�rbr8rrrrr? 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)	N�
HAVE_RENAMEATr�z%src_dir_fd and dst_dir_fd unavailable�a�brr�r�)r�r�r=rr�r�r&r�rbrrrrrr�test_rename_replace+s 

���"�z(TestPosixWeaklinking.test_rename_replacecCs�|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	ddd�Wd�n1s2wY|�td��tj
ddd�Wd�dS1sPwYdS)N�
HAVE_UNLINKATr�r�r�rr:)r�r�r=rr�r�r&r�rbr#r2rrrr�test_unlink_rmdir?s

�"�z&TestPosixWeaklinking.test_unlink_rmdircCsx|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	dtj
dd�Wd�dS1s5wYdS)N�HAVE_OPENATr�r�r�rr:)r�r�r=rr�r�r&r�rbrr�rrrr�	test_openMs

"�zTestPosixWeaklinking.test_opencCr�)N�HAVE_READLINKATr�r�r�rr:)
r�r�r=rr�r�r&r�rbrRrrrr�
test_readlinkXr�z"TestPosixWeaklinking.test_readlinkcCsv|�d�|jdkr|�dtj�dS|�dtj�|�td��tj	dddd�Wd�dS1s4wYdS)N�HAVE_SYMLINKATr�r�r
rrr:)
r�r�r=rr�r�r&r�rbr`rrrr�test_symlinkcs

"�z!TestPosixWeaklinking.test_symlinkcCs�|�d�|�d�|jdkr|�dtj�|�dtj�dS|�dtj�|�dtj�|�td��tj	ddd�Wd�dS1sFwYdS)N�
HAVE_FUTIMENS�HAVE_UTIMENSAT)r�r`r�r�rr:)
r�r�r=rr�r�r&r�rbr�rrrrr�ns


"�zTestPosixWeaklinking.test_utimeN)r!r"r#r!r�r�r,rwr�rZr�rrr7r?rrrrrr�rrrrr��s&
'r�cCr�r")r�
reap_childrenrrrr�tearDownModule}sr�__main__)/�__doc__ryr�test.supportrrr�test.support.script_helperr�
import_modulerr
r�r*r�rbr�rcr%r�rgrr��
contextlibrr�r0�
gettempdirrrar$�maxsizer&rr-�TestCaserr.r\rdrr�r�r�rr!�mainrrrr�<module>sn
��
wA$]$y�

Youez - 2016 - github.com/yon3zu
LinuXploit