o
    fI                     @   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 Z1e12e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rt| 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 )zReturn 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 )zReturn 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~    %
	


