o
    …9j  ã                   @   s’   d dl Z d dlZd dlZd dlZd dlmZ dd„ Zdd„ Zdd„ Z	ddd„Z
dd„ Zdadd„ Zdd„ Zdd„ Zdadd„ Zdd„ Zdd„ ZdS )é    N)Úsupportc                 C   s°   t  | d ¡}t|dƒ\} }t| dƒ\}} t|dƒ\}}g }|r'| d| ¡ |r0| d| ¡ | rG|r<| d|  ¡ n| d| |d   ¡ |sMd| S |d d	… }d
 |¡S )Ng     @�@iè  é<   z%s hourz%s minz%s secz%.1f secz%s msé   ú )ÚmathÚceilÚdivmodÚappendÚjoin)ÚsecondsÚmsÚminutesÚhoursÚparts© r   ú-/usr/lib/python3.10/test/libregrtest/utils.pyÚformat_duration   s"   
r   c                 C   s>   | sd S t | ƒD ]\}}tj |¡\}}|dkr|| |< qd S )Nz.py)Ú	enumerateÚosÚpathÚsplitext)ÚnamesÚidxÚnameÚbasenameÚextr   r   r   Úremovepy!   s   €ýr   c                 C   s    | dkr
d| |f S d| |f S )Né   z%d %sz%d %ssr   )ÚnÚwordr   r   r   Úcount*   s   r    éF   é   c                 C   s:   d| }t tjd dd„ t| ƒD ƒ¡|||d�|d� dS )zÐPrint the elements of iterable x to stdout.

    Optional arg width (default 70) is the maximum line length.
    Optional arg indent (default 4) is the number of blanks with which to
    begin each line.
    r   c                 s   s   � | ]}t |ƒV  qd S ©N)Ústr)Ú.0Úeltr   r   r   Ú	<genexpr>;   s   € zprintlist.<locals>.<genexpr>)Úinitial_indentÚsubsequent_indent)ÚfileN)ÚprintÚtextwrapÚfillr
   Úsorted)ÚxÚwidthÚindentr*   Úblanksr   r   r   Ú	printlist1   s   ÿ
þr3   c                 C   s   t  | ¡ d S r#   )r   Úprint_warning)Úmsgr   r   r   r4   @   s   r4   c                   C   s0   t jd ur
t j ¡  t jd urt j ¡  d S d S r#   )ÚsysÚstdoutÚflushÚstderrr   r   r   r   Úflush_std_streamsG   s
   


ÿr:   c                 C   sJ   dt _tdƒ tj}ztƒ  tjt_t| ƒ tj ¡  W |t_d S |t_w )NTzUnraisable exception)	r   Úenvironment_alteredr4   r6   r9   r:   Ú
__stderr__Úorig_unraisablehookr8   )Ú
unraisableÚ
old_stderrr   r   r   Úregrtest_unraisable_hookN   s   r@   c                   C   s   t jatt _d S r#   )r6   Úunraisablehookr=   r@   r   r   r   r   Úsetup_unraisable_hook\   s   
rB   c                 C   sT   dt _td| jj› �ƒ tj}ztƒ  tjt_t	| ƒ tj 
¡  W |t_d S |t_w )NTzUncaught thread exception: )r   r;   r4   Úexc_typeÚ__name__r6   r9   r:   r<   Úorig_threading_excepthookr8   )Úargsr?   r   r   r   Úregrtest_threading_excepthooke   s   rG   c                  C   s   dd l } | jat| _d S )Nr   )Ú	threadingÚ
excepthookrE   rG   )rH   r   r   r   Úsetup_threading_excepthooks   s   
rJ   c                  C   s`  t j ¡ D ]	} t| dƒr| `qt jt jt jt jfD ]
}|d ur#| 	¡  qzt jd }W n	 t
y4   Y nw |j ¡  zt jd }W n	 t
yJ   Y nw | ¡  zt jd }W n	 t
y_   Y nw |j ¡  zt jd }W n	 t
yu   Y nw | ¡  zt jd }W n	 t
yŠ   Y nw | ¡  zt jd }W n	 t
yŸ   Y nw | ¡  zt jd }W n	 t
y´   Y nw | ¡  zt jd	 }	W n	 t
yÉ   Y nw |	j ¡  zt jd
 }
W n	 t
yß   Y nw |
 ¡  zt jd }W n	 t
yô   Y nw d |_zt jd }W n
 t
�y	   Y nw | ¡  zt jd }W n
 t
�y   Y nw |jD ]}|ƒ  �q#t ¡  d S )NÚ__warningregistry__zdistutils.dir_utilÚreÚ	_strptimezurllib.parsezurllib.requestÚ	linecacheÚ	mimetypesÚfilecmpÚstructÚdoctestÚctypesÚtyping)r6   ÚmodulesÚvaluesÚhasattrrK   r7   r9   Ú
__stdout__r<   r8   ÚKeyErrorÚ_path_createdÚclearÚpurgeÚ_regex_cacheÚclear_cacheÚ
urlcleanupÚ
clearcacheÚ_default_mime_typesÚ_cacheÚ_clearcacheÚmasterÚ_reset_cacheÚ	_cleanupsr   Ú
gc_collect)ÚmodÚstreamÚdistutils_dir_utilrL   rM   Úurllib_parseÚurllib_requestrN   rO   rP   rQ   rR   rS   rT   Úfr   r   r   Úclear_cachesz   s¤   
€€ÿ
ÿÿ
ÿÿÿÿÿ
ÿÿÿÿ

rn   )r!   r"   N)r   Úos.pathr   r6   r,   Útestr   r   r   r    r3   r4   r=   r:   r@   rB   rE   rG   rJ   rn   r   r   r   r   Ú<module>   s$    	
