
    hcX                        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    rdZndZd                    e ej                              Zedz   Zej        dk    rd dlZ ej        de          ZdZej        d	k    rn ej                    j        d
k    rUedz   Z	 e                     ej                                eded ej                    d           dZnj# e$ r Y ncw xY wn^ej        dvrU	 d                     ej                               n1# e$ r) ed                     ej                    d          z   ZY nw xY wdZdD ]6Z	  ej         ej        e                    ek    re	 eZ n# e$ r Y 3w xY w ej                     Z!dZ"dD ]DZ	 e                     ej                               &# e$ r  ej        e          ez   Z"Y  nw xY wereez   Z#ndZ#e#peZ$d Z%da&d Z'd Z(da)d Z*d Z+da,d Z-d Z.da/d Z0d Z1d Z2d  Z3ej        4                    d!          rd;d#Z5d$ Z6d% Z7d& Z8d' Z9nej3        Z6ej:        Z7d( Z8d) Z9d* Z:d+ Z;ej<        d<d,            Z=ej<        d;d-            Z>ej<        d=d/            Z?d0 Z@ej<        d1             ZAd2 ZB G d3 d4          ZCd5 ZD eEed6          rej<        d7             ZFnej<        d8             ZF G d9 d:ejG        jH                  ZIdS )>    Njavaz$testz@testz	{}_{}_tmpu   -àòɘŁğdarwinNFDnt   u   -共Ł♡ͣzWARNING: The filename z, CAN be encoded by the filesystem encoding (z.). Unicode filename tests may not be effective>   wasir   
emscripten   s   -surrogateescape )   æu   İu   Łu   φu   Кu   אu   ،u   تu   ก    u   €)s   wr
   s   s   s   c                      t          t          d          } 	 |                                 |                                  t	          t                     S # |                                  t	          t                     w xY w)z`
    Create an invalid file descriptor by opening and closing a file and return
    its fd.
    wb)openTESTFNfilenocloseunlinkfiles    -/usr/lib/python3.11/test/support/os_helper.pymake_bad_fdr      s]    
 D{{}}

v 	

vs   A *A=c                     t           t           S t          j                            t                    } | dz   }	 t          j        | |           d}t          j        |           n# t          t          t          f$ r d}Y nw xY w|a |S )Ncan_symlinkTF)
_can_symlinkospathabspathr   symlinkremoveOSErrorNotImplementedErrorAttributeError)srcsymlink_pathcans      r   r   r      s     '//&
!
!C&L 

3%%% 		, (.9    LJs   A% %B Bc                 d    t                      }d}|r| n t          j        |          |           S )z8Skip decorator for tests that require functional symlinkz*Requires functional symlink implementation)r   unittestskiptestokmsgs      r   skip_unless_symlinkr/      s4    	B
6C344-8=--d333    c                  h   dd l } t          t          S t          t          d          sd}ndd l}|                                 }|                     |          \  }}	 t          t          d          5 }	 t          j	        |dd           t          j	        |dd	           t          j	        |
                                dd           |                                }t          j        d
