o
    f                     @   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 )zPrint 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$    	
