B
    u9ay  ã               @   sv   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 yd dlZW n e	k
r`   dZY nX dd„ Z
dd„ ZdS )é    N)Úsupportc       	   	   C   s&  yt j ¡ }W n ttfk
r*   d }Y n^X tjd|d g }ttdƒrT| 	tj
¡ ttdƒrj| 	tj¡ x|D ]}tj|d|d qpW tƒ  t t j¡ | jr¸t j dtj | j¡¡ xbt j ¡ D ]T}t|dƒrüx(t|jƒD ]\}}tj |¡|j|< qÞW t|dd ƒrÄtj |j¡|_qÄW | jr,d	tj_| j d k	rDt !| j ¡ | j"d k	r\t# $| j"¡ ydd l%}W n t&k
r~   Y nœX | '|j(|j)B |j*B |j+B ¡ y
|j, W n tk
r¾   Y n\X xX|j-|j.|j/gD ]D}| j0r| j0d
kr| ,||j1¡ | 2||j3¡ n| ,|d¡ qÒW | j4t_4d S )NT)Zall_threadsÚfileÚSIGALRMÚSIGUSR1)Úchainr   r   Ú__path__Ú__file__Fé   )5ÚsysÚ
__stderr__ÚfilenoÚ
ValueErrorÚAttributeErrorÚfaulthandlerZenableÚhasattrÚsignalÚappendr   r   ÚregisterÚreplace_stdoutr   Zrecord_original_stdoutÚstdoutZtestdirÚpathÚinsertÚosÚabspathÚmodulesÚvaluesÚ	enumerater   Úgetattrr   Z
huntrleaksÚunittestZBaseTestSuiteZ_cleanupZmemlimitZset_memlimitZ	thresholdÚgcZset_thresholdÚmsvcrtÚImportErrorZSetErrorModeZSEM_FAILCRITICALERRORSZSEM_NOALIGNMENTFAULTEXCEPTZSEM_NOGPFAULTERRORBOXZSEM_NOOPENFILEERRORBOXZCrtSetReportModeZCRT_WARNZ	CRT_ERRORZ
CRT_ASSERTÚverboseZCRTDBG_MODE_FILEZCrtSetReportFileZCRTDBG_FILE_STDERRZuse_resources)	ÚnsZ	stderr_fdZsignalsZsignumÚmoduleÚindexr   r    Úm© r'   ú/usr/lib/python3.7/setup.pyÚsetup_tests   sZ    






r)   c                 sZ   t j‰ yˆ  ¡ } W n tk
r&   dS X t| dˆ jddddt _‡ fdd„}t |¡ dS )	zˆSet stdout encoder error handler to backslashreplace (as stderr error
    handler) to avoid UnicodeEncodeError when printing a tracebackNÚwÚbackslashreplaceFÚ
)ÚencodingÚerrorsÚclosefdÚnewlinec                  s   t j ¡  ˆ t _d S )N)r
   r   Úcloser'   )r   r'   r(   Úrestore_stdouts   s    
z&replace_stdout.<locals>.restore_stdout)r
   r   r   r   Úopenr-   Úatexitr   )Úfdr2   r'   )r   r(   r   _   s    
r   )r4   r   r   r   r
   r   Ztestr   r   r!   r)   r   r'   r'   r'   r(   Ú<module>   s   
Q