
    daf^                        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
d dlZd dlmZ dZdj                  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(  re ej.                         j$                  d	k\  rwed
z   Z	 ej1                   ej2                                 eded ej2                         d       dZn0ej$                  dvr"	 dj9                   ej2                                	 dZdD ].  Z	  ej@                   ejB                  e            ek7  re"	 eZ n  ejF                         Z$dZ%dD ]#  Z	 ej9                   ej2                                % ereez   Z'ndZ'e'xs eZ(d Z)da*d Z+d Z,da-d Z.d Z/da0d Z1d Z2da3d Z4d Z5d Z6d Z7ej$                  jq                  d       rd?d!Z9d" Z:d# Z;d$ Z<d% Z=nejn                  Z:ej|                  Z;d& Z<d' Z=d( Z>d) Z?ej                  d@d*       ZAej                  d?d+       ZBej                  dAd,       ZCd- ZDej                  d.        ZEd/ ZF G d0 d1      ZGd2 ZH eIed3      rej                  d4        ZJnej                  d5        ZJ G d6 d7ej                  j                        ZM	 ej                  r!d dlOZO eOj                  d8d9:      ZQd	ZRd	ZSd;ZTd<ZUneV	 ej                  d=        ZWy# e$ r Y w xY w# e$ r( edj9                   ej2                         d      z   ZY  w xY w# e"$ r Y (w xY w# e$ rY 	 ej9                   ej2                          ejL                                n# e$ r Y Y &w xY w ejB                  e      ez   Z%Y  w xY w# eXeVf$ r d> ZWY yw xY w)B    N)supportz@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      } 	 | j                         | j                          t	        t               S # | j                          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    1/root/Python-3.12.4/Lib/test/support/os_helper.pymake_bad_fdr      sB    
 D{{}

v 	

vs   A !A"c                     t         t         S t        j                  j                  t              } | dz   }	 t        j
                  | |       d}t        j                  |       |a |S # t        t        t        f$ r d}Y |a |S w xY w)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                 X    t               }d}|r| S  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/      s,    	B
6C43-8==-d33    c                     dd l } t        t        S t        t        d      sd}|a|S dd l}| j                         }| j                  |      \  }}	 t        t        d      5 }	 t        j                  |dd       t        j                  |dd	       t        j                  |j                         dd       |j                         }t        j                  d
|      }|d u xs t        |j                  d            dk\  }d d d        t#        t               t#        |       t%        |       a|S # t         $ r d}Y >w xY w# 1 sw Y   CxY w# t#        t               t#        |       t%        |       w xY w)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      sI   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D0?E 0D>;E=D>>EE
E 'E4c                 X    t               }d}|r| S  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      s,    	B
4C43-8==-d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                  |      k7  }d d d        t        t               a |S # t        $ r}d}Y d }~+d }~ww xY w# 1 sw Y   4xY w# t        t               w xY w)NchmodFr   im  i  )
_can_chmodr9   r   r   r   rM   statst_modeS_IMODEr"   r   )fmode1mode2r'   es        r   	can_chmodrV      s    2w
&$ 		A1A'//'// ll5)T\\%-@@		A 	vJJ  		A 		A 	vsL   D DA:C82+DD 8	DDDDDDD D-c                 X    t               }d}|r| S  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())rV   r)   r*   r+   s      r   skip_unless_working_chmodrX     s.    
 
B
'C43-8==-d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        dad d d        	 t	        j
                  t        d       t        t               t        S # 1 sw Y   CxY w# t        $ r daY Qw xY w# 1 sw Y   VxY w# t        $ r Y Iw xY w# 	 t	        j
                  t        d       n# t        $ r Y nw xY wt        t               w xY w)NFr      Ti  )rV   _can_dac_overrider   r   r   rM   r"   r   )rR   s    r   can_dac_overrider\     s     ;!$  &$ 	)1HHVU#)&$' 
 %)!	)	HHVU# 	v  *$)!*	) 	)  			HHVU# 		vs   C B7B&BB& B7"C +C B#	B&&B41B73B44B77C <C 	CCDC/.D/	C;8D:C;;Dc                 Z    t                }d}|r| S  t        j                  |      |       S )Nz"incompatible with CAP_DAC_OVERRIDEr\   r)   r*   r+   s      r   skip_if_dac_overrider_   :  s0    	B
