
    daf                     d   d dl mZmZ  ej                  d      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Zd dlZ G d dej                        Z G d de      Z ej"                  ee	      \  ZZ G d
 de      Z ej"                  ee	      \  ZZedk(  r ej0                          yy)    )abcutilzimportlib.machineryN)make_legacy_pycc                       e Zd ZdZd Zd ZdddddZd Zd Zd	 Z	d
 Z
d Zd Zd Zd Zd Z ej"                  ej&                  dk7  d      d        Zd Zy)FinderTestsaE  For a top-level module, it should just be found directly in the
    directory being searched. This is true for a directory with source
    [top-level source], bytecode [top-level bc], or both [top-level both].
    There is also the possibility that it is a package [top-level package], in
    which case there will be a directory with the module name and an
    __init__.py file. If there is a directory without an __init__.py an
    ImportWarning is returned [empty dir].

    For sub-modules and sub-packages, the same happens as above but only use
    the tail end of the name [sub module] [sub package] [sub empty].

    When there is a conflict between a package and module having the same name
    in the same directory, the package wins out [package over module]. This is
    so that imports of modules within the package can occur rather than trigger
    an import error.

    When there is a package and module with the same name, always pick the
    package over the module [package over module]. This is so that imports from
    the package have the possibility of succeeding.

    c                     | j                   j                  | j                   j                  f| j                   j                  | j                   j                  fg} | j                   j
                  |g| S N)	machinerySourceFileLoaderSOURCE_SUFFIXESSourcelessFileLoaderBYTECODE_SUFFIXES
FileFinder)selfrootloader_detailss      A/root/Python-3.12.4/Lib/test/test_importlib/source/test_finder.py
get_finderzFinderTests.get_finder(   se    >>:: NN::<>>>> NN<<>? )t~~((???    c                 L    | j                  |      }| j                  ||d      S )NTloader_only)r   _find)r   r   modulefinders       r   import_zFinderTests.import_/   s%    &zz&&dz;;r   Ncompile_unlinkc                   ||h}t        j                  | 5 }|r|D ]  }t        j                  ||           |r.|D ])  }t	        j
                  ||          	 t        ||          + | j                  |d   |      }| j                  t        |d             |cddd       S # t        $ r(}|j                  t        j                  k7  r Y d}~d}~ww xY w# 1 sw Y   yxY w)zTest the finding of 'test' with the creation of modules listed in
        'create'.

        Any names listed in 'compile_' are byte-compiled. Modules
        listed in 'unlink' have their source files deleted.

        N.rootload_module)r   create_modules
py_compilecompileosr   r   OSErrorerrnoENOENTr   
assertTruehasattr)	r   testcreater   r   mappingnameerrorloaders	            r   run_testzFinderTests.run_test3   s     >VF  &) 	W$ 6D&&wt}56" 	"DIIgdm,"'6	" \\''"2D9FOOGFM:;#	 	 # " !;;%,,6! 7	"	 	s6   ACB%(3C%	C.CCCCC"c                 z    | j                  d       | j                  ddhdh       | j                  ddh       y )N	top_levelr   r   r2   r   s    r   test_modulezFinderTests.test_moduleP   s>    k"k[M)] 	 	, 	k[M:r   c                     | j                  ddh       | j                  ddhdhdh       | j                  ddhdh       y )Npkgpkg.__init__r   r5   r6   r7   s    r   test_packagezFinderTests.test_packageZ   sP    en-.en-8H&' 	 	) 	en-8HIr   c                     t        j                  dd      5 }t        j                  j	                  |d         }| j                  |d      }| j                  t        |d             d d d        y # 1 sw Y   y xY w)Nr;   pkg.subr"   r   r#   r&   pathdirnamer   r*   r+   )r   r.   pkg_dirr1   s       r   test_module_in_packagez"FinderTests.test_module_in_packaged   sc      ; 	<wggoogn&=>G\\'95FOOGFM:;	< 	< 	<s   AA00A9c                     t        j                  dd      }|5 }t        j                  j	                  |d         }| j                  |d      }| j                  t        |d             d d d        y # 1 sw Y   y xY w)Nr;   zpkg.sub.__init__r>   r"   r?   )r   contextr.   rB   r1   s        r   test_package_in_packagez#FinderTests.test_package_in_packagek   si    %%n6HI 	<ggoogn&=>G\\'95FOOGFM:;	< 	< 	<s   AA22A;c                     d}| j                  |dj                  |      |h      }| j                  d|j                  |             y )N_tempz{0}.__init____init__)r2   formatassertInget_filename)r   r/   r1   s      r   test_package_over_modulez$FinderTests.test_package_over_modules   s@    tn&;&;D&A4%HIj&"5"5d";<r   c                     t        j                  d      5 }| j                  |d   d      }| j                  || j                         d d d        y # 1 sw Y   y xY w)Nblahr!   
sdfsadsadf)r   r#   r   assertEqual	NOT_FOUND)r   r.   nothings      r   test_failurezFinderTests.test_failurex   sP      ( 	6Gll77#3\BGWdnn5	6 	6 	6s   2AAc                    | j                   j                  d| j                   j                  | j                   j                  f      }t	        ddd      5 }|j                  d       d d d        	 | j                  |dd	      }| j                  t        |d
             t        j                  d       y # 1 sw Y   OxY w# t        j                  d       w xY w)N zmod.pywzutf-8)encodingz# test file for importlibmodTr   r"   )r
   r   r   r   openwriter   r*   r+   r&   r   )r   r   filer1   s       r   test_empty_string_for_dirz%FinderTests.test_empty_string_for_dir}   s    **20O0ONN**0, -(C'2 	4dJJ23	4	 ZZ4Z@FOOGFM:;IIh	4 	4 IIhs   B50/C 5B>Cc                     | j                   j                  d| j                   j                  | j                   j                  f      }d|_        |j                          | j                  |j                  d       y )NrV   *   )r
   r   r   r   _path_mtimeinvalidate_cachesrQ   )r   r   s     r   test_invalidate_cachesz"FinderTests.test_invalidate_caches   s`    **20O0ONN**0, -  "++R0r   c                 .   d}t        j                  |      5 }| j                  |d         }| j                  |dd      }| j	                  |       d d d        | j                  dd      }| j                  || j                         y # 1 sw Y   :xY w)NrY   r!   Tr   )r   r#   r   r   assertIsNotNonerQ   rR   )r   rY   r.   r   founds        r   test_dir_removal_handlingz%FinderTests.test_dir_removal_handling   s      % 	(__WW%56FJJvu$J?E  '	( 

