Rh^ddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl m Z dZdjeej ZedzZej$dk(rddlZej(deZdZej,dk(reej.j$d k\rwed zZ ej1ej2ed ed ej2d dZn0ej$dvr" dj9ej2 dZdD].Z ej@ejBeek7re" eZnejFZ$dZ%dD]#Z ej9ej2%ereezZ'ndZ'e'xseZ(dZ)da*dZ+dZ,da-dZ.dZ/da0dZ1dZ2da3dZ4dZ5dZ6dZ7ej$jqd rd?d!Z9d"Z:d#Z;d$Zd)Z?ejd@d*ZAejd?d+ZBejdAd,ZCd-ZDejd.ZEd/ZFGd0d1ZGd2ZHeIed3rejd4ZJnejd5ZJGd6d7ejjZM e jr!ddlOZOeOjd8d9:ZQd ZRd ZSd;ZTdZWYywxYw)BN)supportz@testz {}_{}_tmpu -àòɘŁğdarwinNFDntu-共Ł♡ͣzWARNING: The filename z, CAN be encoded by the filesystem encoding (z.). Unicode filename tests may not be effective>wasir emscriptens-surrogateescape) æuİuŁuφuКuאu،uتuก u€)swr ssscttd} |j|jt tS#|jt twxYw)z` Create an invalid file descriptor by opening and closing a file and return its fd. wb)openTESTFNfilenocloseunlinkfiles -/usr/lib/python3.12/test/support/os_helper.py make_bad_fdrsB  D{{} v vs A!A"c ttStjjt}|dz} tj ||d}tj ||a|S#tttf$rd}Y|a|SwxYw)N can_symlinkTF) _can_symlinkospathabspathrsymlinkremoveOSErrorNotImplementedErrorAttributeError)src symlink_pathcans rrrs ''//& !C&L  3 % ,L J (. 9L J sA''BBcXt}d}|r|Stj||S)z8Skip decorator for tests that require functional symlinkz*Requires functional symlink implementation)runittestskiptestokmsgs rskip_unless_symlinkr/s, B 6C43-8==-d33cddl}ttSttdsd}|a|Sddl}|j }|j |\}} ttd5} tj|ddtj|dd tj|jdd|j}tjd |}|duxst|jd d k\}dddt#tt#|t%|a|S#t $rd}Y>wxYw#1swYCxYw#t#tt#|t%|wxYw) NrsetxattrFdirrs user.testr0s trusted.foos42z 2.6.(\d{1,2})')tempfile _can_xattrhasattrrplatformmkdtempmkstemprrr2rreleaserematchintgroupr"rrmdir) r7r'r:tmp_dirtmp_fptmp_namefpkernel_versionms r can_xattrrIsI 2z ".J J- ""$#+++8 fd# r  KK c:KK.%@KK \3?%-%5%5%7N!1>BAt);E=D>>EE E 'E4cXt}d}|r|Stj||S)zDSkip decorator for tests that require functional extended attributesz(no non-broken extended attribute support)rIr)r*r+s rskip_unless_xattrrKs, B 4C43-8==-d33r0c`ttSttdsdatS ttd5} tj tdtj tj}tj tdtj tj}t j|t j|k7}dddtta|S#t$r }d}Yd}~+d}~wwxYw#1swY4xYw#ttwxYw)NchmodFrimi) _can_chmodr9rrrrMstatst_modeS_IMODEr"r)fmode1mode2r'es r can_chmodrVs 2w    &$  A1 A'//'//ll5)T\\%-@@ A vJ J   A A vsLDDA:C82+DD8 D DDD  DDDD-cXt}d}|r|Stj||S)z`Skip tests that require working os.chmod() WASI SDK 15.0 cannot change file mode bits. zrequires working os.chmod())rVr)r*r+s rskip_unless_working_chmodrXs. B 'C43-8==-d33r0c"tsdattS ttd5}t j td ttd5 ddddaddd t j tdtttS#1swYCxYw#t $rdaYQwxYw#1swYVxYw#t $rYIwxYw# t j tdn#t $rYnwxYwttwxYw)NFrTi)rV_can_dac_overriderrrrMr"r)rRs rcan_dac_overrider\s ;!$   &$  )1 HHVU # )&$' %)! )  HHVU # v  *$)! *  ) )     HHVU #   vsCB7B&BB& B7"C+CB# B&& B41B73B44B77C<C CCDC/.D/ C;8D:C;;DcZt }d}|r|Stj||S)Nz"incompatible with CAP_DAC_OVERRIDEr\r)r*r+s rskip_if_dac_overrider_:s0   B .C43-8==-d33r0cXt}d}|r|Stj||S)Nzrequires CAP_DAC_OVERRIDEr^r+s rskip_unless_dac_overridera@s-  B %C43-8==-d33r0cF t|y#ttf$rYywxYwN)_unlinkFileNotFoundErrorNotADirectoryErrorfilenames rrrFs'  1 2   s   winc8|||r|}n(tjj|\}}|xsd}d}|dkr?tj|}|r|sy|vsyt j ||dz}|dkr?t jd|ztdy)N.gMbP?g?rz)tests may fail, delete still pending for  stacklevel) rrsplitlistdirtimesleepwarningswarnRuntimeWarning)funcpathnamewaitalldirnamenametimeoutLs r_waitforr}Ns X GGGMM(3MGTnGm 7#A A'+ai JJw  qLGm  AHL$ 4r0c8ttj|yrc)r}rrrgs rrdrdosH%r0c8ttj|yrc)r}rrBrys r_rmdirrrs7#r0cZddlmfdt|dtfd|y)Nr _force_runc|tj|D]}tjj||} tj|j }tj|r't|d|tj||tj|y#t $r-}td|d|tjd}Yd}~d}~wwxYw)Nzsupport.rmtree(): os.lstat(z) failed with rrTrx)rrprjoinlstatrPr"printsys __stderr__rOS_ISDIRr}rBr)rrzfullnamemodeexcr _rmtree_inners rrz_rmtree.._rmtree_innerxs"4T: >77<<d388H-55D <<%]HdCx8<xH= >%s,"~~/D sB44 C*=#C%%C*Trc4|tj|Src)rrB)prs rz_rmtree..s:a15r0) test.supportrr})rrrs @@r_rmtreerus$+ > d35t._rmtree_inners /"4T: :77<<d388H-55D<<%!(+tRXXx8tRYY9 :DsB44 CC)shutilrmtreer"rrB)rrrs @rrrsF  MM$      : d s  %%c|Srcrs rrr r0c: t|y#t$rYywxYwrc)rrers rrBrBs  w     c: t|y#t$rYywxYwrc)rrers rrrs      rc#Kddl}d}|2|j}d}tjj |}n tj |d}|rtj} ||r$tjk(r t|yyy#t $r/}|stjd|d|tdYd}~ud}~wwxYw#|r$tjk(r t|wwwxYww) aReturn 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. rNFTz5tests may fail, unable to create temporary directory : rm) r7r;rrrealpathmkdirr"rsrtrugetpidr)rquietr7 dir_createdrpids rtemp_dirrsK |! ww% 8 HHTNKiik  3"))+- 4L.; 8 MM1153%A(Q 8 8 8 3"))+- 4L.;sF;C=BC=,C0'C= C %C C= CC=(C::C=c#Ktj} tjtjj | tjtj|y#t $r/}|st jd|d|tdYd}~`d}~wwxYw#tj|wxYww)agReturn 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 rrrmN) rgetcwdchdirrrr"rsrtru)rr saved_dirrs r change_cwdrs I4 !!$'(iik  4  &&*XRu6$ 4 44 s@C 2A7 B2!C 7 B/%B*%C *B//C 2C  C c#Kt||5}t||5}|ddddddy#1swYxYw#1swYyxYww)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. )rr)rN)rr)rzr temp_pathcwd_dirs rtemp_cwdr sS t5 )Y   / 7M   s-A A4A A = AA A ctj|tjtjztjz}tj |y)z>Create an empty file. If the file already exists, truncate it.N)rrO_WRONLYO_CREATO_TRUNCr)rhfds rcreate_empty_filers3 2;;3bjj@ ABHHRLr0c#HKtjj|sJtj}t tdr|tj z}tj ||} |tj|y#tj|wxYww)z&Open a file descriptor to a directory. O_DIRECTORYN)rrisdirO_RDONLYr9rrr)rflagsdir_fds r open_dir_fdr$sq 77==   KKEr=!  WWT5 !F  sA+B".B2B"BB"c,ddl}|j|5}|j}|j}||k(r|j } t j j||cdddS#t$r YdddywxYw#1swYyxYw)zODetects if the file system for the specified directory is case-insensitive.rNr3F) r7NamedTemporaryFilerzupperlowerrrsamefilere) directoryr7base base_path case_paths rfs_is_case_insensitiver2s  $ $ $ 3tII OO%  !!)I 77##Iy9 !  s)2B  A33 B<B BB  Bc"eZdZdZdZdZdZy)FakePathz0Simple implementation of the path protocol. c||_yrcr)selfrs r__init__zFakePath.__init__Ds  r0c"d|jdS)Nz rrs r__repr__zFakePath.__repr__GsDII=**r0ct|jts4t|jtr&t |jtr |j|jSrc) isinstancer BaseExceptiontype issubclassrs r __fspath__zFakePath.__fspath__Js? tyy- 0 tyy$ '499m4))O99 r0N)__name__ __module__ __qualname____doc__rrrrr0rrrAs+r0rcDtjjdrd}ntjdk(rd}nd}|$ tj|}t |dz Sd}ttdr tjd }d}tjd k(rQ d dl }|ji}|j|j|jfD]}|j|d ||< d }t#|D]2} tj$|}tj&||dz }4 |=j|j|jfD]}|j||||S#t $rYwxYw#t$rYwxYw#tt f$rYwxYw#t$r(} | j(t(j*k7rYd} ~ d} ~ wwxYw#|>j|j|jfD]}|j|||wwxYw) z/Count the number of open file descriptors. )linuxfreebsdr z /proc/self/fdrz/dev/fdNr5rZsysconf SC_OPEN_MAXwin32r)rr: startswithrrprrer9rr"msvcrtCrtSetReportModeCRT_WARN CRT_ERROR CRT_ASSERTr$rrangeduprerrnoEBADF) fd_pathnamesMAXFD old_modesr report_typecountrfd2rUs rfd_countrSsH ||AB!  ! JJw'Eu:> ! Er9 JJ}-EI ||w D   # # I & & 0 0 & 1 1 3 D *0)@)@AB*D +& D M, B ffRj      & & 0 0 & 1 1 3 M '' Y{5KL M La!       ,   $ 77ekk)*   & & 0 0 & 1 1 3 M '' Y{5KL M !sl"E44FF0GF)G4 FF FFF&%F&) G2GGGGAHumaskc#Ktj|} dtj|y#tj|wxYww)z8Context manager that temporarily sets the process umask.N)rr)roldmasks r temp_umaskrs5((5/   HHW BHHW sA 3A A  A c#Kdyw)z"no-op on platforms without umask()Nr)rs rrrs  scXeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd Zy)EnvironmentVarGuardz_Class to help protect the environment variable properly. Can be used as a context manager.c<tj|_i|_yrc)renviron_environ_changedrs rrzEnvironmentVarGuard.__init__s   r0c |j|Src)r renvvars r __getitem__zEnvironmentVarGuard.__getitem__s}}V$$r0c||jvr(|jj||j|<||j|<yrcr r getrrvalues r __setitem__zEnvironmentVarGuard.__setitem__s9  &$(MM$5$5f$=DMM& ! % fr0c||jvr(|jj||j|<||jvr|j|=yyrcrr s r __delitem__zEnvironmentVarGuard.__delitem__sH  &$(MM$5$5f$=DMM& ! T]] " f% #r0c6|jjSrc)r keysrs rrzEnvironmentVarGuard.keyss}}!!##r0c,t|jSrc)iterr rs r__iter__zEnvironmentVarGuard.__iter__sDMM""r0c,t|jSrc)rr rs r__len__zEnvironmentVarGuard.__len__s4==!!r0c|||<yrcrrs rsetzEnvironmentVarGuard.sets V r0c ||=yrcrr s runsetzEnvironmentVarGuard.unsets Lr0ct|Src)dictrs rcopyzEnvironmentVarGuard.copys Dzr0c|Srcrrs r __enter__zEnvironmentVarGuard.__enter__rr0c|jjD]3\}}|||jvs|j|=%||j|<5|jt_yrc)r itemsr rr )r ignore_exckvs r__exit__zEnvironmentVarGuard.__exit__sZmm))+ %FQy % a(#$ a  % ]] r0N)rrrrrrrrrrrr r"r%r'r-rr0rrrsC%& &$#"#r0rrT)use_last_errorrlc#KttjD]<}|d}tj |ddr t j tk(s<ntjdtjt||s't jt j  |tjttz||s't jt j y#tjttz||s't jt j wxYww)z6Temporarily yield a substitute drive for a given path.:Nrzno available logical drive)reversedstringascii_uppercaserQueryDosDeviceWrget_last_errorERROR_FILE_NOT_FOUNDr)SkipTestDefineDosDeviceWDDD_NO_BROADCAST_SYSTEMWinErrorDDD_REMOVE_DEFINITIONDDD_EXACT_MATCH_ON_REMOVE)rcdrives r subst_driver@s&001 BAcGE,,UD!<))+/CC  B ##$@A A(('6//&"7"7"9: : ?K,,),EE4!oof&;&;&=>>!8,,),EE4!oof&;&;&=>>!s+9EEAE3D7A EA E  Ec,tjd)Nz#ctypes or kernel32 is not available)r)r8rs rr@r@s EFFr0)F)NF)tempcwdF)Ycollections.abc collections contextlibrrr>rOr3rrqr)rsr,r TESTFN_ASCIIformatrTESTFN_UNICODEr: unicodedata normalizeTESTFN_UNENCODABLErzgetwindowsversionencodegetfilesystemencodingrUnicodeEncodeErrordecodeUnicodeDecodeError FS_NONASCII characterfsdecodefsencode UnicodeErrorrSAVEDCWDTESTFN_UNDECODABLEgetfilesystemencodeerrorsTESTFN_NONASCIIrrrrr/r8rIrKrNrVrXr[r\r_rarrr}rdrrrrBrcontextmanagerrrrrrrrrr9rabcMutableMappingr MS_WINDOWSrWinDLLrr7r<r=r:r$r@rrr0rr`s  !!,  <  ==<<8*[**5.AN 77d?s''1,*,MM &  % %&?c&?&?&A B ')B)B)B)DF G"& \\99  0s0023   +IB  2;;{r{{9- .) ;  <   W+\ 299; D"  -C--/0%8"[0OO  (L  (4 B4 0484 4  <<5!4B&$=* iiG XXF0   %%P 6 &     $@F 2w 6#+//886#r"? 6==DA  !$%!"# ??G"    N)oo7c779;LMNNf    F   KK11135557 9!   (R[[6= x ^$GGGs~6 L L/'M 5 M /N8LL)MM MMN50N N5NN5NN54N58 OO