
    5\h<M                        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 d dl	m
Z
 d dl	mZ d dl	mZ d dl	mZ d dl	mZ d dlZd dlZ ej        d          Zd dlZej        j        Zd	 Z G d
 dej                  Z G d dej                  Z G d dej                  Z G d dej                  Z G d dej                  Zedk    r ej                     dS dS )    N)support)import_helper)	os_helper)script_helper)warnings_helper)is_wasiimpc                     	 t          j        |           } t          r t          j        dd          |           S  t          j        t          t          dd           d u d          |           S )NTzNot supoorted in WASIload_dynamiczimp.load_dynamic() required)r   cpython_onlyr   unittestskipIfgetattrr	   )meths    7/opt/python-3.11.14/usr/lib/python3.11/test/test_imp.pyrequires_load_dynamicr      s{    %%D D=xt%<==dCCC:8?73==E8: ::>@ @ @    c                       e Zd Z	 d Zd ZdS )	LockTestsc                 h    |                      t                                          |d|z             d S )Nz!expected imp.lock_held() to be %r)assertEqualr	   	lock_held)selfexpecteds     r   verify_lock_statezLockTests.verify_lock_state%   s=    (@8K	M 	M 	M 	M 	Mr   c                    d}t                                           }|                     |           t          |          D ]0}t                                            |                     d           1t          |          D ]}t                                            |                     |           |sB	 t                                            |                     d           d S # t          $ r Y d S w xY wd S )N2   Tz5release_lock() without lock should raise RuntimeError)r	   r   r   rangeacquire_lockrelease_lockfailRuntimeError)r   LOOPSlock_held_at_startis       r   testLockzLockTests.testLock(   s    !]]__1222u 	) 	)A""4((((u 	 	A 	1222! 	,,  """ 		 + , , , , ,     	, 	,s   4C$ $
C21C2N)__name__
__module____qualname__r   r&    r   r   r   r   !   s8        3M M M, , , , ,r   r   c                   N   e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
ed	             Zed
             Zed             Zed             Zed             Z ej        ej        d          d             Zd Zd Zej        d             Zd Zd Zd Zd Zej        d             ZdS )ImportTestsc                 ^    t          j        d          }|j        | _        |j        | _        d S )Nztest.encoded_modules)	importlibimport_moduletest_strings__path__	test_path)r   mods     r   setUpzImportTests.setUpD   s+    %&<==,r   c                     | j         D ]8\  }}}t          j        d|z             }|                     ||j                   9d S )Nztest.encoded_modules.module_)r0   r.   r/   r   test)r   modnameencodingteststrr3   s        r   test_import_encoded_modulez&ImportTests.test_import_encoded_moduleI   s_    *.*; 	0 	0&GXw) +46=+> ? ?CWch////	0 	0r   c                    | j         D ]b\  }}}t                              d|z   | j                  d         5 }|                     |j        |           d d d            n# 1 swxY w Y   ct          j                            t          j        	                    t                    d          g}|                     t                    5  t                              d|           d d d            d S # 1 swxY w Y   d S )Nmodule_r   tokenizedatabadsyntax_pep3120)r0   r	   find_moduler2   r   r8   ospathjoindirname__file__assertRaisesSyntaxError)r   r3   r8   _fdrA   s         r   test_find_module_encodingz%ImportTests.test_find_module_encodingO   sZ    $ 1 	8 	8C1S$.AA!D 8  h7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 RW__X66GGH{++ 	7 	7OO/666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7s#   AA#	&A#	C11C58C5c                     | j         D ]\  }}}t                              d|z   | j                  \  }}}|5  |                     |d            |                     |j        |           |                     |                                d           |                     |                                d|z             d d d            n# 1 swxY w Y   t                              d          \  }}}|5  |                     |d            |                     |j        d           |                     |                                d           |                     |                                d           d d d            d S # 1 swxY w Y   d S )Nr<   r   z# test %s encoding
