o EhM @sddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ej dkr0dZ ndZ d e eZ e dZejdkrMddlZedeZdZej d krejd kr~e d Zz eeWn eyqYn1wed eefdZn#ejdkrz d eWneye dedZYnw dZdD]ZzeeeekreWn eyYqweZe Z!dZ"dD]Z z e eWqeyee e Z"Ynwere eZ#ndZ#e#pe Z$ddZ%da&ddZ'ddZ(da)ddZ*ddZ+ddZ,ej-dr.dGd!d"Z.d#d$Z/d%d&Z0d'd(Z1d)d*Z2nej,Z/ej3Z0d+d(Z1d,d*Z2d-d.Z3d/d0Z4ej5dHd1d2Z6ej5dGd3d4Z7ej5dId6d7Z8d8d9Z9ej5d:d;Z:dd?d?ZedBrej5dCdDZ?GdEdFdFej@jAZBdS)JNjavaz$testz@testz {}_{}_tmpu -àòɘŁğdarwinNFDntu-共Ł♡ͣztWARNING: The filename %r CAN be encoded by the filesystem encoding (%s). Unicode filename tests may not be effectives-surrogateescape) æuİuŁuφuКuאu،uتuก u€)swrssscCs8ttd}z |W|ttS|ttw)z` Create an invalid file descriptor by opening and closing a file and return its fd. wb)openTESTFNfilenocloseunlinkfiler-/usr/lib/python3.10/test/support/os_helper.py make_bad_fds   rc Cs^tdurtStd}z tt|d}Wntttfy%d}Y|a|Swt||a|S)N can_symlinkTF) _can_symlinkrossymlinkOSErrorNotImplementedErrorAttributeErrorremove) symlink_pathcanrrrrs  rcC t}d}|r |St||S)z8Skip decorator for tests that require functional symlinkz*Requires functional symlink implementation)runittestskiptestokmsgrrrskip_unless_symlinkr(c CsLddl}tdur tSttdsd}|a|Sddl}|}|j|d\}}zsttdD}z0t |ddt |dd t | dd| }t d |}|dupZt|d d k}Wn tygd}YnwWdn1srwYWttt|t||a|SWttt|t||a|Sttt|t|w) NrsetxattrFdirr s user.tests trusted.foos42z 2.6.(\d{1,2})')tempfile _can_xattrhasattrrplatformmkdtempmkstempr rr*rreleaserematchintgrouprrrmdir) r0r r3tmp_dirtmp_fptmp_namefpkernel_versionmrrr can_xattrsL     rBcCr!)zDSkip decorator for tests that require functional extended attributesz(no non-broken extended attribute support)rBr"r#r$rrrskip_unless_xattrr)rCc Cs(zt|WdSttfyYdSwN)_unlinkFileNotFoundErrorNotADirectoryErrorfilenamerrrrs rwinFcCs|||r |}n tj|\}}|pd}d}|dkr9t|}|r&|s,dS||vs,dSt||d9}|dkstjd|tdddS)N.gMbP?g?rz)tests may fail, delete still pending for  stacklevel) rpathsplitlistdirtimesleepwarningswarnRuntimeWarning)funcpathnamewaitalldirnamenametimeoutLrrr_waitfors$    r^cCttj|dSrD)r^rrrHrrrrErEcCr_rD)r^rr;rZrrr_rmdirr`rbcs>ddlmfddt|ddtfdd|dS) Nr _force_runc s|tj|D]L}tj||}zt|j}Wnty7}ztd||ftj dd}WYd}~nd}~wwt |rLt |dd|tj |q|tj|qdS)Nz-support.rmtree(): os.lstat(%r) failed with %srrTrY)rrQrOjoinlstatst_moderprintsys __stderr__statS_ISDIRr^r;r)rOr[fullnamemodeexcrd _rmtree_innerrrrrs$ _rmtree.._rmtree_innerTrecs|tj|SrD)rr;)prcrr.sz_rmtree..) test.supportrdr^rOrrqr_rmtrees rxcCs^zddl}Wn tyY|Sw|t|d}|jj||t|}|r-|d|S|S)Nrr)ctypes ImportErrorcreate_unicode_bufferlenwindllkernel32GetLongPathNameW)rOrybufferlengthrrr _longpath0s    rcsNddl}z||WdStyYnwfdd|t|dS)Nrc sddlm}||tj|D]5}tj||}zt|j}Wn ty)d}Ynwt |r;|||tj |q ||tj |q dS)Nrrc) rvrdrrQrOrfrgrhrrlrmr;r)rOrdr[rnrorrrrrrIs   rs)shutilrmtreerrr;)rOrrrrrxAs    cC|SrDrrwrrrrYcC$zt|WdStyYdSwrD)rbrFrarrrr;]  r;cCrrD)rxrFrwrrrrdrrc csddl}d}|dur|}d}tj|}n-z t|d}Wn#tyD}z|s,tjd|d|t ddWYd}~nd}~ww|rKt }z|VW|r^|t kr`t |dSdSdS|ro|t krpt |www) 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) r0r4rrOrealpathmkdirrrTrUrVgetpidr)rOquietr0 dir_createdrppidrrrtemp_dirks>   rc cst}z ttj|Wn#ty3}z|stjd|d|tddWYd}~nd}~wwz tVWt|dSt|w)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) rgetcwdchdirrOrrrTrUrV)rOr saved_dirrprrr change_cwds&  rtempcwdc csvt||d*}t||d }|VWdn1swYWddSWddS1s4wYdS)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. )rOr)rN)rr)r[r temp_pathcwd_dirrrrtemp_cwds"rcCs(t|tjtjBtjB}t|dS)z>Create an empty file. If the file already exists, truncate it.N)rr O_WRONLYO_CREATO_TRUNCr)rIfdrrrcreate_empty_filesrc csDtj|s Jt|tj}z |VWt|dSt|w)z&Open a file descriptor to a directory.N)rrOisdirr O_RDONLYr)rOdir_fdrrr open_dir_fds rc Csddl}|j|d0}|j}|}||kr|}ztj||WWdSty9YWddSw1s=wYdS)zODetects if the file system for the specified directory is case-insensitive.rNr+F) r0NamedTemporaryFiler[upperlowerrrOsamefilerF) directoryr0base base_path case_pathrrrfs_is_case_insensitives rc@s(eZdZdZddZddZddZdS) FakePathz.Simple implementing of the path protocol. cCs ||_dSrDrw)selfrOrrr__init__ zFakePath.__init__cCsd|jdS)Nz rwrrrr__repr__szFakePath.__repr__cCs0t|jtst|jtrt|jtr|j|jSrD) isinstancerO BaseExceptiontype issubclassrrrr __fspath__s   zFakePath.__fspath__N)__name__ __module__ __qualname____doc__rrrrrrrrs  rc Cstjdrz td}t|dWStyYnwd}ttdr4ztd}Wn t y3Ynwd}tjdkrez d dl }|j Wn t t fyOYnwi}|j|j|jfD] }| |d ||<qZzMd }t|D],}zt|}Wnt y}z |jtjkrWYd}~qld}~wwt||d7}qlW|dur|j|j|jfD] }| |||q|S|dur|j|j|jfD] }| |||qww) z/Count the number of open file descriptors. )linuxfreebsdz /proc/self/fdr.sysconf SC_OPEN_MAXNwin32r)rjr3 startswithrrQr|rFr2rrmsvcrtCrtSetReportModerrzCRT_WARN CRT_ERROR CRT_ASSERTrangeduperrnoEBADFr) namesMAXFD old_modesr report_typecountrfd2errrfd_countsv              rumaskc cs0t|}z dVWt|dSt|w)z8Context manager that temporarily sets the process umask.N)rr)roldmaskrrr temp_umask3s  rc@sheZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZdS)EnvironmentVarGuardz_Class to help protect the environment variable properly. Can be used as a context manager.cCstj|_i|_dSrD)renviron_environ_changedrrrrrBs zEnvironmentVarGuard.__init__cCs |j|SrD)rrenvvarrrr __getitem__FrzEnvironmentVarGuard.__getitem__cCs*||jvr|j||j|<||j|<dSrDrrgetrrvaluerrr __setitem__Is zEnvironmentVarGuard.__setitem__cCs6||jvr|j||j|<||jvr|j|=dSdSrDrrrrr __delitem__Os   zEnvironmentVarGuard.__delitem__cCs |jSrD)rkeysrrrrrVrzEnvironmentVarGuard.keyscC t|jSrD)iterrrrrr__iter__YrzEnvironmentVarGuard.__iter__cCrrD)r|rrrrr__len__\rzEnvironmentVarGuard.__len__cCs |||<dSrDrrrrrset_s zEnvironmentVarGuard.setcCs ||=dSrDrrrrrunsetbrzEnvironmentVarGuard.unsetcCrrDrrrrr __enter__erzEnvironmentVarGuard.__enter__cGsF|jD]\}}|dur||jvr|j|=q||j|<q|jt_dSrD)ritemsrrr)r ignore_exckvrrr__exit__hs   zEnvironmentVarGuard.__exit__N)rrrrrrrrrrrrrrrrrrrr=s r)F)NF)rF)Ccollections.abc collections contextlibrrr7rlrjrRr"rTr[ TESTFN_ASCIIformatrTESTFN_UNICODEr3 unicodedata normalizeTESTFN_UNENCODABLEgetwindowsversionencodegetfilesystemencodingUnicodeEncodeErrorridecodeUnicodeDecodeError FS_NONASCII characterfsdecodefsencode UnicodeErrorrSAVEDCWDTESTFN_UNDECODABLETESTFN_NONASCIIrrrrr(r1rBrCrrr^rErbrxrr;rcontextmanagerrrrrrrrrr2rabcMutableMappingrrrrrs        !    ! !  (     <