o
    éT•j~ ã                   @   s  d Z edkr
edƒ‚ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlmZ zddlmZ W n eyO   dZY nw g d¢Zd	Zejd
krcdejv rcdZnejdkrjdZdZdZdZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ dejƒZdd„ Z dd„ Z!dd „ Z"dZ#dZ$da%da&dZ'd!Z(da)d"d#„ Z*d$d%„ Z+d&d'„ Z,d(d)„ Z-d*d+„ Z.�dd,d-„Z/d.d/„ Z0d0d1„ Z1d2d3„ Z2d4d5„ Z3d!d!d!d6œd7d8„Z4�dd!d!d!d6œd9d:„Z5d;d<„ Z6d=Z7d>Z8e 9e: ;d?¡ <d@¡dA¡Z=�ddCdD„Z>�ddFdG„Z?�ddIdJ„Z@�ddLdM„ZAe 9edN¡ZBej <dO¡ZCeDedPƒZEejdQv�r<eE�r9dRndSZFndZFdTZGd!ZHd!ZIejJ KejJ LeM¡¡ZNejJ KeN¡ZOejJ PeOdU¡ZQdVdW„ ZR�ddXdY„ZSdZd[„ ZT�dddd]œd^d_„ZUd`da„ ZVejWdbdc„ ƒZXddde„ ZYdfdg„ ZZdhdi„ Z[djdk„ Z\ejWdldm„ ƒZ]dndo„ Z^dpZ_dqZ`eDedrƒ�r©dse_ Z_dtZ`e_du Zadvdw„ Zbdxdy„ ZcdzZdd{Zed|d}„ Zfd!d~œdd€„ZgejWd�d‚„ ƒZhdƒd„„ Zid…Zjd†ej Zkd‡ek Zldˆek ZmejnZod‰dŠ„ ZpG d‹dŒ„ dŒƒZq�ddŽd�„Zrd�d‘„ ZsG d’d“„ d“ƒZtd”d•„ Zud–d—„ Zvd˜d™„ Zw�ddšd›„Zxdœd�„ ZydždŸ„ Zzd d¡„ Z{d¢d£„ Z|d¤d¥„ Z}d¦d§„ Z~dada€da�d¨d©„ Z‚dªd«„ Zƒ�dd¬d­„Z„d®d¯„ Z…d°d±„ Z†d²d³„ Z‡ezƒ �oUejd
k�oUe	 ˆd´¡ Z‰e‡j du�o^e‰ ZŠe 9eŠdµ¡Z‹�dd¶d·„ZŒd¸d¹„ Z�d!aŽdºd»„ Z�ejWd¼d½„ ƒZ�ejWd¾d¿„ ƒZ‘dÀdÁ„ Z’dÂdÃ„ Z“G dÄdÅ„ dÅe”ƒZ•da–dÆdÇ„ Z—G dÈdÉ„ dÉƒZ˜dÊdË„ Z™dÌdÍœdÎdÏ„Zš	Ì	Ì�ddÐdÑ„Z›�ddÒdÓ„ZœG dÔdÕ„ dÕƒZ�dÖd×„ ZžejWdØdÙ„ ƒZŸdÚdÛ„ Z �ddÜdÝ„Z¡g fdÞdß„Z¢da£dàdá„ Z¤ejWdâdã„ ƒZ¥G dädå„ dåƒZ¦dædç„ Z§G dèdé„ déƒZ¨e¨ƒ Z©G dêdë„ dëƒZªeªƒ Z«ej¬G dìdí„ díƒƒZ­e­ƒ Z®ej¬G dîdï„ dïƒƒZ¯e¯ƒ Z°dðdñ„ Z±ej²j³Z´e´dòv �s0J ‚dódô„ ZµG dõdö„ döƒZ¶dd÷œdødù„Z·dúdû„ Z¸ejW�ddýdþ„ƒZ¹dÿ�d „ Zº�de»�de»�de”f�d�d„Z¼�de”�ddf�d�d„Z½ejW�d	�d
„ ƒZ¾�de¿e» f�d�d„ZÀdS (  z7Supporting definitions for the Python regression tests.ztest.supportz.support must be imported from the test packageé    Né   )Úget_test_runner)Úunicode_legacy_string)BÚ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Úis_resource_enabledÚrequiresÚrequires_freebsd_versionÚrequires_linux_versionÚrequires_mac_verÚcheck_syntax_errorÚBasicTestRunnerÚrun_unittestÚrun_doctestÚrequires_gzipÚrequires_bz2Úrequires_lzmaÚ
bigmemtestÚbigaddrspacetestÚcpython_onlyÚget_attributeÚrequires_IEEE_754Úrequires_zlibÚanticipate_failureÚload_package_testsÚdetect_api_mismatchÚcheck__all__Úskip_if_buggy_ucrt_strfptimeÚcheck_disallow_instantiationÚcheck_sanitizerÚskip_if_sanitizerÚ	is_jythonÚ
is_androidÚcheck_impl_detailÚ
unix_shellÚsetswitchintervalÚopen_urlresourceÚreap_childrenÚrun_with_localeÚ	swap_itemÚfindfileÚ	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_TIMEOUTg      @Úwin32z 32 bit (ARM)é
   Úvxworksg      N@g      >@g     Àr@c                   @   ó   e Zd ZdZdS )r
   z*Base class for regression test exceptions.N©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© rP   rP   ú,/usr/lib/python3.10/test/support/__init__.pyr
   g   ó    r
   c                   @   rJ   )r   úTest failed.NrK   rP   rP   rP   rQ   r   j   rR   r   c                       s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚTestFailedWithDetailsrS   c                    s&   || _ || _|| _tƒ  |||¡ d S ©N)ÚmsgÚerrorsÚfailuresÚsuperÚ__init__)ÚselfrV   rW   rX   ©Ú	__class__rP   rQ   rZ   o   s   zTestFailedWithDetails.__init__c                 C   s   | j S rU   )rV   ©r[   rP   rP   rQ   Ú__str__u   s   zTestFailedWithDetails.__str__)rL   rM   rN   rO   rZ   r_   Ú__classcell__rP   rP   r\   rQ   rT   m   s    rT   c                   @   rJ   )r   zTest did not run any subtests.NrK   rP   rP   rP   rQ   r   x   rR   r   c                   @   rJ   )r   zàTest 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.
    NrK   rP   rP   rP   rQ   r   {   rR   r   c                 C   s   | rt jS dd„ S )z¯Decorator 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                 S   ó   | S rU   rP   ©ÚfrP   rP   rQ   Ú<lambda>‹   ó    z$anticipate_failure.<locals>.<lambda>)ÚunittestÚexpectedFailure)Ú	conditionrP   rP   rQ   r%   ƒ   s   r%   c                 C   sF   |du rd}t j t j t j t¡¡¡}|j| ||d�}| |¡ |S )zòGeneric 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)
    Nztest*)Ú	start_dirÚtop_level_dirÚpattern)ÚosÚpathÚdirnameÚ__file__ÚdiscoverÚaddTests)Úpkg_dirÚloaderÚstandard_testsrk   Útop_dirÚpackage_testsrP   rP   rQ   r&   �   s   
ÿÿþ
r&   c                 C   s2   zt | |ƒ}W |S  ty   t d| |f ¡‚w )z?Get an attribute, raising SkipTest if AttributeError is raised.zobject %r has no attribute %r)ÚgetattrÚAttributeErrorrf   ÚSkipTest)ÚobjÚnameÚ	attributerP   rP   rQ   r"   ¡   s   ýÿr"   Fc                 C   s   | a d S rU   )Ú_original_stdout)ÚstdoutrP   rP   rQ   r   ¶   s   r   c                   C   s
   t ptjS rU   )r}   Úsysr~   rP   rP   rP   rQ   r   º   ó   
r   c              
   G   st   z||Ž W S  t y9 } z(tdkr$td|jj|f ƒ td|j|f ƒ t | tj¡ ||Ž W  Y d }~S d }~ww )Né   z%s: %szre-run %s%r)	ÚOSErrorr   Úprintr]   rL   rl   ÚchmodÚstatÚS_IRWXU)rm   ÚfuncÚargsÚerrrP   rP   rQ   Ú
