o
    éT•jI  ã                   @   sÞ  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 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mZmZ d dlmZ d dlmZmZ d dlmZ d dlmZ g d¢Z ee!ef Z"ee!e j#f Z$de"de$defdd„Z%		d3de"de$de!de!def
dd„Z&de"de$de'fdd„Z(		d3de"de$de!de!de!f
dd „Z)de"de$dd!fd"d#„Z*d$d%„ Z+d&d'„ Z,d(d)„ Z-de"d*e!de.fd+d,„Z/de"dee! fd-d.„Z0ed/d0„ ƒZ1e1 2e¡d1d2„ ƒZ3dS )4é    Né   )Ú_common)Úas_fileÚfiles)ÚResourceReader)Úsuppress)ÚResourceLoader)Ú
ModuleSpec)ÚBytesIOÚTextIOWrapper)ÚPath)Ú
ModuleType)ÚContextManagerÚIterableÚUnion)Úcast)ÚBinaryIOÚTextIO)ÚSequence)Úsingledispatch)ÚPackageÚResourcer   r   Úcontentsr   Úis_resourceÚopen_binaryÚ	open_textÚpathÚread_binaryÚ	read_textÚpackageÚresourceÚreturnc           	      C   s&  t  |¡}t  | ¡} t  | ¡}|dur| |¡S tt| jƒ}|jdur'|j}n|j	dur8t
j t
j |j	¡¡g}|D ]N}t
j ||¡}z	t|dd�W   S  tyˆ   tt|jƒ}d}t|jdƒrzttƒ� | |¡}W d  ƒ n1 suw   Y  |dur†t|ƒ Y   S Y q:w t|›d|j›�ƒ‚)zDReturn a file-like object opened for binary reading of the resource.NÚrb)ÚmodeÚget_dataz resource not found in )r   Únormalize_pathÚget_packageÚget_resource_readerÚopen_resourcer   r	   Ú__spec__Úsubmodule_search_locationsÚoriginÚosr   ÚdirnameÚabspathÚjoinÚopenÚOSErrorr   ÚloaderÚhasattrr   r$   r
   ÚFileNotFoundErrorÚname)	r   r    ÚreaderÚspecÚpathsÚpackage_pathÚ	full_pathr2   Údata© r<   ú*/usr/lib/python3.10/importlib/resources.pyr   (   s4   






ÿÿ÷r   úutf-8ÚstrictÚencodingÚerrorsc                 C   s   t t| |ƒ||d�S )zBReturn a file-like object opened for text reading of the resource.)r@   rA   )r   r   )r   r    r@   rA   r<   r<   r=   r   J   s   ÿr   c                 C   s6   t | |ƒ�}| ¡ W  d  ƒ S 1 sw   Y  dS )z+Return the binary contents of the resource.N)r   Úread)r   r    Úfpr<   r<   r=   r   V   s   $ÿr   c                 C   s:   t | |||ƒ�}| ¡ W  d  ƒ S 1 sw   Y  dS )z‹Return the decoded string of the resource.

    The decoding-related arguments have the same semantics as those of
    bytes.decode().
    N)r   rB   )r   r    r@   rA   rC   r<   r<   r=   r   \   s   $ÿr   zContextManager[Path]c                 C   s@   t  t  | ¡¡}|rt|t  |¡ƒS t  t  | ¡ t  |¡¡¡S )ak  A context manager providing a file path object to the resource.

    If the resource does not already exist on its own on the file system,
    a temporary file will be created. If the file was created, the file
    will be deleted upon exiting the context manager (no exception is
    raised if the file was deleted prior to the context manager
    exiting).
    )r   r'   r&   Ú_path_from_readerr%   r   r   Újoinpath)r   r    r6   r<   r<   r=   r   k   s   ÿÿÿýr   c                 C   s   t | |ƒp	t| |ƒS ©N)Ú_path_from_resource_pathÚ_path_from_open_resource©r6   r    r<   r<   r=   rD   �   s   ÿrD   c                 C   s:   t tƒ� t|  |¡ƒW  d   ƒ S 1 sw   Y  d S rF   )r   r4   r   Úresource_pathrI   r<   r<   r=   rG   ‡   s   
$ÿrG   c                 C   s$   t  |  |¡ ¡ ¡}tj|j|d�S )N)Úsuffix)Úior
   r(   rB   r   Ú	_tempfile)r6   r    Úsavedr<   r<   r=   rH   Œ   s   rH   r5   c                 C   sZ   t  | ¡} t  |¡ t  | ¡}|dur| |¡S tt| ƒƒ}||vr$dS t  | ¡|  ¡ S )zYTrue if 'name' is a resource inside 'package'.

    Directories are *not* resources.
    NF)	r   r&   r%   r'   r   Úsetr   Úfrom_packageÚis_file)r   r5   r6   Úpackage_contentsr<   r<   r=   r   ‘   s   



r   c                 C   sT   t  | ¡} t  | ¡}|durt| ¡ ƒS t  | ¡}| ¡ r(tdd„ | ¡ D ƒƒS g S )zõReturn an iterable of entries in 'package'.

    Note that not all entries are resources.  Specifically, directories are
    not considered resources.  Use `is_resource()` on each entry returned here
    to check if it is a resource or not.
    Nc                 s   s   � | ]}|j V  qd S rF   )r5   )Ú.0Úitemr<   r<   r=   Ú	<genexpr>®   s   € zcontents.<locals>.<genexpr>)	r   r&   r'   Ú_ensure_sequencer   rP   Úis_dirÚlistÚiterdir)r   r6   Útransversabler<   r<   r=   r   ¡   s   


r   c                 C   s   t | ƒS rF   )rX   ©Úiterabler<   r<   r=   rV   ²   s   rV   c                 C   s   | S rF   r<   r[   r<   r<   r=   Ú_·   s   r]   )r>   r?   )4r,   rL   Ú r   r   r   Úabcr   Ú
contextlibr   Úimportlib.abcr   Úimportlib.machineryr	   r
   r   Úpathlibr   Útypesr   Útypingr   r   r   r   Ú	typing.ior   r   Úcollections.abcr   Ú	functoolsr   Ú__all__Ústrr   ÚPathLiker   r   r   Úbytesr   r   r   rD   rG   rH   Úboolr   r   rV   Úregisterr]   r<   r<   r<   r=   Ú<module>   s~    %üÿþýü
û	üÿþýü
ûÿþ
ý
