a  zek @s* edkredddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZgdZdZej dkre d krd Zd Zd Zd Z Gddde!Z"Gddde"Z#Gddde#Z$Gddde"Z%Gdddej&Z'ej(dpddZ)ddZ*dqddd d!Z+d"d#Z,d$d%Z-d&d'Z.drd(d)Z/d*d+Z0dZ1dZ2da3da4dZ5dZ6da7d,d-Z8d.d/Z9d0d1Z:d2d3Z;ej d9d:Z?d;d<Z@d=d>ZAne jBZ>e jCZ?d?d<Z@d@d>ZAdAdBZBdCdDZCdEdFZDdGdHZEdIdJZFdKdLZGdMdNZHdtdOdPZIdQdRZJdSdTZKdUdVZLdWdXZMdYdZZNd[ZOd\ZPeQeRSd]d?Zdad@dAZej(dBdCZdDdEZGdFdGdGZdHdIZGdJdKdKZGdLdMdMZeZGdNdOdOZeZejGdPdQdQZeZejGdRdSdSZeZdTdUZ ej j Z dVdWZ GdXdYdYZGdZd[d[Zdd\d]d^Zd_d`ZdadbZej(dcddZdedfZej(ddhdiZeeedjdkdlZeddmdndoZdS(z test.supportz.support must be imported from the test packageN)get_test_runner)^ PIPE_MAX_SIZEverbose max_memuse use_resourcesfailfastError TestFailed TestDidNotRunResourceDenied import_moduleimport_fresh_module CleanImportunloadforgetrecord_original_stdoutget_original_stdoutcaptured_stdoutcaptured_stdincaptured_stderrTESTFNSAVEDCWDunlinkrmtreetemp_cwdfindfilecreate_empty_file can_symlinkfs_is_case_insensitiveis_resource_enabledrequiresrequires_freebsd_versionrequires_linux_versionrequires_mac_vercheck_syntax_errorcheck_syntax_warningTransientResourcetime_outsocket_peer_resetioerror_peer_resetBasicTestRunner run_unittest run_doctestskip_unless_symlink requires_gzip requires_bz2 requires_lzma bigmemtestbigaddrspacetest cpython_only get_attributerequires_IEEE_754skip_unless_xattr requires_zlibanticipate_failureload_package_testsdetect_api_mismatch check__all__skip_if_buggy_ucrt_strfptimeignore_warnings is_jython is_androidcheck_impl_detail unix_shellsetswitchintervalopen_urlresource temp_umask reap_childrenthreading_setupthreading_cleanup reap_threads start_threadscheck_warningscheck_no_resource_warningcheck_no_warningsEnvironmentVarGuardrun_with_locale swap_item swap_attrMatcher set_memlimitSuppressCrashReportsortdict run_with_tzPGOmissing_compiler_executablefd_count ALWAYS_EQNEVER_EQLARGESTSMALLESTLOOPBACK_TIMEOUTINTERNET_TIMEOUT SHORT_TIMEOUT LONG_TIMEOUTg@win32ZARM gN@g>@gr@c@s eZdZdS)r N__name__ __module__ __qualname__rhrhI/opt/bitninja-python-dojo/embedded/lib/python3.9/test/support/__init__.pyr vsr c@s eZdZdS)r Nrdrhrhrhrir ysr cs$eZdZfddZddZZS)TestFailedWithDetailscs&||_||_||_t|||dSN)msgerrorsfailuressuper__init__)selfrlrmrn __class__rhrirp~szTestFailedWithDetails.__init__cCs|jSrkrlrqrhrhri__str__szTestFailedWithDetails.__str__)rerfrgrprv __classcell__rhrhrrrirj|s rjc@s eZdZdS)r Nrdrhrhrhrir sr c@s eZdZdS)r Nrdrhrhrhrir sr TccsL|rBt$tddtdVWdqH1s60YndVdS)Nignorez.+ (module|package))warningscatch_warningsfilterwarningsDeprecationWarningrxrhrhri_ignore_deprecated_importss &r~csfdd}|S)Ncstfdd}|S)NcsPt4tjdd|g|Ri|WdS1sB0YdS)Nrxcategory)ryrz simplefilter)rqargskwargs)rtestrhriwrappers z3ignore_warnings..decorator..wrapper functoolswraps)rrrrri decoratorsz"ignore_warnings..decoratorrh)rrrhrrir>s r>Frh) required_onc Cst|pzt|WWdStyh}z,tjt|rFt t |WYd}~n d}~00Wdn1s~0YdSrk) r~ importlibr ImportErrorsysplatform startswithtupleunittestSkipTeststr)name deprecatedrrlrhrhrir s r cCsLi}tdd|D}ttjD]&}||vs6||r tj|||<q |S)Ncss|]}|dVqdS).Nrh).0rrhrhri z+_save_and_remove_modules..)rlistrmodulesrpop)names orig_modulesprefixesmodnamerhrhri_save_and_remove_moduless rcCs|r tjSddS)NcSs|Srkrhfrhrhrirz$anticipate_failure..)rZexpectedFailure)Z conditionrhrhrir9sr9cCsF|dur d}tjtjtjt}|j|||d}|||S)Nztest*)Z start_dirZ top_level_dirpattern)ospathdirname__file__ZdiscoverZaddTests)Zpkg_dirloaderZstandard_testsrZtop_dirZ package_testsrhrhrir:s  r:c Cst|t|}t|}|h||}t|}|D]}dtj|<q4z|z|D] }t|qLWn6tyYWt|tj|WddS0t |Wt|tj|WdSt|tj|0Wdn1s0YdSrk) r~rrrr __import__rupdaterr )rZfreshZblockedrrrrrhrhrirs0      rcCs<zt||}Wn$ty2td||fYn0|SdS)Nzobject %r has no attribute %r)getattrAttributeErrorrr)objrZ attributerhrhrir5!s  r5cCs|adSrk)_original_stdout)stdoutrhrhrir6srcCs tptjSrk)rrrrhrhrhrir:srcCs$z tj|=WntyYn0dSrk)rrKeyError)rrhrhrir=s  rc Gsxz ||WStyr}zPtdkrHtd|jj|ftd|j|ft|tj||WYd}~Sd}~00dS)Nz%s: %sz re-run %s%r) OSErrorrprintrsrerchmodstatS_IRWXU)rfuncrerrrhrhri _force_runCs rwincCs|||r|}ntj|\}}|p(d}d}|dkrjt|}|rJ|sVn||vsVdSt||d9}q.tjd|tdddS)NrMbP?g?rz)tests may fail, delete still pending for  stacklevel) rrsplitlistdirtimesleeprywarnRuntimeWarning)rpathnamewaitallrrtimeoutLrhrhri_waitforNs    rcCsttj|dSrk)rrrfilenamerhrhri_unlinkosrcCsttj|dSrk)rrrmdirrrhrhri_rmdirrsrcs,fddt|ddtdd|dS)Nc st|tj|D]}tj||}zt|j}Wn>tyn}z&td||ft j dd}WYd}~n d}~00t |rt |ddt|tj|qt|tj|qdS)Nz-support.rmtree(): os.lstat(%r) failed with %sfilerTr)rrrrjoinlstatst_moderrr __stderr__rS_ISDIRrrr)rrfullnamemodeexc _rmtree_innerrhrirvs  _rmtree.._rmtree_innerTrcSst|tj|Srk)rrr)prhrhrirrz_rmtree..)rrrhrri_rmtreeus rcCs\z ddl}WntyYn:0|t|d}|jj||t|}|rX|d|S|S)Nrr)ctypesrZcreate_unicode_bufferlenwindllZkernel32ZGetLongPathNameW)rrbufferlengthrhrhri _longpaths    rcsNddl}z||WdSty*Yn0fdd|t|dS)Nrc s~t|tj|D]j}tj||}zt|j}WntyFd}Yn0t |rj|t|tj |qt|tj |qdSNr) rrrrrrrrrrrr)rrrrrrhrirs   r)shutilrrrr)rrrhrrirs   cCs|Srkrhrrhrhrirsc Cs(z t|Wnttfy"Yn0dSrk)rFileNotFoundErrorNotADirectoryErrorrrhrhrirs rcCs$z t|WntyYn0dSrk)rrrrhrhrirs  rcCs$z t|WntyYn0dSrk)rrrrhrhrirs  rcCsBtj|}tjtj|}tj||d}t|||S)Nc) rutilcache_from_sourcerrrabspathrrename)sourceZpyc_fileZup_oneZ legacy_pycrhrhrimake_legacy_pycs   rcCsTt|tjD]@}tj||d}t|ddD]}ttjj||dq4qdS)Nz.pyr)rr) optimization) rrrrrrrrr)rrroptrhrhrirs   rc sttdrtjSd}tjdr0tr0d}nBtjdrddlddld}d}Gfdddj }j j }| }|s |}j}||||||}|sƈ t|j|@sd}ntjd krrdd lm} mm} m } dd lm} | | d } | dkr,d }nFGfddd| }|}| |}| |dksn| |dkrrd}|sz.ddlm}|}| |!|"Wn^t#y}zDt$|}t%|dkr|ddd}d&t'|j(|}WYd}~n d}~00|t_)| t_tjS)Nresultrz(gui is not available on Windows IoT Corerrcs.eZdZdjjfdjjfdjjfgZdS)z*_is_gui_available..USEROBJECTFLAGSZfInheritZ fReserveddwFlagsN)rerfrgwintypesZBOOLDWORD_fields_rh)rrhriUSEROBJECTFLAGSs   rz,gui not available (WSF_VISIBLE flag not set)darwin)cdllc_intpointer Structure) find_libraryZApplicationServicesz0gui tests cannot run without OS X window managercseZdZdfdfgZdS)z._is_gui_available..ProcessSerialNumberZ highLongOfPSNZ lowLongOfPSNN)rerfrgrrh)rrhriProcessSerialNumbersrz#cannot run without OS X gui process)Tk2z [...]zTk unavailable due to {}: {})*hasattr_is_gui_availablerrrrZ win32_is_iotrZctypes.wintypesrrZuser32ZGetProcessWindowStationZWinErrorrrZGetUserObjectInformationWZbyrefZsizeofboolrrrrZ ctypes.utilrZ LoadLibraryZCGMainDisplayIDZGetCurrentProcessZSetFrontProcesstkinterrZwithdrawrZdestroy Exceptionrrformattyperereason)rZ UOI_FLAGSZ WSF_VISIBLErdllhZuofZneededresrrrrZ app_servicesrZpsnZpsn_prrooteZ err_stringrh)rrrirsr         rcCstdup|tvSrk)rresourcerhrhrir -sr cCs<t|s |durd|}t||dkr8ts8ttjdS)Nz"Use of the %r resource not enabledgui)r r rr)rrlrhrhrir!5s r!cCsddl}dtt|}|ddd}||krrzttt|d}Wnt yfd}Yqv0||k}nd}t ||d|d|S)Nrr-rFz version z or higher required, not ) rrmaprreleasersystemrint ValueErrorrskipIf)sysname min_versionrmin_version_txt version_txtversionskiprhrhri_requires_unix_version>s      r$cGs td|S)NZFreeBSDr$rrhrhrir"Ysr"cGs td|S)NZLinuxr%r&rhrhrir#bsr#csfdd}|S)Ncs"tfdd}|_|S)Ncsztjdkrltd}zttt|d}Wnty@Yn,0|krldtt }t d||f|i|S)Nrrrz&Mac OS X %s or higher required, not %s) rrZmac_verrrrrrrrrr)rkwr!r"r )rrrhrirss   z4requires_mac_ver..decorator..wrapper)rrrrrr&rrirrsz#requires_mac_ver..decoratorrh)rrrhr&rir$ks r$cstfdd}|S)Nc sTz|i|Wn<tyN}z$dt|vr8tdWYd}~n d}~00dS)NZCERTIFICATE_VERIFY_FAILEDz.system does not contain necessary certificates)rrrr)rrrrrhridecs   z&system_must_validate_cert..decr)rr*rhrrisystem_must_validate_certsr+i@iZdoubleZIEEEztest requires IEEE 754 doubles requires zlibcCs0z ddl}Wnty"d}Yn0t||Sr)zlibrr skipUnless)rr-rhrhrir8s    r8 requires gzipcCs0z ddl}Wnty"d}Yn0t||Sr)gziprrr.)rr0rhrhrir/s    r/ requires bz2cCs0z ddl}Wnty"d}Yn0t||Sr)bz2rrr.)rr2rhrhrir0s    r0 requires lzmacCs0z ddl}Wnty"d}Yn0t||Sr)lzmarrr.)rr4rhrhrir1s    r1javagetandroidapilevelz/system/bin/shz/bin/shz$testz@testz {}_{}_tmpzhttp://www.pythontest.netr) æuİuŁuφuКuאu،uتuก u€u -àòɘŁğrZNFDntru-共Ł♡ͣztWARNING: The filename %r CAN be encoded by the filesystem encoding (%s). Unicode filename tests may not be effectives-surrogateescape)swr:sssc csddl}d}|dur.|}d}tj|}nZzt|d}WnFty}z.|sVtjd|d|t ddWYd}~n d}~00|rt }z"|VW|r|t krt |n|r|t krt |0dS)NrFTz5tests may fail, unable to create temporary directory : r) tempfilemkdtemprrrealpathmkdirrryrrgetpidr)rquietr>Z dir_createdrpidrhrhritemp_dires6  rEc cst}zttj|WnFtyd}z.|s4tjd|d|tddWYd}~n d}~00ztVWt|n t|0dS)NzBtests may fail, unable to change the current working directory to r<r=r) rgetcwdchdirrr@rryrr)rrCZ saved_dirrrhrhri change_cwds  rHtempcwdc csbt||dB}t||d}|VWdn1s60YWdn1sT0YdS)N)rrC)rC)rErH)rrCZ temp_pathZcwd_dirrhrhrirsrumaskc cs0t|}zdVWt|n t|0dSrk)rrJ)rJZoldmaskrhrhrirEs rEdatacCsXtjdkrdSddl}d}|d}|\}}t||dt|td|dS)Nrrz 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)rrrget_terminal_sizercenter)Z test_namerrlZdetailZpadding_rhrhridarwin_malloc_err_warnings   rOcCsbtj|r|S|dur&tj||}tgtj}|D]&}tj||}tj|r6|Sq6|Srk)rrisabsr TEST_HOME_DIRrexists)rZsubdirrdnfnrhrhrirs  rcCs(t|tjtjBtjB}t|dSrk)ropenO_WRONLYO_CREATO_TRUNCclose)rfdrhrhrirsrcCs,t|}dd|D}d|}d|S)NcSsg|] }d|qS)z%r: %rrh)rZpairrhrhri rzsortdict..z, z{%s})sorteditemsr)dictr]Z reprpairsZ withcommasrhrhrirUs  rUcCs<ttd}z|W|ttS|tt0dS)Nwb)rUrfilenorYrrrhrhri make_bad_fds ralinenooffsetcCs|t|}t|ddWdn1s.0Y|j}||j|dur`||j|||j|dur||j|dS)Nz exec)ZassertRaisesRegex SyntaxErrorcompile exceptionassertIsNotNonerc assertEqualrd)testcase statementerrtextrcrdcmrrhrhrir% s*  r%cCstjdd(}tdtt|ddWdn1s:0Y|t|d||\}|t|j t|j |r| t |j |||j d||j|dur||j|tjdd.}tdtt|||||dWdn1s0Y||gdS) NTrecordalwaysz rererrorrb)ryrzr SyntaxWarningrgrjr assertTrue issubclassrZ assertRegexrmessagerrircr%)rkrlrmrcrdwarnsrrhrhrir&s$ *  $r&c sddl}ddl}z ddl}Wnty2d}Yn0dd|j|ddd}tj t |}fdd}tj |r||}|dur|St |tdtrtd |td |j} |r| jd | j|td }|r |jd dkr |j|d}z\t|d4} |} | r<| | |} q Wdn1sR0YW|n |0||}|dur|Std|dS)Nrcheckr/csDt|gRi}dur"|S|r8|d|S|dSr)rUseekrY)rTrrrxr'rhricheck_valid_file?s z*open_urlresource..check_valid_fileZurlfetchz fetching %s ...r)zAccept-Encodingr0rzContent-Encodingr0)fileobjr_zinvalid resource %r)Zurllib.request urllib.parser0rrparseurlparserrrr TEST_DATA_DIRrRrr!rrrZrequestZ build_openerZ addheadersappendrUr_ZheadersgetZGzipFilereadwriterYr ) urlrr'urllibr0rrTr}ropeneroutsrhr|rirD2sD          . rDc@s0eZdZddZddZeddZddZd S) WarningsRecordercCs||_d|_dSr _warnings_last)rqZ warnings_listrhrhrirplszWarningsRecorder.__init__cCsDt|j|jkr t|jd|S|tjjvr0dStd||fdS)Nrzz%r has no attribute %r)rrrrryWarningMessage_WARNING_DETAILSr)rqattrrhrhri __getattr__ps  zWarningsRecorder.__getattr__cCs|j|jdSrkrrurhrhrirywszWarningsRecorder.warningscCst|j|_dSrk)rrrrurhrhrireset{szWarningsRecorder.resetN)rerfrgrprpropertyryrrhrhrhrirhs  rc cstd}|jd}|r"|tjdd*}tjddt |VWdn1s^0Yt |}g}|D]j\}}d} |ddD]8}|j } t |t| t jrt| j|rd} ||q| sx|sx|||jfqx|rtd|d |rtd |d dS) NrZ__warningregistry__TroryrqFzunhandled warning %srz)filter (%r, %s) did not catch any warning)r _getframe f_globalsrclearryrzrrrrrvrematchrIrursremoverreAssertionError) filtersrCframeregistrywZreraisemissingrlcatseenwarningrhrhri_filterwarningss4  (   rcOs.|d}|s$dtff}|dur$d}t||S)NrCrT)rWarningr)rrrCrhrhrirKs   rKccs\tjdd0}tjd||ddV|r.tWdn1sB0Y||gdS)NTrorq)rvr)ryrzr{ gc_collectrj)rkrvrforce_gcrwrhrhrirMs$rMccs8t|tdddVWdn1s*0YdS)NT)rr)rMResourceWarning)rkrhrhrirLsrLc@s$eZdZddZddZddZdS)rcGsJtj|_|D]4}|tjvrtj|}|j|kr|n|r<|0dSr)r isenableddisableenable)rZhave_gcrhrhri disable_gcs rcCs6tdp d}d}|D]}|dr|}q|dvS)NZ PY_CFLAGSrz-O)rz-O0z-Og) sysconfigget_config_varrr)ZcflagsZ final_optrrhrhripython_is_optimizeds   rZnPZ0nZ getobjectsZ2PZ0PncCstt|tSrk)structcalcsize_header_alignfmtrhrhri calcobjsizesrcCstt|tSrk)rr_vheaderrrrhrhri calcvobjsizesri@icCspddl}t|}t|tkr(|jt@sBt|tkrLt|jt@rL||j7}dt|||f}||||dS)Nrz&wrong size for %s: got %d, expected %d) _testinternalcapir getsizeofr  __flags___TPFLAGS_HEAPTYPE_TPFLAGS_HAVE_GCZSIZEOF_PYGC_HEADrj)rosizerrrlrhrhri check_sizeofs     rc gsz ddl}t||}||}Wn&ty4YnBd}}Yn00|D](}z|||WqvWqLYqL0qLzdVW|r|r|||n|r|r|||0dSr)localer setlocaler)ZcatstrZlocalesrrZ orig_localelocrhrhrirOs(    rOcsfdd}|S)Ncs"fdd}j|_j|_|S)Nc sz tj}Wnty&tdYn0dtjvr>tjd}nd}tjd<|zH|i|W|durttjd=n |tjd<tS|tjd<tn&|durtjd=n |tjd<t0dS)Nztzset requiredZTZ)rtzsetrrrrr)rkwdsrZorig_tz)rtzrhriinner s0           z-run_with_tz..decorator..inner)re__doc__)rrrr)rirszrun_with_tz..decoratorrh)rrrhrrirVs rVircCsdttdtd}td|tjtjB}|dur>td|ftt| d|| d }|a |t krrt }|t dkrtd|f|adS)Nr)rmgtz(\d+(\.\d+)?) (K|M|G|T)b?$zInvalid memory limit %rrr=z$Memory limit %r too low to be useful)_1M_1Grr IGNORECASEVERBOSErrfloatgrouplowerreal_max_memuseMAX_Py_ssize_t_2Gr)limitZsizesrmemlimitrhrhrirS1s" $ rSc@s$eZdZddZddZddZdS)_MemoryWatchdogcCsdjtd|_d|_dS)Nz/proc/{pid}/statm)rDF)r rrBprocfilestartedrurhrhrirpKsz_MemoryWatchdog.__init__c Cszt|jd}WnBtyR}z*td|ttj WYd}~dSd}~00|2t d}t j tj |g|t jd|_Wdn1s0Yd|_dS)Nrz!/proc not available for stats: {}zmemory_watchdog.py)rrT)rUrrryrr rrrflushr subprocessPopen executableDEVNULL mem_watchdogr)rqrrZwatchdog_scriptrhrhristartOs   &z_MemoryWatchdog.startcCs|jr|j|jdSrk)rr terminatewaitrurhrhristop_s z_MemoryWatchdog.stopN)rerfrgrprrrhrhrhrir Fsr csfdd}|S)Ncs fdd__S)Ncsj}j}tsd}n|}ts"sDt||krDtd||dtrztrzttdj||ddt}| nd}z||W|r| Sn|r| 0dS)Ni'not enough memory: %.1fG minimum needed@z* ... expected peak memory use: {peak:.1f}G)Zpeak) rmemuserrrrrr r rr)rqrrmaxsizeZwatchdog)dry_runrrrhrirss<     z.bigmemtest..decorator..wrapper)rrrrrrrrrirrszbigmemtest..decoratorrh)rrrrrhr rir2es !r2csfdd}|S)NcsDttkr8tdkr$tdkr$tdq@tdtdn|SdS)Nllz-not enough memory: try a 32-bit build insteadrr)rr rrrurrhrirsz!bigaddrspacetest..wrapperrhr!rhrrir3s r3c@seZdZddZdS)r+cCst}|||Srk)rZ TestResult)rqrrrhrhrirunszBasicTestRunner.runN)rerfrgr"rhrhrhrir+sr+cCs|Srkrh)rrhrhri_idsr#cCs:|dkrtsttjSt|r&tStd|SdS)Nrzresource {0!r} is not enabled)rrr#rr r#r rrhrhrirequires_resources  r$cCstdd|S)NT)cpython) impl_detailrrhrhrir4sr4cKsZtfi|rtS|durPt|\}}|r0d}nd}t|}|d|}t|S)Nz*implementation detail not available on {0}z%implementation detail specific to {0}z or ) rAr# _parse_guardsr\rr rrr#)rlguardsZ guardnamesdefaultrhrhrir&s  r&cCs*|sddidfSt|d}|| fS)Nr%TFr)rvalues)r(Zis_truerhrhrir's r'cKs t|\}}|t|Srk)r'rrZpython_implementationr)r(r)rhrhrirAs rAcs,ttdsStfdd}|SdS)Ngettracec s>t}z$td|i|Wt|St|0dSrk)rr+settrace)rrZoriginal_tracer)rhrirs  zno_tracing..wrapper)rrrrr(rhr)ri no_tracings  r-cCs tt|Srk)r-r4rrhrhri refcount_testsr.cCsNg}|jD]8}t|tjr0t||||q ||r ||q ||_dSrk)Z_tests isinstancer TestSuite _filter_suiter)suiteZpredZnewtestsrrhrhrir1s     r1cCsttjttdud}||}tdur4t||jsD|j sDt | st |j dkrp|jsp|j dd}n4t |jdkr|j s|jdd}nd}ts|d7}dd|j D}dd|jD}t|||dS) N) verbositycapture_outputrrzmultiple errors occurredz!; run in verbose mode for detailscSsg|]\}}t||fqSrhrrZtcZexc_strrhrhrir[rz_run_suite..cSsg|]\}}t||fqSrhr5r6rhrhrir[r)rrrrjunit_xml_listr"rZget_xml_elementZtestsRunZskippedr Z wasSuccessfulrrmrnrj)r2Zrunnerrrrmrnrhrhri _run_suites&   r8cCstdur dSt|SdSNT)_match_test_funcidrrhrhri match_test(sr<cCsd|votd| S)Nrz[?*\[\]])rsearch)rrhrhri_is_full_match_test0sr>cs~|dur d}|durd}d|tkr4t|\}|tkrHt|\}t|at|adushdurzfdd}|adS)Nrhcs*d}d}r|}r |}|o(| SNTFrh)test_idacceptrxZ accept_funcZ ignore_funcrhrimatch_functionOsz'set_match_tests..match_function)_accept_test_patterns_compile_match_function_ignore_test_patternsrr:)Zaccept_patternsignore_patternsrCrhrBriset_match_tests:s   rHcs^|sd}d}nHttt|r(t|j}n.dttj|}t |j fdd}|}||fS)Nrh|cs$|r dStt|dSdS)NTr)anyrr)r@Z regex_matchrhrimatch_test_regexjsz1_compile_match_function..match_test_regex) allrr>r __contains__rfnmatch translaterrgr)patternsrZregexrLrhrKrirE[s   rEcGstjtjf}t}|D]`}t|trR|tjvrH|ttj|qxt dqt||rh||q|t |qt |t t |dS)Nz)str arguments must be keys in sys.modules)rr0ZTestCaser/rrrZaddTestZ findTestCasesrZ makeSuiter1r<r8)classesZ valid_typesr2clsrhrhrir,zs       r,cCsdSrkrhrhrhrhri_check_docstringssrTZWITH_DOC_STRINGSztest requires docstringscCs`ddl}|durt}nd}|j|||d\}}|rBtd||ftrXtd|j|f||fS)Nr)r optionflagsz%d of %d doctests failedz,doctest (%s) ... %d tests with zero failures)doctestrtestmodr rre)rr3rUrVrrrhrhrir-sr-cCs(|D]}td|tjddqdS)Nz Warning -- T)rr) splitlinesrrr)rllinerhrhri print_warnings rZcCs tjfSrk)rrrrhrhrhri modules_setupsr[cCs:ddtjD}tjtj|tj|dS)NcSs"g|]\}}|dr||fqS)z encodings.)r)rrrrhrhrir[s  z#modules_cleanup..)rrr]rr)Z oldmodules encodingsrhrhrimodules_cleanups  r]cCsttjfSrk)_thread_count threading _danglingrrhrhrhrirGsrGc Gsd}t|D]}ttjf}||kr*q|sda|d}td|d|dd|ddt|d|D]}td |qnd}d}t d t q dS) NdTrz&threading_cleanup() failed to cleanup rz threads (count: z , dangling: )zDangling thread: {Gz?) ranger^r_r`raenvironment_alteredrZrrrr)Zoriginal_valuesZ _MAX_COUNTcountr*Zdangling_threadsthreadrhrhrirHs*   rHcstfdd}|S)Ncs(t}z|Wt|St|0dSrk)rGrH)rkeyr)rhrir s zreap_threads..decoratorr)rrrhr)rirI srIccs|dur t}t}zdVWt}||}t}||kr@qt|krt|}d||d|dd|d|d }t|tdtq.n~t}||}t}||krqt|krt|}d||d|dd|d|d }t|tdtq0dS)Nz!wait_threads() failed to cleanup z threads after .1fz seconds (count: z , old count: rcrd)r`r^r_r monotonicrrr)rZ old_countZ start_timedeadlinergdtrlrhrhriwait_threads_exitsN        rncCs8|dur t}|||r4d|dd}t|dS)Nzfailed to join the thread in rj seconds)r`ris_aliver)rhrrlrhrhri join_thread<s  rqcCshttdrttdsdSztdtj\}}WntyDYqdYn0|dkrPqdtd|daqdS)NwaitpidWNOHANGrzrz%reap_children() reaped child process T)rrrrrsrrZrf)rDstatusrhrhrirFHs   rFccsLddl}t|}g}z.z7Unable to join %d threads during a period of %d minutescSsg|]}|r|qSrhrwrxrhrhrir[rzUnable to join %d threads) faulthandlerrrrrrrrrkrermaxZdump_tracebackrrr)threadsZunlockryrrendtimeZ starttimerrhrhrirJdsz        rJc cst||rHt||}t|||z|VWt|||qt|||0nBt|||zdVWt||rt||nt||rt||0dSrk)rrrdelattr)rrnew_valreal_valrhrhrirQs      rQc csn||vr8||}|||<z|VW|||<qj|||<0n2|||<zdVW||vrj||=n||vrh||=0dSrkrh)ritemr~rrhrhrirPsrPcCstSrk)r_args_from_interpreter_flagsrhrhrhriargs_from_interpreter_flagssrcCstSrk)r"_optim_args_from_interpreter_flagsrhrhrhri!optim_args_from_interpreter_flagssrc@s eZdZdZddZddZdS)rR)rlrvcKs:d}|D],}||}||}||||sd}q6q|Sr?)r match_value)rqdrrrrdvrhrhrimatchess zMatcher.matchescCsHt|t|krd}n.t|tus,||jvr6||k}n||dk}|S)NFr)r r_partial_matchesfind)rqrrrrrhrhrirs  zMatcher.match_valueN)rerfrgrrrrhrhrhrirRsrRc CsXtdur tStd}ztt|d}WntttfyDd}Yn 0t||a|S)NrTF) _can_symlinkrrsymlinkrNotImplementedErrorrr)Z symlink_pathcanrhrhrirs   rcCs t}d}|r|St||S)Nz*Requires functional symlink implementation)rrr#rokrlrhrhrir. sr.cCsXddl}tdurBtjdkr>|ddkr>tjdkr>dandatrTt d|S|S) Nrrbrcp65001rTFz!buggy MSVC UCRT strptime/strftime) r _buggy_ucrtrrgetdefaultlocaler localtimetm_zonerr#)rrrhrhrir= s   r=c@sdeZdZdddZddZejdkr,ddZdd Zd d Zd d Z ddddZ ddddZ dS) PythonSymlinkNcCs@|ptjt|_g|_tjtj|_ g|_ d|_ | dSrk) rrrrlink_linkedr@rrreal _also_link_env_platform_specific)rqrrhrhrirp" s zPythonSymlink.__init__cCsdSrkrhrurhrhrir, sz PythonSymlink._platform_specificrbc Csddl}tj|jr0tj|js0|d|_|tj}tj |}tj |j }|j |tj |tj|fttj t|dD]&}|j |tj |tj|fqddtjD|_tj |j|jd<tdrtj tj|jd<dS)Nrzvcruntime*.dllcSsi|]}|t|qSrh)upperrgetenv)rrrhrhri E rz4PythonSymlink._platform_specific..Z PYTHONHOMETZ PYTHONPATH)_winapirrlexistsrrRZGetModuleFileNamerZ dllhandlerrrrrbasenameglobescaperrrZis_python_buildr)rqrrZsrc_dirZdest_dirZruntimerhrhrir0 s&    cCsJt|j|j|j|j|jD] \}}t|||j|q$|Srk)rrrrrrr)rqrrrhrhrirJ s  zPythonSymlink.__enter__c CsX|jD]L}zt|WqtyP}z tr _can_xattrrrr?mkstemprUrrr`rrrrrrrrr)r>rZtmp_dirZtmp_fpZtmp_namefpZkernel_versionrrhrhri can_xattro s4    *  rcCs t}d}|r|St||S)Nz(no non-broken extended attribute support)rrr#rrhrhrir7 sr7cCs$t pt}d}|r|St||S)Nz#Not run for (non-extended) PGO task)rW PGO_EXTENDEDrr#rrhrhriskip_if_pgo_task s rc Csddl}|j|dn}|j}|}||kr4|}ztj||WWdStyrYWddS0Wdn1s0YdS)NrrF) r>NamedTemporaryFilerrrrrsamefiler)Z directoryr>base base_pathZ case_pathrhrhrir s rr}cCs>tt|tt|}|r(|t|8}tdd|D}|S)Ncss&|]}|dr|dr|VqdS)rN__N)rendswith)rrrhrhrir sz&detect_api_mismatch..)rr)Zref_apiZ other_apirxZ missing_itemsrhrhrir; s  r;cCs|dur|jf}nt|tr"|f}t|}t|D]R}|ds2||vrJq2t||}t|dd|vszt|ds2t|tj s2| |q2| |j |dS)NrNrf) rer/rrrrrrtypes ModuleTypeaddZassertCountEqual__all__)Z test_caserZname_of_moduleextraZ blacklistZexpectedrrrhrhrir< s )      r<cCsz ddl}Wnty YdS0||j|jB|jB|jBt|dr|j|j |j fD]2}|r| ||j | ||jqZ| |dqZdS)NrCrtSetReportMode)msvcrtr SetErrorModeZSEM_FAILCRITICALERRORSZSEM_NOALIGNMENTFAULTEXCEPTSEM_NOGPFAULTERRORBOXZSEM_NOOPENFILEERRORBOXrCRT_WARN CRT_ERROR CRT_ASSERTrCRTDBG_MODE_FILECrtSetReportFileCRTDBG_FILE_STDERR)rrrrhrhrisuppress_msvcrt_asserts s"   rc@s$eZdZdZdZddZddZdS)rTNc Cstjdrz ddl}Wnty,YdS0||j|_||j|jBt|dri|_ |j |j |j fD].}| ||j}|||j}||f|j |<qnnzddl}||_Wntyd|_Yn0|jdur$z2|j|jj|_|j|jjd|jdfWnttfy"Yn0tjdkrgd}tj|tjtjd}||d}Wdn1st0Y|dkrtd d d d |S) Nrrrrr)z/usr/bin/defaultsrzcom.apple.CrashReporterZ DialogType)rrs developerz:this test triggers the Crash Reporter, that is intentionalrT)endr)rrrrrrr old_valuer old_modesrrrrrrrrZ getrlimit RLIMIT_CORE setrlimitrrrrrrstripr) rqr report_typeold_modeold_filerrprocrrhrhrir s\           ,zSuppressCrashReport.__enter__c Gs|jdurdStjdrfddl}||j|jr|jD]$\}\}}|||| ||q>n:|j durz|j |j j |jWnt tfyYn0dS)Nrr)rrrrrrrr]rrrrrrr)rqrrrrrrhrhrirT s     zSuppressCrashReport.__exit__)rerfrgrrrrrhrhrhrirT sCrTc sptdzjWn"ttfy>tdYn0dfdd}||t|dS)NFTcs rtn tdSrk)rr}rhZ attr_is_local attr_nameobject_to_patchrrhricleanup szpatch..cleanup)r__dict__rrZ addCleanupr)Z test_instancerrZ new_valuerrhrripatchi s  rcCsDz ddl}WntyYn0|r2tdddl}||S)NrzUrun_in_subinterp() cannot be used if tracemalloc module is tracing memory allocations) tracemallocr is_tracingrr _testcapirun_in_subinterp)coderrrhrhrir s   rcsHGfddd|}d||||ttt|dS)NcseZdZfddZdS)z%check_free_after_iterating..Acs(dz tWnty"Yn0dSr9)next StopIterationrudoneitrhri__del__ s   z-check_free_after_iterating..A.__del__N)rerfrgrrhrrhriA srF)Z assertRaisesrrrrt)rrrSrrrhrricheck_free_after_iterating s   rcCsddlm}m}m}m}|}|||jdkrXz |Wn|j yVYdS0|j D]F}|rp||vrpq^t ||}|rn|sq^| |ddur^|dSq^dS)Nr) ccompilerrspawnrmZmsvc) Z distutilsrrrrmZ new_compilerZcustomize_compilerZ compiler_typeZ initializeZDistutilsPlatformErrorZ executablesrZfind_executable)Z cmd_namesrrrrmZcompilerrrrhrhrirX s$       rXcCs@d}tr6||kr6tdur.tddgdkatr6|}t|S)Ngh㈵>Zgetpropzro.kernel.qemu1)r@_is_android_emulatorr check_outputrrrC)intervalZminimum_intervalrhrhrirC s rCc csXddl}tj}|}z$|dVW|rT|j|ddn|rR|j|dd0dS)NrT)rZ all_threads)ryrrr` is_enabledrr)ryrZrrhrhridisable_faulthandler s rc Cstjdr8ztd}t|dWSty6Yn0d}ttdrhztd}Wnt yfYn0d}tjdkrzddl }|j Wnt t fyYn,0i}|j|j|jfD]}| |d||<qzd}t|D]\}zt|}Wn6t y }z|jtjkr WYd}~qd}~00t||d7}qW|dur|j|j|jfD]}| |||qRn4|dur|j|j|jfD]}| |||q0|S) N)linuxZfreebsdz /proc/self/fdrsysconf SC_OPEN_MAXrbr)rrrrrrrrrrrrrrrrrreduprEBADFrY) rMAXFDrrrrgrZfd2rrhrhrirY s`            rYc@s$eZdZddZddZddZdS) SaveSignalsc Cs^ddl}||_||_dD]6}zt||}WntyDYqYn0|j|qi|_dS)Nr)SIGKILLSIGSTOP)signal valid_signalssignalsrrrhandlers)rqrsignamesignumrhrhrirp6 s   zSaveSignals.__init__cCs0|jD]$}|j|}|dur q||j|<qdSrk)rr getsignalrrqr handlerrhrhrisaveC s   zSaveSignals.savecCs&|jD]\}}|j||q dSrk)rr]rr rhrhrirestoreO szSaveSignals.restoreN)rerfrgrprrrhrhrhrir- s   rcCsddl}|jSr)rZ WITH_PYMALLOC)rrhrhri with_pymallocT src@s$eZdZddZddZddZdS)FakePathcCs ||_dSrkr)rqrrhrhrirp\ szFakePath.__init__cCsd|jdS)Nz rrurhrhri__repr___ szFakePath.__repr__cCs6t|jts$t|jtr,t|jtr,|jn|jSdSrk)r/r BaseExceptionr rururhrhri __fspath__b s   zFakePath.__fspath__N)rerfrgrprrrhrhrhrirY src@seZdZddZddZdS) _ALWAYS_EQcCsdSr9rhrqotherrhrhri__eq__o sz_ALWAYS_EQ.__eq__cCsdSNFrhrrhrhri__ne__q sz_ALWAYS_EQ.__ne__N)rerfrgrrrhrhrhrirk src@s$eZdZddZddZddZdS) _NEVER_EQcCsdSrrhrrhrhrirz sz_NEVER_EQ.__eq__cCsdSr9rhrrhrhrir| sz_NEVER_EQ.__ne__cCsdS)Nrrhrurhrhri__hash__~ sz_NEVER_EQ.__hash__N)rerfrgrrrrhrhrhrirv src@seZdZddZddZdS)_LARGESTcCs t|tSrk)r/rrrhrhrir sz_LARGEST.__eq__cCsdSrrhrrhrhri__lt__ sz_LARGEST.__lt__N)rerfrgrrrhrhrhrir src@seZdZddZddZdS) _SMALLESTcCs t|tSrk)r/r rrhrhrir sz_SMALLEST.__eq__cCsdSrrhrrhrhri__gt__ sz_SMALLEST.__gt__N)rerfrgrr!rhrhrhrir  sr cCsddl}|jjSr)Zasyncio.eventseventsZ_event_loop_policy)Zasynciorhrhrimaybe_get_event_loop_policy sr#c Cs||}}ddl}|}|d}t|d|_||}|d||}||} || } || } ||d|d||| d| } t| t| fWdS1s0YdS)Nrrr)decimalZ localcontext bit_lengthrzZprecZDecimalrsqrt) ZnbinsZnballsrrr%ctxbitsrSZp1emptyZ meanemptyZoccupiedZ collisionsvarrhrhricollision_stats s     (r+c@s,eZdZddZddZddZddZd S) catch_unraisable_exceptioncCsd|_d|_dSrk) unraisable _old_hookrurhrhrirp sz#catch_unraisable_exception.__init__cCs ||_dSrk)r-)rqr-rhrhri_hook sz catch_unraisable_exception._hookcCstj|_|jt_|Srk)runraisablehookr.r/rurhrhrir sz$catch_unraisable_exception.__enter__cGs|jt_|`dSrk)r.rr0r-rqexc_inforhrhrir sz#catch_unraisable_exception.__exit__Nrerfrgrpr/rrrhrhrhrir, sr,c@s,eZdZddZddZddZddZd S) catch_threading_exceptioncCs"d|_d|_d|_d|_d|_dSrk)rr exc_tracebackrhr.rurhrhrirp s z"catch_threading_exception.__init__cCs$|j|_|j|_|j|_|j|_dSrk)rrr5rh)rqrrhrhrir/ szcatch_threading_exception._hookcCstj|_|jt_|Srk)r` excepthookr.r/rurhrhrir" sz#catch_threading_exception.__enter__cGs|jt_|`|`|`|`dSrk)r.r`r6rrr5rhr1rhrhrir' s z"catch_threading_exception.__exit__Nr3rhrhrhrir4 sr4r~c Cs&tjdkrddl}|durt}t}d}d}t|tj\}}|dkrJqt|} | tkrzt||j t|dWnt yYn0t d|d| ddt |d |}t |q.nt|d\}}t|} | |krt d|d | d |d ||kr"t d |d|dS)Nr9rrrzprocess z is still running after rjrorz exited with code z, but exit code z is expectedzpid z != pid )rrrr`rrkrrrskillrrrminrwaitstatus_to_exitcode) rDexitcoderrt0rZ max_sleepZpid2rtrmZ exitcode2rhrhri wait_process/ s<         r<cCs ddl}|}|dddkS)NrconfigZ_use_peg_parser)rZ get_configs)rr=rhrhriuse_old_parserd sr>cCstt |Srk)rrr>rtrhrhriskip_if_new_parserj sr?c cs<tjdd}zdVW|tjdd<n|tjdd<0dSrk)ryr)Z old_filtersrhrhrisave_restore_warnings_filtersn sr@c Csdtdtd}tjdkr`z|jddWn4ty^}ztd|WYd}~n d}~00dS)N_multiprocessingzmultiprocessing.synchronizer)r(z broken multiprocessing SemLock: )r rrLockrrr) synchronizerrhrhri*skip_if_broken_multiprocessing_synchronizew s rDKc cs8t}zt|dVWt|n t|0dSrk)rgetrecursionlimitsetrecursionlimit)Z max_depthZoriginal_depthrhrhriinfinite_recursion s  rH)rlikereturncCs,t}tjdt||dt|dd|S)Nrx (?#supportrc)rrrv)objectryr{r|r;)rrItokenrhrhriignore_deprecations_from srN)tokensrJc Gs|s tdg}tdd|D}tjD]Z\}}}}}|dkrn|turnt|tjrZ|j}n|p`d}| |rnq(| |||||fq(tj|kr|tjdd<t dS)Nz.rxr) rrryrr|r/rPatternrrr_filters_mutated) rOZ new_filtersractionrvrrrcrlrhrhriclear_ignored_deprecations s   rS)T)F)rhrhF)F)N)r,)r/)r1)r3)NF)F)rIF)N)r)r)F)T)N)NN)Nr)N)N)N)Nrhrh)F)rh)rE(rercollections.abc collections contextlibrrOrrrimportlib.utilrrrrrrrrr^r`rrrryZ testresultrrr^machiner_r`rar r r rjr rr contextmanagerr~r>r rr9r:rr5rrrrr7rrrrrrrrrrrrrrrrrrr r!r$r"r#r$r+rZ SOCK_MAX_SIZEr.r __getformat__r6r8r/r0r1r?rr@rBrZ TESTFN_ASCIIr rBZ TEST_HTTP_URLZ FS_NONASCII characterfsdecodefsencode UnicodeErrorZTESTFN_UNICODE unicodedata normalizegetfilesystemencodingZTESTFN_ENCODINGZTESTFN_UNENCODABLEZgetwindowsversionencodeUnicodeEncodeErrorrdecodeUnicodeDecodeErrorZTESTFN_UNDECODABLEZTESTFN_NONASCIIrrFrrWrrErHrrErrrrZTEST_SUPPORT_DIRrQrrrOrrrUrar%r&rDrLrrrKrrMrLrabcMutableMappingrNrr'rZ ETIMEDOUTr(Z ECONNRESETr)r*rrrrrrrrrrrrrrrrOrVrrr Z_4Grr rSr r2r3r+r#r$r4r&r'rAr-r.r1r8r:rDrFr<r>rHrEr,rTrZMISSING_C_DOCSTRINGSrZHAVE_DOCSTRINGSZrequires_docstringsr-rZr[r]rfrGrHrIrnrqrFrJrQrPrrrRrrr.rr=rrrr7rrr;r<rrTrrrrXrrCrrYrrrrrZrr[total_orderingrr\r r]r# hash_infowidthZ NHASHBITSr+r,r4r<r>r?r@rDrHrrNrSrhrhrhris~ 8    6   !  L           !        '      6 '   5        # 0      !        $ $  "   N    ;a "   ;'     ",95