.C43-8==-d33r0   c                 X    t               }d}|r| S  t        j                  |      |       S )Nzrequires CAP_DAC_OVERRIDEr^   r+   s      r   skip_unless_dac_overridera   @  s-    		B
%C43-8==-d33r0   c                 F    	 t        |        y # t        t        f$ r Y y w xY wN)_unlinkFileNotFoundErrorNotADirectoryErrorfilenames    r   r   r   F  s'    12 s      winc                 8    | |       |r|}n(t         j                  j                  |      \  }}|xs d}d}|dk  r?t        j                  |      }|r|sy |v sy t	        j
                  |       |dz  }|dk  r?t        j                  d|z   t        d       y )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}   N  s    XGGGMM(3MGTnG m 

7#A A '+aiJJwqLG m 	AHL$	4r0   c                 8    t        t        j                  |        y rc   )r}   r   r   rg   s    r   rd   rd   o  s    H%r0   c                 8    t        t        j                  |        y rc   )r}   r   rB   ry   s    r   _rmdirr   r  s    7#r0   c                 Z    ddl m fdt        | d       t        fd|        y )Nr   
_force_runc                     | t         j                  |       D ]  }t         j                  j                  | |      }	 t        j                  |      j
                  }t        j                  |      r't        |d        |t         j                  |        |t         j                  |        y # t        $ r-}t        d|d|t        j                         d}Y d }~d }~ww xY w)Nzsupport.rmtree(): os.lstat(z) failed with r   r   Trx   )r   rp   r   joinlstatrP   r"   printsys
__stderr__rO   S_ISDIRr}   rB   r   )r   rz   fullnamemodeexcr   _rmtree_inners        r   r   z_rmtree.<locals>._rmtree_innerx  s    "4T: >77<<d388H-55D <<%]HdCx8<xH=>  %s,"~~/ D	s   B44	C*=#C%%C*Tr   c                 4     | t         j                  |       S rc   )r   rB   )pr   s    r   <lambda>z_rmtree.<locals>.<lambda>  s    :a15 r0   )test.supportr   r}   )r   r   r   s    @@r   _rmtreer   u  s$    +	> 	d35t<r0   c                     	 dd l } |j                  t        |       dz        }|j                  j                  j                  | |t        |            }|r|d | S | S # t        $ r Y | S w xY w)Nr   r   )ctypescreate_unicode_bufferlenwindllkernel32GetLongPathNameWImportError)r   r   bufferlengths       r   	_longpathr     s{    
	'
 2V11#d)a-@F]]++<<T6=@[JFgv&  	 	s   A 	A*)A*c                     dd l }	 |j                  |        y # t        $ r Y nw xY wfd |        t        j                  |        y )Nr   c                    ddl m}  || t        j                  |       D ]  }t        j                  j                  | |      }	 t        j                  |      j                  }t        j                  |      r! |        || t        j                  |       y || t        j                  |        y # t        $ r d}Y ^w xY w)Nr   r   )r   r   r   rp   r   r   r   rP   r"   rO   r   rB   r   )r   r   rz   r   r   r   s        r   r   z_rmtree.<locals>._rmtree_inner  s    /"4T: 
:77<<d388H-55D <<%!(+tRXXx8tRYY9
:  Ds   B44CC)shutilrmtreer"   r   rB   )r   r   r   s     @r   r   r     sF    	MM$ 			: 	d
s    	%%c                     | S rc    r   s    r   r   r         r0   c                 :    	 t        |        y # t        $ r Y y w xY wrc   )r   re   r   s    r   rB   rB     s     w     	c                 :    	 t        |        y # t        $ r Y y w xY wrc   )r   re   r   s    r   r   r     s      r   c              #     K   ddl }d}| 2|j                         } d}t        j                  j	                  |       } n	 t        j
                  |        d}|rt        j                         }	 |  |r$t        j                         k(  rt        |        yyy# t        $ r/}|s t        j                  d| d| t        d       Y d}~ud}~ww xY w# |r$t        j                         k(  rt        |        w w w xY 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   )r7   r;   r   r   realpathmkdirr"   rs   rt   ru   getpidr   )r   quietr7   dir_createdr   pids         r   temp_dirr     s      K|!ww%	8HHTNK iik
 3"))+-4L .;  	8MM 1153%A(Q8 8	8 3"))+-4L .;sF   ;C=B C=,C 0'C=	C %C