|          }|d u p%t          |                    d                    dk    }n# t           $ r d}Y nw xY wd d d            n# 1 swxY w Y   t#          t                     t#          |           t%          |           n7# t#          t                     t#          |           t%          |           w xY w|a|S )Nr   setxattrFdirr   s	   user.testr0   s   trusted.foos   42z2.6.(\d{1,2})   '   )tempfile
_can_xattrhasattrr   platformmkdtempmkstempr   r   r2   r   releaserematchintgroupr"   r   rmdir)	r7   r'   r:   tmp_dirtmp_fptmp_namefpkernel_versionms	            r   	can_xattrrI      s   OOO2z"" ""$$#+++88	fd##  r  Kc:::K.%@@@K		\3???%-%5%5%7%7N!1>BBAt)<s1771::"'<CC      CCC                               6NNN8'NNNN 6NNN8'NNNNJJsU   E9 3D;5B'DD;D,)D;+D,,D;/E9 ;D??E9 D?E9 94F-c                 d    t                      }d}|r| n t          j        |          |           S )zDSkip decorator for tests that require functional extended attributesz(no non-broken extended attribute support)rI   r)   r*   r+   s      r   skip_unless_xattrrK      s4    	B
4C344-8=--d333r0   c                     t           t           S t          t          d          s	da t           S 	 t          t          d          5 } 	 t          j        t          d           t          j        t                    j        }t          j        t          d           t          j        t                    j        }t          j        |          t          j        |          k    }n# t          $ r}d}Y d }~nd }~ww xY wd d d            n# 1 swxY w Y   t          t                     n# t          t                     w xY w|a |S )NchownFr   i  i  )
_can_chmodr9   r   r   r   chmodstatst_modeS_IMODEr"   r   )fmode1mode2r'   es        r   	can_chmodrW      sg   2w 
&$ 		A1A'''/'''/ l5))T\%-@-@@    		A 		A 		A 		A 		A 		A 		A 		A 		A 		A 		A 		A 		A 		A 		A 	vvJJsZ   D% DA0C 5+D 
C6*C1,D1C66D9D% D		D% D	D% %D;c                 d    t                      }d}|r| n t          j        |          |           S )z`Skip tests that require working os.chmod()

    WASI SDK 15.0 cannot change file mode bits.
    zrequires working os.chmod())rW   r)   r*   r+   s      r   skip_unless_working_chmodrY   
  s6    
 
B
'C344-8=--d333r0   c                     t                      sdat          t          S 	 t          t          d          5 } t	          j        t          d           	 t          t          d          5  	 d d d            n# 1 swxY w Y   dan# t          $ r daY nw xY wd d d            n# 1 swxY w Y   t          t                     n# t          t                     w xY wt          S )NFr      T)rW   _can_dac_overrider   r   r   rO   r"   r   )rS   s    r   can_dac_overrider]     sa    ;; "!$  &$ 	)1HVU###)&$''                
 %)!!  * * *$)!!!*	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	vvsv   C  B B&A4(B4A8	8B;A8	<B?B BB BB C   B$$C  'B$(C   Cc                 f    t                       }d}|r| n t          j        |          |           S )Nz"incompatible with CAP_DAC_OVERRIDEr]   r)   r*   r+   s      r   skip_if_dac_overrider`   2  s9    	B
.C344-8=--d333r0   c                 d    t                      }d}|r| n t          j        |          |           S )Nzrequires CAP_DAC_OVERRIDEr_   r+   s      r   skip_unless_dac_overriderb   8  s6    			B
%C344-8=--d333r0   c                 V    	 t          |            d S # t          t          f$ r Y d S w xY wN)_unlinkFileNotFoundErrorNotADirectoryErrorfilenames    r   r   r   >  sC    12   s    ((winFc                 <    | |           |r|}n&t           j                            |          \  }}|pd}d}|dk     r>t          j        |          }|r|sn||v sd S t	          j        |           |dz  }|dk     >t          j        d|z   t          d           d S )N.gMbP?g      ?r   z)tests may fail, delete still pending for    
stacklevel)	r   r   splitlistdirtimesleepwarningswarnRuntimeWarning)funcpathnamewaitalldirnamenametimeoutLs          r   _waitforr~   F  s    X 	%GGGMM(33MGTnG mm 
7##A  A  daiiJwqLG mm 	AHL$	4 	4 	4 	4 	4 	4r0   c                 :    t          t          j        |            d S rd   )r~   r   r   rh   s    r   re   re   g  s    H%%%%%r0   c                 :    t          t          j        |            d S rd   )r~   r   rB   rz   s    r   _rmdirr   j  s    7#####r0   c                 l    ddl m fdt          | d           t          fd|            d S )Nr   
_force_runc                     | t           j        |           D ]}t           j                            | |          }	 t          j        |          j        }n:# t          $ r-}t          d|d|t          j	                   d}Y d }~nd }~ww xY wt          j        |          r*t          |d            |t           j        |            |t           j        |           d S )Nzsupport.rmtree(): os.lstat(z) failed with r   r   Try   )r   rq   r   joinlstatrQ   r"   printsys
__stderr__rP   S_ISDIRr~   rB   r   )r   r{   fullnamemodeexcr   _rmtree_inners        r   r   z_rmtree.<locals>._rmtree_innerp  s   "
4T:: > >7<<d338H--5DD   E%XXss,"~/ / / / DDDDDD	
 <%% >]HdCCCCJx8<<<<JxH====> >s   A
