o
    JXh                     @   s   d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
 zd dlZW n ey7   dZY nw d dlmZmZ dZdd Zdd	 Zd
d ZdS )    N)support)TESTFN_UNDECODABLEFS_NONASCII)setup_unraisable_hooksetup_threading_excepthookZPYTHONREGRTEST_UNICODE_GUARDc           	   	   C   sj  zt j }W n ttfy   d }Y n-w tjd|d g }ttdr)|	tj
 ttdr4|	tj |D ]
}tj|d|d q6t  t  tt j | jr\t jdtj| j t j D ](}t|dr{t|jD ]\}}tj||j|< qmt|dd rtj|j|_qa| jrd	tj_ t !  | j"d urt#| j" | j$d urt%&| j$ t'| j(o| j(d
k | j)t_)tt drdd }t *| t+  t,  | j-d urt.tj/| j-d t_/t.tj0| j-d t_0t1tj2| j-t_2t1tj3| j-t_3t1tj/| j-t_/t1tj0| j-t_0| j4rddl5m6} d|_7t8r'tj9r'tj:;t<= t8 d S t>r3tj?;t<t> d S d S )NT)Zall_threadsfileSIGALRMSIGUSR1)chainr   r   __path____file__F   addaudithookc                 S   s   d S N )nameargsr   r   @/opt/python-3.10.19/usr/lib/python3.10/test/libregrtest/setup.py_test_audit_hookU   s   z%setup_tests.<locals>._test_audit_hook(      )RegressionTestResult)@sys
__stderr__fileno
ValueErrorAttributeErrorfaulthandlerenablehasattrsignalappendr   r	   register_adjust_resource_limitsreplace_stdoutr   Zrecord_original_stdoutstdoutZtestdirpathinsertosabspathmodulesvalues	enumerater   getattrr   Z
huntrleaksunittestZBaseTestSuite_cleanup_deactivate_opcachememlimitZset_memlimitZ	thresholdgcZset_thresholdZsuppress_msvcrt_assertsverboseZuse_resourcesr   r   r   timeoutmaxZSHORT_TIMEOUTZLONG_TIMEOUTminZLOOPBACK_TIMEOUTZINTERNET_TIMEOUTZxmlpathZtest.support.testresultr   ZUSE_XMLr   supports_bytes_environenvironb
setdefaultUNICODE_GUARD_ENVencoder   environ)	nsZ	stderr_fdZsignalssignummoduleindexr&   r   r   r   r   r   setup_tests   sl   






rA   c                     s\   	 t j z  } W n
 ty   Y d S w t| d jddddt _ fdd}t| d S )NwbackslashreplaceF
)encodingerrorsclosefdnewlinec                      s   t j   t _d S r   )r   r%   closer   r%   r   r   restore_stdout   s   

z&replace_stdout.<locals>.restore_stdout)r   r%   r   r   openrE   atexitr"   )fdrK   r   rJ   r   r$   s   s   r$   c                  C   s   	 zdd l } ddl m}m} W n
 ty   Y d S w | |\}}d}||k ri||k rkt||}z| |||f td| d|  W d S  tt	fyh } ztd| d| d| d	 W Y d }~d S d }~ww d S d S )
Nr   )RLIMIT_NOFILERLIM_INFINITYi   zRaised RLIMIT_NOFILE: z -> z#Unable to raise RLIMIT_NOFILE from z to z: .)
resourcerO   rP   ImportErrorZ	getrlimitr6   Z	setrlimitprintr   OSError)rR   rO   rP   Zfd_limitZmax_fdsZdesired_fdsZnew_fd_limiterrr   r   r   r#      s.   

r#   )rM   r   r(   r    r   r.   testr   Ztest.support.os_helperr   r   r2   rS   Ztest.libregrtest.utilsr   r   r:   rA   r$   r#   r   r   r   r   <module>   s$    ^