
    <et3                        d dl Z d dlZd dlZd dlZd dlmZmZm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Zd dlZd dlZd dlZ ej                    Zde_        de_        dej        v rde_        dej        vrde_         ej                    adt.          _        dt.          _        dt.          _        dt.          _        dt.          _        d Z e             d	 Zd'd
Zd'dZ d'dZ!dZ"ej#        dvrJe$%                                Z&e&e$k    re$'                                Z&e	j        (                    e&          sdZ" ed          d         Z) e*e j+                   e*e)j+                  dZ+d Z,d(dZ-d Z.ej/        d             Z0ej/        d(ddd            Z1ej/        d             Z2 G d d          Z3 G d de3          Z4 G d de3          Z5d  Z6d! Z7ej/        d"             Z8ej/        d#             Z9d$ Z: G d% d&          Z;dS ))    N)	machineryutilinvalidate_caches)import_helper)	os_helpererrno	importlib	_testcapic                  F   t           j        D ]} t          j        D ]}t          j        |z   }t          j                            | |          }t          j                            |          r4| t          _        |t          _	        |t          _
        |t          _          d S d S N)syspathr   EXTENSION_SUFFIXES
EXTENSIONSnameosjoinexistsextfilename	file_path)r   r   r   r   s       //usr/lib/python3.11/test/test_importlib/util.py_extension_detailsr       s     	 	/ 	 	C!,HT844Iw~~i(( "&
!$
&.
#'0
$		 	    c                 r    d| v rdnd}t          j        |           }t          j        | |d          }||dS )zAImport a module from importlib both w/ and w/o _frozen_importlib..)r	    )_frozen_importlib_frozen_importlib_external)freshblockedFrozenSource)r   import_fresh_module)module_namer    frozensources       r   import_importlibr)   0   sT    ![00NNbE.{;;F.{%1df f fF///r   c                 j   |t           j        }nt          |t                    s||         }d                    || j                  }| |f}t          j        ||          }| j        |_        | j        |_	        ||_
        |                                D ]\  }}||         }	t          |||	           |S )Nz{}_{})unittestTestCase
isinstancetypeformat__name__types	new_class
__module___NAME_KINDitemssetattr)
clskindbasekwargsr   basesspecializedattrvaluesvalues
             r   specialize_classrA   9   s     | d## Dz>>$--D$KE/$..K ^KKK * *ftT5))))r   c                 F    t          | d|fi |}t          | d|fi |}||fS )Nr#   r$   )rA   )r8   r:   r;   r'   r(   s        r   split_frozenrC   L   s>    c8T<<V<<Fc8T<<V<<F6>r   c                     t          | |fi |S r   )rC   )
test_classr:   r;   s      r   	test_bothrF   R   s    
D33F333r   T)win32cygwinFr$   r"   c                 J     t          j        t           d          |           S )zRClass decorator that nullifies tests requiring a case-insensitive
    file system.z&requires a case-insensitive filesystem)r+   skipIfCASE_INSENSITIVE_FS)tests    r   case_insensitive_testsrM   e   s6    F8?22DF FFJL L Lr    c                     t           j                            ||dz             }t          |dd          5 }|                    |           d d d            n# 1 swxY w Y   d                    | |          |fS )N.pywutf-8encodingz{}.{})r   r   r   openwriter/   )parentr   pkg_dircontentr   subfiles         r   	submoduler[   l   s    7<<..D	dC'	*	*	* gg              >>&$''--s   AAAc                     t          | d          5 }|                    d           t          j        |          cddd           S # 1 swxY w Y   dS )znReads a pyc file and returns the unmarshalled code object within.

    No header validation is performed.
    rb   N)rU   seekmarshalload)pyc_pathpyc_fs     r   get_code_from_pycrd   s   s    
 
h		 #