_force_run¾   s   
€ûrŠ   c               
      s  t tdƒrtjS dd l} d }tj d¡r|  ¡ rd}n�tj d¡rpdd l‰dd l‰d}d}G ‡fdd„dˆj	ƒ}ˆj
j}| ¡ }|sFˆ ¡ ‚|ƒ }ˆj ¡ }| ||ˆ |¡ˆ |¡ˆ |¡¡}	|	sfˆ ¡ ‚t|j|@ ƒsod}nHtjd	kr¸dd
lm}
m‰ m}m	} ddlm} |
 |dƒ¡}| ¡ dkr—d}n!G ‡ fdd„d|ƒ}|ƒ }||ƒ}| |¡dk s¶| |¡dk r¸d}|sÿzddlm} |ƒ }|  ¡  | !¡  | "¡  W n- t#yþ } z!t$|ƒ}t%|ƒdkrë|d d… d }d &t'|ƒj(|¡}W Y d }~nd }~ww |t_)| t_tjS )NÚresultr   Úwinz(gui is not available on Windows IoT Corer   c                       s.   e Zd Zd” jjfd” jjfd” jjfgZdS )z*_is_gui_available.<locals>.USEROBJECTFLAGSÚfInheritÚ	fReservedÚdwFlagsN)rL   rM   rN   ÚwintypesÚBOOLÚDWORDÚ_fields_rP   )ÚctypesrP   rQ   ÚUSEROBJECTFLAGSØ   s
    


þr•   z,gui not available (WSF_VISIBLE flag not set)Údarwin)ÚcdllÚc_intÚpointerÚ	Structure)Úfind_libraryÚApplicationServicesz0gui tests cannot run without OS X window managerc                       s   e Zd Zd” fd” fgZdS )z._is_gui_available.<locals>.ProcessSerialNumberÚhighLongOfPSNÚlowLongOfPSNN)rL   rM   rN   r“   rP   )r˜   rP   rQ   ÚProcessSerialNumberú   s    ÿrŸ   z#cannot run without OS X gui process)ÚTké2   z [...]zTk unavailable due to {}: {})*ÚhasattrÚ_is_gui_availabler‹   Úplatformr   Ú
startswithÚwin32_is_iotr”   Úctypes.wintypesrš   ÚwindllÚuser32ÚGetProcessWindowStationÚWinErrorr�   r’   ÚGetUserObjectInformationWÚbyrefÚsizeofÚboolr�   r—   r˜   r™   Úctypes.utilr›   ÚLoadLibraryÚCGMainDisplayIDÚGetCurrentProcessÚSetFrontProcessÚtkinterr    ÚwithdrawÚupdateÚdestroyÚ	ExceptionÚstrÚlenÚformatÚtyperL   Úreason)r¤   r¾   Ú	UOI_FLAGSÚWSF_VISIBLEr•   ÚdllÚhÚuofÚneededÚresr—   r™   rš   r›   Úapp_servicesrŸ   ÚpsnÚpsn_pr    ÚrootÚeÚ
err_stringrP   )r˜   r”   rQ   r£   Ê   sx   

ü€
ÿ€ür£   c                 C   s   t du p| t v S )zÁTest 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   ©ÚresourcerP   rP   rQ   r     s   r   c                 C   s@   t | ƒs|du rd|  }t|ƒ‚| dkrtƒ sttjƒ‚dS dS )z@Raise ResourceDenied if the specified resource is not available.Nz"Use of the %r resource not enabledÚgui)r   r   r£   r¾   )rÍ   rV   rP   rP   rQ   r     s   
ÿr   c                 C   s’   ddl }d tt|ƒ¡}| ¡  dd¡d }| ¡ | kr9zttt| d¡ƒƒ}W n t	y3   d}Y nw ||k }nd}t
 || › d|› d|› �¡S )	zàDecorator 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 z or higher required, not )r¤   ÚjoinÚmaprº   ÚreleaseÚsplitÚsystemÚtupleÚintÚ
ValueErrorrf   ÚskipIf)ÚsysnameÚmin_versionr¤   Úmin_version_txtÚversion_txtÚversionÚskiprP   rP   rQ   Ú_requires_unix_version(  s"   ÿ
ÿþrà   c                  G   ó
   t d| ƒS )zÛDecorator 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Û   rP   rP   rQ   r   C  ó   
r   c                  G   rá   )zÚDecorator 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ä   rP   rP   rQ   r   L  rå   r   c                     ó   ‡ fdd„}|S )zÐDecorator 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                    s"   t  ˆ ¡‡ ‡fdd„ƒ}ˆ|_|S )Nc                     s‚   t jdkr:dd l}| ¡ d }zttt| d¡ƒƒ}W n	 ty$   Y nw |ˆk r:d tt	ˆƒ¡}t
 d||f ¡‚ˆ | i |¤ŽS )Nr–   r   rÏ   z&Mac OS X %s or higher required, not %s)r   r¤   Úmac_verrÖ   rÒ   r×   rÔ   rØ   rÑ   rº   rf   ry   )rˆ   Úkwr¤   rÝ   rÞ   rÜ   )r‡   rÛ   rP   rQ   Úwrapper]  s    
ÿÿÿz4requires_mac_ver.<locals>.decorator.<locals>.wrapper)Ú	functoolsÚwrapsrÛ   ©r‡   rê   rä   ©r‡   rQ   Ú	decorator\  s   z#requires_mac_ver.<locals>.decoratorrP   )rÛ   rï   rP   rä   rQ   r   U  s   r   ©ÚaddressÚmemoryÚubc                 C   sx   | s
|s
|s
t dƒ‚t d¡pd}t d¡pd}d|v pd|v }d|v p'd|v }d|v p/d	|v }|r4|p;| o7|p;|o;|S )
z9Returns True if Python is compiled with sanitizer supportz3At least one of address, memory, or ub must be TrueÚCFLAGSÚ ÚCONFIG_ARGSz-fsanitize=memoryz--with-memory-sanitizerz-fsanitize=addressz-fsanitize=undefinedz#--with-undefined-behavior-sanitizer)rØ   Ú	sysconfigÚget_config_var)rñ   rò   ró   Ú_cflagsÚ_config_argsÚmemory_sanitizerÚaddress_sanitizerÚub_sanitizerrP   rP   rQ   r+   r  s$   þþþÿýr+   c                C   s"   | sd} t |||d�}t || ¡S )z>Decorator raising SkipTest if running with a sanitizer active.z"not working with sanitizers activerð   )r+   rf   rÙ   )r¾   rñ   rò   ró   rß   rP   rP   rQ   r,   �  s   r,   c                    s   t  ˆ ¡‡ fdd„ƒ}|S )z5Skip the test on TLS certificate validation failures.c               
      sF   z
ˆ | i |¤Ž W d S  t y" } zdt|ƒv rt d¡‚‚ d }~ww )NÚCERTIFICATE_VERIFY_FAILEDz.system does not contain necessary certificates)r‚   rº   rf   ry   )rˆ   ÚkwargsrÊ   rb   rP   rQ   Údec—  s   
€üz&system_must_validate_cert.<locals>.dec)rë   rì   )rc   r   rP   rb   rQ   Úsystem_must_validate_cert•  s   r  i @ i  ÚdoubleÚIEEEztest requires IEEE 754 doublesúrequires zlibc                 C   ó0   zdd l }W n ty   d }Y nw t || ¡S ©Nr   )ÚzlibÚImportErrorrf   Ú
skipUnless)r¾   r  rP   rP   rQ   r$   µ  ó   ÿr$   úrequires gzipc                 C   r  r  )Úgzipr  rf   r	  )r¾   r  rP   rP   rQ   r   ¼  r
  r   úrequires bz2c                 C   r  r  )Úbz2r  rf   r	  )r¾   r  rP   rP   rQ   r   Ã  r
  r   úrequires lzmac                 C   r  r  )Úlzmar  rf   r	  )r¾   r  rP   rP   rQ   r   Ê  r
  r   zrequires legacy Unicode C APIÚjavaÚgetandroidapilevel)rG   rI   z/system/bin/shz/bin/shzhttp://www.pythontest.netÚdatac                 C   sX   t jdkrdS ddl}d}| › d�}| ¡ \}}t| |d¡ƒ t|ƒ td| ƒ dS )zOAssure 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 bpo-40928.rÐ   )r   r¤   ÚshutilÚget_terminal_sizerƒ   Úcenter)Ú	test_namer  rV   ÚdetailÚpaddingÚ_rP   rP   rQ   Údarwin_malloc_err_warningò  s   

