
    F\hh                    h   S r \S:w  a  \" S5      e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rSSKrSSKr/ SQrSrSrSrS	r\R.                  R1                  \R.                  R3                  \5      5      r\R.                  R1                  \5      r\R.                  R1                  \5      r\R.                  R1                  \5      r " S
 S\5      r  " S S\ 5      r! " S S\!5      r" " S S\ 5      r# " S S\RH                  5      r%S r&S r'S r(Sr)Sr*Sq+Sq,Sr-Sr.Sq/S r0S r1S r2S r3S r4SS jr5S r6S  r7S! r8S" r9SS# jr:SSSSS$.S% jr;SSSSSS$.S& jjr<\;" S'S(9r=S) r>S* r?S+r@S,rA\R                  " \CR                  S-5      R                  S.5      S/5      rFSS0 jrGSS1 jrHSS2 jrISS3 jrJS4 rKSS5 jrL\R                  SS6 j5       rNS7 rO\R                  S8:H  rQ\R                  R                  S95      rR\R                  S::H  rS\R                  S;;  a  \S(       a  S<OS=rTOSrT\R                  S>:H  rU\R                  S?:H  rV\R                  S@;   rW\W=(       d    \R                  SA:H  rX\Y" \SB5      =(       a"    \U=(       d    \V=(       d    \W=(       d    \S(       + rZSC r[\U=(       d    \V=(       d    \W=(       d    \S(       + r\SD r]\U=(       d    \V(       + r^SSE.SF jr_Sr`\R                  S8:w  a   \R                  " SG5      SG:g  r`SHrcSrdSre\R.                  R                  \SI5      rgSJ rhSSK jriSL rjSM\kSN\l\k\m4   4SO jrnSSSSP.SQ jjroSR rp\R                  SS 5       rqST rrSU rsSV rtSW ru\R                  SX 5       rv\R                  SY 5       rwSZ rxS[ ryS\ rz\{" \R                  " S]5      5      r}SS^ jr~S_ r\}(       a  S`rOSarSbr\Sc-   rSd rSe rSfrSgrSh rSSi.Sj jr\R                  Sk 5       rSl rSm rSnrSo\-  rSp\-  rSq\-  r\GR                   rSr\kSN\4Ss jrSr\kSNS4St jr " Su Sv5      rSSw jrSx rSy rSz rS{ rSS| jrS} rS~ rS rS rS r\R                  " S5      =(       d    SS:H  rS rS r\" 5       =(       a-    \R                  S8:g  =(       a    \R                  " S5      (       + r\R                   SLr\=(       a    \(       + r\R                  " \S5      rS rS r\GRT                  \l        SqS r\R                  S 5       r\R                  S 5       rS rS r " S S\m5      rSqS r " S S5      rS rSS.S jr  SS jrSS jr " S S5      rS r\R                  S 5       rS rSS.S jrS rSS jr/ 4S jrSqS rS r\R                  S 5       r " S S5      rS rS r " S S5      r\" 5       r " S S5      r\" 5       r\GR                   " S S5      5       r\" 5       r\GR                   " S S5      5       r\" 5       rS r\GR                  GR                  r\S;   d   eS r " S S5      rSS.S jrS rS rS rS r\R                  S 5       rSS jrS\kS\kSN\m4S jrS\mSNS4S jrS r\GR                  S 5       r\R                  S 5       r\Y" \S5      rS rSS'S.S jjrSSSS'S.S jjr " S S5      r\R                  S 5       rS rS r\Y" \S5      =(       a     \GR                  " 5       GR                  S:H  r\GR                  " \S5      r\Y" \S5      rS r\" SS15      rS rS rS r\R                  S 5       rS rS rSN\l\k\k4   4S jrS r " S S5      rS rg! \b a     GNf = f)z7Supporting definitions for the Python regression tests.ztest.supportz.support must be imported from the test package    N)XPIPE_MAX_SIZEverbose
max_memuseuse_resourcesfailfastError
TestFailedTestDidNotRunResourceDeniedrecord_original_stdoutget_original_stdoutcaptured_stdoutcaptured_stdincaptured_stderrcaptured_outputis_resource_enabledrequiresrequires_freebsd_versionrequires_gil_enabledrequires_linux_versionrequires_mac_vercheck_syntax_errorrequires_gziprequires_bz2requires_lzma
bigmemtestbigaddrspacetestcpython_onlyget_attributerequires_IEEE_754requires_zlibhas_fork_supportrequires_forkhas_subprocess_supportrequires_subprocesshas_socket_supportrequires_working_socketanticipate_failureload_package_testsdetect_api_mismatchcheck__all__skip_if_buggy_ucrt_strfptimecheck_disallow_instantiationcheck_sanitizerskip_if_sanitizerrequires_limited_apirequires_specialization
MS_WINDOWS	is_jython
is_androidis_emscriptenis_wasiis_apple_mobilecheck_impl_detail
unix_shellsetswitchintervalget_pagesizeopen_urlresourcereap_childrenrun_with_locale	swap_itemfindfileinfinite_recursion	swap_attrMatcherset_memlimitSuppressCrashReportsortdictrun_with_tzPGOmissing_compiler_executable	ALWAYS_EQNEVER_EQLARGESTSMALLESTLOOPBACK_TIMEOUTINTERNET_TIMEOUTSHORT_TIMEOUTLONG_TIMEOUTPy_DEBUGexceeds_recursion_limitget_c_recursion_limitskip_on_s390xwithout_optimizerforce_not_colorizedforce_not_colorized_test_classmake_clean_env
BrokenIterg      $@g      N@g      >@g     r@c                       \ rS rSrSrSrg)r   q   z*Base class for regression test exceptions. N__name__
__module____qualname____firstlineno____doc____static_attributes__r]       ,/usr/lib/python3.13/test/support/__init__.pyr   r   q   s    4re   r   c                   :   ^  \ rS rSrSrSS.U 4S jjrS rSrU =r$ )r	   t   Test failed.Nstatsc                @   > Xl         X l        [        TU ]  " U/UQ76   g N)msgrk   super__init__)selfrn   rk   args	__class__s       rf   rp   TestFailed.__init__v   s    
$t$re   c                     U R                   $ rm   rn   rq   s    rf   __str__TestFailed.__str__{   s    xxre   )rn   rk   )	r_   r`   ra   rb   rc   rp   rx   rd   __classcell__rs   s   @rf   r	   r	   t   s    )- % %
 re   r	   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )TestFailedWithDetails~   ri   c                 :   > X l         X0l        [        TU ]  XX4S9  g )Nrj   )errorsfailuresro   rp   )rq   rn   r   r   rk   rs   s        rf   rp   TestFailedWithDetails.__init__   s     h<re   )r   r   )r_   r`   ra   rb   rc   rp   rd   rz   r{   s   @rf   r}   r}   ~   s    = =re   r}   c                       \ rS rSrSrSrg)r
      zTest did not run any subtests.r]   Nr^   r]   re   rf   r
   r
      s    (re   r
   c                       \ rS rSrSrSrg)r      zTest skipped because it requested a disallowed resource.

