
    XIg                     V   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	m
Z
 ddlmZ ddlmZ d dlmZ  G d	 d
e      Zd.dZd/dZ G d de j(                        Z ed e ed            dj3                  d      dj3                  d      d e edd            ddddddddddddiid  e ed            dj3                  d      dj3                  d      d! e ed"d#            id$%      Z G d& d'      Z G d( d)e      Z G d* d+e      Z G d, d-ee      Zy)0    N   )ResourceReader   )import_helper	os_helper)zip)_path)
ModuleSpecc                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)Readerc                 8    t        |       j                  |       y N)varsupdate)selfkwargss     [/var/www/html/answerous/venv/lib/python3.12/site-packages/importlib_resources/tests/util.py__init__zReader.__init__   s    T
&!    c                     | S r    r   packages     r   get_resource_readerzReader.get_resource_reader   s    r   c                 t    || _         t        | j                  t              r| j                  | j                  S r   )r	   
isinstancefile	Exceptionr   paths     r   open_resourcezReader.open_resource   s*    
dii+))Oyyr   c                 t    || _         t        | j                  t              r| j                  | j                  S r   )r	   r   r    r   )r   path_s     r   resource_pathzReader.resource_path   s*    
dii+))Oyyr   c                     | _         t        | j                  t              r| j                  d }t	        fdt        || j                        D              S )Nc                 $    | j                  d      S )N/)split)entrys    r   partz Reader.is_resource.<locals>.part*   s    ;;s##r   c              3   N   K   | ]  }t        |      d k(  xr |d   k(    yw)r   r   N)len).0partsr#   s     r   	<genexpr>z%Reader.is_resource.<locals>.<genexpr>-   s/      
6;CJ!O1aE 11
s   "%)r	   r   r    r   anymap	_contents)r   r#   r*   s    ` r   is_resourcezReader.is_resource%   sM    
dii+))O	$  
?B4?X
 
 	
r   c              #      K   t        | j                  t              r| j                  | j                  E d {    y 7 wr   )r   r    r   r2   r   s    r   contentszReader.contents1   s*     dii+))O>>!!s   6A >A N)	__name__
__module____qualname__r   r   r!   r$   r3   r6   r   r   r   r   r      s     "

"r   r   c                 n    d}t        j                  |      }t        || d|      }||_        | |_        |S )Ntestingpackagezdoes-not-exist)origin
is_package)types
ModuleTyper
   __spec__
__loader__)loaderr=   namemodulespecs        r   create_package_from_loaderrF   7   s<    Dd#FdF+;
SDFOFMr   c                 2    t        t        | ||      |      S )N)r   r    r2   )rF   r   )r   r    r=   r6   s       r   create_packagerH   @   s    %Dtx8 r   c                   d    e Zd ZdZej
                  d        Zd Zd Zd Z	d Z
d Zd Zd	 Zd
 Zy)CommonTestsBasez>
    Tests shared by test_open, test_path, and test_read.
    c                      y)zl
        Call the pertinent legacy API function (e.g. open_text, path)
        on package and path.
        Nr   )r   r   r    s      r   executezCommonTestsBase.executeL   s    r   c                 P    | j                  | j                  j                  d       y)z=
        Passing in the package name should succeed.
        
utf-8.fileN)rL   datar7   r5   s    r   test_package_namez!CommonTestsBase.test_package_nameS   s     	TYY''6r   c                 <    | j                  | j                  d       y)z?
        Passing in the package itself should succeed.
        rN   NrL   rO   r5   s    r   test_package_objectz#CommonTestsBase.test_package_objectY   s     	TYY-r   c                 @    d}| j                  | j                  |       y)zB
        Passing in a string for the path should succeed.
        rN   NrR   r   s     r   test_string_pathz CommonTestsBase.test_string_path_   s     TYY%r   c                 f    t        j                  d      }| j                  | j                  |       y)zS
        Passing in a pathlib.PurePath object for the path should succeed.
        rN   N)pathlibPurePathrL   rO   r   s     r   test_pathlib_pathz!CommonTestsBase.test_pathlib_pathf   s&     -TYY%r   c                     t         j                  | j                  j                  = | j	                  | j                  j                  d       y)z=
        The anchor package can already be imported.
        rN   N)sysmodulesrO   r7   rL   r5   s    r   $test_importing_module_as_side_effectz4CommonTestsBase.test_importing_module_as_side_effectm   s2     KK		**+TYY''6r   c                     t        j                  d      }t        |t                     }| j	                  |d       | j                  |j                  j                  d       y)z
        Attempting to open or read or request the path for a
        non-existent path should succeed if open_resource
        can return a viable data stream.
           Hello, world!r   r    rN   N)ioBytesIOrH   FileNotFoundErrorrL   assertEqualrA   r	   )r   
