o
    éT•jüM  ã                	   @   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Zd dlZd dl	Z	d dl
Z
ejdkr0dZndZd ee ¡ ¡Zed ZejdkrMd dlZe de¡ZdZejd	kre ¡ jd
kr~ed Zz	e e ¡ ¡ W n	 eyq   Y n1w edee ¡ f ƒ dZn#ejdkr¢z	d e ¡ ¡ W n ey    ed e ¡ d¡ ZY nw 	 dZdD ]Zze e e¡¡ekrµe‚W n	 ey¿   Y q¦w eZ e  ¡ Z!dZ"dD ]Zz	e e ¡ ¡ W qË eyç   e e¡e Z"Y  nw erïee Z#ndZ#e#pôeZ$dd„ Z%da&dd„ Z'dd„ Z(da)dd„ Z*dd„ Z+dd„ Z,ej -d¡�r.dGd!d"„Z.d#d$„ Z/d%d&„ Z0d'd(„ Z1d)d*„ Z2nej,Z/ej3Z0d+d(„ Z1d,d*„ Z2d-d.„ Z3d/d0„ Z4ej5dHd1d2„ƒZ6ej5dGd3d4„ƒZ7ej5dId6d7„ƒZ8d8d9„ Z9ej5d:d;„ ƒZ:d<d=„ Z;G d>d?„ d?ƒZ<d@dA„ Z=e>edBƒ�rƒej5dCdD„ ƒZ?G dEdF„ dFej@jAƒZBdS )Jé    NÚjavaz$testz@testz	{}_{}_tmpu   -Ã Ã²É˜Å�ÄŸÚdarwinÚNFDÚnté   u   -å…±Å�â™¡Í£í²€ztWARNING: The filename %r CAN be encoded by the filesystem encoding (%s). Unicode filename tests may not be effectiveó   ÿs   -ÿÚsurrogateescapeÚ )õ   Ã¦u   Ä°u   Å�u   Ï†u   Ðšu   ×�u   ØŒu   Øªu   à¸�õ   Â u   â‚¬)s   çwðr   s   ®Õí²€s   í´€s   �˜c                  C   s8   t tdƒ} z|  ¡ W |  ¡  ttƒ S |  ¡  ttƒ w )z`
    Create an invalid file descriptor by opening and closing a file and return
    its fd.
    Úwb)ÚopenÚTESTFNÚfilenoÚcloseÚunlink©Úfile© r   ú-/usr/lib/python3.10/test/support/os_helper.pyÚmake_bad_fdš   s   

ÿ
r   c               
   C   s^   t d urt S td } z
t t| ¡ d}W n tttfy%   d}Y |a |S w t | ¡ |a |S )NÚcan_symlinkTF)Ú_can_symlinkr   ÚosÚsymlinkÚOSErrorÚNotImplementedErrorÚAttributeErrorÚremove)Úsymlink_pathÚcanr   r   r   r   ª   s   û
r   c                 C   ó    t ƒ }d}|r	| S t |¡| ƒS )z8Skip decorator for tests that require functional symlinkz*Requires functional symlink implementation)r   ÚunittestÚskip©ÚtestÚokÚmsgr   r   r   Úskip_unless_symlinkº   ó   r(   c            	   	   C   sL  dd l } td ur
tS ttdƒsd}|a|S dd l}|  ¡ }| j|d�\}}zsttdƒ�D}z0t 	|dd¡ t 	|dd	¡ t 	| 
¡ dd¡ | ¡ }t d
|¡}|d u pZt| d¡ƒdk}W n tyg   d}Y nw W d   ƒ n1 srw   Y  W ttƒ t|ƒ t|ƒ |a|S W ttƒ t|ƒ t|ƒ |a|S ttƒ t|ƒ t|ƒ w )Nr   ÚsetxattrF©Údirr   s	   user.testó    s   trusted.foos   42z2.6.(\d{1,2})é   é'   )ÚtempfileÚ
_can_xattrÚhasattrr   ÚplatformÚmkdtempÚmkstempr   r   r*   r   ÚreleaseÚreÚmatchÚintÚgroupr   r   Úrmdir)	r0   r    r3   Útmp_dirÚtmp_fpÚtmp_nameÚfpÚkernel_versionÚmr   r   r   Ú	can_xattrÄ   sL   
êÿ€õîü
rB   c                 C   r!   )zDSkip decorator for tests that require functional extended attributesz(no non-broken extended attribute support)rB   r"   r#   r$   r   r   r   Úskip_unless_xattrå   r)   rC   c              	   C   s(   zt | ƒ W d S  ttfy   Y d S w ©N)Ú_unlinkÚFileNotFoundErrorÚNotADirectoryError©Úfilenamer   r   r   r   ì   s
   ÿr   ÚwinFc                 C   sŠ   | |ƒ |r	|}nt j |¡\}}|pd}d}|dk r9t  |¡}|r&|s,d S ||v s,d S t |¡ |d9 }|dk stjd| tdd� d S )NÚ.gü©ñÒMbP?g      ð?r   z)tests may fail, delete still pending for é   ©Ú