r  c                 C   sb   t j | ¡r| S |durt j || ¡} tgtj }|D ]}t j || ¡}t j |¡r.|  S q| S )a[  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.
    N)rl   rm   ÚisabsrÑ   ÚTEST_HOME_DIRr   Úexists)ÚfilenameÚsubdirrm   ÚdnÚfnrP   rP   rQ   r6     s   r6   c                 C   s,   t |  ¡ ƒ}dd„ |D ƒ}d |¡}d| S )z%Like repr(dict), but in sorted order.c                 S   s   g | ]}d | ‘qS )z%r: %rrP   )Ú.0ÚpairrP   rP   rQ   Ú
<listcomp>  ó    zsortdict.<locals>.<listcomp>z, z{%s})ÚsortedÚitemsrÑ   )Údictr(  Ú	reprpairsÚ
withcommasrP   rP   rQ   r;     s   
r;   rõ   )ÚlinenoÚoffsetc                C   sŠ   |   t|¡�}t|ddƒ W d   ƒ n1 sw   Y  |j}|  |j¡ |d ur0|  |j|¡ |  |j¡ |d urC|  |j|¡ d S d S )Nz<test string>Úexec)ÚassertRaisesRegexÚSyntaxErrorÚcompileÚ	exceptionÚassertIsNotNoner,  ÚassertEqualr-  )ÚtestcaseÚ	statementÚerrtextr,  r-  Úcmr‰   rP   rP   rQ   r     s   ÿÿr   c                    s–  dd l }dd l}ddlm} zdd l}W n ty   d }Y nw ˆ dd ¡‰|j | ¡d  	d¡d }t
j t|¡}‡ ‡‡fdd	„}t
j |¡rV||ƒ}	|	d urR|	S ||ƒ td
ƒ tretd|  tƒ d� |j ¡ }
|rr|
j d¡ |
j| td�}	|r‰|	j d¡dkr‰|j|	d�}	z,t|dƒ�}|	 ¡ }|r¡| |¡ |	 ¡ }|s–W d   ƒ n1 s«w   Y  W |	 ¡  n|	 ¡  w ||ƒ}	|	d urÅ|	S td| ƒ‚)Nr   r   )ÚunlinkÚcheckr�   ú/éÿÿÿÿc                    sD   t | gˆ ¢R i ˆ¤Ž}ˆd u r|S ˆ|ƒr| d¡ |S | ¡  d S r  )ÚopenÚseekÚclose)r"  rc   ©rˆ   r:  ré   rP   rQ   Úcheck_valid_file8  s   
z*open_urlresource.<locals>.check_valid_fileÚurlfetchz	fetching %s ...©Úfile)zAccept-Encodingr  ©ÚtimeoutzContent-Encodingr  )ÚfileobjÚwbzinvalid resource %r) Úurllib.requestÚurllib.parseÚ	os_helperr9  r  r  ÚpopÚparseÚurlparserÔ   rl   rm   rÑ   ÚTEST_DATA_DIRr  r   r   rƒ   r   ÚrequestÚbuild_openerÚ
addheadersÚappendr=  rD   ÚheadersÚgetÚGzipFileÚreadÚwriter?  r   )Úurlrˆ   ré   Úurllibr9  r  r  r"  rA  rc   ÚopenerÚoutÚsrP   r@  rQ   r2   *  sP   ÿ	

þ€þ€r2   c              
   c   sR   � ddl }tt| ƒ}tt| | ¡ ƒ ztt| ƒV  W tt| |ƒ dS tt| |ƒ w )z‰Return a context manager used by captured_stdout/stdin/stderr
    that temporarily replaces the sys stream *stream_name* with a StringIO.r   N)Úiorw   r   ÚsetattrÚStringIO)Ústream_namer^  Úorig_stdoutrP   rP   rQ   Úcaptured_outputa  s   €
rc  c                   C   ó   t dƒS )z Capture the output of sys.stdout:

       with captured_stdout() as stdout:
           print("hello")
       self.assertEqual(stdout.getvalue(), "hello\n")
    r~   ©rc  rP   rP   rP   rQ   r   m  ó   r   c                   C   rd  )z±Capture the output of sys.stderr:

       with captured_stderr() as stderr:
           print("hello", file=sys.stderr)
       self.assertEqual(stderr.getvalue(), "hello\n")
    Ústderrre  rP   rP   rP   rQ   r   v  rf  r   c                   C   rd  )a	  Capture 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")
    Ústdinre  rP   rP   rP   rQ   r     s   
r   c                  C   s2   ddl } |  ¡  trt d¡ |  ¡  |  ¡  dS )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Úcollectr-   ÚtimeÚsleep)rj  rP   rP   rQ   Ú
gc_collectŒ  s   

rn  c                  c   sH   � dd l } |  ¡ }|  ¡  zd V  W |r|  ¡  d S d S |r#|  ¡  w w r  )rj  Ú	isenabledÚdisableÚenable)rj  Úhave_gcrP   rP   rQ   Ú
disable_gc�  s   €ÿ
ÿrs  c                  C   s6   t  d¡pd} d}|  ¡ D ]	}| d¡r|}q|dvS )z,Find if Python was built with optimizations.Ú	PY_CFLAGSrõ   z-O)rõ   z-O0z-Og)r÷   rø   rÔ   r¥   )ÚcflagsÚ	final_optÚoptrP   rP   rQ   Úpython_is_optimized©  s   
€rx  ÚnPÚ0nÚ
getobjectsÚ2PÚ0PÚnc                 C   ó   dd l }| t|  t ¡S r  )ÚstructÚcalcsizeÚ_headerÚ_align©Úfmtr€  rP   rP   rQ   Úcalcobjsizeº  ó   r†  c                 C   r  r  )r€  r�  Ú_vheaderrƒ  r„  rP   rP   rQ   Úcalcvobjsize¾  r‡  r‰  i @  i   c                 C   sp   dd l }t |¡}t|ƒtkr|jt@ s!t|ƒtkr&t|ƒjt@ r&||j7 }dt|ƒ||f }|  |||¡ d S )Nr   z&wrong size for %s: got %d, expected %d)	Ú_testinternalcapir   Ú	getsizeofr½   Ú	__flags__Ú_TPFLAGS_HEAPTYPEÚ_TPFLAGS_HAVE_GCÚSIZEOF_PYGC_HEADr4  )ÚtestÚoÚsizerŠ  r‹   rV   rP   rP   rQ   Úcheck_sizeofÆ  s   

ÿr“  )Ú_do_cleanupsc                  sL   d‰t ˆtƒrˆ dd¡ ¡ ‰tˆƒdkrd‰tˆƒ‰‡ ‡‡‡fdd„}|S )z5Run multiple subtests with different parameters.
    Fú,ú r   Tc                    s4   t ˆ tƒr	tdƒ‚t ˆ ¡‡‡‡‡ ‡fdd„ƒ}|S )Nz1subTests() can only decorate methods, not classesc             	      s|   ˆD ]9}ˆr	|f}t tˆ|ƒƒ}| jdi |¤Ž� ˆ| g|¢R i |¤|¤Ž W d   ƒ n1 s0w   Y  ˆ r;|  ¡  qd S )NrP   )r)  ÚzipÚsubTestÚ
doCleanups)r[   rˆ   rÿ   ÚvaluesÚsubtest_kwargs)r”  Ú	arg_namesÚ
arg_valuesr‡   Úsingle_paramrP   rQ   rê   Ý  s   ÿ€ùz,subTests.<locals>.decorator.<locals>.wrapper)Ú
isinstancer½   Ú	TypeErrorrë   rì   rí   ©r”  rœ  r�  rž  rî   rQ   rï   Ú  s
   
	zsubTests.<locals>.decorator)rŸ  rº   ÚreplacerÔ   r»   rÖ   )rœ  r�  r”  rï   rP   r¡  rQ   ÚsubTestsÑ  s   
