a  zek @sB dZedkredddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZgdZdZej d kre d krd Zd Zd Z dZ!Gddde"Z#Gddde#Z$Gddde$Z%Gddde#Z&Gdddej'Z(ej)drddZ*ddZ+dsdd d!d"Z,d#d$Z-d%d&Z.d'd(Z/dtd)d*Z0d+d,Z1dZ2dZ3da4da5dZ6dZ7da8d-d.Z9d/d0Z:d1d2Z;d3d4Zd8d9Z?d:d;Z@dd?ZBne jCZ?e jDZ@d@d=ZAdAd?ZBdBdCZCdDdEZDdFdGZEdHdIZFdJdKZGdLdMZHdNdOZIdvdPdQZJdRdSZKdTdUZLdVdWZMdXdYZNdZd[ZOd\ZPd]ZQeReSTd^=d_d`ZUdwdbdcZVdxdedfZWdydhdiZXdzdkdlZYej =dmZZe[ednZ\ej d kr.e\r(dondpZ]ndZ]e j^dmkrDdqZ_ndrZ_ds`e_e aZ_dtZbduZcdvD]DZdze ee fededkregWnegyYn 0edZcqqde_dwZhej dxkrddliZieijdyehZhekZldZme j^dzkrZgfd?d@ZdadAdBZej)dCdDZdEdFZGdGdHdHZdIdJZGdKdLdLZGdMdNdNZeZGdOdPdPZeZejGdQdRdRZeZejGdSdTdTZeZdUdVZ ej j Z e dWv sbJdXdYZ GdZd[d[ZGd\d]d]Zdd^d_d`ZdadbZdcddZej)dedfZdgdhZej)ddjdkZeeedldmdnZeddodpdqZdS(z7Supporting definitions for the Python regression tests.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@seZdZdZdS)r z*Base class for regression test exceptions.N__name__ __module__ __qualname____doc__ririI/opt/bitninja-python-dojo/embedded/lib/python3.9/test/support/__init__.pyr vsr c@seZdZdZdS)r Test failed.Nrdriririrjr ysr cs(eZdZdZfddZddZZS)TestFailedWithDetailsrkcs&||_||_||_t|||dSN)msgerrorsfailuressuper__init__)selfrnrorp __class__rirjrr~szTestFailedWithDetails.__init__cCs|jSrmrnrsririrj__str__szTestFailedWithDetails.__str__)rerfrgrhrrrx __classcell__ririrtrjrl|s rlc@seZdZdZdS)r zTest did not run any subtests.Nrdriririrjr sr c@seZdZdZdS)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. Nrdriririrjr sr TccsL|rBt$tddtdVWdqH1s60YndVdS)zContext manager to suppress package and module deprecation warnings when importing them. If ignore is False, this context manager has no effect. ignorez.+ (module|package)N)warningscatch_warningsfilterwarningsDeprecationWarningrzririrj_ignore_deprecated_importss &rcsfdd}|S)zDecorator to suppress deprecation warnings. Use of context managers to hide warnings make diffs more noisy and tools like 'git blame' less useful. cstfdd}|S)NcsPt4tjdd|g|Ri|WdS1sB0YdS)Nrzcategory)r{r| simplefilter)rsargskwargs)rtestrirjwrappers z3ignore_warnings..decorator..wrapper functoolswraps)rrrrrj decoratorsz"ignore_warnings..decoratorri)rrrirrjr>s r>Fri) required_onc Cst|pzt|WWdStyh}z,tjt|rFt t |WYd}~n d}~00Wdn1s~0YdS)acImport and return the module to be tested, raising SkipTest if it is not available. If deprecated is True, any module or package deprecation messages will be suppressed. If a module is required on a platform but optional for others, set required_on to an iterable of platform prefixes which will be compared against sys.platform. N) r importlibr ImportErrorsysplatform startswithtupleunittestSkipTeststr)name deprecatedrrnririrjr s r cCsLi}tdd|D}ttjD]&}||vs6||r tj|||<q |S)Ncss|]}|dVqdS).Nri).0rririrj z+_save_and_remove_modules..)rlistrmodulesrpop)names orig_modulesprefixesmodnameririrj_save_and_remove_moduless rcCs|r tjSddS)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. cSs|Srmrifririrjrz$anticipate_failure..)rZexpectedFailure)Z conditionririrjr9sr9cCsF|dur d}tjtjtjt}|j|||d}|||S)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) Nztest*)Z start_dirZ top_level_dirpattern)ospathdirname__file__ZdiscoverZaddTests)Zpkg_dirloaderZstandard_testsrZtop_dirZ package_testsririrjr:s  r:c Cst|t|}t|}|h||}t|}|D]}dtj|<q4z|z|D] }t|qLWn6tyYWt|tj|WddS0t |Wt|tj|WdSt|tj|0Wdn1s0YdS)aImport and return a module, deliberately bypassing sys.modules. This function imports and returns a fresh copy of the named Python module by removing the named module from sys.modules before doing the import. Note that unlike reload, the original module is not affected by this operation. *fresh* is an iterable of additional module names that are also removed from the sys.modules cache before doing the import. If one of these modules can't be imported, None is returned. *blocked* is an iterable of module names that are replaced with None in the module cache during the import to ensure that attempts to import them raise ImportError. The named module and any modules named in the *fresh* and *blocked* parameters are saved before starting the import and then reinserted into sys.modules when the fresh import is complete. Module and package deprecation messages are suppressed during this import if *deprecated* is True. This function will raise ImportError if the named module cannot be imported. If "usefrozen" is False (the default) then the frozen importer is disabled (except for essential modules like importlib._bootstrap). N) rrrrr __import__rupdaterr )rZfreshZblockedrrrrririrjrs0      rcCs<zt||}Wn$ty2td||fYn0|SdS)z?Get an attribute, raising SkipTest if AttributeError is raised.zobject %r has no attribute %rN)getattrAttributeErrorrr)objrZ attributeririrjr5!s  r5cCs|adSrm)_original_stdout)stdoutririrjr6srcCs tptjSrm)rrrriririrjr:srcCs$z tj|=WntyYn0dSrm)rrKeyError)rririrjr=s  rc Gsxz ||WStyr}zPtdkrHtd|jj|ftd|j|ft|tj||WYd}~Sd}~00dS)Nz%s: %sz re-run %s%r) OSErrorrprintrurerchmodstatS_IRWXU)rfuncrerrririrj _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) rrsplitlistdirtimesleepr{warnRuntimeWarning)rpathnamewaitallrrtimeoutLririrj_waitforNs    rcCsttj|dSrm)rrrfilenameririrj_unlinkosrcCsttj|dSrm)rrrmdirrririrj_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_innerrirjrvs  _rmtree.._rmtree_innerTrcSst|tj|Srm)rrr)pririrjrrz_rmtree..)rrrirrj_rmtreeus rcCs\z ddl}WntyYn:0|t|d}|jj||t|}|rX|d|S|S)Nrr)ctypesrZcreate_unicode_bufferlenwindllZkernel32ZGetLongPathNameW)rrbufferlengthririrj _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)rrrrrrirjrs   r)shutilrrrr)rrrirrjrs   cCs|Srmrirririrjrsc Cs(z t|Wnttfy"Yn0dSrm)rFileNotFoundErrorNotADirectoryErrorrririrjrs rcCs$z t|WntyYn0dSrm)rrrririrjrs  rcCs$z t|WntyYn0dSrm)rrrririrjrs  rcCsBtj|}tjtj|}tj||d}t|||S)aMove a PEP 3147/488 pyc file to its legacy pyc location. :param source: The file system path to the source file. The source file does not need to exist, however the PEP 3147/488 pyc file must exist. :return: The file system path to the legacy pyc file. c) rutilcache_from_sourcerrrabspathrrename)sourceZpyc_fileZup_oneZ legacy_pycririrjmake_legacy_pycs   rcCsTt|tjD]@}tj||d}t|ddD]}ttjj||dq4qdS)z'Forget' a module was ever imported. This removes the module from sys.modules and deletes any PEP 3147/488 or legacy .pyc files. z.pyr)rr) optimizationN) rrrrrrrrr)rrroptririrjrs   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_ri)rrirjUSEROBJECTFLAGSs   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)rerfrgrri)rrirjProcessSerialNumbersrz#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_stringri)rrrjr sr         r cCstdup|tvS)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)rresourceririrjr -sr cCs<t|s |durd|}t||dkr8ts8ttjdS)z@Raise ResourceDenied if the specified resource is not available.Nz"Use of the %r resource not enabledgui)r r r r)rrnririrjr!5s r!cCsddl}dtt|}|ddd}||krrzttt|d}Wnt yfd}Yqv0||k}nd}t ||d|d|S) 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. rNr-rFz version z or higher required, not ) rrmaprreleasersystemrint ValueErrorrskipIf)sysname min_versionrmin_version_txt version_txtversionskipririrj_requires_unix_version>s      r&cGs td|S)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. ZFreeBSDr&r!ririrjr"Ysr"cGs td|S)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. ZLinuxr'r(ririrjr#bsr#csfdd}|S)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. cs"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")rr!rirjrss   z4requires_mac_ver..decorator..wrapper)rrr!rrr(rrjrrsz#requires_mac_ver..decoratorri)r!rrir(rjr$ks r$cstfdd}|S)z5Skip the test on TLS certificate validation failures.c sTz|i|Wn<tyN}z$dt|vr8tdWYd}~n d}~00dS)NZCERTIFICATE_VERIFY_FAILEDz.system does not contain necessary certificates)rrrr)rrrrrirjdecs   z&system_must_validate_cert..decr)rr,rirrjsystem_must_validate_certsr-i@iZdoubleZIEEEztest requires IEEE 754 doubles requires zlibcCs0z ddl}Wnty"d}Yn0t||Sr)zlibrr skipUnless)rr/ririrjr8s    r8 requires gzipcCs0z ddl}Wnty"d}Yn0t||Sr)gziprrr0)rr2ririrjr/s    r/ requires bz2cCs0z ddl}Wnty"d}Yn0t||Sr)bz2rrr0)rr4ririrjr0s    r0 requires lzmacCs0z ddl}Wnty"d}Yn0t||Sr)lzmarrr0)rr6ririrjr1s    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) aReturn a context manager that creates a temporary directory. Arguments: path: the directory to create temporarily. If omitted or None, defaults to creating a temporary directory using tempfile.mkdtemp. quiet: if False (the default), the context manager raises an exception on error. Otherwise, if the path is specified and cannot be created, only a warning is issued. rNFTz5tests may fail, unable to create temporary directory : r) tempfilemkdtemprrrealpathmkdirrr{rrgetpidr)rquietr@Z dir_createdrpidririrjtemp_dires6  rGc cst}zttj|WnFtyd}z.|s4tjd|d|tddWYd}~n d}~00ztVWt|n t|0dS)agReturn a context manager that changes the current working directory. Arguments: path: the directory to use as the temporary current working directory. quiet: if False (the default), the context manager raises an exception on error. Otherwise, it issues only a warning and keeps the current working directory the same. zBtests may fail, unable to change the current working directory to r>r?rN) rgetcwdchdirrrBrr{rr)rrEZ saved_dirrririrj change_cwds  rJtempcwdc csbt||dB}t||d}|VWdn1s60YWdn1sT0YdS)a Context manager that temporarily creates and changes the CWD. The function temporarily changes the current working directory after creating a temporary directory in the current directory with name *name*. If *name* is None, the temporary directory is created using tempfile.mkdtemp. If *quiet* is False (default) and it is not possible to create or change the CWD, an error is raised. If *quiet* is True, only a warning is raised and the original CWD is used. )rrE)rEN)rGrJ)rrEZ temp_pathZcwd_dirririrjrsrumaskc cs0t|}zdVWt|n t|0dS)z8Context manager that temporarily sets the process umask.N)rrL)rLZoldmaskririrjrEs rEdatacCsXtjdkrdSddl}d}|d}|\}}t||dt|td|dS)zOAssure user that loud errors generated by macOS libc's malloc are expected.rNrz 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_namerrnZdetailZpadding_ririrjdarwin_malloc_err_warnings   rQcCsbtj|r|S|dur&tj||}tgtj}|D]&}tj||}tj|r6|Sq6|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)rrisabsr TEST_HOME_DIRrexists)rZsubdirrdnfnririrjrs  rcCs(t|tjtjBtjB}t|dS)z>Create an empty file. If the file already exists, truncate it.N)ropenO_WRONLYO_CREATO_TRUNCclose)rfdririrjrsrcCs,t|}dd|D}d|}d|S)z%Like repr(dict), but in sorted order.cSsg|] }d|qS)z%r: %rri)rZpairririrj rzsortdict..z, z{%s})sorteditemsr)dictr_Z reprpairsZ withcommasririrjrUs  rUcCs<ttd}z|W|ttS|tt0dS)z` Create an invalid file descriptor by opening and closing a file and return its fd. wbN)rWrfilenor[rrririrj make_bad_fds rclinenooffsetcCs|t|}t|ddWdn1s.0Y|j}||j|dur`||j|||j|dur||j|dS)Nz exec)ZassertRaisesRegex SyntaxErrorcompile exceptionassertIsNotNonere assertEqualrf)testcase statementerrtextrerfcmrririrjr% 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 rgrerrorrd)r{r|r SyntaxWarningrirlr assertTrue issubclassrZ assertRegexrmessagerrkrer%)rmrnrorerfwarnsrririrjr&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)rWseekr[)rVrrrzr)rirjcheck_valid_file?s z*open_urlresource..check_valid_fileZurlfetchz fetching %s ...r)zAccept-Encodingr2rzContent-Encodingr2)fileobjrazinvalid resource %r)Zurllib.request urllib.parser2rrparseurlparserrrr TEST_DATA_DIRrTrr!rrrZrequestZ build_openerZ addheadersappendrWr_ZheadersgetZGzipFilereadwriter[r ) urlrr)urllibr2rrVrropeneroutsrir~rjrD2sD          . rDc@s4eZdZdZddZddZeddZdd Zd S) WarningsRecorderzyConvenience wrapper for the warnings list returned on entry to the warnings.catch_warnings() context manager. cCs||_d|_dSr _warnings_last)rsZ warnings_listririrjrrlszWarningsRecorder.__init__cCsDt|j|jkr t|jd|S|tjjvr0dStd||fdS)Nr|z%r has no attribute %r)rrrrr{WarningMessage_WARNING_DETAILSr)rsattrririrj __getattr__ps  zWarningsRecorder.__getattr__cCs|j|jdSrmrrwririrjr{wszWarningsRecorder.warningscCst|j|_dSrm)rrrrwririrjreset{szWarningsRecorder.resetN) rerfrgrhrrrpropertyr{rriririrjrhs  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) zCatch the warnings, then check if all the expected warnings have been raised and re-raise unexpected warnings. If 'quiet' is True, only re-raise the unexpected warnings. rZ__warningregistry__Trqr{rsNFzunhandled warning %srz)filter (%r, %s) did not catch any warning)r _getframe f_globalsrclearr{r|rrrrrxrematchrIrwruremoverreAssertionError) filtersrEframeregistrywZreraisemissingrncatseenwarningririrj_filterwarningss4  (   rcOs.|d}|s$dtff}|dur$d}t||S)aContext manager to silence warnings. Accept 2-tuples as positional arguments: ("message regexp", WarningCategory) Optional argument: - if 'quiet' is True, it does not fail if a filter catches nothing (default True without argument, default False if some filters are defined) Without argument, it defaults to: check_warnings(("", Warning), quiet=True) rErNT)rWarningr)rrrEririrjrKs   rKccs\tjdd0}tjd||ddV|r.tWdn1sB0Y||gdS)aContext manager to check that no warnings are emitted. This context manager enables a given warning within its scope and checks that no warnings are emitted even with that warning enabled. If force_gc is True, a garbage collection is attempted before checking for warnings. This may help to catch warnings emitted when objects are deleted, such as ResourceWarning. Other keyword arguments are passed to warnings.filterwarnings(). Trqrs)rxrN)r{r|r} gc_collectrl)rmrxrforce_gcryririrjrMs$rMccs8t|tdddVWdn1s*0YdS)a"Context manager to check that no ResourceWarning is emitted. Usage: with check_no_resource_warning(self): f = open(...) ... del f You must remove the object which may emit ResourceWarning before the end of the context manager. T)rrN)rMResourceWarning)rmririrjrLsrLc@s(eZdZdZddZddZddZdS) ra,Context manager to force import to return a new module reference. This is useful for testing module-level behaviours, such as the emission of a DeprecationWarning on import. Use like this: with CleanImport("foo"): importlib.import_module("foo") # new reference cGsJtj|_|D]4}|tjvrtj|}|j|kr|n|r<|0dSr)r isenableddisableenable)rZhave_gcririrj disable_gcs rcCs6tdp d}d}|D]}|dr|}q|dvS)z,Find if Python was built with optimizations.Z PY_CFLAGSrz-O)rz-O0z-Og) sysconfigget_config_varrr)ZcflagsZ final_optrririrjpython_is_optimizeds   rZnPZ0nZ getobjectsZ2PZ0PncCstt|tSrm)structcalcsize_header_alignfmtririrj calcobjsizesrcCstt|tSrm)rr_vheaderrrririrj 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_HEADrl)rosizerrrnririrj check_sizeofs     rc gsz ddl}t||}||}Wn&ty4YnBd}}Yn00|D](}z|||WqvWqLYqL0qLzdVW|r|r|||n|r|r|||0dSr)localer setlocaler)ZcatstrZlocalesrrZ orig_localelocririrjrOs(    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)rtzrirjinner s0           z-run_with_tz..decorator..inner)rerh)rrrr+rjrszrun_with_tz..decoratorri)rrrirrjrVs 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)limitZsizesrmemlimitririrjrS1s" $ rSc@s(eZdZdZddZddZddZdS) _MemoryWatchdogz`An object which periodically watches the process' memory consumption and prints it out. cCsdjtd|_d|_dS)Nz/proc/{pid}/statm)rFF)rrrDprocfilestartedrwririrjrrKsz_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)rWrrr{rrrrrflushr subprocessPopen executableDEVNULL mem_watchdogr)rsrrZwatchdog_scriptririrjstartOs   &z_MemoryWatchdog.startcCs|jr|j|jdSrm)rr terminatewaitrwririrjstop_s z_MemoryWatchdog.stopN)rerfrgrhrrrrriririrjrFsrcsfdd}|S)atDecorator 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. cs 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) rmemuser rrrrrrrr)rsrrmaxsizeZwatchdog)dry_runrrrirjrss<     z.bigmemtest..decorator..wrapper)rrrr rrrrrjrrszbigmemtest..decoratorri)rrr rrir!rjr2es !r2csfdd}|S)z0Decorator for tests that fill the address space.csDttkr8tdkr$tdkr$tdq@tdtdn|SdS)Nllz-not enough memory: try a 32-bit build insteadrr)rr rrrwrrirjrsz!bigaddrspacetest..wrapperrir"rirrjr3s r3c@seZdZddZdS)r+cCst}|||Srm)rZ TestResult)rsrrririrjrunszBasicTestRunner.runN)rerfrgr#riririrjr+sr+cCs|Srmri)rririrj_idsr$cCs:|dkrtsttjSt|r&tStd|SdS)Nrzresource {0!r} is not enabled)r rr%rr r$rrririrjrequires_resources  r%cCstdd|S)z9 Decorator for tests only applicable on CPython. T)cpython) impl_detailrririrjr4sr4cKsZtfi|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^rrrrr%)rnguardsZ guardnamesdefaultririrjr's  r'cCsH|sddidfSt|d}t||gt|ks>J|| fS)Nr&TFr)rvaluesr)r)Zis_trueririrjr(s  r(cKs t|\}}|t|S)a5This 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(rrZpython_implementationr)r)r*ririrjrAs rAcs,ttdsStfdd}|SdS)zEDecorator to temporarily turn off tracing for the duration of a test.gettracec s>t}z$td|i|Wt|St|0dSrm)rr,settrace)rrZoriginal_tracer+rirjrs  zno_tracing..wrapperN)r rrrr*rir+rj no_tracings  r.cCs tt|S)aDecorator 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.r4rririrj refcount_testsr/cCsNg}|jD]8}t|tjr0t||||q ||r ||q ||_dS)z>Recursively filter test cases in a suite based on a predicate.N)Z_tests isinstancer TestSuite _filter_suiter)suiteZpredZnewtestsrririrjr2s     r2cCsttjttdud}||}tdur4t||jsD|j sDt | st |j dkrp|jsp|j dd}n4t |jdkr|j s|jdd}nd}ts|d7}dd|j D}d d|jD}t|||dS) z2Run tests from a unittest.TestSuite-derived class.N) verbositycapture_outputrrzmultiple errors occurredz!; run in verbose mode for detailscSsg|]\}}t||fqSrirrZtcZexc_strririrjr]rz_run_suite..cSsg|]\}}t||fqSrir6r7ririrjr]r)rrrrjunit_xml_listr#rZget_xml_elementZtestsRunZskippedr Z wasSuccessfulrrorprl)r3Zrunnerrrrorpririrj _run_suites&   r9cCstdur dSt|SdSNT)_match_test_funcidrririrj match_test(sr=cCsd|votd| S)Nrz[?*\[\]])rsearch)rririrj_is_full_match_test0sr?cs~|dur d}|durd}d|tkr4t|\}|tkrHt|\}t|at|adushdurzfdd}|adS)Nrics*d}d}r|}r |}|o(| S)NTFri)test_idacceptrzZ accept_funcZ ignore_funcrirjmatch_functionOsz'set_match_tests..match_function)_accept_test_patterns_compile_match_function_ignore_test_patternsrr;)Zaccept_patternsignore_patternsrCrirBrjset_match_tests:s   rHcs^|sd}d}nHttt|r(t|j}n.dttj|}t |j fdd}|}||fS)Nri|cs$|r dStt|dSdS)NTr)anyrr)r@Z regex_matchrirjmatch_test_regexjsz1_compile_match_function..match_test_regex) allrr?r __contains__rfnmatch translaterrir)patternsrZregexrLrirKrjrE[s   rEcGstjtjf}t}|D]`}t|trR|tjvrH|ttj|qxt dqt||rh||q|t |qt |t t |dS)z1Run tests from unittest.TestCase-derived classes.z)str arguments must be keys in sys.modulesN)rr1ZTestCaser0rrrZaddTestZ findTestCasesrZ makeSuiter2r=r9)classesZ valid_typesr3clsririrjr,zs       r,cCsdS)z,Just used to check if docstrings are enabledNririririrj_check_docstringssrTZWITH_DOC_STRINGSztest requires docstringscCs`ddl}|durt}nd}|j|||d\}}|rBtd||ftrXtd|j|f||fS)aRun 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). rN)r optionflagsz%d of %d doctests failedz,doctest (%s) ... %d tests with zero failures)doctestrtestmodr rre)rr4rUrVrrririrjr-sr-cCs(|D]}td|tjddqdS)Nz Warning -- T)rr) splitlinesrrr)rnlineririrj print_warnings rZcCs tjfSrm)rrrriririrj modules_setupsr[cCs:ddtjD}tjtj|tj|dS)NcSs"g|]\}}|dr||fqS)z encodings.)r)rrrririrjr]s  z#modules_cleanup..)rrr_rr)Z oldmodules encodingsririrjmodules_cleanups  r]cCsttjfSrm)_thread_count threading _danglingrriririrjrGsrGc 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_threadsthreadririrjrHs*   rHcstfdd}|S)zUse this function when threads are being used. This will ensure that the threads are cleaned up even when the test fails. cs(t}z|Wt|St|0dSrm)rGrH)rkeyr+rirjr s zreap_threads..decoratorr)rrrir+rjrI 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) aH bpo-31234: Context manager to wait until all threads created in the with statement exit. Use _thread.count() to check if threads exited. Indirectly, wait until threads exit the internal t_bootstrap() C function of the _thread module. threading_setup() and threading_cleanup() are designed to emit a warning if a test leaves running threads in the background. This context manager is designed to cleanup threads started by the _thread.start_new_thread() which doesn't allow to wait for thread exit, whereas thread.Thread has a join() method. 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_timedeadlinergdtrnririrjwait_threads_exitsN        rncCs8|dur t}|||r4d|dd}t|dS)zcJoin a thread. Raise an AssertionError if the thread is still alive after timeout seconds. Nzfailed to join the thread in rj seconds)r`ris_aliver)rhrrnririrj join_thread<s  rqcCshttdrttdsdSztdtj\}}WntyDYqdYn0|dkrPqdtd|daqdS)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. waitpidWNOHANGNr|rz%reap_children() reaped child process T)r rrrrsrrZrf)rFstatusririrjrFHs   rFccsLddl}t|}g}z.z7Unable to join %d threads during a period of %d minutescSsg|]}|r|qSrirwrxririrjr]rzUnable to join %d threads) faulthandlerrrrrrrrrkrermaxZdump_tracebackrrr)threadsZunlockryrrendtimeZ starttimerririrjrJdsz        rJc cst||rHt||}t|||z|VWt|||qt|||0nBt|||zdVWt||rt||nt||rt||0dS)aTemporary 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 rrdelattr)rrnew_valreal_valririrjrQs      rQc csn||vr8||}|||<z|VW|||<qj|||<0n2|||<zdVW||vrj||=n||vrh||=0dS)aTemporary 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. Nri)ritemr~rririrjrPsrPcCstS)znReturn a list of command-line arguments reproducing the current settings in sys.flags and sys.warnoptions.)r_args_from_interpreter_flagsriririrjargs_from_interpreter_flagssrcCstS)zgReturn a list of command-line arguments reproducing the current optimization settings in sys.flags.)r"_optim_args_from_interpreter_flagsriririrj!optim_args_from_interpreter_flagssrc@s eZdZdZddZddZdS)rR)rnrxcKs:d}|D],}||}||}||||sd}q6q|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)r match_value)rsdrrrrdvririrjmatchess zMatcher.matchescCsHt|t|krd}n.t|tus,||jvr6||k}n||dk}|S)zT Try to match a single stored value (dv) with a supplied value (v). Fr)rr_partial_matchesfind)rsrrrrririrjrs  zMatcher.match_valueN)rerfrgrrrriririrjrRsrRc CsXtdur tStd}ztt|d}WntttfyDd}Yn 0t||a|S)NrTF) _can_symlinkrrsymlinkrNotImplementedErrorrr)Z symlink_pathcanririrjrs   rcCs t}d}|r|St||S)z8Skip decorator for tests that require functional symlinkz*Requires functional symlink implementation)rrr%rokrnririrjr. sr.cCsXddl}tdurBtjdkr>|ddkr>tjdkr>dandatrTt 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 rNrbrcp65001rTFz!buggy MSVC UCRT strptime/strftime) r _buggy_ucrtrrgetdefaultlocaler localtimetm_zonerr%)rrririrjr= s   r=c@sheZdZdZdddZddZejdkr0ddZd d Zd d Z d dZ ddddZ ddddZ dS) PythonSymlinkz3Creates a symlink for the current Python executableNcCs@|ptjt|_g|_tjtj|_ g|_ d|_ | dSrm) rrrrlink_linkedrBrrreal _also_link_env_platform_specific)rsrririrjrr" s zPythonSymlink.__init__cCsdSrmrirwririrjr, 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|qSri)upperrgetenv)rrririrj E rz4PythonSymlink._platform_specific..Z PYTHONHOMETZ PYTHONPATH)_winapirrlexistsrrTZGetModuleFileNamerZ dllhandlerrrrrbasenameglobescaperrrZis_python_buildr)rsrrZsrc_dirZdest_dirZruntimeririrjr0 s&    cCsJt|j|j|j|j|jD] \}}t|||j|q$|Srm)rrrrrrr)rsrrririrjrJ s  zPythonSymlink.__enter__c CsX|jD]L}zt|WqtyP}z trtt|tt|}|r(|t|8}tdd|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 '__'. css&|]}|dr|dr|VqdS)rP__N)rendswith)rrririrjr sz&detect_api_mismatch..)rr)Zref_apiZ other_apirzZ missing_itemsririrjr; s  r;cCs|dur|jf}nt|tr"|f}t|}t|D]R}|ds2||vrJq2t||}t|dd|vszt|ds2t|tj s2| |q2| |j |dS)aAssert 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 'blacklist' 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'} blacklist = {'baz'} # Undocumented name. # bar imports part of its API from _bar. support.check__all__(self, bar, ('bar', '_bar'), extra=extra, blacklist=blacklist) NrPrf) rer0rrrrrr types ModuleTypeaddZassertCountEqual__all__)Z test_caserZname_of_moduleextraZ blacklistZexpectedrrririrjr< 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_NOOPENFILEERRORBOXr CRT_WARN CRT_ERROR CRT_ASSERTrCRTDBG_MODE_FILECrtSetReportFileCRTDBG_FILE_STDERR)rrrririrjsuppress_msvcrt_asserts s"   rc@s(eZdZdZdZdZddZddZdS)rTzTry 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 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|d krtd d d d |S)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. rrNrrr)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) rsr report_typeold_modeold_filerrprocrririrjr s\           ,zSuppressCrashReport.__enter__c Gs|jdurdStjdrfddl}||j|jr|jD]$\}\}}|||| ||q>n:|j durz|j |j j |jWnt tfyYn0dS)zARestore Windows ErrorMode or core file behavior to initial value.Nrr)rrrrrrrr_rrrrrrr)rsrrrrrririrjrT s     zSuppressCrashReport.__exit__)rerfrgrhrrrrriririrjrT s CrTc sptdzjWn"ttfy>tdYn0dfdd}||t|dS)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'. FNTcs rtn tdSrm)rr}riZ attr_is_local attr_nameobject_to_patchrrirjcleanup szpatch..cleanup)r__dict__rrZ addCleanupr)Z test_instancerrZ new_valuerrirrjpatchi s  rcCsDz ddl}WntyYn0|r2tdddl}||S)zi Run code in a subinterpreter. Raise unittest.SkipTest if the tracemalloc module is enabled. rNzUrun_in_subinterp() cannot be used if tracemalloc module is tracing memory allocations) tracemallocr is_tracingrr _testcapirun_in_subinterp)coderrririrjr s   rcsHGfddd|}d||||ttt|dS)NcseZdZfddZdS)z%check_free_after_iterating..Acs(dz tWnty"Yn0dSr:)next StopIterationrwdoneitrirj__del__ s   z-check_free_after_iterating..A.__del__N)rerfrgrrirrirjA srF)Z assertRaisesrrrrv)rrrSrrrirrjcheck_free_after_iterating s   rcCsddlm}m}m}m}|}|||jdkrXz |Wn|j yVYdS0|j D]Z}|rp||vrpq^t ||}|r|dusJd|n|sq^| |ddur^|dSq^dS)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) ccompilerrspawnroZmsvcNz%the '%s' executable is not configured) Z distutilsrrrroZ new_compilerZcustomize_compilerZ compiler_typeZ initializeZDistutilsPlatformErrorZ executablesrZfind_executable)Z cmd_namesrrrroZcompilerrrririrjrX s(        rXcCs@d}tr6||kr6tdur.tddgdkatr6|}t|S)Ngh㈵>Zgetpropzro.kernel.qemu1)r@_is_android_emulatorr check_outputrrrC)intervalZminimum_intervalririrjrC s rCc csXddl}tj}|}z$|dVW|rT|j|ddn|rR|j|dd0dS)NrT)rZ all_threads)ryrrrb is_enabledrr)ryr\rririrjdisable_faulthandler s rc Cstjdr8ztd}t|dWSty6Yn0d}ttdrhztd}Wnt yfYn0d}tjdkrzd dl }|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) z/Count the number of open file descriptors. )linuxZfreebsdz /proc/self/fdrsysconf SC_OPEN_MAXNrbr)rrrrrrrr rrrrrrrrrreduprEBADFr[) rMAXFDrrrrgr\fd2rririrjrY s`            rYc@s(eZdZdZddZddZddZdS) 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 Cs^ddl}||_||_dD]6}zt||}WntyDYqYn0|j|qi|_dS)Nr)SIGKILLSIGSTOP)signal valid_signalssignalsrrrhandlers)rsrsignamesignumririrjrr6 s   zSaveSignals.__init__cCs0|jD]$}|j|}|dur q||j|<qdSrm)rr getsignalrrsr handlerririrjsaveC s   zSaveSignals.savecCs&|jD]\}}|j||q dSrm)rr_rr ririrjrestoreO szSaveSignals.restoreN)rerfrgrhrrrrriririrjr- s  rcCsddl}|jSr)rZ WITH_PYMALLOC)rririrj with_pymallocT src@s(eZdZdZddZddZddZdS) FakePathz.Simple implementing of the path protocol. cCs ||_dSrmr)rsrririrjrr\ szFakePath.__init__cCsd|jdS)Nz rrwririrj__repr___ szFakePath.__repr__cCs6t|jts$t|jtr,t|jtr,|jn|jSdSrm)r0r BaseExceptionrrwrwririrj __fspath__b s   zFakePath.__fspath__N)rerfrgrhrrrrriririrjrY src@s eZdZdZddZddZdS) _ALWAYS_EQz+ Object that is equal to anything. cCsdSr:rirsotherririrj__eq__o sz_ALWAYS_EQ.__eq__cCsdSNFrirririrj__ne__q sz_ALWAYS_EQ.__ne__N)rerfrgrhrrriririrjrk src@s(eZdZdZddZddZddZdS) _NEVER_EQz/ Object that is not equal to anything. cCsdSrrirririrjrz sz_NEVER_EQ.__eq__cCsdSr:rirririrjr| sz_NEVER_EQ.__ne__cCsdS)Nrrirwririrj__hash__~ sz_NEVER_EQ.__hash__N)rerfrgrhrrrriririrjrv src@s eZdZdZddZddZdS)_LARGESTz? Object that is greater than anything (except itself). cCs t|tSrm)r0rrririrjr sz_LARGEST.__eq__cCsdSrrirririrj__lt__ sz_LARGEST.__lt__N)rerfrgrhrrriririrjr src@s eZdZdZddZddZdS) _SMALLESTz< Object that is less than anything (except itself). cCs t|tSrm)r0r rririrjr sz_SMALLEST.__eq__cCsdSrrirririrj__gt__ sz_SMALLEST.__gt__N)rerfrgrhrr!riririrjr  sr cCsddl}|jjS)zDReturn the global event loop policy if one is set, else return None.rN)Zasyncio.eventseventsZ_event_loop_policy)Zasyncioririrjmaybe_get_event_loop_policy sr#) @c Cs||}}ddl}|}|d}t|d|_||}|d||}||} || } || } ||d|d||| d| } t| t| fWdS1s0YdS)Nrrr)decimalZ localcontext bit_lengthrzZprecZDecimalrsqrt) ZnbinsZnballsrrr'ctxbitsrUZp1emptyZ meanemptyZoccupiedZ collisionsvarririrjcollision_stats s     (r-c@s0eZdZdZddZddZddZdd Zd 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) cCsd|_d|_dSrm) unraisable _old_hookrwririrjrr sz#catch_unraisable_exception.__init__cCs ||_dSrm)r/)rsr/ririrj_hook sz catch_unraisable_exception._hookcCstj|_|jt_|Srm)runraisablehookr0r1rwririrjr sz$catch_unraisable_exception.__enter__cGs|jt_|`dSrm)r0rr2r/rsexc_inforirirjr sz#catch_unraisable_exception.__exit__Nrerfrgrhrrr1rrriririrjr. s r.c@s0eZdZdZddZddZddZdd Zd S) catch_threading_exceptiona Context manager catching threading.Thread exception using threading.excepthook. Attributes set when an exception is catched: * exc_type * exc_value * exc_traceback * thread See threading.excepthook() documentation for these attributes. These attributes are deleted at the context manager exit. Usage: with support.catch_threading_exception() as cm: # code spawning a thread which raises an exception ... # check the thread exception, use cm attributes: # exc_type, exc_value, exc_traceback, thread ... # exc_type, exc_value, exc_traceback, thread attributes of cm no longer # exists at this point # (to avoid reference cycles) cCs"d|_d|_d|_d|_d|_dSrm)rr exc_tracebackrhr0rwririrjrr s z"catch_threading_exception.__init__cCs$|j|_|j|_|j|_|j|_dSrm)rrr7rh)rsrririrjr1 szcatch_threading_exception._hookcCstj|_|jt_|Srm)r` excepthookr0r1rwririrjr" sz#catch_threading_exception.__enter__cGs|jt_|`|`|`|`dSrm)r0r`r8rrr7rhr3ririrjr' s z"catch_threading_exception.__exit__Nr5riririrjr6 s r6rc Cs&tjdkrddl}|durt}t}d}d}t|tj\}}|dkrJqt|} | tkrzt||j t|dWnt yYn0t d|d| dd t |d |}t |q.nt|d\}}t|} | |krt d|d | d |d ||kr"t d|d|dS)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 (SHORT_TIMEOUT by default), kill the process (if signal.SIGKILL is available) and raise an AssertionError. The timeout feature is not available on Windows. r;rNrrzprocess z is still running after rjrorz exited with code z, but exit code z is expectedzpid z != pid )rrrr`rrkrrrskillrrrminrwaitstatus_to_exitcode) rFexitcoderrt0rZ max_sleepZpid2rtrmZ exitcode2ririrj wait_process/ s<         r>cCs ddl}|}|dddkS)NrconfigZ_use_peg_parser)rZ get_configs)rr?ririrjuse_old_parserd sr@cCstt |Srm)rrr@rvririrjskip_if_new_parserj srAc cs<tjdd}zdVW|tjdd<n|tjdd<0dSrm)r{r)Z old_filtersririrjsave_restore_warnings_filtersn srBc Csdtdtd}tjdkr`z|jddWn4ty^}ztd|WYd}~n d}~00dS)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). _multiprocessingzmultiprocessing.synchronizerN)r*z broken multiprocessing SemLock: )r rrLockrrr) synchronizerririrj*skip_if_broken_multiprocessing_synchronizew s rFKc cs8t}zt|dVWt|n t|0dSrm)rgetrecursionlimitsetrecursionlimit)Z max_depthZoriginal_depthririrjinfinite_recursion s  rJ)rlikereturncCs,t}tjdt||dt|dd|S)Nrz (?#supportrc)rrrx)objectr{r}r~r<)rrKtokenririrjignore_deprecations_from srP)tokensrLc Gs|s tdg}tdd|D}tjD]Z\}}}}}|dkrn|turnt|tjrZ|j}n|p`d}| |rnq(| |||||fq(tj|kr|tjdd<t dS)Nz.rzr) rrr{rr~r0rPatternrrr_filters_mutated) rQZ new_filtersractionrxrrrernririrjclear_ignored_deprecations s   rU)T)F)ririF)F)N)r.)r1)r3)r5)NF)F)rKF)N)r)r)F)T)N)NN)Nr)N)N)N)Nriri)F)ri)rG(rhrercollections.abc collections contextlibrrOrrrimportlib.utilrrrrrrrrr^r`rrrr{Z testresultrrr^machiner_r`rar r r rlr rr contextmanagerrr>r rr9r:rr5rrrr r8rrrrrrrrrrrrrrrrrr r r!r&r"r#r$r-rZ SOCK_MAX_SIZEr0r __getformat__r6r8r/r0r1r?r r@rBrZ TESTFN_ASCIIrrDZ TEST_HTTP_URLZ FS_NONASCII characterfsdecodefsencode UnicodeErrorZTESTFN_UNICODE unicodedata normalizegetfilesystemencodingZTESTFN_ENCODINGZTESTFN_UNENCODABLEZgetwindowsversionencodeUnicodeEncodeErrorrdecodeUnicodeDecodeErrorZTESTFN_UNDECODABLEZTESTFN_NONASCIIrrHrrWrrGrJrrErrrrZTEST_SUPPORT_DIRrSrrrQrrrUrcr%r&rDrNrrrKrrMrLrabcMutableMappingrNrr'rZ ETIMEDOUTr(Z ECONNRESETr)r*rrrrrrrrrrrrrrrrOrVrrr Z_4Grr rSrr2r3r+r$r%r4r'r(rAr.r/r2r9r;rDrFr=r?rHrEr,rTrZMISSING_C_DOCSTRINGSZHAVE_DOCSTRINGSZrequires_docstringsr-rZr[r]rfrGrHrIrnrqrFrJrQrPrrrRrrr.rr=rrrr7rrr;r<rrTrrrrXrrCrrYrrrrrZrr[total_orderingrr\r r]r# hash_infowidthZ NHASHBITSr-r.r6r>r@rArBrFrJrrPrUriririrjs 8    6   !  L           !        '      6 '   5        # 0      !        $ $  "   N    ;a "   ;'     ",95