stacklevel)	r   ÚpathÚsplitÚlistdirÚtimeÚsleepÚwarningsÚwarnÚRuntimeWarning)ÚfuncÚpathnameÚwaitallÚdirnameÚnameÚtimeoutÚLr   r   r   Ú_waitforô   s$   
ÿ
ó

ÿr^   c                 C   ó   t tj| ƒ d S rD   )r^   r   r   rH   r   r   r   rE     ó   rE   c                 C   r_   rD   )r^   r   r;   ©rZ   r   r   r   Ú_rmdir  r`   rb   c                    s>   ddl m‰  ‡ ‡fdd„‰tˆ| dd� t‡ fdd„| ƒ d S )	Nr   ©Ú
_force_runc                    s¬   ˆ | t j| ƒD ]L}t j | |¡}zt  |¡j}W n ty7 } ztd||f tj	d� d}W Y d }~nd }~ww t
 |¡rLtˆ|dd� ˆ |t j|ƒ qˆ |t j|ƒ qd S )Nz-support.rmtree(): os.lstat(%r) failed with %sr   r   T©rY   )r   rQ   rO   ÚjoinÚlstatÚst_moder   ÚprintÚsysÚ
__stderr__ÚstatÚS_ISDIRr^   r;   r   )rO   r[   ÚfullnameÚmodeÚexc©rd   Ú_rmtree_innerr   r   rr     s$   ÿþ€ü
óú_rmtree.<locals>._rmtree_innerTre   c                    s   ˆ | t j| ƒS rD   )r   r;   )Úprc   r   r   Ú<lambda>.  s    z_rmtree.<locals>.<lambda>)Útest.supportrd   r^   ©rO   r   rq   r   Ú_rmtree  s   rx   c                 C   s^   zdd l }W n
 ty   Y | S w | t| ƒd ¡}|jj | |t|ƒ¡}|r-|d |… S | S )Nr   r   )ÚctypesÚImportErrorÚcreate_unicode_bufferÚlenÚwindllÚkernel32ÚGetLongPathNameW)rO   ry   ÚbufferÚlengthr   r   r   Ú	_longpath0  s   ÷ÿr‚   c                    sN   dd l }z| | ¡ W d S  ty   Y nw ‡ fdd„‰ ˆ | ƒ t | ¡ d S )Nr   c              	      sŠ   ddl m} || tj| ƒD ]5}tj | |¡}zt |¡j}W n ty)   d}Y nw t	 
|¡r;ˆ |ƒ || tj|ƒ q|| tj|ƒ qd S )Nr   rc   )rv   rd   r   rQ   rO   rf   rg   rh   r   rl   rm   r;   r   )rO   rd   r[   rn   ro   ©rr   r   r   rr   I  s   ÿ
örs   )ÚshutilÚrmtreer   r   r;   )rO   r„   r   rƒ   r   rx   A  s   
ÿc                 C   ó   | S rD   r   rw   r   r   r   r‚   Y  ó   c                 C   ó$   zt | ƒ W d S  ty   Y d S w rD   )rb   rF   ra   r   r   r   r;   ]  ó
   ÿr;   c                 C   rˆ   rD   )rx   rF   rw   r   r   r   r…   d  r‰   r…   c              
   c   sâ   � ddl }d}| du r| ¡ } d}tj | ¡} n-z	t | ¡ d}W n# tyD } z|s,‚ tjd| ›d|› �t	dd� W Y d}~nd}~ww |rKt 
¡ }z| V  W |r^|t 
¡ kr`t| ƒ dS dS dS |ro|t 
¡ krpt| ƒ w w w )	a¢  Return a context manager that creates a temporary directory.

    Arguments:

      path: the directory to create temporarily.  If omitted or None,
        defaults to creating a temporary directory using tempfile.mkdtemp.

      quiet: if False (the default), the context manager raises an exception
        on error.  Otherwise, if the path is specified and cannot be
        created, only a warning is issued.

    r   NFTz5tests may fail, unable to create temporary directory ú: é   rM   )r0   r4   r   rO   ÚrealpathÚmkdirr   rT   rU   rV   Úgetpidr…   )rO   Úquietr0   Údir_createdrp   Úpidr   r   r   Útemp_dirk  s>   €