65d
;/	( 	(s   :BBwin32z>os.chmod() does not support the needed arguments under Windowsc                    t        j                         }| j                  |       t        j                  |j
                        j                  }| j                  t        j                  |j
                  |       t        j                  |j
                  t        j                  t        j                  z         | j                  |j
                        }| j                  |d      }| j                  || j                         y Ndoesnotexist)tempfileTemporaryDirectoryenterContextr&   statr/   st_mode
addCleanupchmodS_IWUSRS_IXUSRr   r   rQ   rR   )r   tempdiroriginal_moder   rf   s        r   test_no_read_directoryz"FinderTests.test_no_read_directory   s     --/'" -55',,>
t||dll:;.

6>2/r   c                     t        j                         5 }| j                  |j                        }| j	                  |d      }| j                  || j                         d d d        y # 1 sw Y   y xY wrj   )rl   NamedTemporaryFiler   r/   r   rQ   rR   )r   file_objr   rf   s       r   test_ignore_filezFinderTests.test_ignore_file   s]     ((* 	4h__X]]3FJJv~6EUDNN3	4 	4 	4s   A
A((A1r	   )__name__
__module____qualname____doc__r   r   r2   r8   r<   rC   rF   rM   rT   r]   rc   rg   unittest
skipUnlesssysplatformrw   r{    r   r   r   r      s    ,@<d4 :;J<<=
6

 10 X0LN0N04r   r   c                       e Zd ZdZddZy)FinderTestsPEP451Nc                 D    |j                  |      }||j                  S |S r	   )	find_specr1   r   r   r/   r   specs        r   r   zFinderTestsPEP451._find   s&    %".t{{8D8r   Fr|   r}   r~   rR   r   r   r   r   r   r      s    I9r   r   )r
   c                       e Zd Zdg fZddZy)FinderTestsPEP420Nc                     |j                  |      }|| j                  S |r|j                  S |j                  |j                  fS r	   )r   rR   r1   submodule_search_locationsr   s        r   r   zFinderTestsPEP420._find   sC    %<>>!;;{{D;;;;r   r   r   r   r   r   r   r      s    r
I<r   r   __main__)test.test_importlibr   r   import_importlibr
   r(   r&   r$   ro   r   rl   test.support.import_helperr   r   warningsr   r   	test_bothFrozen_FinderTestsPEP451Source_FinderTestsPEP451r   Frozen_FinderTestsPEP420Source_FinderTestsPEP420r|   mainr   r   r   <module>r      s    )!D!!"78	  	   
  6  a4#// a4H9 9 T^^%;
< 
< T^^%; zHMMO r   