2|E""# # # # # # # # # # # # # # # # # #s   )AAAc               '   <  K   | D ]F}|dv r"t          d                    |                    	 t          j        |= 7# t          $ r Y Cw xY w	 dV  | D ] }	 t          j        |= # t          $ r Y w xY wdS # | D ] }	 t          j        |= # t          $ r Y w xY ww xY w)zUncache a module from sys.modules.

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

    )r   r`   impzcannot uncache {0}N)
ValueErrorr/   r   modulesKeyError)namesr   s     r   uncacherk   }   s        ,,,$++D113 3 3	D!! 	 	 	D	 	 	DK%%   	 	E 	 	DK%%   	sQ   <
A	A	A6 A$$
A10A16B<B
	B

B	BB	B)pkgc          	   #      K    fdt           j        D             }t          j        d           5 }t	           g|R  5  t          j        |          5  t                       t          j	        
                    |           }|r5t          j	        
                    |d          }t          j                    n	|dz   }|d}|?t          |dd          5 }|                    |           d d d            n# 1 swxY w Y   |V  d d d            n# 1 swxY w Y   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 )Nc                 R    g | ]#}|                     d           d         k    !|$S )r   r   )	partition).0nr   s     r   
<listcomp>ztemp_module.<locals>.<listcomp>   s4    GGGq1;;s+;+;A+>$+F+F+F+F+Fr   z__init__.pyrP   rN   rQ   rR   rS   )r   rh   r   temp_cwdrk   r   DirsOnSysPathr   r   r   r   mkdirrU   rV   )r   rY   rl   	conflictscwdlocationmodpathmodfiles   `       r   temp_moduler{      sN     GGGGCKGGGI		D	!	! ST&I&&& 	 	,S11  !###7<<T22 % gll8]CCGHTNNNN&.G"$&gsW=== /g.../ / / / / / / / / / / / / / /!              	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                 s}   ED*BDC8	,D8C<<D?C< DD*DD*DD*E*D.	.E1D.	2EE	Ec               +     K   i }	 dg fdg fdg fdi ffD ]E\  }}t          t          |          ||<   || v r| |         }| |= n|}t          t          ||           Ft          |           r4t	          d                    |                                                     dV  |                                D ]\  }}t          t          ||           dS # |                                D ]\  }}t          t          ||           w xY w)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: {0}N)getattrr   r7   lenrg   r/   keysr6   )r;   	originalsr>   default	new_valuer@   s         r   import_stater      sK      I&*B/&"+R04b9; 		* 		*MD' &c400IdOv~~"4L	4LL#	Cy))))v;; 	I188GGI I I$??,, 	& 	&KD%Cu%%%%	& 	&9??,, 	& 	&KD%Cu%%%%	&s   BC 2Dc                   0    e Zd ZdZi ddZd Zd Zd ZdS )_ImporterMockz0Base class to help with creating importer mocks.)module_codec                   i | _         i | _        |D ]}|                    d          s|}n|d t          d                    }d|vrd }n%||k    r|                    dd          d         }n|}t          j        |          }| |_        d|_        ||_	        ||_
        ||k    rdg|_        || j         |<   ||v r||         | j        |<   d S )N	.__init__r      r   z<mock __file__>z<mock __path__>)rh   r   endswithr   rsplitr1   
ModuleType
__loader____file____package__r>   __path__)selfr   rj   r   import_namepackagemodules          r   __init__z_ImporterMock.__init__   s    	I 	ID==-- 7""#5S%5%5$5#56$$$++c1--a0%%k22F $F/FO!(FFKd""#4"5(.DL%k))0;K0H -)	I 	Ir   c                     | j         |         S r   rh   )r   r   s     r   __getitem__z_ImporterMock.__getitem__   s    |D!!r   c                     t          | j                                         | _        | j                                         | S r   )rk   rh   r   _uncache	__enter__)r   s    r   r   z_ImporterMock.__enter__   s5    !2!2!4!45!!!r   c                 >    | j                             d d d            d S r   )r   __exit__)r   exc_infos     r   r   z_ImporterMock.__exit__   s"    tT400000r   N)r0   r3   __qualname____doc__r   r   r   r   r   r   r   r   r      sh        ::+- I I I I I2" " "  
1 1 1 1 1r   r   c                        e Zd ZdZddZd ZdS )mock_modulesz!Importer mock using PEP 302 APIs.Nc                     || j         vrd S | S r   r   )r   fullnamer   s      r   find_modulezmock_modules.find_module   s    4<''4Kr   c                     || j         vrt          | j         |         t          j         |<   || j        v r3	  | j        |                      n# t          $ r t          j         |=  w xY w| j         |         S r   )rh   ImportErrorr   r   	Exception)r   r   s     r   load_modulezmock_modules.load_module  s    4<''$(L$:CK!4+++.D$X.0000    H- <))s   A A$r   )r0   r3   r   r   r   r   r   r   r   r   r      s=        ++   * * * * *r   r   c                   &    e Zd ZdZddZd Zd ZdS )	mock_specz!Importer mock using PEP 451 APIs.Nc           
          	 | j         |         }n# t          $ r Y d S w xY wt          j        ||j        | t          |dd                     }|S )Nr   )loadersubmodule_search_locations)rh   ri   r   spec_from_file_locationr   r   )r   r   r   rW   r   specs         r   	find_speczmock_spec.find_spec  sp    	\(+FF 	 	 	44	+&/$+26:t+L+LN N N s    
