
    F\hb                     *   S SK rS SKrS SKrS SKrS SKrS SKrS SKrS SKrS SK	r	S SK
r
S SKrS SKrS SKJr  SrSR!                  \\R"                  " 5       5      r\S-   r\R&                  (       a  S SKr\R*                  " S\5      rSr\R.                  S:X  ai  \	R0                  " 5       R2                  S:  aI  \S	-   r \R5                  \	R6                  " 5       5        \" S
\< S\	R6                  " 5       < S35        SrODOC\R&                  (       d2  \	R2                  S;  a"   SR=                  \	R6                  " 5       5         Sr S H/  r! \RD                  " \RF                  " \!5      5      \!:w  a  \$e \!r   O   \RJ                  " 5       r&Sr'S H$  r \R=                  \	R6                  " 5       5        M&     \ (       a  \\ -   r)OSr)\)=(       d    \r*S r+Sq,S r-S r.Sq/S r0S r1Sq2S r3S r4Sq5S r6S r7Sq8S r9S r:S r;S  r<\	R2                  R{                  S!5      (       a  S@S" jr>S# r?S$ r@S% rAS& rBO\Rx                  r?\R                  r@S' rAS( rBS) rCS* rD\R                  SAS+ j5       rF\R                  S@S, j5       rG\R                  SBS- j5       rHS. rI\R                  S/ 5       rJS0 rK " S1 S25      rLS3 rM\N" \S45      (       a  \R                  S5 5       rOO\R                  S6 5       rO " S7 S8\R                  R                  5      rR \R                  (       a  S SKTrT\TR                  " S9S:S;9rVSrWSrXS<rYS=rZO\[e \R                  S> 5       r\g! \ a     GNf = f! \ a(    \SR=                  \	R6                  " 5       S5      -   r GNHf = f! \$ a     GMR  f = f! \ a\     \R=                  \	R6                  " 5       \	RP                  " 5       5        O! \ a      GMQ  f = f\RF                  " \5      \-   r'   GMG  f = f! \]\[4 a    S? r\ gf = f)C    N)supportz@testz	{}_{}_tmpu   -àòɘŁğNFDnt   u   -共Ł♡ͣzWARNING: The filename z, CAN be encoded by the filesystem encoding (z.). Unicode filename tests may not be effective>   wasi
emscripten   s   -surrogateescape )   æu   İu   Łu   φu   Кu   אu   ،u   تu   ก    u   €)s   wr	   s   s   s   c                      [        [        S5      n  U R                  5       U R                  5         [	        [        5        $ ! U R                  5         [	        [        5        f = f)zT
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.13/test/support/os_helper.pymake_bad_fdr      sB    
 D{{}

v 	

vs   A !A"c                     [         b  [         $ [        R                  R                  [        5      n U S-   n [        R
                  " X5        Sn[        R                  " U5        Uq U$ ! [        [        [        4 a    Sn Uq U$ f = f)Ncan_symlinkTF)
_can_symlinkospathabspathr   symlinkremoveOSErrorNotImplementedErrorAttributeError)srcsymlink_pathcans      r   r   r      s     ''//&
!C&L 


3% 			,LJ (.9  LJs   A) )BBc                 d    [        5       nSnU(       a  U $ [        R                  " U5      " U 5      $ )z8Skip decorator for tests that require functional symlinkz*Requires functional symlink implementation)r   unittestskiptestokmsgs      r   skip_unless_symlinkr.      s)    	B
6C438==-d33    c                  t    [         c,  [        [        S5      =(       a    [        R                  (       + q [         $ )Nlink)_can_hardlinkhasattrr   r   
is_android r/   r   can_hardlinkr6      s*      F+FG4F4F0Fr/   c                 d    [        5       nSnU(       a  U $ [        R                  " U5      " U 5      $ )Nzrequires hardlink support)r6   r(   r)   r*   s      r   skip_unless_hardlinkr8      s)    	B
%C438==-d33r/   c                     SS K n [        b  [        $ [        [        S5      (       d  SnUqU$ SS KnU R                  5       nU R                  US9u  pE [        [        S5       n [        R                  " USS5        [        R                  " USS	5        [        R                  " UR                  5       SS5        UR                  5       n[        R                  " S
U5      nUS L =(       d    [        UR                  S5      5      S:  nS S S 5        [#        [        5        [#        U5        [%        U5        WqU$ ! [          a    Sn N?f = f! , (       d  f       NI= f! [#        [        5        [#        U5        [%        U5        f = f)Nr   setxattrFdirr   s	   user.testr/   s   trusted.foos   42z2.6.(\d{1,2})   '   )tempfile
_can_xattrr3   r   platformmkdtempmkstempr   r   r:   r   releaserematchintgroupr!   r   rmdir)	r?   r&   rA   tmp_dirtmp_fptmp_namefpkernel_versionms	            r   	can_xattrrP      sC   2z"". JJ- 	""$#+++8	fd#r  KKc:KK.%@KK		\3?%-%5%5%7N!1>BAt)<s1771:"'<C $ 6N8'NJJ   C  $# 6N8'NsC   E #E%B%D;
E ;E
E	E

E
EE 'Fc                 d    [        5       nSnU(       a  U $ [        R                  " U5      " U 5      $ )zDSkip decorator for tests that require functional extended attributesz(no non-broken extended attribute support)rP   r(   r)   r*   s      r   skip_unless_xattrrR      s)    	B
4C438==-d33r/   c                     [         b  [         $ [        [        S5      (       d  Sq [         $  [        [        S5       n  [        R
                  " [        S5        [        R                  " [        5      R                  n[        R
                  " [        S5        [        R                  " [        5      R                  n[        R                  " U5      [        R                  " U5      :g  nS S S 5        [        [        5        Wq U$ ! [         a  nSn S nAN,S nAff = f! , (       d  f       N:= f! [        [        5        f = f)NchmodFr   im  i  )
_can_chmodr3   r   r   r   rT   statst_modeS_IMODEr!   r   )fmode1mode2r&   es        r   	can_chmodr]     s    2w
&$1A'//'// ll5)T\\%-@@   	vJJ     	vsL   D. DA>D<-D)D. 
DDDDD
D+'D. .D?c                 d    [        5       nSnU(       a  U $ [        R                  " U5      " U 5      $ )zXSkip tests that require working os.chmod()

WASI SDK 15.0 cannot change file mode bits.
zrequires working os.chmod())r]   r(   r)   r*   s      r   skip_unless_working_chmodr_      s+    
 
B
'C438==-d33r/   c                  N   [        5       (       d  Sq[        b  [        $  [        [        S5       n [        R
                  " [        S5         [        [        S5          S S S 5        SqS S S 5         [        R
                  " [        S5        [        [        5        [        $ ! , (       d  f       NI= f! [         a    Sq NXf = f! , (       d  f       Nb= f! [         a     NUf = f!  [        R
                  " [        S5        O! [         a     Of = f[        [        5        f = f)NFr      Ti  )r]   _can_dac_overrider   r   r   rT   r!   r   )rY   s    r   can_dac_overriderc   0  s     ;;!$  &$1HHVU#)&$' (
 %)!  	HHVU# 	v (' *$)!*    			HHVU# 		vs   C& CB3B"B3'C)C& 2C "
B0	,B33C?CCC
CC& 
C#"C#&D$(DD$
DD$DD$c                 n    [        5       (       + nSnU(       a  U $ [        R                  " U5      " U 5      $ )Nz"incompatible with CAP_DAC_OVERRIDErc   r(   r)   r*   s      r   skip_if_dac_overriderf   L  s-    	B
.C438==-d33r/   c                 d    [        5       nSnU(       a  U $ [        R                  " U5      " U 5      $ )Nzrequires CAP_DAC_OVERRIDEre   r*   s      r   skip_unless_dac_overriderh   R  s*    		B
%C438==-d33r/   c                 H     [        U 5        g ! [        [        4 a     g f = fN)_unlinkFileNotFoundErrorNotADirectoryErrorfilenames    r   r   r   X  s'    12 s    !!winc                    U " U5        U(       a  UnO,[         R                  R                  U5      u  p4U=(       d    SnSnUS:  aP  [         R                  " U5      nU(       a	  U(       d	   g WU;   d  g [        R
                  " U5        US-  nUS:  a  MP  [        R                  " [        5      R                  SUSSS9  g )	N.gMbP?g      ?r   z+tests may fail, delete still pending for %sT   )
stack_info
stacklevel)
r   r   splitlistdirtimesleeplogging	getLogger__name__warning)funcpathnamewaitalldirnamenametimeoutLs          r   _waitforr   `  s    XGGGMM(3MGnG m 

7#A A '+aiJJwqLG m 	(#++9	 	, 	
r/   c                 8    [        [        R                  U 5        g rj   )r   r   r   rn   s    r   rk   rk     s    H%r/   c                 8    [        [        R                  U 5        g rj   )r   r   rI   r   s    r   _rmdirr     s    7#r/   c                 X   ^^ SSK Jm  UU4S jm[        TU SS9  [        U4S jU 5        g )Nr   
_force_runc                   > T" U [         R                  U 5       H  n[         R                  R                  X5      n [         R                  " U5      R
                  n[        R                  " U5      (       a%  [        TUSS9  T" U[         R                  U5        M  T" U[         R                  U5        M     g ! [         a,  n[        SU< SU< 3[        R                  S9  Sn S nANS nAff = f)Nzsupport.rmtree(): os.lstat(z) failed with r   r   Tr   )r   rw   r   joinlstatrW   r!   printsys
__stderr__rV   S_ISDIRr   rI   r   )r   r   fullnamemodeexcr   _rmtree_inners        r   r   _rmtree.<locals>._rmtree_inner  s    "4T:77<<388H-55D <<%%]HdCx8<xH= ;  %s,"~~/ D	s    B::
C0"C++C0Tr   c                 4   > T" U [         R                  U 5      $ rj   )r   rI   )pr   s    r   <lambda>_rmtree.<locals>.<lambda>  s    :a15r/   )test.supportr   r   )r   r   r   s    @@r   _rmtreer     s$    +	> 	d35t<r/   c                      SS K nUR                  " [        U 5      S-  5      nUR                  R                  R                  X[        U5      5      nU(       a  US U $  U $ ! [         a     U $ f = f)Nr   r   )ctypescreate_unicode_bufferlenwindllkernel32GetLongPathNameWImportError)r   r   bufferlengths       r   	_longpathr     s|    
	'
 11#d)a-@F]]++<<T=@[JFgv&   	 	s   A" "
A0/A0c                    ^ SS K n UR                  U 5        g ! [         a     Of = fU4S jmT" U 5        [        R                  " U 5        g )Nr   c                   > SSK Jn  U" U [        R                  U 5       H  n[        R                  R                  X5      n [        R                  " U5      R                  n[        R                  " U5      (       a"  T" U5        U" U [        R                  U5        M  U" U [        R                  U5        M     g ! [         a    Sn Nhf = f)Nr   r   )r   r   r   rw   r   r   r   rW   r!   rV   r   rI   r   )r   r   r   r   r   r   s        r   r   r     s    /"4T:77<<388H-55D <<%%!(+tRXXx8tRYY9 ;  Ds    B==CC)shutilrmtreer!   r   rI   )r   r   r   s     @r   r   r     sF    	MM$ 			: 	d
s    
&&c                     U $ rj   r5   r   s    r   r   r         r/   c                 <     [        U 5        g ! [         a     g f = frj   )r   rl   r   s    r   rI   rI     s     w     
c                 <     [        U 5        g ! [         a     g f = frj   )r   rl   r   s    r   r   r     s      r   c           
   #   J  #    SSK nSnU c2  UR                  5       n Sn[        R                  R	                  U 5      n O [        R
                  " U 5        SnU(       a  [        R                  " 5       n U v   U(       a&  W[        R                  " 5       :X  a  [        U 5        ggg! [         a>  nU(       d  e [        R                  " [        5      R                  SU UUSSS9   SnANSnAff = f! U(       a&  W[        R                  " 5       :X  a  [        U 5        f f f = f7f)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   NFTz;tests may fail, unable to create temporary directory %r: %s   exc_infort   ru   )r?   rB   r   r   realpathmkdirr!   rz   r{   r|   r}   getpidr   )r   quietr?   dir_createdr   pids         r   temp_dirr     s      K|!ww%	HHTNK iik
 3"))+-4L .;%  
	h'//M 0 
	$ 3"))+-4L .;sF   <D#B& D#4C1 8.D#&
C.04C)$D#)C..D#1/D  D#c           
   #     #    [         R                  " 5       n [         R                  " [         R                  R	                  U 5      5         [         R                  " 5       v   [         R                  " U5        g! [
         a>  nU(       d  e [        R                  " [        5      R                  SU UUSSS9   SnANrSnAff = f! [         R                  " U5        f = f7f)aO  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.

zHtests may fail, unable to change the current working directory to %r: %sTr   r   N)
r   getcwdchdirr   r   r!   rz   r{   r|   r}   )r   r   	saved_dirr   s       r   
change_cwdr   	  s      		I

!!$'(iik
  
(#++ 	, 	

 	s@   C!3A; C $C!;
C4B>9C!>CC!CC!c              #      #    [        XS9 n[        X!S9 nUv   SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f7f)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<      
t	)Y	/7M 0 
*	)// 
*	)s)   
A
=,=	A
:	=
AAc                     [         R                  " U [         R                  [         R                  -  [         R                  -  5      n[         R
                  " U5        g)z>Create an empty file. If the file already exists, truncate it.N)r   r   O_WRONLYO_CREATO_TRUNCr   )ro   fds     r   create_empty_filer   ?  s3    	2;;3bjj@	ABHHRLr/   c              #   `  #    [         R                  R                  U 5      (       d   e[         R                  n[	        [         S5      (       a  U[         R
                  -  n[         R                  " X5      n Uv   [         R                  " U5        g! [         R                  " U5        f = f7f)z&Open a file descriptor to a directory.O_DIRECTORYN)r   r   isdirO_RDONLYr3   r   r   r   )r   flagsdir_fds      r   open_dir_fdr   E  st      77==KKEr=!!WWT!F
s   A5B.8B <B.B++B.c                 0   SSK nUR                  U S9 nUR                  nUR                  5       nXC:X  a  UR	                  5       n [
        R                  R                  X45      sSSS5        $ ! [         a     SSS5        gf = f! , (       d  f       g= f)zKDetects if the file system for the specified directory
is case-insensitive.r   Nr;   F)	r?   NamedTemporaryFiler   upperlowerr   r   samefilerl   )	directoryr?   base	base_path	case_paths        r   fs_is_case_insensitiver   S  s     		$	$	$	3tII	OO%	!!)I	77##I9 
4	3 ! 	 
4	3	 
4	3s)   2BA//
B9BBB
Bc                   *    \ rS rSrSrS rS rS rSrg)FakePathib  z0Simple implementation of the path protocol.
    c                     Xl         g rj   r   )selfr   s     r   __init__FakePath.__init__e  s    	r/   c                 $    SU R                   < S3$ )Nz
<FakePath >r   r   s    r   __repr__FakePath.__repr__h  s    DII=**r/   c                     [        U R                  [        5      (       d>  [        U R                  [        5      (       a+  [	        U R                  [        5      (       a  U R                  eU R                  $ rj   )
isinstancer   BaseExceptiontype
issubclassr   s    r   
__fspath__FakePath.__fspath__k  sH    tyy-00tyy$''499m44))O99r/   r   N)	r|   
__module____qualname____firstlineno____doc__r   r   r   __static_attributes__r5   r/   r   r   r   b  s    +r/   r   c                  ~   [         R                  R                  S5      (       a  Sn O[        R                  (       a  Sn OSn U b%   [
        R                  " U 5      n[        U5      S-
  $ Sn[        [
        S5      (       a   [
        R                  " S5      nSn[         R                  S	:X  aQ   S
SKnUR                    0 nUR                  UR                  UR                   4 H  nUR                  US
5      X5'   M      S
n['        U5       H5  n [
        R(                  " U5      n[
        R*                  " U5        US-  nM7     Ub>  WR                  UR                  UR                   4 H  nUR                  XSU   5        M     U$ ! [         a     GN,f = f! [         a     GNf = f! ["        [$        4 a     Nf = f! [         a*  n	U	R,                  [,        R.                  :w  a  e  Sn	A	M  Sn	A	ff = f! Ub?  WR                  UR                  UR                   4 H  nUR                  XSU   5        M     f f = f)z/Count the number of open file descriptors.
    )linuxandroidfreebsdr   z/proc/self/fdz/dev/fdNr=   ra   sysconfSC_OPEN_MAXwin32r   )r   rA   
startswithr   is_appler   rw   r   rl   r3   r   r!   msvcrtCrtSetReportModeCRT_WARN	CRT_ERROR
CRT_ASSERTr#   r   rangedupr   errnoEBADF)
fd_pathnamesMAXFD	old_modesr   report_typecountr   fd2r\   s
             r   fd_countr  t  s+    ||LMM!				JJw'E u:>! Er9	JJ}-E I
||w	D##
 I & & 0 0 & 1 1 3 *0)@)@AB*D	& 3M,B	 ffRj
 
    & & 0 0 & 1 1 3 ''{5KL 3
 La ! 		  		 , 		$  77ekk) *   & & 0 0 & 1 1 3 ''{5KL 3 !sm   #F	 F /F+  G8 G'G8 	
FF
F('F(+F>=F>
G5G0*G8 0G55G8 8AH<umaskc              #      #    [         R                  " U 5      n Sv   [         R                  " U5        g! [         R                  " U5        f = f7f)z8Context manager that temporarily sets the process umask.N)r   r  )r  oldmasks     r   
temp_umaskr    s4      ((5/	HHWBHHWs   A5 AAAc              #      #    Sv   g7f)z"no-op on platforms without umask()Nr5   )r  s    r   r  r    s
      	s   c                   `    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rSrg)EnvironmentVarGuardi  z\Class to help protect the environment variable properly.

Can be used as a context manager.
c                 <    [         R                  U l        0 U l        g rj   )r   environ_environ_changedr   s    r   r   EnvironmentVarGuard.__init__  s    

r/   c                      U R                   U   $ rj   )r  r   envvars     r   __getitem__EnvironmentVarGuard.__getitem__  s    }}V$$r/   c                     XR                   ;  a(  U R                  R                  U5      U R                   U'   X R                  U'   g rj   r  r  getr   r  values      r   __setitem__EnvironmentVarGuard.__setitem__  s5    &$(MM$5$5f$=DMM&! %fr/   c                     XR                   ;  a(  U R                  R                  U5      U R                   U'   XR                  ;   a  U R                  U	 g g rj   r#  r  s     r   __delitem__EnvironmentVarGuard.__delitem__  sD    &$(MM$5$5f$=DMM&!]]"f% #r/   c                 6    U R                   R                  5       $ rj   )r  keysr   s    r   r-  EnvironmentVarGuard.keys  s    }}!!##r/   c                 ,    [        U R                  5      $ rj   )iterr  r   s    r   __iter__EnvironmentVarGuard.__iter__  s    DMM""r/   c                 ,    [        U R                  5      $ rj   )r   r  r   s    r   __len__EnvironmentVarGuard.__len__  s    4==!!r/   c                     X U'   g rj   r5   r%  s      r   setEnvironmentVarGuard.set  s	    Vr/   c                "    U/UQ7 H  nX	 M     g)z(Unset one or more environment variables.Nr5   )r   r  envvarsevs       r   unsetEnvironmentVarGuard.unset  s    $G$B %r/   c                     [        U 5      $ rj   )dictr   s    r   copyEnvironmentVarGuard.copy  s    Dzr/   c                     U $ rj   r5   r   s    r   	__enter__EnvironmentVarGuard.__enter__  r   r/   c                     U R                   R                  5        H6  u  p#Uc   X R                  ;   a  U R                  U	 M&  M(  X0R                  U'   M8     U R                  [        l        g rj   )r  itemsr  r   r  )r   
ignore_exckvs       r   __exit__EnvironmentVarGuard.__exit__  sV    mm))+FQy%a( & $%a  , ]]
r/   )r  r  N)r|   r   r   r   r   r   r   r'  r*  r-  r1  r4  r7  r<  r@  rC  rJ  r   r5   r/   r   r  r    sC    
%&&$#"
#r/   r  r   T)use_last_errorrs      c              #     #    [        [        R                  5       HE  nU S3n[        R	                  USS5      (       a  M&  [
        R                  " 5       [        :X  d  ME    O   [        R                  " S5      e[        R                  [        X 5      (       d)  [
        R                  " [
        R                  " 5       5      e Uv   [        R                  [        [        -  X 5      (       d)  [
        R                  " [
        R                  " 5       5      eg! [        R                  [        [        -  X 5      (       d)  [
        R                  " [
        R                  " 5       5      ef = f7f)z6Temporarily yield a substitute drive for a given path.:Nr   zno available logical drive)reversedstringascii_uppercaser   QueryDosDeviceWr   get_last_errorERROR_FILE_NOT_FOUNDr(   SkipTestDefineDosDeviceWDDD_NO_BROADCAST_SYSTEMWinErrorDDD_REMOVE_DEFINITIONDDD_EXACT_MATCH_ON_REMOVE)r   cdrives      r   subst_driver^    s     &001AcGE,,UD!<<))+/CC	 2 ##$@AA(('6 6//&"7"7"9::	?K,,),EE! ! oof&;&;&=>>!8,,),EE! ! oof&;&;&=>>!s,   <E,E,!A"E,D AE,AE))E,c                 .    [         R                  " S5      e)Nz#ctypes or kernel32 is not available)r(   rV  r   s    r   r^  r^    s     EFFr/   )F)NF)tempcwdF)^collections.abccollections
contextlibr  rz   r   rE   rV   rQ  r   rx   r(   warningsr+   r   TESTFN_ASCIIformatr   TESTFN_UNICODEr   unicodedata	normalizeTESTFN_UNENCODABLEr   getwindowsversionrA   encodegetfilesystemencodingr   UnicodeEncodeErrordecodeUnicodeDecodeErrorFS_NONASCII	characterfsdecodefsencodeUnicodeErrorr   SAVEDCWDTESTFN_UNDECODABLEgetfilesystemencodeerrorsTESTFN_NONASCIIr   r   r   r   r.   r2   r6   r8   r@   rP   rR   rU   r]   r_   rb   rc   rf   rh   r   r   r   rk   r   r   r   rI   r   contextmanagerr   r   r   r   r   r   r   r  r3   r  abcMutableMappingr  
MS_WINDOWSr   WinDLLr   rU  rZ  r[  rX  r#   r^  r   r5   r/   r   <module>r     s       	 	   
      !!,		<  ==
  **5.AN
  77d?
''1, *,MM	&%%c&?&?&AB ')B)B)DF G "& - 
		cll2HH
s0023 	  IB
 ;;r{{9-.); <
  W \ 99;  D"	C--/0%8 "[0OO		(L
 (4 4 
B4 
04  844 <<5!!#
J&$=* iiGXXF0 * *Z  B  & 
 
 $@F 2w   
9#+//88 9#x"?==DA  !$%!"# 	  ? ?M " 		  N)ooc779;LMNNf  F  	KK1135579! 		[[6=~ 	^$ GGGs~   > M $ M  (N N1P MM *NNNNP&0OPO#P"O##P PPP