
    F\h)                        S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKrS SKrSSK	J
r
Jr  \ R                  SS j5       rS rS rS rSS	S
.S jjrS r\ R                  SS j5       r\ R                  SS j5       rSSSS.S jjr " S S\5      r " S S\5      rS rS r\ R                  S 5       rS r\ R                  SS j5       rg)    N   )unlinktemp_dirc              #      #    U (       a?  [         R                  " 5          [         R                  " SS[        5        Sv   SSS5        gSv   g! , (       d  f       g= f7f)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)warningscatch_warningsfilterwarningsDeprecationWarning)r   s    1/usr/lib/python3.13/test/support/import_helper.py_ignore_deprecated_importsr      sD      $$&##H.C$68 '&
 	 '&s   A!A A
AAc                 H     [         R                  U 	 g ! [         a     g f = fN)sysmodulesKeyError)names    r   unloadr      s%    KK s    
!!c           	         [        U 5        [        R                   Hb  n[        R                  R	                  XS-   5      n[        US-   5        S H)  n[        [        R                  R                  X#S95        M+     Md     g)z'Forget' a module was ever imported.

This removes the module from sys.modules and deletes any PEP 3147/488 or
legacy .pyc files.
.pyc) r      )optimizationN)	r   r   pathosjoinr   	importlibutilcache_from_source)modnamedirnamesourceopts       r   forgetr%   %   sa     7O88g7 	v|C9>>33F3MN      c                     [         R                  R                  U 5      nU R                  S5      (       d   eU S-   n[        R
                  " X5        U$ )a  Move 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   r   )r   r   r    endswithshutilmove)r#   pyc_file
legacy_pycs      r   make_legacy_pycr-   5   sH     ~~//7H??5!!!!#J
KK%r&   F )required_onc                :   [        U5          [        R                  " U 5      sSSS5        $ ! [         aR  n[        R
                  R                  [        U5      5      (       a  e [        R                  " [        U5      5      eSnAff = f! , (       d  f       g= f)aK  Import 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ImportErrorr   platform
startswithtupleunittestSkipTeststr)r   
deprecatedr/   msgs       r   r1   r1   C   st     
$J	/	.**40 
0	/  	.||&&u['9::##CH--	. 
0	/s&   B-
B	ABB		B
Bc                     0 n[        S U  5       5      n[        [        R                  5       HA  nX0;   d  UR	                  U5      (       d  M   [        R                  R                  U5      X'   MC     U$ )Nc              3   *   #    U  H	  oS -   v   M     g7f).Nr.   ).0r   s     r   	<genexpr>+_save_and_remove_modules.<locals>.<genexpr>W   s     2EDCZEs   )r5   listr   r   r4   pop)namesorig_modulesprefixesr!   s       r   _save_and_remove_modulesrF   U   s]    L2E22H$w11(;;$'KKOOG$<L! % r&   c              #      #    [         R                  " U (       a  SOS5         Sv   [         R                  " S5        g! [         R                  " S5        f = f7f)zForce frozen modules to be used (or not).

This only applies to modules that haven't been imported yet.
Also, some essential modules will always be imported frozen.
r   Nr   )_imp"_override_frozen_modules_for_tests)enableds    r   frozen_modulesrL   ^   s=      	++AbA3//2//2    A> AAAc              #      #    [         R                  " U (       a  SOS5      n Sv   [         R                  " U5        g! [         R                  " U5        f = f7f)ah  Force 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
_interpreters.create()).

Also see importlib.utils.allowing_all_extensions().
r   rH   N)rI   '_override_multi_interp_extensions_check)rK   olds     r   multi_interp_extensions_checkrQ   l   s?      
6
6Gq
LC:44S944S9rM   )r9   	usefrozenc                ,   [        U5         [        U5      n[        U5      nU 1UkUkn[        U5      nU H  nS[        R                  U'   M      [        U5          U H  n[        U5        M     [        R                  " U 5      sSSS5        [        U5        [        R                  R                  U5        sSSS5        $ ! [         a=     SSS5        [        U5        [        R                  R                  U5        SSS5        gf = f! , (       d  f       O= f [        U5        [        R                  R                  U5        O/! [        U5        [        R                  R                  U5        f = f SSS5        g! , (       d  f       g= f)aw  Import 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   rA   rF   r   r   rL   
__import__r2   updater   r1   )r   freshblockedr9   rR   rC   rD   r!   s           r   import_fresh_modulerX      sG   D 
$J	/ Uw-(((/6G#'CKK  	-	* #("7+ $) !..t4 +* %U+KK|,+ 
0	/  #   + %U+KK|,+ 
0	/   +** %U+KK|, %U+KK|,,+ 
0	/	/sr   AFEDC3D	E*F
DDE*FDD
D	E!+F,E88F
Fc                   2    \ rS rSrSrSS.S jrS rS rSrg	)
CleanImport   a  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

If "usefrozen" is False (the default) then the frozen importer is
disabled (except for essential modules like importlib._bootstrap).
F)rR   c                F   [         R                  R                  5       U l        U Hh  nU[         R                  ;   d  M  [         R                  U   nUR                  U:w  a  [         R                  UR                  	 [         R                  U	 Mj     [        U5      U l        g r   )r   r   copyoriginal_modules__name__rL   _frozen_modules)selfrR   module_namesmodule_namemodules        r   __init__CleanImport.__init__   st     # 0 0 2'Kckk)[1
 ??k1FOO4KK, (  .i8r&   c                 :    U R                   R                  5         U $ r   )r`   	__enter__ra   s    r   rh   CleanImport.__enter__   s    &&(r&   c                     [         R                  R                  U R                  5        U R                  R
                  " U6   g r   )r   r   rU   r^   r`   __exit__ra   
ignore_excs     r   rl   CleanImport.__exit__   s.    4001%%z2r&   )r`   r^   N	r_   
__module____qualname____firstlineno____doc__re   rh   rl   __static_attributes__r.   r&   r   rZ   rZ      s     16 93r&   rZ   c                   *    \ rS rSrSrS rS rS rSrg)DirsOnSysPath   ar  Context 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.
c                     [         R                  S S  U l        [         R                  U l        [         R                  R	                  U5        g r   )r   r   original_valueoriginal_objectextend)ra   pathss     r   re   DirsOnSysPath.__init__   s.    !hhqk"xxr&   c                     U $ r   r.   ri   s    r   rh   DirsOnSysPath.__enter__   s    r&   c                 h    U R                   [        l        U R                  [        R                  S S & g r   )r{   r   r   rz   rm   s     r   rl   DirsOnSysPath.__exit__   s"    ''))r&   )r{   rz   Nrp   r.   r&   r   rw   rw      s    	
*r&   rw   c                  @    [         R                  R                  5       4$ r   )r   r   r]   r.   r&   r   modules_setupr      s    ;;r&   c                 ^   [         R                  R                  5        VVs/ s H   u  pUR                  S5      (       d  M  X4PM"     nnn[         R                  R	                  5         [         R                  R                  U5        [         R                  R                  U 5        g s  snnf )Nz
encodings.)r   r   itemsr4   clearrU   )
oldmoduleskv	encodingss       r   modules_cleanupr      s{     %(KK$5$5$7 0$7DALL. !$7I 0KKKKy! KKz"0s   B)B)c               #   d   #    [        5       u  n  Sv   [        U 5        g! [        U 5        f = f7f)z,
Save modules on entry and cleanup on exit.
N)r   r   )saveds    r   isolated_modulesr     s(     
 HUs   0  0-0c                 :    SSK Jn  UR                  SSS9" U 5      $ )Nr   )mockzos.register_at_forkT)create)r6   r   patch)funcr   s     r   mock_register_at_forkr     s      ::+D:9$??r&   c              #   L  #    SSK Jn  U =(       d    Sn [        5        nUR                  X0U5      n[        R
                  R                  U S 5      n [        R                  R                  SU5        X4v   [        R                  R                  U5        Ub  U[        R
                  U '   O![        R
                  R                  U S 5         S S S 5        g ! Ub  U[        R
                  U '   f [        R
                  R                  U S 5        f = f! , (       d  f       g = f7f)Nr   )script_helperspam)
test.supportr   r   make_scriptr   r   rB   r   insertremove)r   r#   r   tempdirr   
old_modules         r   ready_to_importr   #  s     * >6D	w((?[[__T40
	,HHOOAw'*HHOOG$%$.D!d+ 
 %$.D!d+ 
s5   D$3DAC8D	D$9DD
D!D$)T)F)r.   r.   )Nr   )
contextlibrI   r   importlib.utilr   r)   r   r6   r   	os_helperr   r   contextmanagerr   r   r%   r-   r1   rF   rL   rQ   rX   objectrZ   rw   r   r   r   r   r   r.   r&   r   <module>r      s        	  
   '  O . .$ 
3 
3 : :&7-#("'7-t#3& #3L*F *2#$  @ , ,r&   