B #BBTr   c                 2     | t           j        |           S rd   )r   rB   )pr   s    r   <lambda>z_rmtree.<locals>.<lambda>  s    ::a155 r0   )test.supportr   r~   )r   r   r   s    @@r   _rmtreer   m  sk    ++++++	> 	> 	> 	> 	> 	> 	d33335555t<<<<<r0   c                     	 dd l }|                    t          |           dz            }|j        j                            | |t          |                    }|r
|d |         S n# t          $ r Y nw xY w| S )Nr   r   )ctypescreate_unicode_bufferlenwindllkernel32GetLongPathNameWImportError)r   r   bufferlengths       r   	_longpathr     s    
	'MMM
 11#d))a-@@F]+<<T6=@[[J JF 'gvg&'  	 	 	D	 s   A& &
A32A3c                     dd l }	 |                    |            d S # t          $ r Y nw xY wfd |            t          j        |            d S )Nr   c                 ~   ddl m}  || t          j        |           D ]}t          j                            | |          }	 t          j        |          j        }n# t          $ r d}Y nw xY wt          j
        |          r# |            || t          j        |            || t          j        |           d S )Nr   r   )r   r   r   rq   r   r   r   rQ   r"   rP   r   rB   r   )r   r   r{   r   r   r   s        r   r   z_rmtree.<locals>._rmtree_inner  s    //////"
4T:: 
: 
:7<<d338H--5DD   DDD<%% :!M(+++JtRXx8888JtRY9999
: 
:s   AA+*A+)shutilrmtreer"   r   rB   )r   r   r   s     @r   r   r     s    	MM$F 	 	 	D		: 	: 	: 	: 	: 	d
s    
++c                     | S rd    r   s    r   r   r         r0   c                 H    	 t          |            d S # t          $ r Y d S w xY wrd   )r   rf   r   s    r   rB   rB     s8    w       
!!c                 H    	 t          |            d S # t          $ r Y d S w xY wrd   )r   rf   r   s    r   r   r     s8       r   c              #     K   ddl }d}| 6|                                } d}t          j                            |           } nT	 t          j        |            d}n<# t          $ r/}|s t          j        d| d| t          d           Y d}~nd}~ww xY w|rt          j
                    }	 | V  |r(|t          j
                    k    rt          |            dS dS dS # |r'|t          j
                    k    rt          |            w w w xY 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 :    rn   )r7   r;   r   r   realpathmkdirr"   rt   ru   rv   getpidr   )r   quietr7   dir_createdr   pids         r   temp_dirr     sr      OOOK|!!w%%	8HTNNNKK 	8 	8 	8 M A15A A;>A A(Q8 8 8 8 8 8 8 8 8	8  ikk


  	3")++--4LLLLL	 	--; 	3")++--4LLLL	-s$   A 
B#%BB+C ,D	c              #     K   t          j                    }	 t          j        t           j                            |                      n<# t
          $ r/}|s t          j        d| d| t          d           Y d}~nd}~ww xY w	 t          j                    V  t          j        |           dS # t          j        |           w xY 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   rn   N)	r   getcwdchdirr   r   r"   rt   ru   rv   )r   r   	saved_dirr   s       r   