This is raised when a test calls requires() for a resource that
has not be enabled.  It is used to distinguish between expected
and unexpected skips.
r]   Nr^   r]   re   rf   r   r      s    re   r   c                 6    U (       a  [         R                  $ S $ )zDecorator to mark a test that is known to be broken in some cases

Any use of this decorator should have a comment identifying the
associated tracker issue.
c                     U $ rm   r]   )fs    rf   <lambda>$anticipate_failure.<locals>.<lambda>   s    Qre   )unittestexpectedFailure)	conditions    rf   r(   r(      s     '''re   c                 `    Uc  Sn[         nUR                  U UUS9nUR                  U5        U$ )zGeneric load_tests implementation for simple test packages.

Most packages can implement load_tests using this function as follows:

   def load_tests(*args):
       return load_package_tests(os.path.dirname(__file__), *args)
ztest*)	start_dirtop_level_dirpattern)
STDLIB_DIRdiscoveraddTests)pkg_dirloaderstandard_testsr   top_dirpackage_testss         rf   r)   r)      sD     GOOg29,3 $ 5M M*re   c                 v     [        X5      nU$ ! [         a    [        R                  " SU < SU< 35      ef = f)z?Get an attribute, raising SkipTest if AttributeError is raised.zobject z has no attribute )getattrAttributeErrorr   SkipTest)objname	attributes      rf   r   r      sB    C&	   O3 MNNOs    )8   Fc                     U q g rm   )_original_stdout)stdouts    rf   r   r      s    re   c                  <    [         =(       d    [        R                  $ rm   )r   sysr   r]   re   rf   r   r      s    )szz)re   c                     U" U6 $ ! [          a6  n[        S:  a&  [        UR                  R                  < SU< 35        e S nAf[
         a  n[        S:  aB  [        UR                  R                  < SU< 35        [        SUR                  < U< 35        [        R                  " U [        R                  5        U" U6 s S nA$ S nAff = f)N   : zre-run )
FileNotFoundErrorr   printrs   r_   OSErroroschmodstatS_IRWXU)pathfuncrr   errs       rf   
_force_runr      s    T{ a<cmm44c:; a<cmm44c:;4==$78
t||$T{s'    
C1ACA5C
C
Cc            	        ^ [        [        S5      (       a  [        R                  $ SS Kn S n[        R                  R                  S5      (       a  U R                  5       (       a  SnGO[        R                  R                  S5      (       a  SS KmSS KmSnSn " U4S jSTR                  5      nTR                  R                  nUR                  5       nU(       d  TR                  5       eU" 5       nTR                  R                  5       nUR!                  UUTR#                  U5      TR%                  U5      TR#                  U5      5      n	U	(       d  TR                  5       e['        UR(                  U-  5      (       d  SnOb[        R                  S	:X  aN  SS Kn
 U
R-                  S
S/SSS9nUR.                  R1                  S5      R3                  5       nUS:w  a  SU< S3nU(       d>   SSKJn  U" 5       nUR;                  5         UR=                  5         UR?                  5         U[        l&        U(       + [        l        [        R                  $ ! U
R4                   a    Sn Nf = f! [@         aQ  n[C        U5      n[E        U5      S:  a  US S S-   nSRG                  [I        U5      RJ                  U5      n S nANS nAff = f)Nresultr   winz(gui is not available on Windows IoT Corer   c                      > \ rS rSrS Y R                  R
                  4S Y R                  R
                  4S Y R                  R                  4/rSrg)*_is_gui_available.<locals>.USEROBJECTFLAGS   fInherit	fReserveddwFlagsr]   N)	r_   r`   ra   rb   wintypesBOOLDWORD_fields_rd   )ctypess   rf   USEROBJECTFLAGSr      s@    #V__%9%9:$foo&:&:;"FOO$9$9:<Hre   r   z,gui not available (WSF_VISIBLE flag not set)darwin	launchctlmanagernameT)capture_outputcheckzutf-8Aquazmanagername=z' -- can only run in a macOS GUI sessionz*unable to detect macOS launchd job manager)Tk2   z [...]zTk unavailable due to {}: {})'hasattr_is_gui_availabler   platformr   
startswithwin32_is_iotr   ctypes.wintypes	Structurewindlluser32GetProcessWindowStationWinErrorr   r   GetUserObjectInformationWbyrefsizeofboolr   
subprocessrunr   decodestripCalledProcessErrortkinterr   withdrawupdatedestroy	Exceptionstrlenformattyper_   reason)r   r   	UOI_FLAGSWSF_VISIBLEr   dllhuofneededresr   rcr   r   roote
err_stringr   s                    @rf   r   r      si    (++ '''F
||u%%(*?*?*A*A;		 	 	'	' 			<f.. 	< mm""'')//##&&(++ALLMM#LL 	"
 //##CKK+-..CF		! 		Rm </34   AB))**7399;K f$(K>)PQ 	G"4DMMOKKMLLN  &#)z###1 ,, 	BAF	B  	GQJ:#'_x7
3::47;K;K;EGF		Gs+   "<I 3=I3 I0/I03
K=AK		Kc                 2    [         SL =(       d	    U [         ;   $ )zTest whether a resource is enabled.

Known resources are set by regrtest.py.  If not running under regrtest.py,
all resources are assumed enabled unless use_resources has been set.
N)r   resources    rf   r   r   !  s     D =H$==re   c                     [        U 5      (       d  Uc  SU -  n[        U5      eU S;   a  [        (       d  [        S5      eU S:X  a)  [        5       (       d  [        [        R                  5      egg)z@Raise ResourceDenied if the specified resource is not available.Nz"Use of the %r resource not enabled>   networkurlfetchzNo socket supportgui)r   r   r&   r   r   )r   rn   s     rf   r   r   )  sm    x((;6ACS!!**3E3E0115!2!4!4.5566 "5re   c                 x   SSK nSR                  [        [        U5      5      nUR	                  5       R                  SS5      S   nUR                  5       U :X  a.   [        [        [        UR                  S5      5      5      nXQ:  nOSn[        R                  " UU  SU SU 35      $ ! [         a    Sn N-f = f)	zDecorator raising SkipTest if the OS is `sysname` and the version is less
than `min_version`.

For example, @_requires_unix_version('FreeBSD', (7, 2)) raises SkipTest if
the FreeBSD version is less than 7.2.
r   N.-r   Fz	 version  or higher required, not )r   joinmapr   releasesplitsystemtupleint
ValueErrorr   skipIf)sysnamemin_versionr   min_version_txtversion_txtversionskips          rf   _requires_unix_versionr  4  s     hhs345O""$**3215KG#	)C[%6%6s%;<=G (D??)9_--F-	   	D	s   (B* *B98B9c                      [        SU 5      $ )zDecorator raising SkipTest if the OS is FreeBSD and the FreeBSD version is
less than `min_version`.

For example, @requires_freebsd_version(7, 2) raises SkipTest if the FreeBSD
version is less than 7.2.
FreeBSDr  r  s    rf   r   r   O  s     ")[99re   c                      [        SU 5      $ )zDecorator raising SkipTest if the OS is Linux and the Linux version is
less than `min_version`.

For example, @requires_linux_version(2, 6, 32) raises SkipTest if the Linux
version is less than 2.6.32.
Linuxr  r  s    rf   r   r   X  s     "';77re   c                     ^  U 4S jnU$ )zDecorator raising SkipTest if the OS is Mac OS X and the OS X
version if less than min_version.

For example, @requires_mac_ver(10, 5) raises SkipTest if the OS X version
is lesser than 10.5.
c                 X   >^  [         R                  " T 5      U U4S j5       nTUl        U$ )Nc                  d  > [         R                  S:X  a  SS KnUR                  5       S   n [        [	        [
        UR                  S5      5      5      nUT:  a=  SR                  [	        [        T5      5      n[        R                  " SU< SU< 35      e T" U 0 UD6$ ! [         a     Nf = f)Nr   r   r   z	Mac OS X r   )r   r   mac_verr  r  r  r  r  r   r   r   r  )rr   kwr   r  r  r  r   r  s         rf   wrapper4requires_mac_ver.<locals>.decorator.<locals>.wrapperi  s    ||x'&..03	>#C[->->s-C$DEG ,*-((3sK3H*I&//.=> > -
 $$$ " s   (B" "
B/.B/)	functoolswrapsr  )r   r  r  s   ` rf   	decorator#requires_mac_ver.<locals>.decoratorh  s-    			% 
	% *re   r]   )r  r   s   ` rf   r   r   a  s    & re   c                    SSK nU (       d  Sn  UR                  5       R                  5       S:H  n[        R                  " X 5      $ ! [        [        4 a4  n[
        R                  " [        5      R                  SX3S9  Sn SnANUSnAff = f)z4Decorator raising SkipTest if running on a buildbot.r   Nznot suitable for buildbotsbuildbotzgetpass.getuser() failed %s.exc_infoF)getpassgetuserlowerKeyErrorr   logging	getLoggerr_   warningr   r	  )r   r&  
isbuildbotr   s       rf   skip_if_buildbotr.  ~  sx    -__&,,.*<
 ??:.. g (#++,JC+^
s   !A B
*BB
addressmemoryubthreadc                    U (       d   U(       d  U(       d  U(       d  [        S5      e[        R                  " S5      =(       d    Sn[        R                  " S5      =(       d    SnSU;   =(       d    SU;   nSU;   =(       d    SU;   nS	U;   =(       d    S
U;   nSU;   =(       d    SU;   n	U=(       a    U=(       d/    U =(       a    U=(       d    U=(       a    U=(       d    U=(       a    U	$ )z9Returns True if Python is compiled with sanitizer supportz:At least one of address, memory, ub or thread must be TrueCFLAGS CONFIG_ARGSz-fsanitize=memoryz--with-memory-sanitizerz-fsanitize=addressz--with-address-sanitizerz-fsanitize=undefinedz#--with-undefined-behavior-sanitizerz-fsanitize=threadz--with-thread-sanitizer)r  	sysconfigget_config_var)
r0  r1  r2  r3  cflagsconfig_argsmemory_sanitizeraddress_sanitizerub_sanitizerthread_sanitizers
             rf   r.   r.     s    vvUVV %%h/52F**=9?RKv% 	1![0 
 	& 	2"k1 
 	&( 	=-< 
 	v% 	1![0 
 
	$$ 	&		&&	&			& 
	$$	re   c                T    U (       d  Sn [        XX4S9n[        R                  " XP5      $ )z>Decorator raising SkipTest if running with a sanitizer active.z"not working with sanitizers activer/  )r.   r   r	  )r   r0  r1  r2  r3  r  s         rf   r/   r/     s%    57bPD??4((re   T)r0  c                 J    S H  nX ;   a  X==   SU 3-  ss'   M  XU'   M     g )N)ASAN_OPTIONSMSAN_OPTIONSUBSAN_OPTIONSTSAN_OPTIONS:r]   )envoptionr   s      rf   set_sanitizer_env_varrI    s+    Q;I1VH%II	 Rre   c                 F   ^  [         R                  " T 5      U 4S j5       nU$ )z5Skip the test on TLS certificate validation failures.c                     >  T" U 0 UD6  g ! [          a+  nS[        U5      ;   a  [        R                  " S5      ee S nAff = f)NCERTIFICATE_VERIFY_FAILEDz.system does not contain necessary certificates)r   r   r   r   )rr   kwargsr   r   s      rf   dec&system_must_validate_cert.<locals>.dec  sO    	tv 	*c!f4'' )A B B		s    
A&<Ar  r  )r   rN  s   ` rf   system_must_validate_certrQ    s%    __Q  Jre   i @ i  doubleIEEEztest requires IEEE 754 doublesc                 \     SS K n[        R                  " X5      $ ! [         a    S n N$f = fNr   )zlibImportErrorr   
skipUnless)r   rV  s     rf   r!   r!     3     t,,      ++c                 \     SS K n[        R                  " X5      $ ! [         a    S n N$f = frU  )gziprW  r   rX  )r   r\  s     rf   r   r     rY  rZ  c                 \     SS K n[        R                  " X5      $ ! [         a    S n N$f = frU  )bz2rW  r   rX  )r   r^  s     rf   r   r     s3     s++  rZ  c                 \     SS K n[        R                  " X5      $ ! [         a    S n N$f = frU  )lzmarW  r   rX  )r   r`  s     rf   r   r     rY  rZ  c                       SS K n U R	                  5       n[        US   5      (       + $ ! [         a    [        R                  " S5      ef = f)Nr   _testinternalcapi requiredcode_debug_ranges)_testinternalcapirW  r   r   
get_configr   )rd  configs     rf   has_no_debug_rangesrg    sQ    >  ))+FF./000  > <==>s	   ) !A
c                 @    [         R                  " [        5       U 5      $ rm   )r   r	  rg  )r   s    rf   requires_debug_rangesri    s    ??.0&99re   c              #      #     SSK nU (       d  Sv   gUR                  S5         Sv   UR                  S5        g! [         a    Sv    gf = f! UR                  S5        f = f7f)z-Suppress immortalization of deferred objects.r   NTF)rd  rW  suppress_immortalization)suppressrd  s     rf   rk  rk    sc      
 ..t4:2259   	2259s;   A&< A&A A&A
A&AA&A##A&c                  v     SS K n [        R                  " U R	                  5       S5      $ ! [         a     g f = f)Nr   z,requires immortalization of deferred objects)rd  rW  r   rX  get_immortalize_deferred)rd  s    rf    skip_if_suppress_immortalizationro    sD      0IIK NP P  s   + 
88win32javaandroid>   iostvosrp  vxworkswatchosz/system/bin/shz/bin/sh
emscriptenwasi>   rs  rt  rv  r   forkc                  8    [         R                  " [        S5      $ )Nzrequires working os.fork())r   rX  r"   r]   re   rf   r#   r#   @  s    /1MNNre   c                  8    [         R                  " [        S5      $ )z3Used for subprocess, os.spawn calls, fd inheritancezrequires subprocess support)r   rX  r$   r]   re   rf   r%   r%   O  s    57TUUre   )modulec                     SnU (       a"  [         (       d  [        R                  " U5      eg[        R                  " [         U5      $ )z{Skip tests or modules that require working sockets

Can be used as a function/class decorator or to skip an entire module.
zrequires socket supportN)r&   r   r   rX  )r|  rn   s     rf   r'   r'   Y  s>    
 $C!!##C(( " ""#5s;;re   z%4Yzhttp://www.pythontest.netdatac                     [         R                  S:w  a  gSSKnSnU  S3nUR                  5       u  pE[	        UR                  US5      5        [	        U5        [	        SU-  5        g)zKAssure user that loud errors generated by macOS libc's malloc are
expected.r   Nr   z NOTICE z may generate "malloc can't allocate region"
warnings on macOS systems. This behavior is known. Do not
report a bug unless tests are also failing.
See https://github.com/python/cpython/issues/85100r   )r   r   shutilget_terminal_sizer   center)	test_namer  rn   detailpadding_s         rf   darwin_malloc_err_warningr  ~  sf     ||x
C C CF
 ))+JG	#**Wc
"#	&M	#-re   c                 f   [         R                  R                  U 5      (       a  U $ Ub  [         R                  R                  X5      n [        /[
        R                  -   nU HJ  n[         R                  R                  X05      n[         R                  R                  U5      (       d  MH  Us  $    U $ )aG  Try to find a file on sys.path or in the test directory.  If it is not
found the argument passed to the function is returned (this does not
necessarily signal failure; could still be the legitimate path).

Setting *subdir* indicates a relative path to use to find the file
rather than looking directly in the path directories.
)r   r   isabsr  TEST_HOME_DIRr   exists)filenamesubdirr   dnfns        rf   r@   r@     s~     
ww}}X77<<1?SXX%DWW\\"'77>>"by  Ore   c                     [        U R                  5       5      nU Vs/ s H  nSU-  PM
     nnSR                  U5      nSU-  $ s  snf )z%Like repr(dict), but in sorted order.z%r: %rz, z{%s})sorteditemsr  )dictr  pair	reprpairs
withcommass        rf   rF   rF     sH    4::< E-23UTDUI39%JJ 4s   Acodereturnc                 J    0 n[        [        R                  " U 5      U5        U$ )zHRun a piece of code after dedenting it, and return its global namespace.)exectextwrapdedent)r  nss     rf   run_coder    s    	B	#Ire   )linenooffsetc                   U R                  [        U5       n[        USS5        S S S 5        WR                  nU R	                  UR
                  5        Ub  U R                  UR
                  U5        U R	                  UR                  5        Ub  U R                  UR                  U5        g g ! , (       d  f       N= f)Nz<test string>r  )assertRaisesRegexSyntaxErrorcompile	exceptionassertIsNotNoner  assertEqualr  )testcase	statementerrtextr  r  cmr   s          rf   r   r     s    		#	#K	9R	?F3 
:
,,CSZZ(SZZ0SZZ(SZZ0  
:	9s   B//
B=c                 R  ^^^ SS K nSS KnSSKJn   SS KnTR                  SS 5      mUR                  R                  U 5      S   R                  S5      S   n[        R                  R                  [        U5      nUUU4S jn[        R                  R                  U5      (       a  U" U5      n	U	b  U	$ U" U5        [        S	5        [         (       a  [#        S
U -  [%        5       S9  UR&                  R)                  5       n
U(       a  U
R*                  R-                  S5        U
R/                  U [0        S9n	U(       a.  U	R2                  R5                  S5      S:X  a  UR7                  U	S9n	 [/        US5       nU	R9                  5       nU(       a*  UR;                  U5        U	R9                  5       nU(       a  M*  S S S 5        U	R=                  5         U" U5      n	U	b  U	$ [?        SU-  5      e! [
         a    S n GNf = f! , (       d  f       NL= f! U	R=                  5         f = f)Nr   r   )unlinkr   r   /c                    > [        U /TQ70 TD6nTc  U$ T" U5      (       a  UR                  S5        U$ UR                  5         g rU  )openseekclose)r  r   rr   r   r  s     rf   check_valid_file*open_urlresource.<locals>.check_valid_file  sC    !d!b!=H1XXFF1IH		re   r   z	fetching %s ...file)zAccept-Encodingr\  timeoutzContent-Encodingr\  )fileobjwbzinvalid resource %r) urllib.requesturllib.parse	os_helperr  r\  rW  popparseurlparser  r   r   r  TEST_DATA_DIRr  r   r   r   r   requestbuild_opener
addheadersappendr  rO   headersgetGzipFilereadwriter  r	   )urlrr   r  urllibr  r\  r  r  r  r   openeroutsr   s    ``          @rf   r<   r<     s   '! FF7D!E||$$S)!,2237;H	mX	.B 
ww~~bR =Hr
 Zw!C'.A.CD^^((*F  !<=C!12A		01V;MM!M$"d^sA		!FFH !  	
	A}
*R/
00_  H ^ 	
	s6   G0 /H ;A H=H 0H ?H 
HH H&c              #      #    SSK n[        [        U 5      n[        [        XR	                  5       5         [        [        U 5      v   [        [        X5        g! [        [        X5        f = f7f)zReturn a context manager used by captured_stdout/stdin/stderr
that temporarily replaces the sys stream *stream_name* with a StringIO.r   N)ior   r   setattrStringIO)stream_namer  orig_stdouts      rf   r   r     sL      #{+KCkkm,/c;''[.[.s   3A.A A.A++A.c                      [        S5      $ )zCapture the output of sys.stdout:

with captured_stdout() as stdout:
    print("hello")
self.assertEqual(stdout.getvalue(), "hello\n")
r   r   r]   re   rf   r   r          8$$re   c                      [        S5      $ )zCapture the output of sys.stderr:

with captured_stderr() as stderr:
    print("hello", file=sys.stderr)
self.assertEqual(stderr.getvalue(), "hello\n")
stderrr  r]   re   rf   r   r     r  re   c                      [        S5      $ )zCapture the input to sys.stdin:

with captured_stdin() as stdin:
    stdin.write('hello\n')
    stdin.seek(0)
    # call test code that consumes from sys.stdin
    captured = input()
self.assertEqual(captured, "hello")
stdinr  r]   re   rf   r   r     s     7##re   c                  l    SSK n U R                  5         U R                  5         U R                  5         g)a  Force as many objects as possible to be collected.

In non-CPython implementations of Python, this is needed because timely
deallocation is not guaranteed by the garbage collector.  (Even in CPython
this can be the case in case of reference cycles.)  This means that __del__
methods may be called later than expected and weakrefs may remain alive for
longer than expected.  This function tries its best to force all garbage
objects to disappear.
r   N)gccollect)r  s    rf   
gc_collectr  !  s"     JJLJJLJJLre   c               #      #    SS K n U R                  5       nU R                  5          S v   U(       a  U R                  5         g g ! U(       a  U R                  5         f f = f7frU  )r  	isenableddisableenable)r  have_gcs     rf   
disable_gcr  0  sF     llnGJJLIIK 7IIK s   %A"A A"AA"c               '      #    SS K nUR                  5       nUR                  " U 6    S v   UR                  " U6   g ! UR                  " U6   f = f7frU  )r  get_thresholdset_threshold)rr   r  old_thresholds      rf   gc_thresholdr  ;  sH     $$&Md)
-(-(s   $A; AAAc                      [         R                  " S5      =(       d    Sn SnU R                  5        H  nUR                  S5      (       d  M  UnM     [         R                  " S5      S:X  a  SnX;  $ SnX;  $ )z,Find if Python was built with optimizations.	PY_CFLAGSr6  z-OCCgcc)r6  -O0z-Og)r6  r  )r8  r9  r  r   )r:  	final_optoptnon_optss       rf   python_is_optimizedr  E  su    %%k28bFI||~>>$I  %.% $$ $$re   c                     ^ [         R                  " S5      =(       d    Sm/ SQn [         R                  " S5      nU(       a  U R                  U5        [        U4S jU  5       5      $ )NPY_CFLAGS_NODISTr6  )z-fprofile-usez-fprofile-instr-usez	-prof-usePGO_PROF_USE_FLAGc              3   ,   >#    U  H	  oT;   v   M     g 7frm   r]   ).0rH  cflags_nodists     rf   	<genexpr>#check_cflags_pgo.<locals>.<genexpr>b  s     A[6&[s   )r8  r9  r  any)pgo_optionsr  r  s     @rf   check_cflags_pgor   S  sY     ,,-?@FBMK "001DE,-A[AAAre   c                  b    [         (       a  g[        R                  " S5      =(       d    Sn SU ;   $ )NFr7  r6  z--enable-bolt)r6   r8  r9  )r;  s    rf   check_bolt_optimizedr  e  s,     w**=9?RKk))re   Py_GIL_DISABLEDc                 8    [         R                  " [        U 5      $ )z8Decorator for skipping tests on the free-threaded build.)r   r	  r  rv   s    rf   r   r   p  s    ???C00re   c                  >    [         (       a  [        R                  $ S $ )z+Expect test failure if the GIL is disabled.c                     U $ rm   r]   )	test_cases    rf   r   2expected_failure_if_gil_disabled.<locals>.<lambda>x  s    Yre   )r  r   r   r]   re   rf    expected_failure_if_gil_disabledr	  t  s    '''&&re   PHBBInPnP0nnc                 H    SS K nUR                  [        U -   [        -   5      $ rU  )structcalcsize_header_alignfmtr  s     rf   calcobjsizer    s    ??7S=6122re   c                 H    SS K nUR                  [        U -   [        -   5      $ rU  )r  r  _vheaderr  r  s     rf   calcvobjsizer    s    ??8c>F233re   i @  i   c                     SS K n[        R
                  " U5      n[        U5      [        :X  a  UR                  [        -  (       d4  [        U5      [        :w  a/  [        U5      R                  [        -  (       a  X#R                  -  nS[        U5      XB4-  nU R                  XBU5        g ! [         a    [        R                  " S5      ef = f)Nr   rb  z&wrong size for %s: got %d, expected %d)rd  rW  r   r   r   	getsizeofr   	__flags___TPFLAGS_HEAPTYPE_TPFLAGS_HAVE_GCSIZEOF_PYGC_HEADr  )testosizerd  r   rn   s         rf   check_sizeofr"    s    >  ]]1F	aDq{{->>
q'T/Q 1 14D D222
2Aw%&CV3'  > <==>s   B, ,!C)_do_cleanupsc                  ^ ^^^ Sm[        T [        5      (       a1  T R                  SS5      R                  5       m [	        T 5      S:X  a  Sm[        T5      mUU UU4S jnU$ )z5Run multiple subtests with different parameters.
    F, r   Tc                    >^  [        T [        5      (       a  [        S5      e[        R                  " T 5      UUUU U4S j5       nU$ )Nz1subTests() can only decorate methods, not classesc                   > T Hd  nT	(       a  U4n[        [        TU5      5      nU R                  " S0 UD6   T" U /UQ70 UDUD6  S S S 5        T(       d  MT  U R                  5         Mf     g ! , (       d  f       N,= f)Nr]   )r  zipsubTest
doCleanups)
rq   rr   rM  valuessubtest_kwargsr#  	arg_names
arg_valuesr   single_params
        rf   r  ,subTests.<locals>.decorator.<locals>.wrapper  sk    $$YF!%c)V&<!=\\3N3AAA.A 4<OO% % 43s   A--
A;	)
isinstancer   	TypeErrorr  r  )r   r  r#  r.  r/  r0  s   ` rf   r   subTests.<locals>.decorator  sC    dD!!OPP			& 	& 
	& re   )r2  r   replacer  r   r  )r.  r/  r#  r   r0  s   ``` @rf   subTestsr6    s_     L)S!!%%c#.446	y>QLz"J  re   c              '      #     SS K n[        X 5      nUR                  U5      nU H  n UR                  X55          O"   SU;  a  [        R
                  " SU 35      e  S v   U(       a  U(       a  UR                  WU5        g g g ! UR                   a     Mt  f = f! [         a    e [         a"    S =p$SU;  a  [        R
                  " S5      e Ntf = f! U(       a  U(       a  UR                  WU5        f f f = f7f)Nr   r6  zno locales z
no locales)localer   	setlocaler   r   r   r   r   )catstrlocalesr8  categoryorig_localelocs         rf   r>   r>     s    A6*&&x0 C  /   ''+gY(?@@ !4kX{3 "6 <<    2##W##L11 2& kX{3 "6sa   C> B C>B$C> C $#C>BC>BC>3CC>CC>$C;;C>c                    ^ ^ U U4S jnU$ )Nc                 L   >^  [         R                  " T 5      UU U4S j5       nU$ )Nc                N  > ST
;   n SS K n[        UT5      nUR                  U5      n T
 H;  nU R                  US9    UR                  XW5        SnT	" U /UQ70 UD6  S S S 5        M=     UR                  XV5        U(       a%  U R                  S S9   T	" U /UQ70 UD6  S S S 5        g g ! UR                   a    U R                  SU< 35         Nqf = f! , (       d  f       M  = f! UR                  XV5        f = f! [         a    e [         a     Nf = f! , (       d  f       g = f)Nr6  r   )r8  Fz
no locale )r8  r   r9  r*  r   skipTestr   r   )rq   rr   rM  dry_runr8  r<  r=  r>  r:  r   r;  s           rf   r  /run_with_locales.<locals>.deco.<locals>.wrapper  s.   GmG<"662$..x8<&!\\\5< & 0 0 ? +0 $T ;D ;F ; 65  ' $$X; \\\./// /.  $*<< D $
3'.B CD 65 $$X;% "  & /.sc   !C< C& C B)CC& D)%CCCC
C#	C& &C9<DD
D$rP  )r   r  r:  r;  s   ` rf   decorun_with_locales.<locals>.deco  s%    			0 
	0< re   r]   )r:  r;  rE  s   `` rf   run_with_localesrG    s     B Kre   c                    ^  U 4S jnU$ )Nc                 \   >^  U U4S jnT R                   Ul         T R                  Ul        U$ )Nc                    >  [         R                  nS[
        R                  ;   a  [
        R                  S   nOS nT[
        R                  S'   U" 5          T" U 0 UD6Uc  [
        R                  S	 OU[
        R                  S'   [         R                  " 5         $ ! [         a    [        R                  " S5      ef = f! Uc  [
        R                  S	 OU[
        R                  S'   [         R                  " 5         f = f)Nztzset requiredTZ)timetzsetr   r   r   r   environ)rr   kwdsrM  orig_tzr   tzs       rf   inner-run_with_tz.<locals>.decorator.<locals>.inner  s    :

 rzz!**T*!BJJtGT*T*?

4('.BJJt$

# " :''(899: ?

4('.BJJt$

s   B C !B>?D )r_   rc   )r   rR  rQ  s   ` rf   r   run_with_tz.<locals>.decorator  s%    	, re   r]   )rQ  r   s   ` rf   rG   rG     s    4 re   i      r      limitc                 J   S[         [        S[        -  S.n[        R                  " SU [        R                  [        R
                  -  5      nUc  [        SU < 35      e[        [        UR                  S5      5      XR                  S5      R                  5          -  5      $ )NrU  )kmgtz(\d+(?:\.\d+)?) (K|M|G|T)b?$zInvalid memory limit: r   r   )_1M_1Grematch
IGNORECASEVERBOSEr  r  floatgroupr(  )rW  sizesrZ  s      rf   _parse_memlimitrf  -  s    #X	E 	0%+	-Ay1%;<<uQWWQZ 5)9)9);#<<==re   c                 |    [        U 5      nU[        S-
  :  a  [        SU < S35      eUq[	        U[
        5      nUqg )Nr   zMemory limit z too low to be useful)rf  _2Gr  real_max_memuseminMAX_Py_ssize_tr   )rW  memlimits     rf   rD   rD   :  sE     u%H#'=	1FGHHO8^,HJre   c                   *    \ rS rSrSrS rS rS rSrg)_MemoryWatchdogiF  zXAn object which periodically watches the process' memory consumption
and prints it out.
c                 `    SR                  [        R                  " 5       S9U l        SU l        g )Nz/proc/{pid}/statm)pidF)r   r   getpidprocfilestartedrw   s    rf   rp   _MemoryWatchdog.__init__K  s$    +22ryy{2Cre   c                    SS K n [        U R                  S5      nSS KnU   [        S5      nUR                  [        R                  U/UUR                  S9U l        S S S 5        SU l        g ! [         aP  n[        R
                  " [        5      R                  SX3S9  [        R                  R                  5          S nAg S nAff = f! , (       d  f       Ns= f)Nr   rz!/proc not available for stats: %sr$  zmemory_watchdog.py)r  r  T)warningsr  rr  r   r*  r+  r_   r,  r   r  flushr   r@   Popen
executableDEVNULLmem_watchdogrs  )rq   rw  r   r   r   watchdog_scripts         rf   start_MemoryWatchdog.startO  s    	T]]C(A 	&';<O * 0 0#../1R788B8J8J !1 !LD 
   	h'//0SUV/cJJ	 Qs#   A. <C.
C8ACC
Cc                     U R                   (       a5  U R                  R                  5         U R                  R                  5         g g rm   )rs  r|  	terminatewaitrw   s    rf   stop_MemoryWatchdog.stop`  s2    <<'')""$ re   )r|  rr  rs  N)	r_   r`   ra   rb   rc   rp   r~  r  rd   r]   re   rf   rn  rn  F  s    "%re   rn  c                    ^ ^^ UUU 4S jnU$ )aP  Decorator for bigmem tests.

'size' is a requested size for the test (in arbitrary, test-interpreted
units.) 'memuse' is the number of bytes per unit for the test, or a good
estimate of it. For example, a test that needs two byte buffers, of 4 GiB
each, could be decorated with @bigmemtest(size=_4G, memuse=2).

The 'size' argument is normally passed to the decorated test method as an
extra argument. If 'dry_run' is true, the value passed to the test method
may be less than the requested value. If 'dry_run' is false, it means the
test doesn't support dummy runs when -M is not specified.
c                 8   >^ ^ UU U4S jmTTl         TTl        T$ )Nc                   > TR                   nTR                  n[        (       d  SnOUn[        (       d  T(       d*  [        X2-  :  a  [        R                  " SX-  S-  -  5      e[        (       aM  [
        (       aB  [        5         [        SR                  X-  S-  S95        [        5       nUR                  5         OS n T" X5      U(       a  UR                  5         $ $ ! U(       a  UR                  5         f f = f)Ni  'not enough memory: %.1fG minimum needed   @z* ... expected peak memory use: {peak:.1f}G)peak)r!  memuseri  r   r   r   r   r   rn  r~  r  )rq   r!  r  maxsizewatchdogrC  r   r  s        rf   r  .bigmemtest.<locals>.decorator.<locals>.wrappert  s    <<D^^F"? #g&66''=}	245 5 77Bv4=I#>v?A*, $'MMO 8MMO s   C! !C;)r!  r  )r   r  rC  r  r!  s   `@rf   r   bigmemtest.<locals>.decorators  s    	$: re   r]   )r!  r  rC  r   s   ``` rf   r   r   f  s     B re   c                    ^  U 4S jnU$ )z0Decorator for tests that fill the address space.c                    > [         [        :  aJ  [        S:  a   [         S:  a  [        R                  " S5      e[        R                  " S[        S-  -  5      eT" U 5      $ )Nl    l        z-not enough memory: try a 32-bit build insteadr  r  )r   rk  r   r   )rq   r   s    rf   r  !bigaddrspacetest.<locals>.wrapper  sb    &*zU/B''CE E ''=%356 6 T7Nre   r]   )r   r  s   ` rf   r   r     s    
 Nre   c                     U $ rm   r]   )r   s    rf   _idr    s    Jre   c                     U S:X  a3  [        5       (       d$  [        R                  " [         R                  5      $ [	        U 5      (       a  [
        $ [        R                  " SR                  U 5      5      $ )Nr   zresource {0!r} is not enabled)r   r   r  r   r   r  r   r   s    rf   requires_resourcer    sT    5!2!4!4}}.55668$$
}}<CCHMNNre   c                      [        SS9" U 5      $ )z1
Decorator for tests only applicable on CPython.
T)cpython)impl_detailr  s    rf   r   r     s     t$T**re   c                    [        S0 UD6(       a  [        $ U cR  [        U5      u  p#U(       a  Sn OSn [        UR	                  5       5      nU R                  SR                  U5      5      n [        R                  " U 5      $ )Nz*implementation detail not available on {0}z%implementation detail specific to {0}z or r]   )	r8   r  _parse_guardsr  keysr   r  r   r  )rn   guards
guardnamesdefaults       rf   r  r    sh    "6"

{+F3
>C9CJOO-.
jjZ01==re   c                     U (       d  SS0S4$ [        U R                  5       5      S   n[        U R                  5       5      U/[        U 5      -  :X  d   eX(       + 4$ )Nr  TFr   )listr,  r   )r  is_trues     rf   r  r    sY    D!5))6==?#A&G WIF$;;;;K  re   c                  p    [        U 5      u  pU R                  [        R                  R                  U5      $ )a  This function returns True or False depending on the host platform.
Examples:
   if check_impl_detail():               # only on CPython (default)
   if check_impl_detail(jython=True):    # only on Jython
   if check_impl_detail(cpython=False):  # everywhere except on CPython
)r  r  r   implementationr   )r  r  s     rf   r8   r8     s-     $F+OF::c((--w77re   c                   ^ ^^ T m[        [        S5      (       a  [        R                  " T 5      U 4S j5       mTnS[        R                  ;   a:  [        R
                  R                  m[        R                  " T 5      UU4S j5       nU$ )zEDecorator to temporarily turn off tracing for the duration of a test.gettracec                     > [         R                  " 5       n [         R                  " S 5        T" U 0 UD6[         R                  " U5        $ ! [         R                  " U5        f = frm   )r   r  settrace)rr   rM  original_tracer   s      rf   trace_wrapper!no_tracing.<locals>.trace_wrapper  sE     \\^N-T"T,V,^,^,s   A A$ztest.covc                    > [         R                  R                  T5      n [         R                  R                  TS5        T" U 0 UD6[         R                  R                  TU5        $ ! [         R                  R                  TU5        f = frU  )r   
monitoring
get_events
set_events)rr   rM  original_eventscovr  s      rf   coverage_wrapper$no_tracing.<locals>.coverage_wrapper  sg    !nn77<O@))#q1$d5f5))#?))#?s   'A* *"B)r   r   r  r  modulesr  COVERAGE_ID)r   r  r  r  s   ` @@rf   
no_tracingr    sx    MsJ			- 
	- %S[[ nn((			@ 
	@ re   c                 *    [        [        U 5      5      $ )zDecorator for tests which involve reference counting.

To start, the decorator does not run the test if is not run by CPython.
After that, any trace function is unset during the test to prevent
unexpected refcounts caused by the trace function.

)r  r   r  s    rf   refcount_testr    s     l4())re   c                 p     SS K nSS KnU $ ! [         a    [        R                  " S5      " U 5      s $ f = f)Nr   z,needs _testcapi and _testlimitedcapi modules)	_testcapi_testlimitedcapirW  r   r  )r  r  r  s      rf   r0   r0     s=    S K  S}}KLTRRSs    &55TEST_MODULESyesc                 X    [         R                  " [        R                  S5      " U 5      $ )Nzrequires specialization)r   rX  _opcodeENABLE_SPECIALIZATIONr  s    rf   r1   r1     s,    %%'@BBFH Hre   c                      g)z,Just used to check if docstrings are enabledNr]   r]   re   rf   _check_docstringsr    s    re   WITH_DOC_STRINGSztest requires docstringsc                      [         R                  b  [         R                  R                  5         [         R                  b  [         R                  R                  5         g g rm   )r   r   rx  r  r]   re   rf   flush_std_streamsr  +  s;    
zz


zz

 re   c                     [        5         [        R                  nU R                  5        H  n[	        SU 3US9  M     UR                  5         g )NzWarning -- r  )r  print_warningorig_stderr
splitlinesr   rx  )rn   streamlines      rf   r  r  2  s>    &&F D6"0 !
LLNre   c                     [        [        S5      (       a  [        [        S5      (       d  g[        (       d  g  [        R                  " S[        R                  5      u  pU S:X  a  g[        SU  35        SqMA  ! [
         a     gf = f)zUse this function at the end of test_main() whenever sub-processes
are started.  This will help ensure that no extra children (zombies)
stick around to hog resources and create problems when looking
for refleaks.
waitpidWNOHANGNTr  r   z%reap_children() reaped child process )r   r   r$   r  r  r   r  environment_altered)rp  statuss     rf   r=   r=   G  s     B	""wr9'='=## 	**R4KC !8=cUCD"   		s   'A: :
BBc              #   <  #    [        X5      (       a)  [        X5      n[        XU5         Uv   [        XU5        g[        XU5         Sv   [        X5      (       a  [        X5        gg! [        XU5        f = f! [        X5      (       a  [        X5        f f = f7f)a  Temporary swap out an attribute with a new object.

Usage:
    with swap_attr(obj, "attr", 5):
        ...

    This will set obj.attr to 5 for the duration of the with: block,
    restoring the old value at the end of the block. If `attr` doesn't
    exist on `obj`, it will be created and then deleted at the end of the
    block.

    The old value (or None if it doesn't exist) will be assigned to the
    target of the "as" clause, if there is one.
N)r   r   r  delattr)r   attrnew_valreal_vals       rf   rB   rB   e  s       s3%7#	)NCx(7#	#s!!" " Cx( s!!" "s3   (BA* B	A; B*A88B;BBc              #      #    X;   a  X   nX U'    Uv   X0U'   gX U'    Sv   X;   a  X	 gg! X0U'   f = f! X;   a  X	 f f = f7f)a  Temporary swap out an item with a new object.

Usage:
    with swap_item(obj, "item", 5):
        ...

    This will set obj["item"] to 5 for the duration of the with: block,
    restoring the old value at the end of the block. If `item` doesn't
    exist on `obj`, it will be created and then deleted at the end of the
    block.

    The old value (or None if it doesn't exist) will be assigned to the
    target of the "as" clause, if there is one.
Nr]   )r   itemr  r  s       rf   r?   r?     se       {9D		!N ID		{I  !I {I s)   A, 	A5 	A2A
?Ac                  *    SSK n U R                  5       $ )zjReturn a list of command-line arguments reproducing the current
settings in sys.flags and sys.warnoptions.r   N)r   _args_from_interpreter_flagsr   s    rf   args_from_interpreter_flagsr    s     2244re   c                  *    SSK n U R                  5       $ )zcReturn a list of command-line arguments reproducing the current
optimization settings in sys.flags.r   N)r   "_optim_args_from_interpreter_flagsr  s    rf   !optim_args_from_interpreter_flagsr    s     88::re   c                   $    \ rS rSrSrS rS rSrg)rC   i  )rn   messagec                 ~    SnU H4  nX$   nUR                  U5      nU R                  XFU5      (       a  M1  Sn  U$    U$ )a  
Try to match a single dict with the supplied arguments.

Keys whose values are strings and which are in self._partial_matches
will be checked for partial (i.e. substring) matches. You can extend
this scheme to (for example) do regular expression matching, etc.
TF)r  match_value)rq   drM  r   rY  vdvs          rf   matchesMatcher.matches  sN     A	AqB##A1--  re   c                     [        U5      [        U5      :w  a  SnU$ [        U5      [        Ld  XR                  ;  a  X2:H  nU$ UR                  U5      S:  nU$ )zD
Try to match a single stored value (dv) with a supplied value (v).
Fr   )r   r   _partial_matchesfind)rq   rY  r  r  r   s        rf   r  Matcher.match_value  s_     7d2hF
 	 "XS A-B-B$BgF  WWQZ1_Fre   r]   N)r_   r`   ra   rb   r  r  r  rd   r]   re   rf   rC   rC     s    )"
re   rC   c                 
   SSK n[        cP  [        R                  S:X  a:  UR	                  5       S:X  a&  [
        R                  " 5       R                  S:X  a  SqOSq[        (       a  [        R                  " S5      " U 5      $ U $ )	a  
Skip decorator for tests that use buggy strptime/strftime

If the UCRT bugs are present time.localtime().tm_zone will be
an empty string, otherwise we assume the UCRT bugs are fixed

See bpo-37552 [Windows] strptime/strftime return invalid
results with UCRT version 17763.615
r   Nrp  cp65001r6  TFz!buggy MSVC UCRT strptime/strftime)
r8  _buggy_ucrtr   r   getencodingrL  	localtimetm_zoner   r  )r  r8  s     rf   r,   r,     sh     <<7"""$	1 ((B.KKGR{8==<=dC\X\\re   c                   ~    \ rS rSrSrSS jr\R                  S:X  a  S rOS rS r	S	 r
S
 rSS.S jrSS.S jrSrg)PythonSymlinki  z3Creates a symlink for the current Python executableNc                    SSK Jn  U=(       d    [        R                  R	                  U5      U l        / U l        [        R                  R                  [        R                  5      U l
        / U l        S U l        U R                  5         g )Nr   )TESTFN)r  r  r   r   abspathlink_linkedrealpathr   rz  real
_also_link_env_platform_specific)rq   r  r  s      rf   rp   PythonSymlink.__init__  sY    %3BGGOOF3	GG$$S^^4		!re   rp  c           
         SS K nSS Kn[        R                  R	                  U R
                  5      (       aD  [        R                  R                  U R
                  5      (       d  UR                  S5      U l        UR                  [        R                  5      n[        R                  R                  U5      n[        R                  R                  U R                  5      nU R                  R                  U[        R                  R                  U[        R                  R                  U5      5      45        UR                  [        R                  R                  UR!                  U5      S5      5       H[  nU R                  R                  U[        R                  R                  U[        R                  R                  U5      5      45        M]     [        R"                   Vs0 s H'  owR%                  5       [        R&                  " U5      _M)     snU l        [        R                  R                  U R
                  5      U R(                  S'   [*        R,                  " 5       (       a  [.        U R(                  S'   g g s  snf )Nr   zvcruntime*.dll
PYTHONHOME
PYTHONPATH)glob_winapir   r   lexistsr  r  GetModuleFileNamer   	dllhandledirnamer  r  r  r  basenameescaperN  uppergetenvr  r8  is_python_buildr   )rq   r  r  r   src_dirdest_dirruntimerY  s           rf   r   PythonSymlink._platform_specific  s   wwtyy))"''..2K2K $55a8	++CMM:Cggooc*Gwwtyy1HOO""Xrww'7'7'<=$   99RWW\\$++g2FHX%YZ&&GGLL277+;+;G+DE(  [ ;=**E*QBIIaL0*EDI&(ggoodii&@DIIl#((***4		,' + Fs   ).Jc                     g rm   r]   rw   s    rf   r  r        re   c                 2   [         R                  " U R                  U R                  5        U R                  R                  U R                  5        U R                   H6  u  p[         R                  " X5        U R                  R                  U5        M8     U $ rm   )r   symlinkr  r  r  r  r  )rq   r  r  s      rf   	__enter__PythonSymlink.__enter__  sc    


499dii(DII&//JDJJt"LL% * re   c                     U R                    H  n [        R                  " U5        M     g ! [         a6  n[        (       a   [        SR                  XE5      5         S nAMT   S nAMZ  S nAff = f)Nzfailed to clean up {}: {})r  r   removeIOErrorr   r   r   )rq   exc_type	exc_valueexc_tbr  exs         rf   __exit__PythonSymlink.__exit__  sV    LLDH		$ !  H75<<TFGG Hs   ,
A,%A''A,c                 v   SS K nU/UQnUR                  XeR                  UR                  US9nUR                  5       nUR                  U:w  aj  [
        (       a;  [        [        US   5      5        [        [        US   5      [        R                  S9  [        SR                  UR                  5      5      eU$ )Nr   )r   r  rG  r   r  z'unexpected return code: {0} (0x{0:08X}))r   ry  PIPEcommunicate
returncoder   r   reprr   r  RuntimeErrorr   )	rq   pythonrr   rG  r$  r   cmdprv  s	            rf   _callPythonSymlink._call%  s    ooS$.OO  >MMO<<:%wd1Q4j!d1Q4jszz29@@NP Pre   r   )r$  c                >    U R                  U R                  US U5      $ rm   )r*  r  rq   r$  rr   s      rf   	call_realPythonSymlink.call_real3  s    zz$))T4<<re   c                P    U R                  U R                  X R                  U5      $ rm   )r*  r  r  r-  s      rf   	call_linkPythonSymlink.call_link6  s    zz$))T99jAAre   )r  r  r  r  r  rm   )r_   r`   ra   rb   rc   rp   r   r   r  r  r  r*  r.  r1  rd   r]   re   rf   r  r    sM    =
" ||w	56	H +, = +, B Bre   r  c                     [         (       + =(       d    [        nSnU(       a  U $ [        R                  " U5      " U 5      $ )z;Skip decorator for tests not run in (non-extended) PGO taskz#Not run for (non-extended) PGO task)rH   PGO_EXTENDEDr   r  )r  okrn   s      rf   skip_if_pgo_taskr6  :  s.    	 LB
/C438==-d33re   r]   )ignorec                    [        [        U 5      5      [        [        U5      5      -
  nU(       a  U[        U5      -  n[        S U 5       5      nU$ )zReturns the set of items in ref_api not in other_api, except for a
defined list of items to be ignored in this check.

By default this skips private attributes beginning with '_' but
includes all magic methods, i.e. those starting and ending in '__'.
c              3      #    U  H5  nUR                  S 5      (       a  UR                  S5      (       d  M1  Uv   M7     g7f)r  __N)r   endswith)r  rZ  s     rf   r  &detect_api_mismatch.<locals>.<genexpr>K  s2      F=a ||C00AJJt4D =s   0?	?)setdir)ref_api	other_apir7  missing_itemss       rf   r*   r*   A  sP     G%C	N(;;MV$ F= F FMre   c                    Uc  UR                   4nO[        U[        5      (       a  U4n[        U5      n[	        U5       H  nUR                  S5      (       d  Xd;   a  M   [        X5      n[        USS5      U;   d4  [        US5      (       a  MO  [        U[        R                  5      (       a  Mp  UR                  U5        M     U R                  UR                  U5        g)a  Assert that the __all__ variable of 'module' contains all public names.

The module's public names (its API) are detected automatically based on
whether they match the public name convention and were defined in
'module'.

The 'name_of_module' argument can specify (as a string or tuple thereof)
what module(s) an API could be defined in in order to be detected as a
public API. One case for this is when 'module' imports part of its public
API from other modules, possibly a C backend (like 'csv' and its '_csv').

The 'extra' argument can be a set of names that wouldn't otherwise be
automatically detected as "public", like objects without a proper
'__module__' attribute. If provided, it will be added to the
automatically detected ones.

The 'not_exported' argument can be a set of names that must not be treated
as part of the public API even though their names indicate otherwise.

Usage:
    import bar
    import foo
    import unittest
    from test import support

    class MiscTestCase(unittest.TestCase):
        def test__all__(self):
            support.check__all__(self, foo)

    class OtherTestCase(unittest.TestCase):
        def test__all__(self):
            extra = {'BAR_CONST', 'FOO_CONST'}
            not_exported = {'baz'}  # Undocumented name.
            # bar imports part of its API from _bar.
            support.check__all__(self, bar, ('bar', '_bar'),
                                 extra=extra, not_exported=not_exported)

Nr  r`   )r_   r2  r   r=  r>  r   r   r   types
ModuleTypeaddassertCountEqual__all__)r  r|  name_of_moduleextranot_exportedexpectedr   r   s           rf   r+   r+   P  s    R  //,	NC	(	((+5zHF??34#7f#Ct,>S,//U%5%566LL  v~~x8re   c                     SS K nUR                  UR                  UR                  -  UR
                  -  UR                  -  5        [        US5      (       a|  UR                  UR                  UR                  4 HT  nU (       a8  UR                  X!R                  5        UR                  X!R                  5        MB  UR                  US5        MV     g g ! [         a     g f = f)Nr   CrtSetReportMode)msvcrtrW  SetErrorModeSEM_FAILCRITICALERRORSSEM_NOALIGNMENTFAULTEXCEPTSEM_NOGPFAULTERRORBOXSEM_NOOPENFILEERRORBOXr   CRT_WARN	CRT_ERROR
CRT_ASSERTrM  CRTDBG_MODE_FILECrtSetReportFileCRTDBG_FILE_STDERR)r   rN  rZ  s      rf   suppress_msvcrt_assertsrZ    s     55 ;;< 667 !778 9 v)**//6#3#3V5F5FGA''+B+BC''+D+DE''1- H +  s   C 
C#"C#c                   ,    \ rS rSrSrSrSrS rS rSr	g)rE   i  zTry to prevent a crash report from popping up.

On Windows, don't display the Windows Error Reporting dialog.  On UNIX,
disable the creation of coredump file.
Nc                    [         R                  R                  S5      (       a   SSKnUR                  5       U l        UR                  U R                  UR                  -  5        [        US5      (       ay  0 U l
        UR                  UR                  UR                  4 HK  nUR                  UUR                  5      nUR!                  UUR"                  5      nX44U R                  U'   MM     U $  SSKnXPl        U R$                  bt   U R$                  R'                  U R$                  R(                  5      U l        U R$                  R+                  U R$                  R(                  SU R                  S   45        [         R                  S:X  aj  SSKn/ SQnUR3                  UUR4                  UR4                  S9nU   UR7                  5       S   n	SSS5        W	R9                  5       S	:X  a  [;        S
SSS9  U $ ! [         a     gf = f! [         a    SU l         GN%f = f! [,        [.        4 a     Nf = f! , (       d  f       Nm= f)zOn Windows, disable Windows Error Reporting dialogs using
SetErrorMode() and CrtSetReportMode().

On UNIX, try to save the previous core file size limit, then set
soft limit to 0.
r   r   NrM  r   r   )z/usr/bin/defaultsr  zcom.apple.CrashReporter
DialogType)r   r  s	   developerz:this test triggers the Crash Reporter, that is intentionalr6  T)endrx  )r   r   r   rN  rW  GetErrorMode	old_valuerO  rR  r   	old_modesrT  rU  rV  rM  rW  rX  rY  r   	getrlimitRLIMIT_CORE	setrlimitr  r   r   ry  r"  r#  r   r   )
rq   rN  report_typeold_modeold_filer   r   r(  procr   s
             rf   r  SuppressCrashReport.__enter__  s    <<""5)) $002DN1M1M MN v122!#$*OO$*$4$4$*$5$5$7K  &66{"33 5H%66{"55 7H2:2DDNN;/$7T A% ( }}(%)]]%<%<T]]=V=V%WDNMM++DMM,E,E-.q0A,BD
 ||x'!@!''/9/9 ( @ !--/2F <<>\1 057tE k  0  % $% #G,   TsB   G? 4
H A3H' H=?
HHH$#H$'H:9H:=
Ic                    U R                   c  g[        R                  R                  S5      (       az  SSKnUR                  U R                   5        U R                  (       aI  U R                  R                  5        H*  u  nu  pEUR                  X45        UR                  X55        M,     ggU R                  b<   U R                  R                  U R                  R                  U R                   5        gg! [        [        4 a     gf = f)zARestore Windows ErrorMode or core file behavior to initial value.Nr   r   )r`  r   r   r   rN  rO  ra  r  rM  rX  r   rd  rc  r  r   )rq   
ignore_excrN  re  rf  rg  s         rf   r  SuppressCrashReport.__exit__  s    >>!<<""5))/~~9=9M9M9O5K!5(++KB++KB :P 
 }}(MM++DMM,E,Et~~V ) #G, s   ;:C7 7D
	D
)ra  r`  r   )
r_   r`   ra   rb   rc   r`  ra  r  r  rd   r]   re   rf   rE   rE     s    
 II@Dre   rE   c                    ^^^^ [        TT5        Sm TR                  T   mSmUUUU4S jnU R	                  U5        [        TTU5        g! [        [        4 a    [        TTS5      m NGf = f)zOverride 'object_to_patch'.'attr_name' with 'new_value'.

Also, add a cleanup procedure to 'test_instance' to restore
'object_to_patch' value for 'attr_name'.
The 'attr_name' should be a valid attribute for 'object_to_patch'.

FTNc                  H   > T (       a  [        TTT5        g [        TT5        g rm   )r  r  )attr_is_local	attr_nameobject_to_patchr`  s   rf   cleanuppatch.<locals>.cleanup  s    OY	:OY/re   )r   __dict__r   r)  
addCleanupr  )test_instancerq  rp  	new_valuerr  ro  r`  s    ``  @@rf   patchrx     s~     OY' M#,,Y7	 0 0 W% OY	2 H% >OY=	>s   A A-,A-c              #   <   #     U SS nSv   XSS& g! WU SS& f = f7f)z-Like unittest.mock.patch.dict, but for lists.Nr]   )origsaveds     rf   
patch_listr|  "  s&     QQ%Qs   	 c                     [        5          SSKnUR                  U 5      $ ! [         a    [        R                  " S5      ef = f)]
Run code in a subinterpreter. Raise unittest.SkipTest if the tracemalloc
module is enabled.
r   Nrequires _testcapi)_check_tracemallocr  rW  r   r   run_in_subinterp)r  r  s     rf   r  r  ,  sH    
 6 %%d++  6 4556s	   ! !A)own_gilc                   [        5          SSKnUb  SU;  d   X45       eU(       a  SOSUS'   OIUS   nUS:X  a  SUS'   O8US:X  a  SUS'   O,US	:X  a  SUS'   O [        U[        5      (       d  [        U5      e[        R                  " S
0 UD6nUR                  X5      $ ! [         a    [        R                  " S5      ef = f)r~  r   Nzrequires _testinternalcapigilownsharedr  r   r   r]   )r  rd  rW  r   r   r2  r   NotImplementedErrorrC  SimpleNamespacerun_in_subinterp_with_config)r  r  rf  rd  r  s        rf   r  r  9  s    
 >  F"5W$55"!(huUm!8%F5MAX$F5MAX!F5MC%%%c**"",V,F99$GG!  > <==>s   B   !Cc                       SS K n U R                  5       (       a  [        R                  " S5      eg ! [         a     g f = f)Nr   zUrun_in_subinterp() cannot be used if tracemalloc module is tracing memory allocations)tracemalloc
is_tracingr   r   rW  )r  s    rf   r  r  T  sL    ; !!#### %: ; ; $  s   2 
??c                 j   ^ ^^^^ SmUUUUU 4S jnU" 5         [        5         T R                  T5        g )NFc                  r   >^  " UU4S jST5      n T" U " T6 5      mTR                  [        [        T5        g )Nc                   $   > \ rS rSrU U4S jrSrg)6check_free_after_iterating.<locals>.wrapper.<locals>.Aie  c                 B   > Sm [        T5        g ! [         a     g f = fNT)nextStopIteration)rq   doneits    rf   __del__>check_free_after_iterating.<locals>.wrapper.<locals>.A.__del__f  s&    H$ s    
r]   N)r_   r`   ra   rb   r  rd   )r  r  s   rf   Ar  e  s     re   r  )assertRaisesr  r  )r  r  rr   clsr  iterr  s    @rf   r  +check_free_after_iterating.<locals>.wrapperd  s5    	 	 	 !T(^-r2re   )r  
assertTrue)r  r  r  rr   r  r  s   ```` @rf   check_free_after_iteratingr  b  s*    D3 3 ILOODre   c                    SSK JnJn  SSKJn  SSKnUR                  5       nUR                  " U5        UR                  S:X  a   UR                  5         UR                   HV  nU (       a  X`;  a  M  [        XV5      nU (       a  Uc
   SU-  5       eO	U(       d  M:  UR                  US   5      b  MQ  US   s  $    g! UR                   a     gf = f)a(  Check if the compiler components used to build the interpreter exist.

Check for the existence of the compiler executables whose names are listed
in 'cmd_names' or all the compiler executables when 'cmd_names' is empty
and return the first missing executable or None when none is found
missing.

r   )	ccompilerr8  )r   Nmsvcz%the '%s' executable is not configured)setuptools._distutilsr  r8  
setuptoolsr   r  new_compilercustomize_compilercompiler_type
initializePlatformErrorexecutablesr   which)	cmd_namesr  r8  r   r  compilerr   r(  s           rf   rI   rI   x  s     ;!%%'H  *'	! $$.h%? C;dBC?<<A'q6M % ## 		s   B= =CCc                     Sn[         (       aO  X:  aJ  [        c6  SS KnUR                  5       nUR                  =(       a    UR
                  S:  q[        (       a  Un [        R                  " U 5      $ )Ng-C6?r      )r4   _old_android_emulatorr   android_veris_emulator	api_levelr   r:   )intervalminimum_intervalr   avs       rf   r:   r:     s_     zh1 (%%'B$&NN$Hr||b7H!  'H  **re   c                       [         R                  " S5      n U $ ! [        [        4 a5     [         R                  " S5      n  U $ ! [        [        4 a    Sn   U $ f = ff = f)zGet size of a page in bytes.SC_PAGESIZESC_PAGE_SIZEi   )r   sysconfr  r   )	page_sizes    rf   r;   r;     so    JJ}-	  ' 	

>2I  N+ 	I	s&    AAAAAAc               #     #    SS K n [        R                  R                  5       nU R	                  5       n U R                  5         S v   U(       a  U R                  USS9  g g ! U(       a  U R                  USS9  f f = f7f)Nr   T)r  all_threads)faulthandlerr   
__stderr__fileno
is_enabledr  r  )r  fdr  s      rf   disable_faulthandlerr    st     
 
			 B((*J;RT: :RT: s   3B A# 
B #A==B c                   *    \ rS rSrSrS rS rS rSrg)SaveSignalsi  z
Save and restore signal handlers.

This class is only able to save/restore signal handlers registered
by the Python signal module: see bpo-13285 for "external" signal
handlers.
c                     SS K nXl         UR                  5       U l        S H*  n [        X5      nU R                  R                  U5        M,     0 U l        g ! [         a     MC  f = f)Nr   )SIGKILLSIGSTOP)signalvalid_signalssignalsr   r   r  handlers)rq   r  signamesignums       rf   rp   SaveSignals.__init__  sd    ++--G 1 LL' .  " s   A
A&%A&c                     U R                    H1  nU R                  R                  U5      nUc  M#  X R                  U'   M3     g rm   )r  r  	getsignalr  rq   r  handlers      rf   saveSaveSignals.save  s:    llFkk++F3G $+MM&! #re   c                     U R                   R                  5        H   u  pU R                  R                  X5        M"     g rm   )r  r  r  r  s      rf   restoreSaveSignals.restore  s-    #}}224OFKKv/  5re   )r  r  r  N)	r_   r`   ra   rb   rc   rp   r  r  rd   r]   re   rf   r  r    s    
,0re   r  c                       SS K n U R                  =(       a    [
        (       + $ ! [         a    [        R                  " S5      ef = fNr   r  )r  rW  r   r   WITH_PYMALLOCr  r  s    rf   with_pymallocr    sC    6 "":?'::  6 4556s	   $ !Ac                  l     SS K n U R                  $ ! [         a    [        R                  " S5      ef = fr  )r  rW  r   r   WITH_MIMALLOCr  s    rf   with_mimallocr    s;    6 """  6 4556s    !3c                   $    \ rS rSrSrS rS rSrg)
_ALWAYS_EQi  z#
Object that is equal to anything.
c                     gr  r]   rq   others     rf   __eq___ALWAYS_EQ.__eq__      re   c                     gNFr]   r  s     rf   __ne___ALWAYS_EQ.__ne__      re   r]   N)r_   r`   ra   rb   rc   r  r  rd   r]   re   rf   r  r    s    re   r  c                   *    \ rS rSrSrS rS rS rSrg)	_NEVER_EQi
  z'
Object that is not equal to anything.
c                     gr  r]   r  s     rf   r  _NEVER_EQ.__eq__  r  re   c                     gr  r]   r  s     rf   r  _NEVER_EQ.__ne__  r  re   c                     g)Nr   r]   rw   s    rf   __hash___NEVER_EQ.__hash__  s    re   r]   N)	r_   r`   ra   rb   rc   r  r  r  rd   r]   re   rf   r  r  
  s    re   r  c                   $    \ rS rSrSrS rS rSrg)_LARGESTi  z7
Object that is greater than anything (except itself).
c                 "    [        U[        5      $ rm   )r2  r  r  s     rf   r  _LARGEST.__eq__  s    %**re   c                     gr  r]   r  s     rf   __lt___LARGEST.__lt__  r  re   r]   N)r_   r`   ra   rb   rc   r  r  rd   r]   re   rf   r  r    s    +re   r  c                   $    \ rS rSrSrS rS rSrg)	_SMALLESTi#  z4
Object that is less than anything (except itself).
c                 "    [        U[        5      $ rm   )r2  r  r  s     rf   r  _SMALLEST.__eq__(  s    %++re   c                     gr  r]   r  s     rf   __gt___SMALLEST.__gt__*  r  re   r]   N)r_   r`   ra   rb   rc   r  r  rd   r]   re   rf   r  r  #  s    ,re   r  c                  6    SSK n U R                  R                  $ )zDReturn the global event loop policy if one is set, else return None.r   N)asyncio.eventsevents_event_loop_policy)asyncios    rf   maybe_get_event_loop_policyr
  /  s    >>,,,re   )    @   c                 |   Xp2SS K nUR                  5        nUR                  5       S-  n[        US5      Ul        UR                  U5      nUS-
  U-  U-  nX(-  n	X)-
  n
X:-
  nXwS-
  -  US-
  U-  U-  -  U	SU	-
  -  -   n[        U5      [        UR                  5       5      4sS S S 5        $ ! , (       d  f       g = f)Nr   r      r   )decimallocalcontext
bit_lengthmaxprecDecimalrc  sqrt)nbinsnballsr  rY  r  ctxbitsr  p1empty	meanemptyoccupied
collisionsvars                rf   collision_statsr  <  s    q$ 				3||~! tR=__QFb=Q&K	=\
Q$i"Q$Q&a)m)DDZ %
"33 
 		s   BB--
B;c                   0    \ rS rSrSrS rS rS rS rSr	g)	catch_unraisable_exceptioni^  a  
Context manager catching unraisable exception using sys.unraisablehook.

Storing the exception value (cm.unraisable.exc_value) creates a reference
cycle. The reference cycle is broken explicitly when the context manager
exits.

Storing the object (cm.unraisable.object) can resurrect it if it is set to
an object which is being finalized. Exiting the context manager clears the
stored object.

Usage:

    with support.catch_unraisable_exception() as cm:
        # code creating an "unraisable exception"
        ...

        # check the unraisable exception: use cm.unraisable
        ...

    # cm.unraisable attribute no longer exists at this point
    # (to break a reference cycle)
c                      S U l         S U l        g rm   )
unraisable	_old_hookrw   s    rf   rp   #catch_unraisable_exception.__init__w  s    re   c                     Xl         g rm   )r#  )rq   r#  s     rf   _hook catch_unraisable_exception._hook{  s	     %re   c                 Z    [         R                  U l        U R                  [         l        U $ rm   )r   unraisablehookr$  r'  rw   s    rf   r  $catch_unraisable_exception.__enter__  s     ++!ZZre   c                 2    U R                   [        l        U ?g rm   )r$  r   r*  r#  )rq   r%  s     rf   r  #catch_unraisable_exception.__exit__  s    !^^Ore   )r$  r#  N)
r_   r`   ra   rb   rc   rp   r'  r  r  rd   r]   re   rf   r!  r!  ^  s    0%

re   r!  r  c          	         [         R                  S:w  a  SSKnUc  [        n[        R
                  " 5       n[        USS9 H2  n[         R                  " U [         R                  5      u  pgUS:w  d  M2    O~    [         R                  " XR                  5        [         R                  " U S5        [        R
                  " 5       U-
  n[        SU  SUS S	35      e[         R                  " U S5      u  pg[         R                  " U5      n	X:w  a  [        SU  S
U	 SU S35      eX`:w  a  [        SU SU  35      eg! [         a     Nf = f)al  
Wait until process pid completes and check that the process exit code is
exitcode.

Raise an AssertionError if the process exit code is not equal to exitcode.

If the process runs longer than timeout seconds (LONG_TIMEOUT by default),
kill the process (if signal.SIGKILL is available) and raise an
AssertionError. The timeout feature is not available on Windows.
ntr   NFerrorzprocess z is still running after .1fz secondsz exited with code z, but exit code z is expectedzpid z != pid )r   r   r  rQ   rL  	monotonicsleeping_retryr  r  killr  r   AssertionErrorwaitstatus_to_exitcode)
rp  exitcoder  r  
start_timer  pid2r  dt	exitcode2s
             rf   wait_processr=    sF    
ww$?"G^^%
u5A::c2::6LDqy 6^^,

3"
 !J.B 8C5 1**,S"; < < zz#q)))&1Ixu,>yk J..6Z|E F 	F {tD6#788 #  s   87D: :
EEc                      SSK Jn   U " S5        U " S5      n[        R                  S:X  a   UR	                  SS9  gg! [
         a  n[        R                  " SU< 35      eSnAff = f)	z
Skip tests if the multiprocessing.synchronize module is missing, if there
is no available semaphore implementation, or if creating a lock raises an
OSError (on Linux only).
r   )import_module_multiprocessingzmultiprocessing.synchronizelinuxN)r  z broken multiprocessing SemLock: )import_helperr?  r   r   Lockr   r   r   )r?  synchronizeexcs      rf   *skip_if_broken_multiprocessing_synchronizerF    sv     - $%   =>K
||w	P &   	P##&Fsg$NOO	Ps   = 
A&A!!A&c                     UR                   nUR                  nUS:w  a  U SU 3nOU nS[        R                  " U5       S3nU R                  " [
        Xq/UQ70 UD6  g)z
Check that given type cannot be instantiated using *args and **kwds.

See bpo-43916: Add Py_TPFLAGS_DISALLOW_INSTANTIATION type flag.
builtinsr   zcannot create 'z' instancesN)r`   r_   r_  r
  r  r3  )r  tprr   rO  modr   qualnamern   s           rf   r-   r-     sf     --C;;D
jU!D6?VBIIh/0
<Cy#ADADAre   c                       SSK n U R                  5       n[        US-
  S5      $ ! [        [        4 aD  n Sn[        R
                  " 5       nUb  US-  nUR                  nUb  M  Sn SnANW! Snf = fSnAff = f)znGet the recursion depth of the caller function.

In the __main__ module, at the module level, it should be 1.
r   Nr   )rd  get_recursion_depthrW  RecursionErrorr   	_getframef_backr  )rd  depthrE  frames       rf   rM  rM    s    
 !557 uqy! ( 
	EMMOE#
 #
 EDE
s&   % A9.A-&A4-A11A44A9c                  H    [         R                  " 5       n [        5       nX-
  $ )zGet the number of available frames before RecursionError.

It depends on the current recursion depth of the caller function and
sys.getrecursionlimit().
)r   getrecursionlimitrM  )rW  rQ  s     rf   get_recursion_availablerU    s"     !!#E!E=re   c              #      #    [         R                  " 5       n [         R                  " U 5        Sv   [         R                  " U5        g! [         R                  " U5        f = f7f)z'Temporarily change the recursion limit.N)r   rT  setrecursionlimit)rW  original_limits     rf   set_recursion_limitrY  	  sG      **,N.e$n-n-   A%A
 A%
A""A%c                     U c  Sn OU S:  a  [        SU  35      e[        5       n[        US-
  S5      nX-   n[        U5      $ )Ni N     z"max_depth must be at least 3, got r   )r  rM  r  rY  )	max_depthrQ  rW  s      rf   rA   rA   	  sT     		Q=i[IJJ!E	1EEu%%re   r|  likec          
      p    [        5       n[        R                  " S[        U US[	        U5       S3-   S9  U$ )Nr7  
(?#support))r<  r|  r  )objectrw  filterwarningsDeprecationWarningid)r|  r^  tokens      rf   ignore_deprecations_fromrg  	  s<    HE#*RYKq11	 Lre   tokensc                     U (       d  [        S5      e/ n[        S U  5       5      n[        R                   Hy  u  p4pVnUS:X  aX  U[        L aO  [        U[        R                  5      (       a  UR                  nOU=(       d    SnUR                  U5      (       a  Me  UR                  X4XVU45        M{     [        R                  U:w  a)  U[        R                  S S & [        R                  " 5         g g )Nz<Provide token or tokens returned by ignore_deprecations_fromc              3   @   #    U  H  nS [        U5       S3v   M     g7f)r`  ra  N)re  )r  rf  s     rf   r  -clear_ignored_deprecations.<locals>.<genexpr>(	  s     DVE
2e9+Q/Vs   r7  r6  )r  r  rw  filtersrd  r2  r_  Patternr   r;  r  _filters_mutated)	rh  new_filtersr;  actionr  r<  r|  r  rn   s	            rf   clear_ignored_deprecationsrq  #	  s    WXXKDVDDH5=5E5E16X(.@"@'2::..oom||H%%FXvFG 6F ;&)!!# 're   c                       SS K n  SS Kn[        R
                  " US5      $ ! [         a    [        R                  " SS5      s $ f = f! [         a    S n NLf = f)Nr   Tzvenv: ensurepip requires zlibzvenv: pip requires ctypes)rV  rW  r   r	  r   rX  )rV  r   s     rf   requires_venv_with_piprs  8	  sc    F v'BCC  Ft%DEEF  s    " A	 !AA	AAc                    [         R                  " S5      =(       d$    [        R                  R	                  [
        S5      n[        R                  " U5      n[        USS9nU HW  nUR                  S5      (       d  M  U S-   nUR                  U5      (       d  M8  [        R                  R	                  X5      s  $    [        SU  SU 35      e)	zTry to find a wheel with the package specified as pkgname.

If set, the wheels are searched for in WHEEL_PKG_DIR (see ensurepip).
Otherwise, they are searched for in the test directory.
WHEEL_PKG_DIR	wheeldataT)reversez.whlr   zNo wheel for z
 found in )r8  r9  r   r   r  r  listdirr  r;  r   r   )pkgname	wheel_dir	filenamesr  prefixs        rf   
_findwheelr}  H	  s     ((9 RWW\\{>I 

9%Iy$/I  ((3v&&77<<	44  mG9JykJ
KKre   c           
   #   .  ^#    SS K mSSKJn  U4S jnU" 5        n[        R                  SSSSU /nU" U5        [
        R                  R                  X05      n[
        R                  R                  [        R                  5      n[        R                  S	:X  a"  [
        R                  R                  US
U5      nO![
        R                  R                  USU5      nUSSSSS[        S5      4nU" U5        Uv   S S S 5        g ! , (       d  f       g = f7f)Nr   r   )temp_cwdc           	        > [         (       aN  SS Kn[        5         [        SSR                  [	        UR
                  U 5      5      5        TR                  U SS9  g TR                  U TR                  TR                  SS9  g )Nr   zRun:r&  T)r   )r   r  r   )	r   shlexr   r  r  quoter   r"  STDOUT)r(  r  r   s     rf   run_command3setup_venv_with_pip_setuptools.<locals>.run_commande	  sd    7G&#((3u{{C#89:NN3dN+NN3",//","3"3!%  're   z-Xdevz-mvenvrp  Scriptsbinpipinstallr  )r   r  r  r   rz  r   r   r  r	  r   r}  )	venv_dirr  r  temp_dirr(  r  
python_exer'  r   s	           @rf   setup_venv_with_pip_setuptoolsr  `	  s     #
' 
x~~tUD&(CCww||H/ WW%%cnn5
<<7"WW\\$	:>FWW\\$z:FtUUI,' 	C) 
s   DC D;	D
DDgettotalrefcountc                     U /nUR                  U5        SSKnS nXl        UR                  U5        [	        [
        S5      (       a  S nXl        [
        R                  " US9  gg)aR  
Keep a Python alive as long as possible.

Create a reference cycle and store the cycle in an object deleted late in
Python finalization. Try to keep the object alive until the very last
garbage collection.

The function keeps a strong reference by design. It should be called in a
subprocess to not mark a test as "leaking a reference".
r   Nc                     g rm   r]   )encodings    rf   search_func"late_deletion.<locals>.search_func	  r  re   register_at_forkc                      g rm   r]   r]   re   rf   atfork_func"late_deletion.<locals>.atfork_func	  r  re   )before)r  codecs	referenceregisterr   r   r  )r   	ref_cycler  r  r  s        rf   late_deletionr  	  sa    & IY %
OOK r%&&	 )
;/ 're   r0  c            #      #    U S::  a  [        S5      e[        R                  " 5       nX0-   n Sv   [        R                  " 5       U:  a  OM   U(       a8  [        R                  " 5       U-
  nSUS S3nU(       a  U SU 3n[        U5      eg7f)a  
Run the loop body until "break" stops the loop.

After *timeout* seconds, raise an AssertionError if *error* is true,
or just stop if *error is false.

Example:

    for _ in support.busy_retry(support.SHORT_TIMEOUT):
        if check():
            break

Example of error=False usage:

    for _ in support.busy_retry(support.SHORT_TIMEOUT, error=False):
        if check():
            break
    else:
        raise RuntimeError('my custom error')

r   z!timeout must be greater than zeroNz	timeout (r2  z	 seconds)r   )r  rL  r3  r6  )r  err_msgr1  r9  deadliner;  rn   s          rf   
busy_retryr  	  s     , !|<==!J#H
>>x'	  ^^
*"S+EG9%CS!! s   BBg{Gz?g      ?)
init_delay	max_delayr1  c            #      #    Un[        XUS9 H,  nSv   [        R                  " U5        [        US-  U5      nM.     g7f)a  
Wait strategy that applies exponential backoff.

Run the loop body until "break" stops the loop. Sleep at each loop
iteration, but not at the first iteration. The sleep delay is doubled at
each iteration (up to *max_delay* seconds).

See busy_retry() documentation for the parameters usage.

Example raising an exception after SHORT_TIMEOUT seconds:

    for _ in support.sleeping_retry(support.SHORT_TIMEOUT):
        if check():
            break

Example of error=False usage:

    for _ in support.sleeping_retry(support.SHORT_TIMEOUT, error=False):
        if check():
            break
    else:
        raise RuntimeError('my custom error')
r0  Nr   )r  rL  sleeprj  )r  r  r  r  r1  delayr  s          rf   r4  r4  	  s<     4 E6

5EAIy)	 7s   >A c                   $    \ rS rSrSrS rS rSrg)CPUStopwatchi	  a  Context manager to roughly time a CPU-bound operation.

Disables GC. Uses CPU time if it can (i.e. excludes sleeps & time of
other processes).

N.B.:
- This *includes* time spent in other threads.
- Some systems only have a coarse resolution; check
  stopwatch.clock_info.rseolution if.

Usage:

with ProcessStopwatch() as stopwatch:
    ...
elapsed = stopwatch.seconds
resolution = stopwatch.clock_info.resolution
c                 6   [         R                  n[         R                  " S5      nU" 5       S::  a&  [         R                  n[         R                  " S5      n[	        5       U l        U R
                  R                  5         Xl        X l        U" 5       U l	        U $ )Nprocess_timer   r3  )
rL  r  get_clock_infor3  r  contextr  get_time
clock_infor9  )rq   r  r  s      rf   r  CPUStopwatch.__enter__
  sp    $$((8
:?~~H,,[9J!|  $"*re   c                      U R                  5       nU R                  R                  " U6 nX R                  -
  U l        U$ ! U R                  R                  " U6 nf = frm   )r  r  r  r9  seconds)rq   rE  end_timer   s       rf   r  CPUStopwatch.__exit__
  sQ    	1}}H\\**C0F//1 \\**C0Fs   A   A)r  r  r  r  r9  N)r_   r`   ra   rb   rc   r  r  rd   r]   re   rf   r  r  	  s    "re   r  c              #      #    [         R                  " 5       n [         R                  " U 5        Sv   [         R                  " U5        g! [         R                  " U5        f = f7f)z>Temporarily change the integer string conversion length limit.N)r   get_int_max_str_digitsset_int_max_str_digits)
max_digitscurrents     rf   adjust_int_max_str_digitsr  &
  sG      ((*G,"":.""7+""7+rZ  c                  l     SS K n U R                  $ ! [         a    [        R                  " S5      ef = fr  )r  Py_C_RECURSION_LIMITrW  r   r   r  s    rf   rT   rT   1
  s7    6--- 6 4556s    !3c                      [        5       S-  $ )z<For recursion tests, easily exceeds default recursion limit.r\  )rT   r]   re   rf   rS   rS   9
  s     "Q&&re   unames390xzskipped on s390x
getobjectsc                    ^ ^^  SSK JmJm  [        R
                  " T 5      U UU4S j5       nU$ ! [         a    T s $ f = f)Nr   )get_optimizerset_optimizerc                  ^   > T" 5       n T" S 5        T" U 0 UD6T" U5        $ ! T" U5        f = frm   r]   )rr   rM  save_optr   r  r  s      rf   r  "without_optimizer.<locals>.wrapperJ
  s5     ?	$$(((#M(#s   " 
,)rd  r  r  rW  r  r  )r   r  r  r  s   ` @@rf   rV   rV   E
  sE    B __T$ $ N  s   0 ??z.git__pycache__c                     [         n[        R                  R                  U 5      S:X  a	  USS1-  nU$ SU;   a  US1-  nU$ )NDocbuildr  Modules) _BASE_COPY_SRC_DIR_IGNORED_NAMESr   r   r	  )r   namesignoreds      rf   copy_python_src_ignorer  ]
  s]    .G	ww&	
 	
 N 
e	
 	
 Nre   c               #      #    [         R                  5        H2  n [        U [        5      (       d  M  U nUR                  S:w  a  M.  Uv   M4     g 7f)NrH  )__builtins__r,  r2  r   r`   )r   r  s     rf   iter_builtin_typesr  p
  sA     ""$#t$$>>Z'	 %s   AAc              #     ^ #    T R                   S:X  d   T 5       eU 4S jn[        T 5      n[        U5      n[        T 5       H  nXB;   a  UR	                  U5         [        T U5      nUR                  S5      (       a  UR                  S5      (       d  U" XE5      (       a	   T XE45       eU" XE5      (       d%  XB;   a  U" XBU   5      (       a   T XEX$   45       eM  M  XB;   a  X$   UL d   T XEX$   45       eUS4v   M  US4v   M     U H  nX$   nU" T XE5      (       d  M  US4v   M     g ! [         a:    US;   d	   T U45       eXB;   a!  U" XBU   5      (       a  UR                  U5         GM+  f = f7f)NrH  c                   > [        U[        R                  5      (       d)  [        U5      R	                  S5      (       a	   TX45       eg[        U5      R	                  S5      (       d	   TX45       e[        U5      (       d	   TX45       eU R	                  S5      (       a  U R                  S5      (       d	   TX45       eg)Nz<slot wrapper Fr:  T)r2  rC  WrapperDescriptorTyper%  r   callabler;  )r   valuer  s     rf   is_slot_wrapper+iter_slot_wrappers.<locals>.is_slot_wrapper}
  s    %!<!<==E{--.>??S#tASS?E{%%&677K#t9KK72d 22t$$t)<)<PsD>PP<re   )__annotate____annotations____abstractmethods__r:  TF)
r`   varsr=  r>  r  r   r   rE  r   r;  )r  r  r  unusedr   r  s   `     rf   iter_slot_wrappersr  z
  s    >>Z',,' 
cBWFC:MM$	C&E t$$DMM$,?,?&t33Gc45GG3t++z*4D::XS$rx<XX::  zx5(F3RX*FF(Dj Ek!/ 2 3,,* '  	UUbX[]aWbbUzodtH==

4 	s1   AE1D*(B3E1E1*?E.)E1-E..E1c               #     #    SS K n SSKJn  [        U SS
S j5         U" 5        nUR	                  SSS5        UR                  SS	5        S v   S S S 5        S S S 5        g ! , (       d  f       N= f! , (       d  f       g = f7f)Nr   r   )EnvironmentVarGuardcan_colorizec                     gr  r]   r  s    rf   r   no_color.<locals>.<lambda>
  s    ure   FORCE_COLORNO_COLORPYTHON_COLORS1rm   )	_colorizer  r  rB   unsetr=  )r  r  rG  s      rf   no_colorr  
  sa     . 	)^-DE		-_=
C 	 	 	FE 	FEs3   BA1*A A1	B 
A.	*A11
A?;Bc                 F   ^  [         R                  " T 5      U 4S j5       nU$ )z'Force the terminal not to be colorized.c                  ^   > [        5          T" U 0 UD6sS S S 5        $ ! , (       d  f       g = frm   )r  )rr   rM  r   s     rf   r  $force_not_colorized.<locals>.wrapper
  s    Z(( ZZs   
,rP  )r   r  s   ` rf   rW   rW   
  s%    __T) ) Nre   c                    ^ U R                   m[        [        R                  " U R                   5      U4S j5       5       nXl         U $ )zAForce the terminal not to be colorized for the entire test class.c                 F   > U R                  [        5       5        T" 5         g rm   )enterClassContextr  )r  original_setUpClasss    rf   new_setUpClass6force_not_colorized_test_class.<locals>.new_setUpClass
  s     	hj)re   )
setUpClassclassmethodr  r  )r  r  r  s     @rf   rX   rX   
  s@    ..__S^^$ %  $NJre   c                  
   [         R                  R                  5       n U R                  5        H,  nUR                  S5      (       d  M  U R	                  U5        M.     U R	                  SS 5        U R	                  SS 5        U $ )NPYTHONr  r  )r   rN  copyr   r  )	clean_envrY  s     rf   rY   rY   
  sb    

!I^^<<!!MM!  MM-&MM*d#re   c                  <    [        [        R                  S   S5      $ )z<Detect whether PyREPL was used during Python initialization.__main____file__)r   r   r  r]   re   rf   initialized_with_pyreplr  
  s     3;;z*J77re   c                   *    \ rS rSrSS jrS rS rSrg)rZ   i
  c                 4    U(       a  SS-    X l         X0l        g Nr   r   )next_raisesiter_raises)rq   init_raisesr  r  s       rf   rp   BrokenIter.__init__
  s    aC&&re   c                 2    U R                   (       a  SS-    g g r  )r  rw   s    rf   __next__BrokenIter.__next__
  s    aC re   c                 2    U R                   (       a  SS-    U $ r  )r  rw   s    rf   __iter__BrokenIter.__iter__
  s    aCre   )r  r  N)FFF)r_   r`   ra   rb   rp   r  r  rd   r]   re   rf   rZ   rZ   
  s    're   rZ   c                      [         R                  S:w  a  gSSKn [        [         S[         R                  5      nSU/n U R                  USU R                  S9nS	U;   $ ! [        U R                  4 a     gf = f)
z@
Test if the Python executable is linked to the musl C library.
rA  Fr   N_base_executablelddT)textr  musl)	r   r   r   r   rz  check_outputr  r   r   )r   exer(  r   s       rf   linked_to_muslr  
  s     ||w
#)3>>
:C#,C((.20:0A0A ) C
 f Z223 s   A A76A7rm   )zrequires zlib)zrequires gzip)zrequires bz2)zrequires lzma)z$requires co_positions / debug_ranges)T)r6  )zneeds the GIL enabled)Nr]   r]   )F)r]   (   rc   r_   rW  
contextlibdataclassesr  r*  r  r   r_  r   r   r8  r  rL  rC  r   rw  rG  rN   rO   rP   rQ   r   r  r  r  TEST_SUPPORT_DIRr  r   	REPO_ROOTr   r   r	   r}   r
   r   r   r(   r)   r   r   r   r   ri  junit_xml_listr   r   r   r   r   r   r   r   r  r   r   r   r.  r.   r/   HAVE_ASAN_FORK_BUGrI  rQ  r   SOCK_MAX_SIZErX  rc  __getformat__r   r    r!   r   r   r   rg  ri  contextmanagerrk  ro  r   r2   r3   r4   r9   r5   r6   r7   is_appler   r"   r#   r$   r%   r&   r'   has_strftime_extensionsstrftimer  TEST_HTTP_URLrH   r4  r  r  r  r@   rF   r   r  rb  r  r   r<   r   r   r   r   r  r  r  r  r   r  r   r9  r  r   r	  r  r  r  r  r  r  r  r"  r6  r>   rG  rG   r]  r^  rh  _4Gr  rk  r  rf  rD   rn  r   r   r  r  r   r  r  r8   r  r  r0   TEST_MODULES_ENABLEDr1   r  MISSING_C_DOCSTRINGSHAVE_PY_DOCSTRINGSHAVE_DOCSTRINGSrequires_docstringsr  r  r  r  r  r=   rB   r?   r  r  rC   r  r,   r  r6  r*   r+   rZ  rE   rx  r|  r  r  r  r  rI   r  r:   r;   r  r  r  r  r  rJ   r  rK   total_orderingr  rL   r  rM   r
  	hash_infowidth	NHASHBITSr  r!  r=  rF  r-   rM  rU  rY  rA   rg  rq  rs  cacher}  r  rR   r  r  r4  r  r  rT   rS   r  machineis_s390xr	  rU   Py_TRACE_REFSrV   	frozensetr  r  r  r  r  rW   rX   rY   r  rZ   r  r]   re   rf   <module>r1     s	   =~
F
GG      	 	  
      ,p       77??277??8#<=  01WW__]+
GGOOJ'	5I 5 =J =)E )X&& $ 

  *"E$N>	76:8:
/  %UuU @)eEeTY ) %T2 $ $ % ''	!,,V4$& --,-1: : :$P llg%
 LL##F+	\\Y&
<<EE%/!YJJ ,
,,&
 ,,"<<6cllh62v& 	  	, O
   
 V   
 ', 
<   <<7"&--"6%"? ,   ]F3&&3 4V, 	1$t 	141n 	/ 	/%%
$   ) )%B$* y//0ABC1' GG	S=34
   ( 8= : 4 4D"PF 
Sj#g#g>3 >3 >	 	 	% %@.`$O+!88* "00@IEeS H7 *+ I/I%445GHH  '..d: %B.B*B))/*DF   JJ   #< # #<  <5;f D ]*OB OBd4 79  @B 89v.*] ]@3D  
, 37 H6;, +- D  +	 ; ;"$0 $0N;#  L		 	 ;
   *
   ;- MM	H 4D) )X ,0 -9^P2B. . .&S 3 6 $ $4 $*D  L L. $ $R 3*+"0J'"$ '"T*#(Ct*D% %P , ,6' 2wABHHJ$6$6'$A*<=\*  $-
	. $  &*Z 
 
S#X 8 "ED  s   ^' '^10^1