tokenizeutf-8z*"""Tokenization help for Python programs.
)	r0   r	   r?   r2   assertNotEqualr   r8   tellreadline)r   r3   r8   rG   fpfilenameinfos          r   test_issue1267zImportTests.test_issue1267X   s#    $ 1 	- 	-C1"%//)c/26.#B #BB$ - -##B---  h777  A...  0F#+1, - - -	- - - - - - - - - - - - - - - !__Z88Hd 	L 	LD)))R['222RWWYY***R[[]]JL L L		L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	Ls%   BCC	C	4BFF
Fc                 `   d}t           j                            dd           	 t          |dz   dd          5 }|                    d           d d d            n# 1 swxY w Y   t
                              |          \  }}}|                                 |                     |j	        d	           t           j        d= t          j        |dz              t          j        |d
z              d S # t           j        d= t          j        |dz              t          j        |d
z              w xY w)Ntest_imp_helperr   ..pywzlatin-1r8   z%# coding: cp1252
u = 'test.test_imp'
cp1252.pyc)sysrA   insertopenwriter	   r?   closer   r8   r   unlink)r   temp_mod_namefilerQ   rR   s        r   test_issue3594zImportTests.test_issue3594k   sg   )3		5me+S9EEE F

DEEEF F F F F F F F F F F F F F F#&??=#A#A D(DJJLLLT]H555]U2333]V344444 ]U2333]V34444s/   C0 AC0 AC0 "A#AC0 0=D-c                 
   t          j                    }ddddddddddd
}t           j        dk    r|                     |d           d	}n|                    |          }|s|                     d
|z             |                    |          }d|z   }d|z   }t          j        	                    |d          }	 t           j        
                    dt          j                   t          |dz   dd          5 }|                    d           d d d            n# 1 swxY w Y   t                              |          \  }}	}
|5  |                     |           |                     |	d d                             |                     |                     |
d         d           |                     |
d         d           |                     |
d         t          j                   t                              |||	|
          }|                     |j        d           d d d            n# 1 swxY w Y   t-          j                    5  t-          j        d           t                              ||dz             }d d d            n# 1 swxY w Y   |                     |j        d           t-          j                    5  t-          j        d           t           j        s6t                              |t                              |dz                       }d d d            n# 1 swxY w Y   |                     |j        d           t          j                            |          st          j        |           t          |dd          5 }|                    d           d d d            n# 1 swxY w Y   t-          j                    5  t-          j        d           t                              ||          }d d d            n# 1 swxY w Y   |                     |j         d           t           j        d= dD ]0}tC          j"        ||z              tC          j"        ||z              1tC          j#        |           tC          j#        d           d S # t           j        d= dD ]0}tC          j"        ||z              tC          j"        ||z              1tC          j#        |           tC          j#        d           w xY w)Ns   ä            )
rL   cp1250cp1251rZ   cp1253cp1254cp1255cp1256cp1257cp1258darwinrL   s   äz2can't run this test with %s as filesystem encodingtest_imp_helper_test_imp_helper_package_z__init__.pyr   rW   rX   rY   za = 1
   r   ignorezb = 2
)rW   r[   __pycache__)$r\   getfilesystemencodingplatformr   getskipTestdecoder@   rA   rB   r]   curdirr^   r_   r	   r?   assertIsNotNone
assertTrueendswith	PY_SOURCEload_moduleawarningscatch_warningssimplefilterload_sourcedont_write_bytecodeload_compiledcache_from_sourceexistsmkdirload_packagebr   ra   rmtree)r   fs_encodingknown_localesspecial_chardecoded_charrb   test_package_nameinit_file_namerc   rQ   rR   r3   packageexts                 r   test_issue5604zImportTests.test_issue5604y   s    /11 "  <8##['222 (LL(,,[99L 	)MMN'( ) ) )#**;77*\96E&7GG,	, HOOAry)))me+S7CCC &t

9%%%& & & & & & & & & & & & & & &#&??=#A#A D(D + +$$T***" 6 6} E EFFF  a%000  a#...  a#-888oomT8TJJ  ***+ + + + + + + + + + + + + + + (** L L%h///oom]U5JKKL L L L L L L L L L L L L L L SUA&&&(** F F%h///. F++%--me.CDDF FCF F F F F F F F F F F F F F F SUA&&&7>>"344 ,*+++ncG<<< &

9%%%& & & & & & & & & & & & & & &(** Q Q%h///**+<>OPPQ Q Q Q Q Q Q Q Q Q Q Q Q Q Q WY***& 7 7 !4555 #!56666.///]+++++ & 7 7 !4555 #!56666.///]++++s   9?R 8DR DR !D"#R CH-!R -H11R 4H15R 3J
>R 
JR J1R AL&R &L**R -L*.A#R N3'R 3N77R :N7;R 0PR PR PR A*Tc                     t           j                            t           j                            t                    d          }|                     t          t          j        d|g           d S )Nr=   r>   )	r@   rA   rB   rC   rD   rE   rF   r	   r?   )r   rA   s     r   test_issue9319zImportTests.test_issue9319   sV    w||BGOOH55~FF+/-&	" 	" 	" 	" 	"r   c                    t          j        ddt                    5  dd l}|j        }|j        }t          j                    5  t          	                    d          }| 
                    |d         j                   t          j        dg|R  }|                     ||           |                     ||j                   |                     ||j                   d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr@   zos.pathr   )r   CleanImportOS_PATH_NAMEr@   rA   getenvr   EnvironmentVarGuardr	   r?   
addCleanupr`   r   assertIsassertIsNot)r   r@   	orig_pathorig_getenvxnew_oss         r   test_load_from_sourcez!ImportTests.test_load_from_source   sz    &tYEE 
	= 
	=IIII)K.00 = =OOD))!
+++2222b&)))i555  fm<<<= = = = = = = = = = = = = = =	
	= 
	= 
	= 
	= 
	= 
	= 
	= 
	= 
	= 
	= 
	= 
	= 
	= 
	= 
	= 
	= 
	= 
	=s6   &C?BC'C?'C+	+C?.C+	/C??DDc                     d}t                               |          }|d         }||                     |j                   t          j        |g|R  }|                     |j        |           d S )N_heapqr   )r	   r?   r   r`   r   r   r'   )r   exampler   file_r3   s        r   test_issue15828_load_extensionsz+ImportTests.test_issue15828_load_extensions   sr     OOG$$!OOEK(((og****w/////r   c                 N   d}t                               |          \  }}}|                                 t                               ||          }t                               d|          }t                               d|          }|                     |j        |           |                     |j        d           |                     |j        d           |                     t                    5  t                               d|           d d d            d S # 1 swxY w Y   d S )N_testimportmultiple_testimportmultiple_foo_testimportmultiple_barnonexistent)r	   r?   r`   r   r   r'   rE   ImportError)r   mfileobjpathnamedescriptionmod0mod1mod2s           r   +test_issue16421_multiple_modules_in_one_dllz7ImportTests.test_issue16421_multiple_modules_in_one_dll   sG    "),););&;8,, 98DD 98DD***(ABBB(ABBB{++ 	6 	6]H555	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6 	6s   1DD!Dc                 (   d}d}|                      t                    5 }t                              ||           d d d            n# 1 swxY w Y   |                     ||j        j                   |                     ||j        j                   d S )Nzbogus file path	extension)	rE   r   r	   r   assertIn	exceptionrA   r   name)r   rA   r   errs       r   "test_load_dynamic_ImportError_pathz.ImportTests.test_load_dynamic_ImportError_path  s    
 !{++ 	)sT4(((	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	) 	)dCM.///s}122222s   AAAc                    d}t                               |          }|d         |d                                          |d         d         t           j        k    r|                     d           t          j        |d g|dd          R   d S )Nr   r   rx   z/found module doesn't appear to be a C extensionrv   )r	   r?   r`   C_EXTENSIONr~   r   )r   r   founds      r   'test_load_module_extension_file_is_Nonez3ImportTests.test_load_module_extension_file_is_None  s    
 %%%8!HNN8A;#/))MMKLLLd/U122Y//////r   c                    d}	 t           j        |= n# t          $ r Y nw xY w	 t          j        |          }t          j                            d          }t                              ||j	                  }| 
                    |j        |           | 
                    |j        j        |           | 
                    |j        j	        |j	                   |                     t          t           |d           | 
                    |j        d           |                     t           j        |         |           	 t           j        |= d S # t          $ r Y d S w xY w# 	 t           j        |= w # t          $ r Y w w xY wxY w)Nztest.imp_dummy_testmultiphase
dummy_namei  )r\   modulesKeyErrorr.   r/   util	find_specr	   r   originr   r'   __spec__r   rE   AttributeErrorr   	int_constr   )r   r   modulespecs       r   3test_issue24748_load_module_skips_sys_modules_checkz?ImportTests.test_issue24748_load_module_skips_sys_modules_check   s   	D!! 	 	 	D		,T22F>++,=>>D%%dDK88FV_d333V_14888V_3T[AAAngv|LLLV-t444MM#+d+V444K%%%   K%%   sN    
DE :E	 	
EEE:E*)E:*
E74E:6E77E:z*test meaningful only when writing bytecodec                 
   t          j                    5  t           j        dz   }t          j        |           |                     t          dt          j        t           j        dg           d d d            d S # 1 swxY w Y   d S )NrW   z
^No modulerV   )	r   temp_cwdTESTFNr@   r   assertRaisesRegexr   r	   r?   )r   sources     r   test_bug7732zImportTests.test_bug77327  s     !! 	: 	:%-FHV"";!1C5: : :	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:s   AA88A<?A<c                     t                               dt           j        t          t           j        d                    }|                    t           j                   |                    t           j                   d S )Nr	   rL   rY   )r	   _LoadSourceCompatibilityrD   r^   get_data)r   loaders     r   test_multiple_calls_to_get_dataz+ImportTests.test_multiple_calls_to_get_data@  s_    --eS\.23<'.R.R.RT T%%%%%%%%r   c                    dt            } t          t          j        t                              |          }t	          j        t          j        ||          5  |                     t          d          5  t          	                    |t          dz              d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Ntmpzembedded null )r'   typer\   r   r   	swap_itemr   
ValueErrorr	   r   rD   )r   r7   r3   s      r   test_load_sourcezImportTests.test_load_sourceG  s-    #"")d3;x())'22s{GS99 	: 	:''
ODD : :D999: : : : : : : : : : : : : : :	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	: 	:s6   B<4$B$B<$B(	(B<+B(	,B<<C C c                     t          j        t          d          } G d d          }|                     t                    5   | |                       d d d            d S # 1 swxY w Y   d S )Ncreate_dynamicc                       e Zd ZdZdZdS ),ImportTests.test_issue31315.<locals>.BadSpecNfoo)r'   r(   r)   r   r   r*   r   r   BadSpecr   U  s        DFFFr   r   )r   get_attributer	   rE   	TypeError)r   r   r   s      r   test_issue31315zImportTests.test_issue31315P  s     !.s4DEE	 	 	 	 	 	 	 	 y)) 	& 	&N7799%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s   A##A'*A'c                     dd l }|                     |j        j        d           dd l}|                     |j        j        d           d S )Nr   frozen)_frozen_importlib_externalr   r   r   _frozen_importlib)r   r   r   s      r   test_issue_35321zImportTests.test_issue_35321[  s\    
 	*)))3<CXNNN    *3:HEEEEEr   c                     |                      t          j        dd          d           |                      t          j        dd          d           d S )N*   s   his   G$~+   s   /CC)r   _impsource_hash)r   s    r   test_source_hashzImportTests.test_source_hashf  sP    )"e446PQQQ)"e446PQQQQQr   c                     g dfddgdfddgdfddgdfg}|D ]Z\  }}|ddgz   }t          j        | }|                     |j                                                            d          |           [d S )Ndefaultz--check-hash-based-pycsalwaysneverz-cz.import _imp; print(_imp.check_hash_based_pycs)rL   )r   assert_python_okr   outstripr   )r   casesinterp_argsr   argsress         r   'test_pyc_invalidation_mode_from_cmdlinez3ImportTests.test_pyc_invalidation_mode_from_cmdlinej  s    O'3Y?'2H='17;	
 &+ 	H 	H!K@" D  0$7CSW]]__33G<<hGGGG	H 	Hr   c                    t          j                    5  t          dd          5 }|                    d           d d d            n# 1 swxY w Y   t	          j        ddt          j        j                   t          	                    ddg          \  }}}t          
                    d|||          }d d d            n# 1 swxY w Y   |                     |j        d	           d S )
Nzmymod.pywbs   x = 42
T)doraiseinvalidation_modemymodrV   )rA   r   )r   r   r^   r_   
py_compilecompilePycInvalidationModeCHECKED_HASHr	   r?   r   r   r   )r   rP   rc   rA   r   r3   s         r   test_find_and_load_checked_pycz*ImportTests.test_find_and_load_checked_pycy  sk   !! 		D 		Dj$'' &2%%%& & & & & & & & & & & & & & &","@"M   
 '*oogSEo&J&J#D$//'4{CCC		D 		D 		D 		D 		D 		D 		D 		D 		D 		D 		D 		D 		D 		D 		D 	#####s4   CACA	CA	A'CC	Cc                      dd l t          j        t          d          } G d d          } |             fd} |             t          j        d          }                     |d            |             d S )Nr   create_builtinc                       e Zd ZdZdS )7ImportTests.test_create_builtin_subinterp.<locals>.SpecbuiltinsN)r'   r(   r)   r   r*   r   r   Specr    s        DDDr   r  c                      t          j                  } t          j                  }                    |                               t          j                  | dz              t          j                     d S )Nrv   )r\   getrefcountr   r  r   r   gccollect)refcntr3   r  r   r   s     r   check_get_builtinszEImportTests.test_create_builtin_subinterp.<locals>.check_get_builtins  si    _X..F%d++CMM#x(((S_X66
CCCJLLLLLr   zimport builtins)r  r   r   r   run_in_subinterpr   )r   r  r  r  retr  r   s   `    @@r   test_create_builtin_subinterpz)ImportTests.test_create_builtin_subinterp  s     	 .t5EFF	 	 	 	 	 	 	 	tvv	 	 	 	 	 	 	 	&'899a   r   N) r'   r(   r)   r4   r:   rI   rS   rd   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*   r   r   r,   r,   C   s       & & &
0 0 07 7 7L L L&5 5 5U, U, U,n" " "= = =* 	0 	0 	0 6 6 6 	3 	3 	3 
0 
0 
0   , X_S,46 6: :6 6:& & &: : : & & &	F 	F 	FR R RH H H$ $ $     r   r,   c                   (    e Zd Z	 d Zd Zd Zd ZdS )ReloadTestsc                     t          j                    5  dd l}t                              |           d d d            d S # 1 swxY w Y   d S )Nr   )r   r   r@   r	   reload)r   r@   s     r   test_sourcezReloadTests.test_source  s     *,, 	 	IIIJJrNNN	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A  AAc                     t          j        d          5  dd l}t                              |           d d d            d S # 1 swxY w Y   d S )Ntimer   )r   r   r(  r	   r%  )r   r(  s     r   test_extensionzReloadTests.test_extension  s    &v.. 	 	KKKJJt	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   AAAc                     t          j        d          5  dd l}t                              |           d d d            d S # 1 swxY w Y   d S )Nmarshalr   )r   r   r,  r	   r%  )r   r,  s     r   test_builtinzReloadTests.test_builtin  s    &y11 	  	 NNNJJw	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 r*  c                 "   ddl m} t          j                            d          fd}|                     |           |                     t          d          5  t          	                    |           d d d            d S # 1 swxY w Y   d S )Nr   )parserhtmlc                  &     t           j        d<   d S )Nr0  )r\   r   )r0  s   r   cleanupz5ReloadTests.test_with_deleted_parent.<locals>.cleanup  s    "&CKr   )
r0  r/  r\   r   popr   r   r   r	   r%  )r   r/  r2  r0  s      @r   test_with_deleted_parentz$ReloadTests.test_with_deleted_parent  s    {v&&	' 	' 	' 	' 	'   ##K88 	 	JJv	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   BBBN)r'   r(   r)   r&  r)  r-  r4  r*   r   r   r#  r#    sU        
 
 
  
     
    r   r#  c                       e Zd Z	 e                                Z ej        ej	        j
        dud          d             Z ej        ej	        j
        dud          d             ZdS )PEP3147TestsNz1requires sys.implementation.cache_tag not be Nonec           	         t           j                            dddd          }t           j                            ddddd                    | j                            }|                     t                              |d          |           d S )Nr   barbazqux.pyrz   
qux.{}.pycT)r@   rA   rB   formattagr   r	   r   r   rA   expects      r   test_cache_from_sourcez#PEP3147Tests.test_cache_from_source  sy    
 w||E5%::eUE=*11$(;;= =..tT::FCCCCCr   z4requires sys.implementation.cache_tag to not be Nonec           	         t           j                            ddddd                    | j                            }t           j                            dddd          }|                     t                              |          |           d S )Nr   r8  r9  rz   r;  r:  )r@   rA   rB   r<  r=  r   r	   source_from_cacher>  s      r   test_source_from_cachez#PEP3147Tests.test_source_from_cache  sw     w||E5%(//99; ;eUE8<<..t44f=====r   )r'   r(   r)   r	   get_tagr=  r   
skipUnlessr\   implementation	cache_tagr@  rC  r*   r   r   r6  r6    s        
++--CX+5TALN ND DN ND X+5TA ! !> >! !> > >r   r6  c                   P    e Zd Z ej        ej        du d          d             ZdS )NullImporterTestsNzNeed an undecodeable filenamec                     t           j        }t          j        |           	 |                     t
          t          j        |           t          j        |           d S # t          j        |           w xY w)N)	r   TESTFN_UNENCODABLEr@   r   rE   r   r	   NullImporterrmdir)r   r   s     r   test_unencodeablez#NullImporterTests.test_unencodeable  s\     +
	k3+;TBBBHTNNNNNBHTNNNNs   &A A4)r'   r(   r)   r   r   r   rK  rN  r*   r   r   rI  rI    sK        X_Y1T946 6 6 6  r   rI  __main__)r  r.   importlib.utilr@   os.pathr  r\   r6   r   test.supportr   r   r   r   r   r   r   import_deprecatedr	   r   rA   r'   r   r   TestCaser   r,   r#  r6  rI  mainr*   r   r   <module>rV     s   				         				      



       & & & & & & " " " " " " & & & & & & ( ( ( ( ( (              'o'..  w@ @ @ ,  ,  ,  ,  ,!  ,  ,  ,D_ _ _ _ _(# _ _ _D# # # # #(# # # #L> > > > >8$ > > >6	 	 	 	 	) 	 	 	 zHMOOOOO r   