C=
CC=(C::C=c              #     K   t        j                         }	 t        j                  t         j                  j	                  |              	 t        j                          t        j                  |       y# t
        $ r/}|s t        j                  d| d| t        d       Y d}~`d}~ww xY w# t        j                  |       w xY w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chdirr   r   r"   rs   rt   ru   )r   r   	saved_dirr   s       r   
change_cwdr     s      		I4
!!$'(iik
  4 &&*XRu6$	4 	44 	s@   C2A7 B2 !C7	B/ %B*%C*B//C2C		Cc              #      K   t        | |      5 }t        ||      5 }| ddd       ddd       y# 1 sw Y   xY w# 1 sw Y   yxY ww)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   )rz   r   	temp_pathcwd_dirs       r   temp_cwdr   
  sS      
t5	) Y	/ 	7M	 	 	 s-   AA 4A 	A=	A  A	Ac                     t        j                  | t         j                  t         j                  z  t         j                  z        }t        j
                  |       y)z>Create an empty file. If the file already exists, truncate it.N)r   r   O_WRONLYO_CREATO_TRUNCr   )rh   fds     r   create_empty_filer     s3    	2;;3bjj@	ABHHRLr0   c              #   H  K   t         j                  j                  |       sJ t         j                  }t	        t         d      r|t         j
                  z  }t        j                  | |      }	 | t        j                  |       y# t        j                  |       w xY w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   $  sq      77==KKEr=!WWT5!F
s   A+B".B 2B"BB"c                 ,   ddl }|j                  |       5 }|j                  }|j                         }||k(  r|j	                         }	 t
        j                  j                  ||      cddd       S # t        $ r Y ddd       yw xY w# 1 sw Y   yxY w)zODetects if the file system for the specified directory
    is case-insensitive.r   Nr3   F)	r7   NamedTemporaryFilerz   upperlowerr   r   samefilere   )	directoryr7   base	base_path	case_paths        r   fs_is_case_insensitiver   2  s     		$	$	$	3 tII	OO%		!!)I	77##Iy9  ! 	 	 s)   2B

A33	B<B
BB

Bc                   "    e Zd ZdZd Zd Zd Zy)FakePathz0Simple implementation of the path protocol.
    c                     || _         y rc   r   )selfr   s     r   __init__zFakePath.__init__D  s	    	r0   c                 "    d| j                   dS )Nz
<FakePath >r   r   s    r   __repr__zFakePath.__repr__G  s    DII=**r0   c                     t        | j                  t              s4t        | j                  t              r&t	        | j                  t              r| j                  | j                  S rc   )
isinstancer   BaseExceptiontype
issubclassr   s    r   
__fspath__zFakePath.__fspath__J  s?    tyy-0tyy$'499m4))O99r0   N)__name__
__module____qualname____doc__r   r   r   r   r0   r   r   r   A  s    +r0   r   c                  D   t         j                  j                  d      rd} nt         j                  dk(  rd} nd} | $	 t        j                  |       }t        |      dz
  S d}t        t        d      r	 t        j                  d	      }d}t         j                  d
k(  rQ	 ddl
}|j                   i }|j                  |j                  |j                  fD ]  }|j                  |d      ||<    	 	 d}t#        |      D ]2  }	 t        j$                  |      }t        j&                  |       |dz  }4 	 |=j                  |j                  |j                  fD ]  }|j                  |||           |S # t        $ r Y w xY w# t        $ r Y w xY w# t        t         f$ r Y w xY w# t        $ r(}	|	j(                  t(        j*                  k7  r Y d}	~	d}	~	ww xY w# |>j                  |j                  |j                  fD ]  }|j                  |||           w w xY w)z/Count the number of open file descriptors.
    )linuxfreebsdr	   z/proc/self/fdr   z/dev/fdNr5   rZ   sysconfSC_OPEN_MAXwin32r   )r   r:   
startswithr   rp   r   re   r9   r   r"   msvcrtCrtSetReportModeCRT_WARN	CRT_ERROR
CRT_ASSERTr$   r   rangedupr   errnoEBADF)
fd_pathnamesMAXFD	old_modesr   report_typecountr   fd2rU   s
             r   fd_countr   S  sH    ||AB!		!	JJw'E u:>! Er9	JJ}-E I
||w	D##
 I & & 0 0 & 1 1 3 D *0)@)@AB*D	+&DM, 
	B	 ffRj
 

	   & & 0 0 & 1 1 3 M ''Y{5KLM
 La ! 		  		 , 		$  77ekk) *   & & 0 0 & 1 1 3 M ''Y{5KLM !sl   "E4 4F F 0G F)G 4	F F	FFF&%F&)	G2GG GG AHumaskc              #      K   t        j                  |       }	 d t        j                  |       y# t        j                  |       w xY ww)z8Context manager that temporarily sets the process umask.N)r   r  )r  oldmasks     r   
temp_umaskr    s5      ((5/	HHWBHHWs   A3 AA

Ac              #      K   d yw)z"no-op on platforms without umask()Nr   )r  s    r   r  r    s      	s   c                   X    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y)EnvironmentVarGuardz_Class to help protect the environment variable properly.  Can be used as
    a context manager.c                 <    t         j                  | _        i | _        y rc   )r   environ_environ_changedr   s    r   r   zEnvironmentVarGuard.__init__  s    

r0   c                      | j                   |   S rc   )r
  r   envvars     r   __getitem__zEnvironmentVarGuard.__getitem__  s    }}V$$r0   c                     || j                   vr(| j                  j                  |      | j                   |<   || j                  |<   y rc   r  r
  getr   r  values      r   __setitem__zEnvironmentVarGuard.__setitem__  s9    &$(MM$5$5f$=DMM&! %fr0   c                     || j                   vr(| j                  j                  |      | j                   |<   || j                  v r| j                  |= y y rc   r  r  s     r   __delitem__zEnvironmentVarGuard.__delitem__  sH    &$(MM$5$5f$=DMM&!T]]"f% #r0   c                 6    | j                   j                         S rc   )r
  keysr   s    r   r  zEnvironmentVarGuard.keys  s    }}!!##r0   c                 ,    t        | j                        S rc   )iterr
  r   s    r   __iter__zEnvironmentVarGuard.__iter__  s    DMM""r0   c                 ,    t        | j                        S rc   )r   r
  r   s    r   __len__zEnvironmentVarGuard.__len__  s    4==!!r0   c                     || |<   y rc   r   r  s      r   setzEnvironmentVarGuard.set  s    Vr0   c                 
    | |= y rc   r   r  s     r   unsetzEnvironmentVarGuard.unset  s	    Lr0   c                     t        |       S rc   )dictr   s    r   copyzEnvironmentVarGuard.copy  s    Dzr0   c                     | S rc   r   r   s    r   	__enter__zEnvironmentVarGuard.__enter__  r   r0   c                     | j                   j                         D ]3  \  }}||| j                  v s| j                  |= %|| j                  |<   5 | j                  t        _        y rc   )r  itemsr
  r   r	  )r   
ignore_exckvs       r   __exit__zEnvironmentVarGuard.__exit__  sZ    mm))+ 	%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    sC    %&&$#"#r0   r  r   T)use_last_errorrl      c              #     K   t        t        j                        D ]<  }| d}t        j	                  |dd      r t        j                         t        k(  s< n t        j                  d      t        j                  t        ||       s't        j                  t        j                               	 | t        j                  t        t        z  ||       s't        j                  t        j                               y# t        j                  t        t        z  ||       s't        j                  t        j                               w xY ww)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1 	BAcGE,,UD!<))+/CC		B ##$@AA(('6//&"7"7"9::	?K,,),EE4! oof&;&;&=>>!8,,),EE4! oof&;&;&=>>!s+   9EEAE3D 7A
EAEEc                 ,    t        j                  d      )Nz#ctypes or kernel32 is not available)r)   r8  r   s    r   r@  r@    s     EFFr0   )F)NF)tempcwdF)Ycollections.abccollections
contextlibr   r   r>   rO   r3  r   rq   r)   rs   r,   r   TESTFN_ASCIIformatr   TESTFN_UNICODEr:   unicodedata	normalizeTESTFN_UNENCODABLErz   getwindowsversionencodegetfilesystemencodingr   UnicodeEncodeErrordecodeUnicodeDecodeErrorFS_NONASCII	characterfsdecodefsencodeUnicodeErrorr   SAVEDCWDTESTFN_UNDECODABLEgetfilesystemencodeerrorsTESTFN_NONASCIIr   r   r   r   r/   r8   rI   rK   rN   rV   rX   r[   r\   r_   ra   r   r   r}   rd   r   r   r   rB   r   contextmanagerr   r   r   r   r   r   r   r   r9   r  abcMutableMappingr  
MS_WINDOWSr   WinDLLr   r7  r<  r=  r:  r$   r@  r   r   r0   r   <module>r`     s      	 	   
      !!,			<  ==<<8 *[**5.AN
  77d?s''1, *,MM	&%%&?c&?&?&AB ')B)B)B)DF G "&\\99
0s0023 	   +IB
 2;;{r{{9-.); <
  W+\ 299;   D"	-C--/0%8 "[0OO		(L
 (4 
B4 
04  844 <<5!4B&$=* iiGXXF0 % %P  6  & 
 
 $@F 2w   
6#+//88 6#r"? 6==DA  !$%!"# 	  ? ?G " 		  N)oo7c779;LMNNf  F  	KK111355579! 		(R[[6=x 	^$ GGGs~   6 L  L /'M5 M/N8 LL)MMMMN50NN5NN5NN54N58
OO