bytes_datar   s      r   test_missing_pathz!CommonTestsBase.test_missing_patht   sM     ZZ 01
 j7H7JKWl+++11<@r   c                     t        j                  d      }t        }t        ||      }| j	                  |d       | j                  |j                  j                  d       y )Nr_   r`   rN   )ra   rb   __file__rH   rL   rd   rA   r	   )r   re   r    r   s       r   test_extant_pathz CommonTestsBase.test_extant_path   sN     ZZ 01
 jt<Wl+++11<@r   c                     t        t               t                     }| j                  t              5  | j                  |d       d d d        y # 1 sw Y   y xY w)Nr`   rN   )rH   rc   assertRaisesrL   r   s     r   test_useless_loaderz#CommonTestsBase.test_useless_loader   sH     &7&9@Q@ST01 	0LL,/	0 	0 	0s   AAN)r7   r8   r9   __doc__abcabstractmethodrL   rP   rS   rU   rY   r]   rf   ri   rl   r   r   r   rJ   rJ   G   sK     	 7.&&7	A	A0r   rJ   )	metaclass    zHello, UTF-16 world!
zutf-16zHello, UTF-8 world!
zutf-8   )__init__.pybinary.file)rt   ru   utf-16.filerN   subdirectoryzone resource)rt   zresource1.txtztwo resource)rt   zresource2.txt	subsubdirzresource.txtz
a resource)rt   onetworw   ru         )ru   rv   rN   rw   )data01data02namespacedata01c                       e Zd Zd Zd Zy)ModuleSetupc                    t        j                         | _        | j                  | j                  j                         | j                  j                  t        j                                | j                  | j                        | _
        y r   )
contextlib	ExitStackfixtures
addCleanupcloseenter_contextr   isolated_modulesload_fixtureMODULErO   r5   s    r   setUpzModuleSetup.setUp   sY    ",,.++,##M$B$B$DE%%dkk2	r   c                 `    | j                  |t        |   i       t        j                  |      S r   )tree_on_pathr   	importlibimport_module)r   rD   s     r   r   zModuleSetup.load_fixture   s+    68F#345&&v..r   N)r7   r8   r9   r   r   r   r   r   r   r      s    3/r   r   c                       e Zd ZdZd Zy)ZipSetupr}   c           
      $   | j                   j                  t        j                               }t	        j
                  |      dz  }| j                   j                  t        j                  t        t        j                  ||                         y )Nzzipped modules.zip)r   r   r   temp_dirrW   Pathr   DirsOnSysPathstrzip_make_zip_file)r   rE   r   r\   s       r   r   zZipSetup.tree_on_path   se    ==..y/A/A/CD,,x(+??##''D,>,>tW,M(NO	
r   Nr7   r8   r9   r   r   r   r   r   r   r      s    F
r   r   c                       e Zd ZdZd Zy)	DiskSetupr}   c                    | j                   j                  t        j                               }t	        j
                  |t        j                  |             | j                   j                  t        j                  |             y r   )
r   r   r   r   r	   buildrW   r   r   r   )r   rE   r   s      r   r   zDiskSetup.tree_on_path   sS    ==..y/A/A/CDD',,x01##M$?$?$IJr   Nr   r   r   r   r   r      s    FKr   r   c                       e Zd Zy)CommonTestsN)r7   r8   r9   r   r   r   r   r      s    r   r   )T)NNTr   )rn   r   ra   r[   r>   rW   r   r   compat.py39r   r   rq   r   r   r	   importlib.machineryr
   r   rF   rH   ABCMetarJ   dictbytesrangeencoder   r   r   r   r   r   r   r   <module>r      sB   
  	 
      1   +""^ ""JF0 F0R U1X/66x@-44W= q!-
	 !NC!NC$~|&DE	 U1X/66x@-44W=5r2/
	#8
/ 
/
{ 
K K	)_ 	r   