c                 P    |j         | j        vrt          | j        |j                  S r   )r   rh   r   )r   r   s     r   create_modulezmock_spec.create_module  s&    9DL((|DI&&r   c                 h    	  | j         |j        j                              d S # t          $ r Y d S w xY wr   )r   __spec__r   ri   )r   r   s     r   exec_modulezmock_spec.exec_module"  sJ    	2DV_1244444 	 	 	DD	s   # 
11)NN)r0   r3   r   r   r   r   r   r   r   r   r   r     sL        ++   ' ' '
    r   r   c                      t           j        r t          j        d                     S t	          j                    fd            }|S )ztDecorator 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                      t           j        }dt           _        	  | i |}|t           _        n# |t           _        w xY w|S )NF)r   dont_write_bytecode)argsr;   original	to_returnfxns       r   wrapperz&writes_bytecode_files.<locals>.wrapper.  sQ    *"'	/T,V,,I&.C##hC#....s   0 >)r   r   r+   skip	functoolswraps)r   r   s   ` r   writes_bytecode_filesr   )  sa      @:x}9::3???_S     Nr   c                     	 t          j        t           j                            |                      dS # t          $ r!}|j        t
          j        k    r Y d}~dS d}~ww xY w)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   :  sp    

//00000   ;%,&& '&&&&&s   15 
A AA c              #   ~   K   t           j        }| t           _        	 dV  |t           _        dS # |t           _        w xY w)z&Adjust and restore sys.pycache_prefix.N)r   pycache_prefix)prefix_orig_prefixs     r   temporary_pycache_prefixr   F  sH       %LC*)\))))s   . <c               '   *  K   d}g }i }d}d}	 t          j                    }||d<   t                      }| D ]}|                    d          s|}	n|dt	          d                    }	|                    |	           |	t          j        v rt          j        |	= |                    d          }
|}|
dd         D ]j}t          j
                            ||          }t          j
                            |          s)t          j        |           |                    |           kt          j
                            ||
d         dz             }t          |d	d
          5 }|                    |                    |                     ddd           n# 1 swxY w Y   |                    |           |||<   t%          | }|                                 t)          |g          }|                                 |V  ||                    ddd           ||                    ddd           t-          j        |           dS # ||                    ddd           ||                    ddd           t-          j        |           w xY w)aR  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   rP   rQ   rR   rS   )r   )tempfilemkdtempsetr   r   addr   rh   splitr   r   r   r   ru   appendrU   rV   r/   rk   r   r   r   r   rmtree)rj   r(   created_pathsmappingstate_manageruncache_managertemp_dirimport_namesr   r   
name_partsr   	directoryfiles                 r   create_modulesr   Q  s       FMGMO"##%%#uu 	& 	&D==,, 7""#5S%5%5$5#56[)))ck))K,CJ I'_ 4 4	GLLI>>	w~~i00 4HY'''!((333Y
20FGGIiw777 04

6==..///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  +++%GDMM!<0!!###$8*555!!!$""4t444&$$T4666"""""	 $""4t444&$$T4666""""s2   EI
  )F	I
 F	I
 F	A%I
 
AJc                       fd}|S )zA mock sys.path_hooks entry.c                     | vrt           S r   )r   )entryentriesimporters    r   hookzmock_path_hook.<locals>.hook  s    r   r   )r   r   r   s   `` r   mock_path_hookr     s)          Kr   c                       e Zd Zd ZdS )CASEOKTestBasec                x     d}t           fd|D                       |k    r                     d           d S d S )N)s   PYTHONCASEOKPYTHONCASEOKc              3   H   K   | ]}|j         j        j        j        v V  d S r   )r	   _bootstrap_external_osenviron)rp   xr   s     r   	<genexpr>z4CASEOKTestBase.caseok_env_changed.<locals>.<genexpr>  sG       , , DN6:BB , , , , , ,r   z/os.environ changes not reflected in _os.environ)anyskipTest)r   should_existpossibilitiess   `  r   caseok_env_changedz!CASEOKTestBase.caseok_env_changed  sk    7 , , , ,*, , , , ,/;< <MMKLLLLL< <r   N)r0   r3   r   r   r   r   r   r   r     s(        M M M M Mr   r   r   )rN   )<builtins
contextlibr   r   r	   r   r   r   r`   r   os.pathtest.supportr   r   r+   r   r   r1   SimpleNamespaceBUILTINS	good_namebad_namebuiltin_module_namesr   r   r   r   r   r   r   r)   rA   rC   rF   rK   platformr   upperchanged_namelowerr   source_importlibstaticmethod
__import__rM   r[   rd   contextmanagerrk   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r     s             8 8 8 8 8 8 8 8 8 8  				  & & & & & & " " " " " "  



   !5 ""  
c&&& Hc...#H"U"$$



 
 
       0 0 0   &   4 4 4 4   <***>>##Lx~~''7>>,'' $###K00: $X%899$%5%@AAC C
L L L. . . .# # #   2      . & & &<&1 &1 &1 &1 &1 &1 &1 &1R* * * * *= * * *0       4  "	 	 	 * * * 6# 6# 6#r  M M M M M M M M M Mr   