r£  c              
   g   s®   � zdd l }t|| ƒ}| |¡}W n ty   ‚    d  }}Y n|D ]}z	| ||¡ W  n   Y q$zd V  W |rF|rH| ||¡ d S d S d S |rU|rV| ||¡ w w w r  )Úlocalerw   Ú	setlocalerx   )ÚcatstrÚlocalesr¤  ÚcategoryÚorig_localeÚlocrP   rP   rQ   r4   î  s,   €
ÿÿr4   c                    rç   )Nc                    s"   ‡ ‡fdd„}ˆ j |_ ˆ j|_|S )Nc               	      sª   zt j}W n ty   t d¡‚w dtjv rtjd }nd }ˆtjd< |ƒ  zˆ | i |¤ŽW |d u r8tjd= n|tjd< t  ¡  S |d u rKtjd= n|tjd< t  ¡  w )Nztzset requiredÚTZ)rl  Útzsetrx   rf   ry   rl   Úenviron)rˆ   Úkwdsr¬  Úorig_tz)r‡   ÚtzrP   rQ   Úinner  s(   

ÿ




ü


z-run_with_tz.<locals>.decorator.<locals>.inner)rL   rO   )r‡   r±  ©r°  rî   rQ   rï     s   zrun_with_tz.<locals>.decoratorrP   )r°  rï   rP   r²  rQ   r<     s   r<   i   é   r�   é   c                 C   s”   dt tdt dœ}t d| tjtjB ¡}|d u rtd| f ƒ‚tt| 	d¡ƒ|| 	d¡ 
¡   ƒ}|a|tkr9t}|td k rFtd| f ƒ‚|ad S )Nr³  )ÚkÚmÚgÚtz(\d+(\.\d+)?) (K|M|G|T)b?$zInvalid memory limit %rr   é   z$Memory limit %r too low to be useful)Ú_1MÚ_1GÚreÚmatchÚ
IGNORECASEÚVERBOSErØ   r×   ÚfloatÚgroupÚlowerÚreal_max_memuseÚMAX_Py_ssize_tÚ_2Gr   )ÚlimitÚsizesr¶  ÚmemlimitrP   rP   rQ   r9   6  s"   ü
ÿ$r9   c                   @   ó(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú_MemoryWatchdogz`An object which periodically watches the process' memory consumption
    and prints it out.
    c                 C   s   dj t ¡ d�| _d| _d S )Nz/proc/{pid}/statm)ÚpidF)r¼   rl   ÚgetpidÚprocfileÚstartedr^   rP   rP   rQ   rZ   P  s   
z_MemoryWatchdog.__init__c              
   C   s´   dd l }zt| jdƒ}W n! ty- } z| d |¡t¡ tj 	¡  W Y d }~d S d }~ww dd l
}|� tdƒ}|jtj|g||jd�| _W d   ƒ n1 sPw   Y  d| _d S )Nr   Úrz!/proc not available for stats: {}zmemory_watchdog.py)rh  rg  T)Úwarningsr=  rÍ  r‚   Úwarnr¼   ÚRuntimeWarningr   rg  ÚflushÚ
subprocessr6   ÚPopenÚ
executableÚDEVNULLÚmem_watchdogrÎ  )r[   rÐ  rc   rÊ   rÔ  Úwatchdog_scriptrP   rP   rQ   ÚstartT  s(   ÿ
€ü
þþ
z_MemoryWatchdog.startc                 C   s"   | j r| j ¡  | j ¡  d S d S rU   )rÎ  rØ  Ú	terminateÚwaitr^   rP   rP   rQ   Ústopf  s   
þz_MemoryWatchdog.stopN)rL   rM   rN   rO   rZ   rÚ  rÝ  rP   rP   rP   rQ   rÊ  K  s
    rÊ  Tc                    s   ‡ ‡‡fdd„}|S )at  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                    s    ‡‡ ‡fdd„‰ˆˆ_ ˆˆ_ˆS )Nc                    sª   ˆj }ˆj}tsd}n|}tsˆ s"t|| k r"t d|| d  ¡‚tr=tr=tƒ  tdj|| d d�ƒ tƒ }| 	¡  nd }zˆ| |ƒW |rL| 
¡  S S |rT| 
¡  w w )Ni  ú'not enough memory: %.1fG minimum neededé   @z* ... expected peak memory use: {peak:.1f}G)Úpeak)r’  ÚmemuserÃ  rf   ry   r   rƒ   r¼   rÊ  rÚ  rÝ  )r[   r’  rá  ÚmaxsizeÚwatchdog)Údry_runrc   rê   rP   rQ   rê   z  s6   
ÿÿÿ


ÿ
ÿz.bigmemtest.<locals>.decorator.<locals>.wrapper)r’  rá  rb   ©rä  rá  r’  ©rc   rê   rQ   rï   y  s   zbigmemtest.<locals>.decoratorrP   )r’  rá  rä  rï   rP   rå  rQ   r   l  s   !r   c                    rç   )z0Decorator for tests that fill the address space.c                    s<   t tk rtdkrt dkrt d¡‚t dtd  ¡‚ˆ | ƒS )Nl   ÿÿÿÿ l        z-not enough memory: try a 32-bit build insteadrÞ  rß  )r   rÄ  rf   ry   r^   rb   rP   rQ   rê   ž  s   ÿÿÿz!bigaddrspacetest.<locals>.wrapperrP   ræ  rP   rb   rQ   r    œ  s   r    c                   @   s   e Zd Zdd„ ZdS )r   c                 C   s   t  ¡ }||ƒ |S rU   )rf   Ú
TestResult)r[   r�  r‹   rP   rP   rQ   Úrun¯  ó   zBasicTestRunner.runN)rL   rM   rN   rè  rP   rP   rP   rQ   r   ®  s    r   c                 C   ra   rU   rP   )rz   rP   rP   rQ   Ú_id´  ó   rê  c                 C   s6   | dkrt ƒ st t j¡S t| ƒrtS t d | ¡¡S )NrÎ   zresource {0!r} is not enabled)r£   rf   rß   r¾   r   rê  r¼   rÌ   rP   rP   rQ   Úrequires_resource·  s
   rì  c                 C   s   t dd�| ƒS )z9
    Decorator for tests only applicable on CPython.
    T)Úcpython)Úimpl_detail©r�  rP   rP   rQ   r!   ¿  s   r!   c                 K   sZ   t di |¤Žr	tS | d u r(t|ƒ\}}|rd} nd} t| ¡ ƒ}|  d |¡¡} t | ¡S )Nz*implementation detail not available on {0}z%implementation detail specific to {0}z or rP   )	r/   rê  Ú_parse_guardsr'  Úkeysr¼   rÑ   rf   rß   )rV   ÚguardsÚ
guardnamesÚdefaultrP   rP   rQ   rî  Å  s   
rî  c                 C   sH   | sddidfS t |  ¡ ƒd }t |  ¡ ƒ|gt| ƒ ksJ ‚| | fS )Nrí  TFr   )Úlistrš  r»   )rò  Úis_truerP   rP   rQ   rð  Ò  s
   
rð  c                  K   s   t | ƒ\} }|  tjj|¡S )a5  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ð  rU  r   Úimplementationr{   )rò  rô  rP   rP   rQ   r/   Ü  s   r/   c                    s(   t tdƒsˆ S t ˆ ¡‡ fdd„ƒ}|S )zEDecorator to temporarily turn off tracing for the duration of a test.Úgettracec               	      s:   t  ¡ }zt  d ¡ ˆ | i |¤ŽW t  |¡ S t  |¡ w rU   )r   rø  Úsettrace)rˆ   rÿ   Úoriginal_tracerî   rP   rQ   rê   ì  s
   
zno_tracing.<locals>.wrapper)r¢   r   rë   rì   rí   rP   rî   rQ   Ú
no_tracingç  s
   
rû  c                 C   s   t t| ƒƒS )a  Decorator 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ï  rP   rP   rQ   Úrefcount_test÷  s   rü  c                 C   sN   g }| j D ]}t|tjƒrt||ƒ | |¡ q||ƒr!| |¡ q|| _ dS )z>Recursively filter test cases in a suite based on a predicate.N)Ú_testsrŸ  rf   Ú	TestSuiteÚ_filter_suiterS  )ÚsuiteÚpredÚnewtestsr�  rP   rP   rQ   rÿ    s   


€
rÿ  c                 C   sÔ   t tjttdud�}| | ¡}tdurt | ¡ ¡ |js"|j	s"t
‚| ¡ sht|jƒdkr8|js8|jd d }nt|jƒdkrJ|jsJ|jd d }nd}tsR|d7 }dd„ |jD ƒ}d	d„ |jD ƒ}t|||ƒ‚dS )
z2Run tests from a unittest.TestSuite-derived class.N)Ú	verbosityÚcapture_outputr   r   zmultiple errors occurredz!; run in verbose mode for detailsc                 S   ó   g | ]
\}}t |ƒ|f‘qS rP   ©rº   ©r#  ÚtcÚexc_strrP   rP   rQ   r%  #  ó    z_run_suite.<locals>.<listcomp>c                 S   r  rP   r  r  rP   rP   rQ   r%  $  r
  )r   r   r~   r   Újunit_xml_listrè  rS  Úget_xml_elementÚtestsRunÚskippedr   ÚwasSuccessfulr»   rW   rX   rT   )r   Úrunnerr‹   r‰   rW   rX   rP   rP   rQ   Ú
_run_suite  s(   þ
ör  c                 C   s   t d u rdS t |  ¡ ƒS ©NT)Ú_match_test_funcÚidrï  rP   rP   rQ   Ú
match_test/  s   r  c                 C   s   d| v o
t  d| ¡ S )NrÏ   z[?*\[\]])r¼  Úsearch)rk   rP   rP   rQ   Ú_is_full_match_test7  s   r  c                    s‚   | d u rd} |d u rd}d  ‰ ‰| t krt| ƒ\} ‰ |tkr$t|ƒ\}‰t| ƒa t|ƒaˆ d us4ˆd ur?‡ ‡fdd„}|ad S d S )NrP   c                    s*   d}d}ˆ r
ˆ | ƒ}ˆrˆ| ƒ}|o| S )NTFrP   )Útest_idÚacceptÚignore©Úaccept_funcÚignore_funcrP   rQ   Úmatch_functionV  s   
z'set_match_tests.<locals>.match_function)Ú_accept_test_patternsÚ_compile_match_functionÚ_ignore_test_patternsrÖ   r  )Úaccept_patternsÚignore_patternsr  rP   r  rQ   Úset_match_testsA  s   	ör$  c                    sr   | s
d }d} | |fS t tt| ƒƒrt| ƒj}| |fS dd l}d t|j| ƒ¡}t 	|¡j
‰ ‡ fdd„}|}| |fS )NrP   r   ú|c                    s    ˆ | ƒrdS t tˆ |  d¡ƒƒS )NTrÏ   )ÚanyrÒ   rÔ   )r  ©Úregex_matchrP   rQ   Úmatch_test_regexr  s   z1_compile_match_function.<locals>.match_test_regex)ÚallrÒ   r  ÚsetÚ__contains__ÚfnmatchrÑ   Ú	translater¼  r1  r½  )Úpatternsr‡   r-  Úregexr)  rP   r'  rQ   r   b  s   è
ír   c                  G   sŽ   t jt jf}t  ¡ }| D ]/}t|tƒr(|tjv r$| t  tj| ¡¡ qt	dƒ‚t||ƒr3| |¡ q| t  
|¡¡ qt|tƒ t|ƒ dS )z1Run tests from unittest.TestCase-derived classes.z)str arguments must be keys in sys.modulesN)rf   rþ  ÚTestCaserŸ  rº   r   ÚmodulesÚaddTestÚfindTestCasesrØ   Ú	makeSuiterÿ  r  r  )ÚclassesÚvalid_typesr   ÚclsrP   rP   rQ   r   ‚  s   



r   c                   C   ó   dS )z,Just used to check if docstrings are enabledNrP   rP   rP   rP   rQ   Ú_check_docstrings™  re   r:  ÚWITH_DOC_STRINGSztest requires docstringsc                 C   s`   ddl }|du rt}nd}|j| ||d�\}}|r!td||f ƒ‚tr,td| j|f ƒ ||fS )a  Run doctest on the given module.  Return (#failures, #tests).

    If optional argument verbosity is not specified (or is None), pass
    support's belief about verbosity on to doctest.  Else doctest's
    usual behavior is used (it searches sys.argv for -v).
    r   N)r   Úoptionflagsz%d of %d doctests failedz,doctest (%s) ... %d tests with zero failures)Údoctestr   Útestmodr   rƒ   rL   )Úmoduler  r<  r=  rc   r¸  rP   rP   rQ   r   ª  s   ÿr   c                 C   s(   |   ¡ D ]}td|› �tjdd� qd S )NzWarning -- T)rD  rÓ  )Ú
