
    z%i]                     d   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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j-                   ej.                                 ed
ed ej.                         d       dZn0ej                   dvr"	 dj5                   ej.                                	 dZdD ].  Z	  ej<                   ej>                  e            ek7  re 	 eZ n  ejB                         Z"dZ#dD ]#  Z	 ej5                   ej.                                % 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a.d Z/d Z0da1d Z2d Z3d Z4d Z5ej                   jm                  d      rd>d Z7d! Z8d" Z9d# Z:d$ Z;nejj                  Z8ejx                  Z9d% Z:d& Z;d' Z<d( Z=ej|                  d?d)       Z?ej|                  d>d*       Z@ej|                  d@d+       ZAd, ZBej|                  d-        ZCd. ZD G d/ d0      ZEd1 ZF eGed2      rej|                  d3        ZHnej|                  d4        ZH G d5 d6ej                  j                        ZK	 d dlLZL eLj                  d7d89      ZNdZOdZPd:ZQd;ZRej|                  d<        ZSy# e$ r Y w xY w# e$ r( edj5                   ej.                         d      z   ZY w xY w# e $ r Y w xY w# e$ rY 	 ej5                   ej.                          ejH                                n# e$ r Y Y w xY w ej>                  e      ez   Z#Y  w xY w# eTeUf$ r d= ZSY yw xY w)A    Nz@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    J/home/uftp/.pyenv/versions/3.12.0/lib/python3.12/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.testr/   s   trusted.foos   42z2.6.(\d{1,2})   '   )tempfile
_can_xattrhasattrr   platformmkdtempmkstempr   r   r1   r   releaserematchintgroupr!   r   rmdir)	r6   r&   r9   tmp_dirtmp_fptmp_namefpkernel_versionms	            r   	can_xattrrH      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)rH   r(   r)   r*   s      r   skip_unless_xattrrJ      s,    	B
4C43-8==-d33r/   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chownFr   i  i  )
_can_chmodr8   r   r   r   chmod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3r/   c                  x   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        t               t        S # 1 sw Y   (xY w# t        $ r daY 6w xY w# 1 sw Y   ;xY w# t        t               w xY w)NFr      T)rV   _can_dac_overrider   r   r   rN   r!   r   )rR   s    r   can_dac_overrider\     s     ;!$  &$ 	)1HHVU#)&$' 
 %)!	) 	v  *$)!*	) 	) 	vs^   B( BBA?B B"B( ?B	BBBBBB%!B( (B9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_   4  s0    	B
.C43-8==-d33r/   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3r/   c                 F    	 t        |        y # t        t        f$ r Y y w xY wN)_unlinkFileNotFoundErrorNotADirectoryErrorfilenames    r   r   r   @  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}   H  s    XGGGMM(3MGTnG m 

7#A A '+aiJJwqLG m 	AHL$	4r/   c                 8    t        t        j                  |        y rc   )r}   r   r   rg   s    r   rd   rd   i  s    H%r/   c                 8    t        t        j                  |        y rc   )r}   r   rA   ry   s    r   _rmdirr   l  s    7#r/   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}   rA   r   )r   rz   fullnamemodeexcr   _rmtree_inners        r   r   z_rmtree.<locals>._rmtree_innerr  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   rA   )pr   s    r   <lambda>z_rmtree.<locals>.<lambda>  s    :a15 r/   )test.supportr   r}   )r   r   r   s    @@r   _rmtreer   o  s$    +	> 	d35t<r/   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   rA   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   rA   )r   r   r   s     @r   r   r     sF    	MM$ 			: 	d
s    	%%c                     | S rc    r   s    r   r   r         r/   c                 :    	 t        |        y # t        $ r Y y w xY wrc   )r   re   r   s    r   rA   rA     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   )r6   r:   r   r   realpathmkdirr!   rs   rt   ru   getpidr   )r   quietr6   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HHRLr/   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_RDONLYr8   r   r   r   )r   flagsdir_fds      r   open_dir_fdr     sn      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   Nr2   F)	r6   NamedTemporaryFilerz   upperlowerr   r   samefilere   )	directoryr6   base	base_path	case_paths        r   fs_is_case_insensitiver   ,  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__>  s	    	r/   c                 "    d| j                   dS )Nz
<FakePath >r   r   s    r   __repr__zFakePath.__repr__A  s    DII=**r/   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__D  s?    tyy-0tyy$'499m4))O99r/   N)__name__
__module____qualname____doc__r   r   r   r   r/   r   r   r   ;  s    +r/   r   c                  
   t         j                  j                  d      r$	 t        j                  d      } 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/fdr4   rZ   sysconfSC_OPEN_MAXNwin32r   )r   r9   
startswithr   rp   r   re   r8   r   r!   msvcrtCrtSetReportModeCRT_WARN	CRT_ERROR
CRT_ASSERTr#   r   rangedupr   errnoEBADF)	namesMAXFD	old_modesr   report_typecountr   fd2rU   s	            r   fd_countr   M  s'    ||AB	JJ/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   "E E' E7 G  $F9G  	E$#E$'	E43E47F	F		F=F83G  8F==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    

r/   c                      | j                   |   S rc   )r	  r   envvars     r   __getitem__zEnvironmentVarGuard.__getitem__  s    }}V$$r/   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r/   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% #r/   c                 6    | j                   j                         S rc   )r	  keysr   s    r   r  zEnvironmentVarGuard.keys  s    }}!!##r/   c                 ,    t        | j                        S rc   )iterr	  r   s    r   __iter__zEnvironmentVarGuard.__iter__  s    DMM""r/   c                 ,    t        | j                        S rc   )r   r	  r   s    r   __len__zEnvironmentVarGuard.__len__  s    4==!!r/   c                     || |<   y rc   r   r  s      r   setzEnvironmentVarGuard.set  s    Vr/   c                 
    | |= y rc   r   r  s     r   unsetzEnvironmentVarGuard.unset  s	    Lr/   c                     t        |       S rc   )dictr   s    r   copyzEnvironmentVarGuard.copy  s    Dzr/   c                     | S rc   r   r   s    r   	__enter__zEnvironmentVarGuard.__enter__  r   r/   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 	% ]]
r/   N)r   r   r   r   r   r  r  r  r  r  r  r  r!  r$  r&  r,  r   r/   r   r  r    sC    %&&$#"#r/   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(   r7  r   s    r   r?  r?    s     EFFr/   )F)NF)tempcwdF)Vcollections.abccollections
contextlibr   r   r=   rO   r2  r   rq   r(   rs   TESTFN_ASCIIformatr   TESTFN_UNICODEr9   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.   r7   rH   rJ   rM   rV   rX   r[   r\   r_   ra   r   r   r}   rd   r   r   r   rA   r   contextmanagerr   r   r   r   r   r   r   r   r8   r  abcMutableMappingr  r   WinDLLr   r6  r;  r<  r9  r?  r   r#   r   r/   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  044 <<5!4B&$=* iiGXXF0 % %P  6  & 
 
 $9x 2w   
6#+//88 6#r?v}}Z=H !
 ? ?k " 		  N)oo7c779;LMNNf  F  	KK111355579! 		(R[[6=\ 	^$ GGGs~   0 K9   L )'L5/ M N" 9LL)L21L25L>=L>N0M87N8N=NNNN"
N/.N/