ÿÿþ€ýÿ
ÿr’   c              
   c   s�   � t  ¡ }zt  t j | ¡¡ W n# ty3 } z|s‚ tjd| ›d|› �tdd� W Y d}~nd}~ww zt  ¡ V  W t  |¡ dS t  |¡ w )ag  Return a context manager that changes the current working directory.

    Arguments:

      path: the directory to use as the temporary current working directory.

      quiet: if False (the default), the context manager raises an exception
        on error.  Otherwise, it issues only a warning and keeps the current
        working directory the same.

    zBtests may fail, unable to change the current working directory to rŠ   r‹   rM   N)	r   ÚgetcwdÚchdirrO   rŒ   r   rT   rU   rV   )rO   r�   Ú	saved_dirrp   r   r   r   Ú
change_cwd”  s&   €ÿÿþ€ýr–   Útempcwdc              	   c   sv   � t | |d��*}t||d��}|V  W d  ƒ n1 sw   Y  W d  ƒ dS W d  ƒ dS 1 s4w   Y  dS )aö  
    Context manager that temporarily creates and changes the CWD.

    The function temporarily changes the current working directory
    after creating a temporary directory in the current directory with
    name *name*.  If *name* is None, the temporary directory is
    created using tempfile.mkdtemp.

    If *quiet* is False (default) and it is not possible to
    create or change the CWD, an error is raised.  If *quiet* is True,
    only a warning is raised and the original CWD is used.

    )rO   r�   )r�   N)r’   r–   )r[   r�   Ú	temp_pathÚcwd_dirr   r   r   Útemp_cwd°  s   €ÿÿ"ÿrš   c                 C   s(   t  | t jt jB t jB ¡}t  |¡ dS )z>Create an empty file. If the file already exists, truncate it.N)r   r   ÚO_WRONLYÚO_CREATÚO_TRUNCr   )rI   Úfdr   r   r   Úcreate_empty_fileÄ  s   rŸ   c              	   c   sD   � t j | ¡s	J ‚t  | t j¡}z|V  W t  |¡ dS t  |¡ w )z&Open a file descriptor to a directory.N)r   rO   Úisdirr   ÚO_RDONLYr   )rO   Údir_fdr   r   r   Úopen_dir_fdÊ  s   €r£   c              	   C   sˆ   ddl }|j| d��0}|j}| ¡ }||kr| ¡ }ztj ||¡W W  d  ƒ S  ty9   Y W d  ƒ dS w 1 s=w   Y  dS )zODetects if the file system for the specified directory
    is case-insensitive.r   Nr+   F)	r0   ÚNamedTemporaryFiler[   ÚupperÚlowerr   rO   ÚsamefilerF   )Ú	directoryr0   ÚbaseÚ	base_pathÚ	case_pathr   r   r   Úfs_is_case_insensitiveÕ  s   úøùr¬   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚFakePathz.Simple implementing of the path protocol.
    c                 C   s
   || _ d S rD   rw   )ÚselfrO   r   r   r   Ú__init__ç  ó   
zFakePath.__init__c                 C   s   d| j ›d�S )Nz
<FakePath ú>rw   ©r®   r   r   r   Ú__repr__ê  s   zFakePath.__repr__c                 C   s0   t | jtƒst | jtƒrt| jtƒr| j‚| jS rD   )Ú
isinstancerO   ÚBaseExceptionÚtypeÚ
issubclassr²   r   r   r   Ú
__fspath__í  s   
ÿ
þzFakePath.__fspath__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r¯   r³   r¸   r   r   r   r   r­   ä  s
    r­   c            	      C   s˜  t j d¡rzt d¡} t| ƒd W S  ty   Y nw d}ttdƒr4zt d¡}W n	 t	y3   Y nw d}t jdkrez	d	dl
}|j W n ttfyO   Y nw i }|j|j|jfD ]
}| |d	¡||< qZzMd	}t|ƒD ],}zt |¡}W n t	yŽ } z|jtjkr„‚ W Y d}~qld}~ww t |¡ |d7 }qlW |dur±|j|j|jfD ]
}| ||| ¡ q¦|S |durÊ|j|j|jfD ]}| ||| ¡ q¿w w )
z/Count the number of open file descriptors.
    )ÚlinuxÚfreebsdz/proc/self/fdr.   é   ÚsysconfÚSC_OPEN_MAXNÚwin32r   )rj   r3   Ú