splitlinesrƒ   r   Ú
__stderr__)rV   ÚlinerP   rP   rQ   Úprint_warningÅ  s   ÿrC  c                  C   sf   t tdƒr
t tdƒsdS 	 zt dtj¡\} }W n
 ty"   Y dS w | dkr)dS td| › �ƒ daq)zåUse 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¢   rl   rD  rE  r‚   rC  Úenvironment_altered)rË  ÚstatusrP   rP   rQ   r3   Ô  s   	ÿõr3   c              
   c   s”   � t | |ƒr%t| |ƒ}t| ||ƒ z|V  W t| ||ƒ dS t| ||ƒ w t| ||ƒ zdV  W t | |ƒr<t| |ƒ dS dS t | |ƒrIt| |ƒ w w )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¢   rw   r_  Údelattr)rz   ÚattrÚnew_valÚreal_valrP   rP   rQ   r7   ð  s   €


ÿÿr7   c              	   c   sr   � || v r| | }|| |< z
|V  W || |< dS || |< w || |< zdV  W || v r/| |= dS dS || v r8| |= w )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.
    NrP   )rz   ÚitemrJ  rK  rP   rP   rQ   r5     s   €
ÿr5   c                  C   ó   ddl } |  ¡ S )znReturn a list of command-line arguments reproducing the current
    settings in sys.flags and sys.warnoptions.r   N)rÔ  Ú_args_from_interpreter_flags©rÔ  rP   rP   rQ   Úargs_from_interpreter_flags.  ó   rP  c                  C   rM  )zgReturn a list of command-line arguments reproducing the current
    optimization settings in sys.flags.r   N)rÔ  Ú"_optim_args_from_interpreter_flagsrO  rP   rP   rQ   Ú!optim_args_from_interpreter_flags4  rQ  rS  c                   @   ó    e Zd ZdZdd„ Zdd„ ZdS )r8   )rV   Úmessagec                 K   s<   d}|D ]}|| }|  |¡}|  |||¡sd} |S q|S )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)rU  Úmatch_value)r[   Údrÿ   r‹   rµ  ÚvÚdvrP   rP   rQ   Úmatches?  s   
ýzMatcher.matchesc                 C   sL   t |ƒt |ƒkrd}|S t |ƒtus|| jvr||k}|S | |¡dk}|S )zT
        Try to match a single stored value (dv) with a supplied value (v).
        Fr   )r½   rº   Ú_partial_matchesÚfind)r[   rµ  rY  rX  r‹   rP   rP   rQ   rV  P  s   üÿzMatcher.match_valueN)rL   rM   rN   r[  rZ  rV  rP   rP   rP   rQ   r8   ;  s    r8   c                 C   sX   ddl }tdu r!tjdkr| ¡ d dkrt ¡ jdkrdandatr*t 	d	¡| ƒS | S )
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   NrG   r   Úcp65001rõ   TFz!buggy MSVC UCRT strptime/strftime)
r¤  Ú_buggy_ucrtr   r¤   Úgetdefaultlocalerl  Ú	localtimeÚtm_zonerf   rß   )r�  r¤  rP   rP   rQ   r)   ^  s   

