
    3hh3                        S SK r S SKrS SKrS SKrS SKJrJrJr  S SKrS SK	r	S SK
r	S SKJr  S SKJr  S SKJr  S SKJr  S SKJr  S SKrS SKrS SKrS SKr\R.                  " S5      r\R2                  " 5       rS\l        S\l        S	\R:                  ;   a  S	\l        S
\R:                  ;  a  S
\l        \R<                  (       a  S rOK\R2                  " 5       q S[@        l!        S[@        l"        S[@        l#        S[@        l$        S[@        l%        S r\" 5         S r&S(S jr'S(S jr(S(S jr)Sr*\RV                  S;  aH  \,R[                  5       r.\.\,:X  a  \,R_                  5       r.\	RB                  Ra                  \.5      (       d  Sr*\&" S
5      S   r1\2" \ Rf                  5      \2" \1Rf                  5      S.r3S r4S)S jr5S r6\Rn                  S 5       r8\Rn                  S)SS.S jj5       r9\Rn                  S 5       r: " S S5      r; " S S \;5      r<S! r=S" r>\Rn                  S# 5       r?\Rn                  S$ 5       r@S% rA " S& S'5      rBg)*    N)	machineryutilinvalidate_caches)support)import_helper)is_apple_mobile)	os_helper)ExtraAssertions_testsinglephaseerrno	importlibc                      S q g N)
EXTENSIONS     A/opt/python-3.13.8/usr/lib/python3.13/test/test_importlib/util.py_extension_detailsr   #   s    
r   c                     [         R                   H  n [        R                   H  n[        (       a  UR                  SS5      n[        R                  U-   n[        R                  R                  X5      n[        R                  R                  U5      (       d  Mx  U [        l        U[        l        U[        l        U[        l            g    M     g )Nz.soz.fwork)syspathr   EXTENSION_SUFFIXESr   replacer   nameosjoinexistsextfilename	file_path)r   r   r   r    s       r   r   r   .   s    HHD 33 #?++eX6C%??S0GGLL8	77>>),,&*JO%(JN*2J'+4J( 4 r   c                 t    SU ;   a  SOSn[         R                  " U 5      n[         R                  " XSS9nX#S.$ )zAImport a module from importlib both w/ and w/o _frozen_importlib..)r   r   )_frozen_importlib_frozen_importlib_external)freshblockedFrozenSource)r   import_fresh_module)module_namer%   frozensources       r   import_importlibr.   C   s?    ![0NbE..{;F..{1dfF//r   c                 t   Uc  [         R                  nO[        U[        5      (       d  X!   nSR	                  XR
                  5      nX[        4n[        R                  " XE5      nU R                  Ul	        U R
                  Ul
        Xl        UR                  5        H  u  pxX   n	[        XgU	5        M     U$ )Nz{}_{})unittestTestCase
isinstancetypeformat__name__r
   types	new_class
__module___NAME_KINDitemssetattr)
clskindbasekwargsr   basesspecializedattrvaluesvalues
             r   specialize_classrF   L   s     |  d##z>>$-D(E//$.K ^^KK5) ' r   c                 @    [        U SU40 UD6n[        U SU40 UD6nX44$ )Nr(   r)   )rF   )r=   r?   r@   r,   r-   s        r   split_frozenrH   _   s0    c8T<V<Fc8T<V<F>r   c                     [        X40 UD6$ r   )rH   )
test_classr?   r@   s      r   	test_bothrK   e   s    
3F33r   T)win32cygwinFr)   r'   c                 N    [         R                  " [        (       + S5      " U 5      $ )zNClass decorator that nullifies tests requiring a case-insensitive
file system.z&requires a case-insensitive filesystem)r0   skipIfCASE_INSENSITIVE_FS)tests    r   case_insensitive_testsrR   x   s)     ??22DFFJL Lr   c                     [         R                  R                  X!S-   5      n[        USSS9 nUR	                  U5        S S S 5        SR                  X5      U4$ ! , (       d  f       N!= f)N.pywutf-8encodingz{}.{})r   r   r   openwriter4   )parentr   pkg_dircontentr   subfiles         r   	submoduler_      sT    77<<.D	dC'	*gg 
+>>&'-- 
+	*s   A
A)c                     [        U S5       nUR                  S5        [        R                  " U5      sSSS5        $ ! , (       d  f       g= f)zfReads a pyc file and returns the unmarshalled code object within.

No header validation is performed.
rb   N)rY   seekmarshalload)pyc_pathpyc_fs     r   get_code_from_pycrh      s3    
 
h	

2||E" 
		s	   '>
Ac               '   h  #    U  H5  nUS;   a  [        SR                  U5      5      e [        R                  U	 M7      Sv   U  H  n [        R                  U	 M     g! [         a     Mg  f = f! [         a     M8  f = f! U  H&  n [        R                  U	 M  ! [         a     M$  f = f   f = f7f)zUncache a module from sys.modules.

A basic sanity check is performed to prevent uncaching modules that either
cannot/shouldn't be uncached.

)r   rd   zcannot uncache {}N)
ValueErrorr4   r   modulesKeyError)namesr   s     r   uncachern      s      %%077=>>	D!	 DKK%   		   DKK%  s   &B2AB2B B2	A0B2
A-)B2,A--B20
A>:B2=A>>B2B/BB/
B)	%B/(B)	)B//B2)pkgc          	   #     #    [         R                   Vs/ s H  o3R                  S5      S   U :X  d  M  UPM      nn[        R                  " S 5       n[        U /UQ76    [        R                  " U5         [        5         [        R                  R                  XP5      nU(       a7  [        R                  R                  US5      n[        R                  " U 5        O
US-   nUc  SnUb%  [        USSS9 nUR                  U5        S S S 5        Uv   S S S 5        S S S 5        S S S 5        g s  snf ! , (       d  f       N0= f! , (       d  f       N5= f! , (       d  f       N>= f! , (       d  f       g = f7f)	Nr"   r   z__init__.pyrT    rU   rV   rW   )r   rk   	partitionr	   temp_cwdrn   r   DirsOnSysPathr   r   r   r   mkdirrY   rZ   )	r   r]   ro   n	conflictscwdlocationmodpathmodfiles	            r   temp_moduler|      s    KKGKq;;s+;A+>$+FKIG			D	!ST&I&,,S1!#77<<2 ggll8]CGHHTN&.G"$&gsW=g. >! 2 ' 
"	! H" >= 21 '& 
"	!su   E6D-D-E6E%E6B E6D2	EEE%$E62
E <E
EE
E"	E%%
E3/E6c               +     #    0 n S/ 4S/ 4S/ 4S0 44 H5  u  p#[        [        U5      X'   X ;   a  X   nX	 OUn[        [        X$5        M7     [        U 5      (       a  [	        SR                  U 5      5      eSv   UR                  5        H  u  p%[        [        X%5        M     g! UR                  5        H  u  p%[        [        X%5        M     f = f7f)a  Context manager to manage the various importers and stored state in the
sys module.

The 'modules' attribute is not supported as the interpreter state stores a
pointer to the dict that the interpreter uses internally;
reassigning to sys.modules does not have the desired effect.

	meta_pathr   
path_hookspath_importer_cachezunrecognized arguments: {}N)getattrr   r<   lenrj   r4   r;   )r@   	originalsrC   default	new_valuerE   s         r   import_stater      s      I&*B/&"+R04b9;MD &c40IO~"L	L#	C); v;;9@@HII$??,KDC% -9??,KDC% -s   CA5B% ;*C%+CCc                   8    \ rS rSrSr0 S.S jrS rS rS rSr	g	)
_ImporterMock   z0Base class to help with creating importer mocks.)module_codec                   0 U l         0 U l        U H  nUR                  S5      (       d  UnOUS [        S5      *  nSU;  a  S nOXC:X  a  UR	                  SS5      S   nOUn[
        R                  " U5      nXl        SUl        XVl	        X6l
        XC:w  a  S/Ul        X`R                   U'   XA;   d  M  X   U R                  U'   M     g )N	.__init__r"      r   z<mock __file__>z<mock __path__>)rk   r   endswithr   rsplitr6   
ModuleType
__loader____file____package__rC   __path__)selfr   rm   r   import_namepackagemodules          r   __init___ImporterMock.__init__   s    D==--""#5S%5$56$$++c1-a0%%%k2F $/FO!(K"#4"5(.LL%)0;0H  -) r   c                      U R                   U   $ r   )rk   )r   r   s     r   __getitem___ImporterMock.__getitem__   s    ||D!!r   c                     [        U R                  R                  5       6 U l        U R                  R	                  5         U $ r   )rn   rk   keys_uncache	__enter__)r   s    r   r   _ImporterMock.__enter__   s0    !2!2!45!r   c                 >    U R                   R                  S S S 5        g r   )r   __exit__)r   exc_infos     r   r   _ImporterMock.__exit__  s    tT40r   )r   r   rk   N)
r5   r8   __qualname____firstlineno____doc__r   r   r   r   __static_attributes__r   r   r   r   r      s    :+- I2"
1r   r   c                   .    \ rS rSrSrSS jrS rS rSrg)		mock_speci  z!Importer mock using PEP 451 APIs.Nc           
           U R                   U   n[        R                  " XR                  U [        USS 5      S9nU$ ! [         a     g f = f)Nr   )loadersubmodule_search_locations)rk   rl   r   spec_from_file_locationr   r   )r   fullnamer   r[   r   specs         r   	find_specmock_spec.find_spec  sX    	\\(+F ++//$+26:t+LN   		s   > 
A
Ac                 t    UR                   U R                  ;  a  [        eU R                  UR                      $ r   )r   rk   ImportError)r   r   s     r   create_modulemock_spec.create_module  s+    99DLL(||DII&&r   c                 v     U R                   UR                  R                     " 5         g ! [         a     g f = fr   )r   __spec__r   rl   )r   r   s     r   exec_modulemock_spec.exec_module  s4    	V__1124 		s   (+ 
88r   )NN)	r5   r8   r   r   r   r   r   r   r   r   r   r   r   r     s    +'
r   r   c                    ^  [         R                  (       a  [        R                  " S5      " T 5      $ [        R
                  " T 5      U 4S j5       nU$ )zpDecorator to protect sys.dont_write_bytecode from mutation and to skip
tests that require it to be set to False.zrelies on writing bytecodec                     > [         R                  nS[         l         T" U 0 UD6nU[         l        U$ ! U[         l        f = f)NF)r   dont_write_bytecode)argsr@   original	to_returnfxns       r   wrapper&writes_bytecode_files.<locals>.wrapper'  sD    **"'	/T,V,I&.C# '/C#s	   3 A )r   r   r0   skip	functoolswraps)r   r   s   ` r   writes_bytecode_filesr   "  sE     }}9:3??__S  Nr   c                      [         R                  " [         R                  R                  U 5      5        g! [         a)  nUR
                  [
        R                  :w  a  e  SnAgSnAff = f)zEnsure that the __pycache__ directory for PEP 3147 pyc file exists.

:param bytecode_path: File system path to PEP 3147 pyc file.
N)r   ru   r   dirnameOSErrorr   EEXIST)bytecode_patherrors     r   ensure_bytecode_pathr   3  sH    

/0 ;;%,,& 's   36 
A) A$$A)c              #      #    [         R                  nU [         l         Sv   U[         l        g! U[         l        f = f7f)z&Adjust and restore sys.pycache_prefix.N)r   pycache_prefix)prefix_orig_prefixs     r   temporary_pycache_prefixr   ?  s2      %%LC*)\s   ?/ ?<?c               '     #    Sn/ n0 nSnSn [         R                  " 5       nXcS'   [        5       nU  GH[  nUR                  S5      (       d  Un	OUS[	        S5      *  n	UR                  U	5        U	[        R                  ;   a  [        R                  U		 UR                  S5      n
UnU
SS  Ho  n[        R                  R                  X5      n[        R                  R                  U5      (       a  MH  [        R                  " U5        UR                  U5        Mq     [        R                  R                  XS   S-   5      n[        US	S
S9 nUR!                  UR#                  U5      5        SSS5        UR                  U5        XU'   GM^     [%        U6 nUR'                  5         [)        U/S9nUR'                  5         Uv   Ub  UR+                  SSS5        Ub  UR+                  SSS5        [,        R.                  " U5        g! , (       d  f       N= f! Ub  UR+                  SSS5        Ub  UR+                  SSS5        [,        R.                  " W5        f = f7f)a*  Temporarily create each named module with an attribute (named 'attr')
that contains the name passed into the context manager that caused the
creation of the module.

All files are created in a temporary directory returned by
tempfile.mkdtemp(). This directory is inserted at the beginning of
sys.path. When the context manager exits all created files (source and
bytecode) are explicitly deleted.

No magic is performed when creating packages! This means that if you create
a module within a package you must also create the package's __init__ as
well.

zattr = {0!r}Nz.rootr   r   r"   rT   rU   rV   rW   )r   )tempfilemkdtempsetr   r   addr   rk   splitr   r   r   r   ru   appendrY   rZ   r4   rn   r   r   r   r	   rmtree)rm   r-   created_pathsmappingstate_manageruncache_managertemp_dirimport_namesr   r   
name_partsr    	directoryfiles                 r   create_modulesr   J  s      FMGMO"###%#uD==,,""#5S%5$56[)ckk)KK,CJ I'_	GGLL>	ww~~i00HHY'!((3	 -
 Y20FGIiw74

6==./ 8  +%DM' ( "<0!!#$8*5!$""4t4&$$T46" 87 $""4t4&$$T46"s?   I$C#H 5AH !H1AH 	AI$
H	H AI!!I$c                    ^ ^ UU 4S jnU$ )zA mock sys.path_hooks entry.c                     > U T;  a  [         eT$ r   )r   )entryentriesimporters    r   hookmock_path_hook.<locals>.hook  s    r   r   )r   r   r   s   `` r   mock_path_hookr     s     Kr   c                       \ rS rSrS rSrg)CASEOKTestBasei  c                `   ^  Sn[        U 4S jU 5       5      U:w  a  T R                  S5        g g )N)s   PYTHONCASEOKPYTHONCASEOKc              3   ~   >#    U  H2  nUTR                   R                  R                  R                  ;   v   M4     g 7fr   )r   _bootstrap_external_osenviron).0xr   s     r   	<genexpr>4CASEOKTestBase.caseok_env_changed.<locals>.<genexpr>  s3      ,* DNN66::BBB*s   :=z/os.environ changes not reflected in _os.environ)anyskipTest)r   should_existpossibilitiess   `  r   caseok_env_changed!CASEOKTestBase.caseok_env_changed  s7    7 ,*, ,/;<MMKL<r   r   N)r5   r8   r   r   r  r   r   r   r   r   r     s    Mr   r   r   )rq   )Cbuiltins
contextlibr   r   r   r   r   r   rd   r   os.pathrQ   r   test.supportr   r   r	   test.support.testcaser
   r0   r   r   r6   import_moduler   SimpleNamespaceBUILTINS	good_namebad_namebuiltin_module_namesis_wasir   r   r   r   r   r    r   r.   rF   rH   rK   rP   platformr   upperchanged_namelowerr   source_importlibstaticmethod
__import__rR   r_   rh   contextmanagerrn   r|   r   r   r   r   r   r   r   r   r   r   r   r   <module>r     sL       8 8  	   & ( " 1  
   ../AB    "  
c&&& Hc...#H
??
 &&(JJOJNJJ(JO$  0&4   <<**>>#Lx~~'77>>,''##K0: $X%8%89$%5%@%@AC
L.#  0   . & &:&1 &1R 4"	 * * 6# 6#rM Mr   