startswithr   rQ   r|   rF   r2   rÀ   r   ÚmsvcrtÚCrtSetReportModer   rz   ÚCRT_WARNÚ	CRT_ERRORÚ
CRT_ASSERTÚrangeÚdupÚerrnoÚEBADFr   )	ÚnamesÚMAXFDÚ	old_modesrÄ   Úreport_typeÚcountrž   Úfd2Úer   r   r   Úfd_countö  sv   
ÿ
ÿ

þþ
ÿÿ€ÿ

öþúþürÔ   Úumaskc              	   c   s0   � t  | ¡}zdV  W t  |¡ dS t  |¡ w )z8Context manager that temporarily sets the process umask.N)r   rÕ   )rÕ   Úoldmaskr   r   r   Ú
temp_umask3  s
   €
r×   c                   @   sh   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )ÚEnvironmentVarGuardz_Class to help protect the environment variable properly.  Can be used as
    a context manager.c                 C   s   t j| _i | _d S rD   )r   ÚenvironÚ_environÚ_changedr²   r   r   r   r¯   B  s   
zEnvironmentVarGuard.__init__c                 C   s
   | j | S rD   )rÚ   ©r®   Úenvvarr   r   r   Ú__getitem__F  r°   zEnvironmentVarGuard.__getitem__c                 C   s*   || j vr| j |¡| j |< || j|< d S rD   ©rÛ   rÚ   Úget©r®   rÝ   Úvaluer   r   r   Ú__setitem__I  s   
zEnvironmentVarGuard.__setitem__c                 C   s6   || j vr| j |¡| j |< || jv r| j|= d S d S rD   rß   rÜ   r   r   r   Ú__delitem__O  s
   

ÿzEnvironmentVarGuard.__delitem__c                 C   s
   | j  ¡ S rD   )rÚ   Úkeysr²   r   r   r   rå   V  r°   zEnvironmentVarGuard.keysc                 C   ó
   t | jƒS rD   )ÚiterrÚ   r²   r   r   r   Ú__iter__Y  r°   zEnvironmentVarGuard.__iter__c                 C   ræ   rD   )r|   rÚ   r²   r   r   r   Ú__len__\  r°   zEnvironmentVarGuard.__len__c                 C   s   || |< d S rD   r   rá   r   r   r   Úset_  s   zEnvironmentVarGuard.setc                 C   s
   | |= d S rD   r   rÜ   r   r   r   Úunsetb  r°   zEnvironmentVarGuard.unsetc                 C   r†   rD   r   r²   r   r   r   Ú	__enter__e  r‡   zEnvironmentVarGuard.__enter__c                 G   sF   | j  ¡ D ]\}}|d u r|| jv r| j|= q|| j|< q| jt_d S rD   )rÛ   ÚitemsrÚ   r   rÙ   )r®   Ú
ignore_excÚkÚvr   r   r   Ú__exit__h  s   
€zEnvironmentVarGuard.__exit__N)r¹   rº   r»   r¼   r¯   rÞ   rã   rä   rå   rè   ré   rê   rë   rì   rñ   r   r   r   r   rØ   =  s    rØ   )F)NF)r—   F)CÚcollections.abcÚcollectionsÚ
contextlibrË   r   r7   rl   rj   rR   r"   rT   r[   ÚTESTFN_ASCIIÚformatrŽ   ÚTESTFN_UNICODEr3   ÚunicodedataÚ	normalizeÚTESTFN_UNENCODABLEÚgetwindowsversionÚencodeÚgetfilesystemencodingÚUnicodeEncodeErrorri   ÚdecodeÚUnicodeDecodeErrorÚFS_NONASCIIÚ	characterÚfsdecodeÚfsencodeÚUnicodeErrorr“   ÚSAVEDCWDÚTESTFN_UNDECODABLEÚTESTFN_NONASCIIr   r   r   r   r(   r1   rB   rC   r   rÃ   r^   rE   rb   rx   r‚   r;   r…   Úcontextmanagerr’   r–   rš   rŸ   r£   r¬   r­   rÔ   r2   r×   ÚabcÚMutableMappingrØ   r   r   r   r   Ú<module>   sÊ    


ÿ
þ€
ÿþ!ÿÿþ
!
!
(

<
	