r)   c                   @   sj   e Zd ZdZddd„Zejdkrdd„ Zndd„ Zd	d
„ Zdd„ Z	dd„ Z
ddœdd„Zddœdd„ZdS )ÚPythonSymlinkz3Creates a symlink for the current Python executableNc                 C   sL   ddl m} |ptj |¡| _g | _tj tj	¡| _
g | _d | _|  ¡  d S )Nr   )ÚTESTFN)rK  rc  rl   rm   ÚabspathÚlinkÚ_linkedÚrealpathr   rÖ  ÚrealÚ
_also_linkÚ_envÚ_platform_specific)r[   re  rc  rP   rP   rQ   rZ   u  s   zPythonSymlink.__init__rG   c              
   C   s  dd l }dd l}tj | j¡rtj | j¡s| d¡| _| tj	¡}tj 
|¡}tj 
| j¡}| j |tj |tj |¡¡f¡ |  tj | |¡d¡¡D ]}| j |tj |tj |¡¡f¡ qMdd„ tjD ƒ| _tj 
| j¡| jd< t d¡r…tj 
tj¡| jd< d S d S )Nr   zvcruntime*.dllc                 S   s   i | ]
}|  ¡ t |¡“qS rP   )Úupperrl   Úgetenv)r#  rµ  rP   rP   rQ   Ú
<dictcomp>˜  r
  z4PythonSymlink._platform_specific.<locals>.<dictcomp>Ú
PYTHONHOMETÚ
PYTHONPATH)ÚglobÚ_winapirl   rm   Úlexistsrh  r  ÚGetModuleFileNamer   Ú	dllhandlern   re  ri  rS  rÑ   ÚbasenameÚescaper­  rj  r÷   Úis_python_buildro   )r[   rq  rr  rÁ   Úsrc_dirÚdest_dirÚruntimerP   rP   rQ   rk  ‚  s*   þþ
ÿz PythonSymlink._platform_specificc                 C   s   d S rU   rP   r^   rP   rP   rQ   rk  �  rë  c                 C   sJ   t  | j| j¡ | j | j¡ | jD ]\}}t  ||¡ | j |¡ q| S rU   )rl   Úsymlinkrh  re  rf  rS  ri  )r[   rh  re  rP   rP   rQ   Ú	__enter__   s   zPythonSymlink.__enter__c                 C   sV   | j D ]%}zt |¡ W q ty( } ztrtd ||¡ƒ W Y d }~qd }~ww d S )Nzfailed to clean up {}: {})rf  rl   ÚremoveÚIOErrorr   rƒ   r¼   )r[   Úexc_typeÚ	exc_valueÚexc_tbre  ÚexrP   rP   rQ   Ú__exit__¨  s   
€þýzPythonSymlink.__exit__c           	      C   sx   dd l }|g|¢}|j||j|j|d�}| ¡ }|j|kr:tr2tt|d ƒƒ tt|d ƒtj	d� t
d |j¡ƒ‚|S )Nr   )r~   rg  Úenvr   rC  z'unexpected return code: {0} (0x{0:08X}))rÔ  rÕ  ÚPIPEÚcommunicateÚ
returncoder   rƒ   Úreprr   rg  ÚRuntimeErrorr¼   )	r[   Úpythonrˆ   r…  rˆ  rÔ  ÚcmdÚprÏ  rP   rP   rQ   Ú_call°  s   

ÿ

ÿzPythonSymlink._callr   )rˆ  c                G   s   |   | j|d |¡S rU   )rŽ  rh  ©r[   rˆ  rˆ   rP   rP   rQ   Ú	call_real¾  s   zPythonSymlink.call_realc                G   s   |   | j|| j|¡S rU   )rŽ  re  rj  r�  rP   rP   rQ   Ú	call_linkÁ  s   zPythonSymlink.call_linkrU   )rL   rM   rN   rO   rZ   r   r¤   rk  r}  r„  rŽ  r�  r‘  rP   rP   rP   rQ   rb  s  s    


rb  c                 C   s$   t  pt}d}|r| S t |¡| ƒS )z;Skip decorator for tests not run in (non-extended) PGO taskz#Not run for (non-extended) PGO task)r=   ÚPGO_EXTENDEDrf   rß   )r�  ÚokrV   rP   rP   rQ   Úskip_if_pgo_taskÅ  s   
r”  rP   )r  c                C   s>   t t| ƒƒt t|ƒƒ }|r|t |ƒ8 }t dd„ |D ƒƒ}|S )a  Returns 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                 s   s(   � | ]}|  d ¡r| d¡r|V  qdS )r  Ú__N)r¥   Úendswith)r#  r¶  rP   rP   rQ   Ú	<genexpr>Ö  s   € ÿÿz&detect_api_mismatch.<locals>.<genexpr>)r+  Údir)Úref_apiÚ	other_apir  Úmissing_itemsrP   rP   rQ   r'   Ì  s
   r'   c                 C   s˜   |du r	|j f}nt|tƒr|f}t|ƒ}t|ƒD ])}| d¡s$||v r%qt||ƒ}t|ddƒ|v s=t|dƒsBt|tj	ƒsB| 
|¡ q|  |j|¡ dS )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  rM   )rL   rŸ  rº   r+  r˜  r¥   rw   r¢   ÚtypesÚ
ModuleTypeÚaddÚassertCountEqualÚ__all__)Ú	test_caser?  Úname_of_moduleÚextraÚnot_exportedÚexpectedr{   rz   rP   rP   rQ   r(   Û  s"   )


ÿ
þ
€r(   c                 C   s–   zdd l }W n
 ty   Y d S w | |j|jB |jB |jB ¡ t|dƒrG|j|j	|j
fD ]}| r@| ||j¡ | ||j¡ q-| |d¡ q-d S d S )Nr   ÚCrtSetReportMode)Úmsvcrtr  ÚSetErrorModeÚSEM_FAILCRITICALERRORSÚSEM_NOALIGNMENTFAULTEXCEPTÚSEM_NOGPFAULTERRORBOXÚSEM_NOOPENFILEERRORBOXr¢   ÚCRT_WARNÚ	CRT_ERRORÚ
CRT_ASSERTr¦  ÚCRTDBG_MODE_FILEÚCrtSetReportFileÚCRTDBG_FILE_STDERR)r   r§  r¶  rP   rP   rQ   Úsuppress_msvcrt_asserts  s(   ÿÿþý
úr³  c                   @   s(   e Zd ZdZdZdZdd„ Zdd„ ZdS )r:   z«Try 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           
   	   C   sš  t j d¡rOzddl}W n
 ty   Y dS w | ¡ | _| | j|jB ¡ t	|dƒrMi | _
|j|j|jfD ]}| ||j¡}| ||j¡}||f| j
|< q5| S z	ddl}|| _W n tyd   d| _Y nw | jdur�z| j | jj¡| _| j | jjd| jd f¡ W n ttfyŽ   Y nw t jdkrËddl}g d¢}|j||j|jd�}|� | ¡ d }	W d  ƒ n1 s¹w   Y  |	 ¡ d	krËtd
ddd� | S )zÔOn 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   Nr¦  r   r–   )z/usr/bin/defaultsrW  zcom.apple.CrashReporterÚ
DialogType)r~   rg  s	   developerz:this test triggers the Crash Reporter, that is intentionalrõ   T)ÚendrÓ  )r   r¤   r¥   r§  r  ÚGetErrorModeÚ	old_valuer¨  r«  r¢   Ú	old_modesr­  r®  r¯  r¦  r°  r±  r²  rÍ   Ú	getrlimitÚRLIMIT_COREÚ	setrlimitrØ   r‚   rÔ  rÕ  r†  r‡  Ústriprƒ   )
r[   r§  Úreport_typeÚold_modeÚold_filerÍ   rÔ  rŒ  Úprocr~   rP   rP   rQ   r}  4  sh   ÿ

þÿÿ#à

