U
    ^»{j|  ã                   @   sf   d dl Z d dlZd dlmZ d dlmZ ddlmZmZ dd„ Z	dd	„ Z
G d
d„ dejƒZdd„ ZdS )é    N)Úsuppress)ÚSimpleNamespaceé   )ÚreadersÚ	_adaptersc                    s   t  ˆ ¡‡ fdd„ƒ}|S )zw
    Wrap _adapters.TraversableResourcesLoader.get_resource_reader
    and intercept any standard library readers.
    c                     s~   zˆ | |Ž}W n t k
r$   Y dS X |jj}| d¡rF| d¡rFdS t|tjƒrz|jj	jj d¡sv|jj	jj d¡rzdS |S )z¡
        If the reader is from the standard library, return None to allow
        allow likely newer implementations in this library to take precedence.
        Nz
importlib.r   Ú	zipimportÚ_frozen_importlib_external)
ÚNotADirectoryErrorÚ	__class__Ú
__module__Ú
startswithÚendswithÚ
isinstancer   ÚCompatibilityFilesÚspecÚloader)ÚargsÚkwargsÚreaderÚmod_name©Úreader_getter© úb/var/www/html/bwave/python/venv/lib/python3.8/site-packages/importlib_resources/future/adapters.pyÚwrapper   s     ÿÿþz _block_standard.<locals>.wrapper)Ú	functoolsÚwraps)r   r   r   r   r   Ú_block_standard	   s    r   c                 C   s    t | tjƒo| j }|s| S dS )z/
    Mask any degenerate reader. Ref #298.
    N)r   r   r   Z_reader)r   Zis_degenerater   r   r   Ú_skip_degenerate+   s    ÿr   c                       s@   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Z‡  Z	S )ÚTraversableResourcesLoaderz­
    Adapt loaders to provide TraversableResources and other
    compatibility.

    Ensures the readers from importlib_resources are preferred
    over stdlib readers.
    c                    s(   t ttƒ jƒ|ƒƒp&|  ¡ p&tƒ  |¡S ©N)r   r   ÚsuperÚget_resource_readerÚ_standard_reader)ÚselfÚname©r
   r   r   r"   >   s
    ÿ
ýz.TraversableResourcesLoader.get_resource_readerc                 C   s   |   ¡ p|  ¡ p|  ¡ S r    )Ú_zip_readerÚ_namespace_readerÚ_file_reader©r$   r   r   r   r#   E   s    z+TraversableResourcesLoader._standard_readerc              
   C   s4   t tƒ�" t | jj| jj¡W  5 Q R £ S Q R X d S r    )r   ÚAttributeErrorr   Z	ZipReaderr   r   r%   r*   r   r   r   r'   H   s    
z&TraversableResourcesLoader._zip_readerc              
   C   s0   t ttƒ� t | jj¡W  5 Q R £ S Q R X d S r    )r   r+   Ú
ValueErrorr   ZNamespaceReaderr   Úsubmodule_search_locationsr*   r   r   r   r(   L   s    z,TraversableResourcesLoader._namespace_readerc                 C   sF   zt  | jj¡}W n tk
r(   Y d S X | ¡ rBt t|d�¡S d S )N)Úpath)	ÚpathlibÚPathr   ÚoriginÚ	TypeErrorÚexistsr   Z
FileReaderr   )r$   r.   r   r   r   r)   P   s    z'TraversableResourcesLoader._file_reader)
Ú__name__r   Ú__qualname__Ú__doc__r"   r#   r'   r(   r)   Ú__classcell__r   r   r&   r   r   5   s   r   c                 C   s   t  | jt¡S )zŸ
    Override _adapters.wrap_spec to use TraversableResourcesLoader
    from above. Ensures that future behavior is always available on older
    Pythons.
    )r   ZSpecLoaderAdapterÚ__spec__r   )Úpackager   r   r   Ú	wrap_specY   s    r:   )r   r/   Ú
contextlibr   Útypesr   Ú r   r   r   r   r   r:   r   r   r   r   Ú<module>   s   "
$