change_cwdr     s       	I4
!!$''(((( 4 4 4 	 6&*6 6036 6$	4 	4 	4 	4 	4 	4 	4 	4 	44ikk
s#   1A	 	
B%A==BB1 1Ctempcwdc              #      K   t          | |          5 }t          ||          5 }|V  ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w 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.

    )r   r   )r   N)r   r   )r{   r   	temp_pathcwd_dirs       r   temp_cwdr     s       
t5	)	)	) Y	/// 	7MMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                 s,   A7A;	A;	AAAc                     t          j        | t           j        t           j        z  t           j        z            }t          j        |           dS )z>Create an empty file. If the file already exists, truncate it.N)r   r   O_WRONLYO_CREATO_TRUNCr   )ri   fds     r   create_empty_filer     s4    	2;3bj@	A	ABHRLLLLLr0   c              #   :  K   t           j                            |           sJ t           j        }t	          t           d          r|t           j        z  }t          j        | |          }	 |V  t          j        |           dS # t          j        |           w xY w)z&Open a file descriptor to a directory.O_DIRECTORYN)r   r   isdirO_RDONLYr9   r   r   r   )r   flagsdir_fds      r   open_dir_fdr     s       7==KEr=!!  WT5!!F
s   *B Bc                 N   ddl }|                    |           5 }|j        }|                                }||k    r|                                }	 t
          j                            ||          cddd           S # t          $ r Y ddd           dS w xY w# 1 swxY w Y   dS )zODetects if the file system for the specified directory
    is case-insensitive.r   Nr3   F)	r7   NamedTemporaryFiler{   upperlowerr   r   samefilerf   )	directoryr7   base	base_path	case_paths        r   fs_is_case_insensitiver   *  s    OOO		$	$	$	3	3 tI	OO%%		!!!))I	7##Iy99        ! 	 	 	       	         s/   6BA>>
BBBBB!Bc                   $    e Zd ZdZd Zd Zd ZdS )FakePathz.Simple implementing of the path protocol.
    c                     || _         d S rd   r   )selfr   s     r   __init__zFakePath.__init__<  s    			r0   c                     d| j         dS )Nz
<FakePath >r   r   s    r   __repr__zFakePath.__repr__?  s    *DI****r0   c                     t          | j        t                    s4t          | j        t                    r!t	          | j        t                    r| j        | j        S rd   )
isinstancer   BaseExceptiontype
issubclassr   s    r   
__fspath__zFakePath.__fspath__B  sO    ty-00 	ty$''	49m44	 )O9r0   N)__name__
__module____qualname____doc__r   r   r   r   r0   r   r   r   9  sK           + + +    r0   r   c                     t           j                            d          r7	 t          j        d          } t          |           dz
  S # t          $ r Y nw xY wd}t          t          d          r&	 t          j        d          }n# t          $ r Y nw xY wd}t           j        dk    rV	 d	dl
}|j         i }|j        |j        |j        fD ]}|                    |d	          ||<   n# t          t           f$ r Y nw xY w	 d	}t#          |          D ]]}	 t          j        |          }t          j        |           |dz  }1# t          $ r }|j        t(          j        k    r Y d}~Vd}~ww xY w	 |3|j        |j        |j        fD ]}|                    |||                    n;# |3|j        |j        |j        fD ]}|                    |||                    w w xY w|S )
z/Count the number of open file descriptors.
    )linuxfreebsdr	   z/proc/self/fdr5   r[   sysconfSC_OPEN_MAXNwin32r   )r   r:   