ÿ
ÿÿ
þÿÿzSuppressCrashReport.__enter__c              	   G   s®   | j du rdS tj d¡r6ddl}| | j ¡ | jr2| j ¡ D ]\}\}}| ||¡ | 	||¡ qdS dS | j
durUz| j
 | j
j| j ¡ W dS  ttfyT   Y dS w dS )zARestore Windows ErrorMode or core file behavior to initial value.NrŒ   r   )r·  r   r¤   r¥   r§  r¨  r¸  r(  r¦  r±  rÍ   r»  rº  rØ   r‚   )r[   Ú
ignore_excr§  r½  r¾  r¿  rP   rP   rQ   r„  v  s$   
ý
ÿýzSuppressCrashReport.__exit__)rL   rM   rN   rO   r·  r¸  r}  r„  rP   rP   rP   rQ   r:   +  s    Br:   c              	      sp   t ˆˆƒ d‰ zˆjˆ ‰W n ttfy   t ˆˆdƒ‰Y nw d‰ ‡ ‡‡‡fdd„}|  |¡ tˆˆ|ƒ dS )zóOverride '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'.

    FNTc                      s"   ˆ r
t ˆˆˆƒ d S tˆˆƒ d S rU   )r_  rH  rP   ©Úattr_is_localÚ	attr_nameÚobject_to_patchr·  rP   rQ   Úcleanup¡  s   zpatch.<locals>.cleanup)rw   Ú__dict__rx   ÚKeyErrorÚ
addCleanupr_  )Útest_instancerÅ  rÄ  Ú	new_valuerÆ  rP   rÂ  rQ   Úpatch‹  s   

ÿ
rÌ  c              
   c   s6   � z| dd… }dV  W || dd…< dS || dd…< w )z-Like unittest.mock.patch.dict, but for lists.NrP   )ÚorigÚsavedrP   rP   rQ   Ú
patch_list­  s
   €rÏ  c                 C   sD   zddl }W n	 ty   Y n
w | ¡ rt d¡‚ddl}| | ¡S )zi
    Run code in a subinterpreter. Raise unittest.SkipTest if the tracemalloc
    module is enabled.
    r   NzUrun_in_subinterp() cannot be used if tracemalloc module is tracing memory allocations)Útracemallocr  Ú
is_tracingrf   ry   Ú	_testcapiÚrun_in_subinterp)ÚcoderÐ  rÒ  rP   rP   rQ   rÓ  ·  s   ÿ

rÓ  c                    sH   G ‡ ‡fdd„d|ƒ}d‰ |||Ž ƒ‰|   ttˆ¡ tƒ  |  ˆ ¡ d S )Nc                       s   e Zd Z‡ ‡fdd„ZdS )z%check_free_after_iterating.<locals>.Ac                    s(   d‰ zt ˆƒ W d S  ty   Y d S w r  )ÚnextÚStopIterationr^   ©ÚdoneÚitrP   rQ   Ú__del__Í  s   ÿz-check_free_after_iterating.<locals>.A.__del__N)rL   rM   rN   rÚ  rP   r×  rP   rQ   ÚAÌ  s    rÛ  F)ÚassertRaisesrÖ  rÕ  rn  Ú
assertTrue)r�  Úiterr8  rˆ   rÛ  rP   r×  rQ   Úcheck_free_after_iteratingË  s   	rß  c                 C   s¾   ddl m}m}m}m} | ¡ }| |¡ |jdkr,z| ¡  W n |j	y+   Y dS w |j
D ]-}| r8|| vr8q/t||ƒ}| rJ|dusIJ d| ƒ‚n|sMq/| |d ¡du r\|d   S q/dS )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   )Ú	ccompilerr÷   ÚspawnrW   ÚmsvcNz%the '%s' executable is not configured)Ú	distutilsrà  r÷   rá  rW   Únew_compilerÚcustomize_compilerÚcompiler_typeÚ
initializeÚDistutilsPlatformErrorÚexecutablesrw   Úfind_executable)Ú	cmd_namesrà  r÷   rá  rW   Úcompilerr{   rŒ  rP   rP   rQ   r>   Þ  s.   


ÿ


ÿÿ÷r>   c                 C   sH   d}t r| |k rtd u rdd l}| ddg¡ ¡ dkatr|} t | ¡S )Ngñhãˆµøä>r   Úgetpropzro.kernel.qemuó   1)r.   Ú_is_android_emulatorrÔ  Úcheck_outputr¼  r   r1   )ÚintervalÚminimum_intervalrÔ  rP   rP   rQ   r1   ÿ  s   ÿÿ
r1   c               
   c   s^   � dd l } tj ¡ }|  ¡ }z|  ¡  d V  W |r"| j|dd� d S d S |r.| j|dd� w w )Nr   T)rD  Úall_threads)Úfaulthandlerr   rA  ÚfilenoÚ
is_enabledrp  rq  )rô  Úfdrö  rP   rP   rQ   Údisable_faulthandler  s   €
ÿÿrø  c                   @   rÉ  )	ÚSaveSignalszÆ
    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              	   C   sZ   dd l }|| _ | ¡ | _dD ]}zt||ƒ}W n	 ty    Y qw | j |¡ qi | _d S )Nr   )ÚSIGKILLÚSIGSTOP)ÚsignalÚvalid_signalsÚsignalsrw   rx   r~  Úhandlers)r[   rü  ÚsignameÚsignumrP   rP   rQ   rZ   )  s   
ÿ
zSaveSignals.__init__c                 C   s0   | j D ]}| j |¡}|d u rq|| j|< qd S rU   )rþ  rü  Ú	getsignalrÿ  ©r[   r  ÚhandlerrP   rP   rQ   Úsave6  s   
÷zSaveSignals.savec                 C   s&   | j  ¡ D ]\}}| j ||¡ qd S rU   )rÿ  r(  rü  r  rP   rP   rQ   ÚrestoreB  s   ÿzSaveSignals.restoreN)rL   rM   rN   rO   rZ   r  r  rP   rP   rP   rQ   rù     s
    rù  c                  C   s   dd l } | jS r  )rÒ  ÚWITH_PYMALLOC)rÒ  rP   rP   rQ   Úwith_pymallocG  s   r  c                   @   rT  )Ú
_ALWAYS_EQz+
    Object that is equal to anything.
    c                 C   r9  r  rP   ©r[   ÚotherrP   rP   rQ   Ú__eq__P  rë  z_ALWAYS_EQ.__eq__c                 C   r9  ©NFrP   r
  rP   rP   rQ   Ú__ne__R  rë  z_ALWAYS_EQ.__ne__N)rL   rM   rN   rO   r  r  rP   rP   rP   rQ   r	  L  s    r	  c                   @   rÉ  )	Ú	_NEVER_EQz/
    Object that is not equal to anything.
    c                 C   r9  r  rP   r
  rP   rP   rQ   r  [  rë  z_NEVER_EQ.__eq__c                 C   r9  r  rP   r
  rP   rP   rQ   r  ]  rë  z_NEVER_EQ.__ne__c                 C   r9  )Nr   rP   r^   rP   rP   rQ   Ú__hash___  rë  z_NEVER_EQ.__hash__N)rL   rM   rN   rO   r  r  r  rP   rP   rP   rQ   r  W  s
    r  c                   @   rT  )Ú_LARGESTz?
    Object that is greater than anything (except itself).
    c                 C   ó
   t |tƒS rU   )rŸ  r  r
  rP   rP   rQ   r  i  r€   z_LARGEST.__eq__c                 C   r9  r  rP   r
  rP   rP   rQ   Ú__lt__k  rë  z_LARGEST.__lt__N)rL   rM   rN   rO   r  r  rP   rP   rP   rQ   r  d  ó    r  c                   @   rT  )Ú	_SMALLESTz<
    Object that is less than anything (except itself).
    c                 C   r  rU   )rŸ  r  r
  rP   rP   rQ   r  u  r€   z_SMALLEST.__eq__c                 C   r9  r  rP   r
  rP   rP   rQ   Ú__gt__w  rë  z_SMALLEST.__gt__N)rL   rM   rN   rO   r  r  rP   rP   rP   rQ   r  p  r  r  c                  C   s   ddl } | jjS )zDReturn the global event loop policy if one is set, else return None.r   N)Úasyncio.eventsÚeventsÚ_event_loop_policy)ÚasynciorP   rP   rQ   Úmaybe_get_event_loop_policy|  s   r  )é    é@   c                 C   sÄ   | |}}dd l }| ¡ �K}| ¡ d }t|dƒ|_| |¡}|d | | }|| }	||	 }
