Rh)ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z m Z ejddZ dZdZdZdd d d Zd Zejdd ZejddZdddddZGddeZGddeZdZdZejdZdZejddZy)N)unlinktemp_dirc#K|r=tj5tjddtddddydy#1swYyxYww)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_warningsfilterwarningsDeprecationWarning)rs 1/usr/lib/python3.12/test/support/import_helper.py_ignore_deprecated_importsr sN  $ $ &   # #H.C$6 8       sA AAA AcF tj|=y#t$rYywxYwN)sysmodulesKeyError)names r unloadrs% KK     s   ct|tjD]d}tjj ||dz}t |dzdD],}t t jj||.fy)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.pyc)r) optimizationN) rrpathosjoinr importlibutilcache_from_source)modnamedirnamesourceopts r forgetr$%ss  7O88Ogw7 v| OC 9>>33F3M N O Oc.tjj|}tjj tjj |}tjj||dz}tj|||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. r) rrrrrr!abspathrshutilmove)r"pyc_fileup_one legacy_pycs r make_legacy_pycr-5sc~~//7H WW__RWW__V4 5Fffsl3J KK*% r%F) required_onc t|5 tj|cdddS#t$rL}tj j t|rtjt|d}~wwxYw#1swYyxYw)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 r import_module ImportErrorrplatform startswithtupleunittestSkipTeststr)r deprecatedr/msgs r r1r1Csz $J /. .**40.. .||&&u['9:##CH- - ...s&B, BAA<<BBB ci}td|D}ttjD]:}||vs|j |stjj |||<<|S)Nc3&K|] }|dz yw).Nr.).0rs r z+_save_and_remove_modules..Ws2DTCZ2s)r5listrrr4pop)names orig_modulesprefixesr s r _save_and_remove_modulesrEUscL2E22H $= e w11(;$'KKOOG$ ++AbA3  //2//2A7AAAc#Ktj|rdnd} dtj|y#tj|wxYww)aForce legacy modules to be allowed in subinterpreters (or not). ("legacy" == single-phase init) This only applies to modules that haven't been imported yet. It overrides the PyInterpreterConfig.check_multi_interp_extensions setting (see support.run_in_subinterp_with_config() and _xxsubinterpreters.create()). Also see importlib.utils.allowing_all_extensions(). rrGN)rH'_override_multi_interp_extensions_check)rJolds r multi_interp_extensions_checkrPls@  6 6Gq LC:  44S944S9rL)r9 usefrozenct|5t|}t|}|h||}t|}|D]}dtj|< t |5 |D] }t | tj|cdddt|tjj|cdddS#t$r=Ydddt|tjj|dddywxYw#1swYnxYw t|tjj|n/#t|tjj|wxYw dddy#1swYyxYw)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) r r@rErrrK __import__r2updaterr1)rfreshblockedr9rQrBrCr s r import_fresh_modulerWsiD $J /-U w-(((/6  (G#'CKK  ( - * 5 #(,"7+,!..t4 5 5 %U + KK  | ,+-- #   5 %U + KK  | ,+--   5 5 5 %U + KK  | , %U + KK  | , ,+---srAE; ED C/D  E *E; D D  E*E;DD  D E+E;,E..E;;Fc(eZdZdZdddZdZdZy) CleanImportaContext 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 If "usefrozen" is False (the default) then the frozen importer is disabled (except for essential modules like importlib._bootstrap). F)rQc:tjj|_|D]c}|tjvstj|}|j|k7rtj|j=tj|=et ||_yr)rrcopyoriginal_modules__name__rK_frozen_modules)selfrQ module_names module_namemodules r __init__zCleanImport.__init__sy # 0 0 2' -Kckk)[1 ??k1 FOO4KK , - .i8r%c:|jj|Sr)r^ __enter__r_s r rezCleanImport.__enter__s &&( r%ctjj|j|jj |yr)rrrTr\r^__exit__r_ ignore_excs r rhzCleanImport.__exit__s0 4001%%%z2r%Nr] __module__ __qualname____doc__rcrerhr.r%r rYrYs 16 93r%rYc"eZdZdZdZdZdZy) DirsOnSysPathaContext manager to temporarily add directories to sys.path. This makes a copy of sys.path, appends any directories given as positional arguments, then reverts sys.path to the copied settings when the context ends. Note that *all* sys.path modifications in the body of the context manager, including replacement of the object, will be reverted at the end of the block. ctjdd|_tj|_tjj |yr)rroriginal_valueoriginal_objectextend)r_pathss r rczDirsOnSysPath.__init__s.!hhqk"xx r%c|Srr.rfs r rezDirsOnSysPath.__enter__s r%ch|jt_|jtjddyr)rsrrrrris r rhzDirsOnSysPath.__exit__s"'')) r%Nrkr.r%r rprps  *r%rpc@tjjfSr)rrr[r.r%r modules_setuprys ;;    r%cNtjjDcgc]\}}|jdr||f}}}tjj tjj |tjj |ycc}}w)Nz encodings.)rritemsr4clearrT) oldmoduleskv encodingss r modules_cleanuprs|%(KK$5$5$70DAqLL.Q0I0KKKKy!KKz"0sB!c#dKt\} dt|y#t|wxYww)z4 Save modules on entry and cleanup on exit. N)ryr)saveds r isolated_modulesrs) HU s 0 0 -0c@ddlm}|jdd|S)Nr)mockzos.register_at_forkT)create)r6rpatch)funcrs r mock_register_at_forkrs" 94::+D: 9$ ??r%c#8Kddlm}|xsd}t5}|j|||}tj j |d} tjjd|||ftjj|||tj |<n!tj j |d dddy#||tj |<wtj j |dwxYw#1swYyxYww)Nr) script_helperspam) test.supportrr make_scriptrrrArinsertremove)rr"rtempdirr old_modules r ready_to_importr#s* >6D  ,w(($?[[__T40  , HHOOAw '*  HHOOG $%$. D! d+ , ,%$. D! d+ , ,s5D4DAC7D D8D  DDD)T)F)r.r.)Nr) contextlibrHrimportlib.utilrr(rr6r os_helperrrcontextmanagerr rr$r-r1rErKrPrWobjectrYrpryrrrrr.r%r rs  '     O ..$  3 3 ::&7-#("'7-t#3&#3L*F*2#$ @ ,,r%