startswithr   rq   r   rf   r9   r   r"   msvcrtCrtSetReportModeCRT_WARN	CRT_ERROR
CRT_ASSERTr$   r   rangedupr   errnoEBADF)	namesMAXFD	old_modesr   report_typecountr   fd2rV   s	            r   fd_countr  K  s    |ABB 	J//E u::>!  	 	 	D	 Er9 	J}--EE 	 	 	D	 I
|w	DMMM##
 I & & 0 & 1 3 D D *0)@)@AB*D *D	+&&D , 	 	 	D	M,, 
	 
	B	 fRjj
 
    7ek)) *))))
	   & & 0 & 1 3 M M ''Y{5KLLLL	   & & 0 & 1 3 M M ''Y{5KLLLL	 !M
 Lsk   %A 
AA/B 
BB'C% %C98C9=F# D?%F# ?
E)	E$F# $E))F# #8Gumaskc              #      K   t          j        |           }	 dV  t          j        |           dS # t          j        |           w xY w)z8Context manager that temporarily sets the process umask.N)r   r  )r  oldmasks     r   
temp_umaskr    sO       (5//	EEEHWBHWs	   2 Ac              #      K   dV  dS )z"no-op on platforms without umask()Nr   )r  s    r   r  r    s       	r0   c                   Z    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd ZdS )EnvironmentVarGuardz_Class to help protect the environment variable properly.  Can be used as
    a context manager.c                 6    t           j        | _        i | _        d S rd   )r   environ_environ_changedr   s    r   r   zEnvironmentVarGuard.__init__  s    
r0   c                     | j         |         S rd   )r  r   envvars     r   __getitem__zEnvironmentVarGuard.__getitem__  s    }V$$r0   c                 p    || j         vr"| j                            |          | j         |<   || j        |<   d S rd   r  r  getr   r  values      r   __setitem__zEnvironmentVarGuard.__setitem__  s=    &&$(M$5$5f$=$=DM&! %fr0   c                     || j         vr"| j                            |          | j         |<   || j        v r
| j        |= d S d S rd   r  r  s     r   __delitem__zEnvironmentVarGuard.__delitem__  sP    &&$(M$5$5f$=$=DM&!T]""f%%% #"r0   c                 4    | j                                         S rd   )r  keysr   s    r   r  zEnvironmentVarGuard.keys  s    }!!###r0   c                 *    t          | j                  S rd   )iterr  r   s    r   __iter__zEnvironmentVarGuard.__iter__  s    DM"""r0   c                 *    t          | j                  S rd   )r   r  r   s    r   __len__zEnvironmentVarGuard.__len__  s    4=!!!r0   c                     || |<   d S rd   r   r  s      r   setzEnvironmentVarGuard.set  s    Vr0   c                     | |= d S rd   r   r  s     r   unsetzEnvironmentVarGuard.unset  s    LLLr0   c                      t          |           S rd   )dictr   s    r   copyzEnvironmentVarGuard.copy  s    Dzzr0   c                     | S rd   r   r   s    r   	__enter__zEnvironmentVarGuard.__enter__  r   r0   c                     | j                                         D ]#\  }}||| j        v r| j        |= || j        |<   $| j        t          _        d S rd   )r  itemsr  r   r
  )r   
ignore_exckvs       r   __exit__zEnvironmentVarGuard.__exit__  s\    m))++ 	% 	%FQy%%a(#$a  ]


r0   N)r   r   r   r   r   r  r  r  r  r  r  r!  r#  r&  r(  r.  r   r0   r   r  r    s           % % %& & && & &$ $ $# # #" " "        # # # # #r0   r  )F)NF)r   F)Jcollections.abccollections
contextlibr   r   r>   rP   r   rr   r)   rt   r{   TESTFN_ASCIIformatr   TESTFN_UNICODEr:   unicodedata	normalizeTESTFN_UNENCODABLEgetwindowsversionencodegetfilesystemencodingr   UnicodeEncodeErrordecodeUnicodeDecodeErrorFS_NONASCII	characterfsdecodefsencodeUnicodeErrorr   SAVEDCWDTESTFN_UNDECODABLETESTFN_NONASCIIr   r   r   r   r/   r8   rI   rK   rN   rW   rY   r\   r]   r`   rb   r   r   r~   re   r   r   r   rB   r   contextmanagerr   r   r   r   r   r   r   r  r9   r  abcMutableMappingr  r   r0   r   <module>rI     sM            				 				  



    7fLLL !!,		<<  ==<8 *[*5.AAN
  7d??s'1,, *,MM	&%%&?c&?&A&ABBB EE''')B)B)D)D)D)DF G G G "& " 	 	 	D	 - 	\999
0s022333 	  N N N)oo7c799;LMMNN   + +IB
 2;{r{9--..);; <
  	     29;;    D"-C-//0000   (R[66=  "[0OOO		(L
 
 
   (4 4 4 
  B4 4 4 
  04 4 4    04 4 44 4 4   <5!! g4 4 4 4B& & &$ $ $= = =*    iGXF  0       % % % %P    6    &   
 
 
         $9 9 9x 72w       
6# 6# 6# 6# 6#+/8 6# 6# 6# 6# 6#sH   ,"C0 0C87C8"D) )+EE!$F

FF+"GG*)G*