||
 }||d  |d | |  |	d|	   }t|ƒt| ¡ ƒfW  d   ƒ S 1 s[w   Y  d S )Nr   r�   é   r   )ÚdecimalÚlocalcontextÚ
bit_lengthÚmaxÚprecÚDecimalrÀ  Úsqrt)ÚnbinsÚnballsr~  rµ  r  ÚctxÚbitsr!  Úp1emptyÚ	meanemptyÚoccupiedÚ
collisionsÚvarrP   rP   rQ   Úcollision_stats‰  s   


($õr/  c                   @   s0   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
S )Úcatch_unraisable_exceptionað  
    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                 C   s   d | _ d | _d S rU   )Ú
unraisableÚ	_old_hookr^   rP   rP   rQ   rZ   Ä  s   
z#catch_unraisable_exception.__init__c                 C   s
   || _ d S rU   )r1  )r[   r1  rP   rP   rQ   Ú_hookÈ  s   
z catch_unraisable_exception._hookc                 C   s   t j| _| jt _| S rU   )r   Úunraisablehookr2  r3  r^   rP   rP   rQ   r}  Í  ré  z$catch_unraisable_exception.__enter__c                 G   s   | j t_| `d S rU   )r2  r   r4  r1  )r[   Úexc_inforP   rP   rQ   r„  Ò  s   z#catch_unraisable_exception.__exit__N)rL   rM   rN   rO   rZ   r3  r}  r„  rP   rP   rP   rQ   r0  «  s    r0  rE  c                C   s$  t jdkrcddl}|du rt}t ¡ }d}d}	 t  | t j¡\}}|dkr&n<t ¡ | }	|	|krUzt  | |j	¡ t  | d¡ W n	 t
yH   Y nw td| › d|	d	›d
�ƒ‚t|d |ƒ}t |¡ qnt  | d¡\}}t  |¡}
|
|kr‚td| › d|
› d|› d�ƒ‚|| kr�td|› d| › �ƒ‚dS )aˆ  
    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   Ngü©ñÒMbP?ri  Tzprocess z is still running after z.1fz secondsr�   z exited with code z, but exit code z is expectedzpid z != pid )rl   r{   rü  rF   rl  Ú	monotonicrD  rE  Úkillrú  r‚   ÚAssertionErrorÚminrm  Úwaitstatus_to_exitcode)rË  ÚexitcoderF  rü  Út0rm  Ú	max_sleepÚpid2rG  ÚdtÚ	exitcode2rP   rP   rQ   Úwait_process×  sF   
þ

ÿ
í

ÿÿrB  c               
   C   sf   ddl m}  | dƒ | dƒ}tjdkr1z	|jdd� W dS  ty0 } zt d|›�¡‚d}~ww dS )	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_helperrC  r   r¤   ÚLockr‚   rf   ry   )rC  ÚsynchronizeÚexcrP   rP   rQ   Ú*skip_if_broken_multiprocessing_synchronize  s   
€ÿúrJ  éK   c              	   c   s8   � t  ¡ }zt  | ¡ d V  W t  |¡ d S t  |¡ w rU   )r   ÚgetrecursionlimitÚsetrecursionlimit)Ú	max_depthÚoriginal_depthrP   rP   rQ   Úinfinite_recursion$  s   €
rP  c                 O   s\   |j }|j}|dkr|› d|› �}n|› }dt |¡› d�}| jt||g|¢R i |¤Ž dS )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)rM   rL   r¼  rw  r/  r   )r5  Útprˆ   r®  Úmodr{   ÚqualnamerV   rP   rP   rQ   r*   .  s    r*   r?  ÚlikeÚreturnc                C   s,   t ƒ }tjdt| |dt|ƒ› d� d� |S )Nr  ú
(?#supportú))r¨  r?  rU  )ÚobjectrÐ  ÚfilterwarningsÚDeprecationWarningr  )r?  rU  ÚtokenrP   rP   rQ   Úignore_deprecations_from>  s   ür]  Útokensc            	      G   s¬   | st dƒ‚g }tdd„ | D ƒƒ}tjD ]-\}}}}}|dkr7|tu r7t|tjƒr-|j}n|p0d}| 	|¡r7q| 
|||||f¡ qtj|krT|tjd d …< t ¡  d S d S )Nz<Provide token or tokens returned by ignore_deprecations_fromc                 s   s    � | ]}d t |ƒ› d�V  qdS )rW  rX  N)r  )r#  r\  rP   rP   rQ   r—  N  s   € z-clear_ignored_deprecations.<locals>.<genexpr>r  rõ   )rØ   rÖ   rÐ  Úfiltersr[  rŸ  r¼  ÚPatternrk   r–  rS  Ú_filters_mutated)	r^  Únew_filtersr–  ÚactionrU  r¨  r?  r,  rV   rP   rP   rQ   Úclear_ignored_deprecationsI  s    

þrd  c              	   c   s8   � t  ¡ }zt  | ¡ dV  W t  |¡ dS t  |¡ w )z>Temporarily change the integer string conversion length limit.N)r   Úget_int_max_str_digitsÚset_int_max_str_digits)Ú
max_digitsÚcurrentrP   rP   rQ   Úadjust_int_max_str_digits]  s   €
ri  c                   C   s   dd„ t ddƒD ƒdg S )z�Returns a list of C0 control characters as strings.
    C0 control characters defined as the byte range 0x00-0x1F, and 0x7F.
    c                 S   s   g | ]}t |ƒ‘qS rP   )Úchr)r#  ÚcrP   rP   rQ   r%  l  r&  z)control_characters_c0.<locals>.<listcomp>r   r  ú)ÚrangerP   rP   rP   rQ   Úcontrol_characters_c0h  s   rn  rU   )r  )r  )r  )r  )rõ   )T)NNr  )NrP   rP   )F)rP   )rK  )ÁrO   rL   r  Ú
contextlibrë   rl   r¼  r…   r   r÷   rl  rœ  rf   rÐ  Ú
testresultr   rÒ  r   r   rC   r¤   rÞ   rD   rE   rF   r¹   r
   r   rT   r   ry   r   r%   r&   r"   r   r   r   rÃ  r  r	   r}   r   r   rŠ   r£   r   r   rà   r   r   r   r+   r,   r  r   ÚSOCK_MAX_SIZEr	  rÀ  Ú__getformat__r¥   r#   r$   r   r   r   Úrequires_legacy_unicode_capir-   r¢   r.   r0   ÚTEST_HTTP_URLr=   r’  rm   rn   rd  ro   ÚTEST_SUPPORT_DIRr  rÑ   rO  r  r6   r;   r   r2   Úcontextmanagerrc  r   r   r   rn  rs  rx  r‚  rƒ  rˆ  r†  r‰  rŽ  r�  r“  r£  r4   r<   rº  r»  rÅ  Ú_4Grâ  rÄ  r9   rÊ  r   r    r   rê  rì  r!   rî  rð  r/   rû  rü  rÿ  r  r  r  r!  r  r  r$  r   r   r:  rø   ÚMISSING_C_DOCSTRINGSÚHAVE_DOCSTRINGSÚrequires_docstringsr   rC  rF  r3   r7   r5   rP  rS  rY  r8   r^  r)   rb  r”  r'   r(   r³  r:   rÌ  rÏ  rÓ  rß  r>   rï  r1   rø  rù  r  r	  r?   r  r@   Útotal_orderingr  rA   r  rB   r  Ú	hash_infoÚwidthÚ	NHASHBITSr/  r0  rB  rJ  rP  r*   rº   r]  rd  ri  rõ  rn  rP   rP   rP   rQ   Ú<module>   s    ÿ,

	M			þÿ
7
		


#!0

! ÿ
þÿÿ

"Rÿ;`"
	 
'			",4
	 
